Skip to content

Commit cb47b45

Browse files
authored
[rtsan] Fix RTTI issue, make a better c test (#108720)
Later in a development branch, our c tests were failing, this was due to the lack of RTTI. This follows very similar patterns found in the other sanitizers
1 parent c29dfb3 commit cb47b45

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

compiler-rt/lib/rtsan/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ set(RTSAN_LINK_LIBS
2929
${COMPILER_RT_UNWINDER_LINK_LIBS}
3030
${COMPILER_RT_CXX_LINK_LIBS})
3131

32+
append_rtti_flag(OFF RTSAN_CFLAGS)
33+
3234
if(APPLE)
3335
add_compiler_rt_object_libraries(RTRtsan
3436
OS ${SANITIZER_COMMON_SUPPORTED_OS}

compiler-rt/test/rtsan/basic.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
// RUN: %clangxx -fsanitize=realtime %s -o %t
2-
// RUN: %clang -fsanitize=realtime %s -o %t
32
// RUN: not %run %t 2>&1 | FileCheck %s
43
// UNSUPPORTED: ios
54

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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(2);
18+
printf("ptr: %p\n", ptr); // ensure we don't optimize out the malloc
19+
}
20+
21+
int main() {
22+
nonblocking_function();
23+
printf("Done\n");
24+
return 0;
25+
}
26+
27+
// CHECK: ==ERROR: RealtimeSanitizer
28+
// CHECK-NO-SANITIZE: Done

0 commit comments

Comments
 (0)