| 1 | // RUN: %clang -fsanitize=realtime %s -o %t |
| 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
| 3 | // RUN: %clang %s -o %t |
| 4 | // RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE |
| 5 | #ifdef __cplusplus |
| 6 | # error "This test must be built in C mode" |
| 7 | #endif |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | |
| 12 | // Check that we can build and run C code. |
| 13 | |
| 14 | void nonblocking_function(void) __attribute__((nonblocking)); |
| 15 | |
| 16 | void nonblocking_function(void) __attribute__((nonblocking)) { |
| 17 | void *ptr = malloc(size: 2); |
| 18 | printf(format: "ptr: %p\n" , ptr); // ensure we don't optimize out the malloc |
| 19 | } |
| 20 | |
| 21 | int main() { |
| 22 | nonblocking_function(); |
| 23 | printf(format: "Done\n" ); |
| 24 | return 0; |
| 25 | } |
| 26 | |
| 27 | // CHECK: ==ERROR: RealtimeSanitizer |
| 28 | // CHECK-NO-SANITIZE: Done |
| 29 | |