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