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