| 1 | // RUN: %clangxx -fsanitize=realtime %s -o %t |
| 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
| 3 | // UNSUPPORTED: ios |
| 4 | |
| 5 | // Intent: Ensure that an intercepted call in a [[clang::nonblocking]] function |
| 6 | // is flagged as an error. Basic smoke test. |
| 7 | |
| 8 | #include <stdio.h> |
| 9 | #include <stdlib.h> |
| 10 | |
| 11 | void violation() [[clang::nonblocking]] { |
| 12 | void *ptr = malloc(size: 2); |
| 13 | printf(format: "ptr: %p\n" , ptr); // ensure we don't optimize out the malloc |
| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | violation(); |
| 18 | return 0; |
| 19 | // CHECK: ==ERROR: RealtimeSanitizer: unsafe-library-call |
| 20 | // CHECK-NEXT: Intercepted call to real-time unsafe function `malloc` in real-time context! |
| 21 | // CHECK-NEXT: {{.*malloc*}} |
| 22 | } |
| 23 | |