Skip to content

[rtsan] Fix RTTI issue, make a better c test #108720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2024
Merged

Conversation

cjappl
Copy link
Contributor

@cjappl cjappl commented Sep 14, 2024

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:

append_rtti_flag(OFF ASAN_CFLAGS)

append_rtti_flag(OFF TSAN_CFLAGS)

append_rtti_flag(OFF UBSAN_CFLAGS)

Adding a more fully fledged c test that ensures we will catch these issues in the future.

@llvmbot
Copy link
Member

llvmbot commented Sep 14, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Chris Apple (cjappl)

Changes

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:

append_rtti_flag(OFF ASAN_CFLAGS)

append_rtti_flag(OFF TSAN_CFLAGS)

append_rtti_flag(OFF UBSAN_CFLAGS)

Adding a more fully fledged c test that ensures we will catch these issues in the future.


Full diff: https://github.com/llvm/llvm-project/pull/108720.diff

3 Files Affected:

  • (modified) compiler-rt/lib/rtsan/CMakeLists.txt (+2)
  • (modified) compiler-rt/test/rtsan/basic.cpp (-1)
  • (added) compiler-rt/test/rtsan/sanity_check_pure_c.c (+28)
diff --git a/compiler-rt/lib/rtsan/CMakeLists.txt b/compiler-rt/lib/rtsan/CMakeLists.txt
index 3f146a757a97eb..07a21b49eb45aa 100644
--- a/compiler-rt/lib/rtsan/CMakeLists.txt
+++ b/compiler-rt/lib/rtsan/CMakeLists.txt
@@ -29,6 +29,8 @@ set(RTSAN_LINK_LIBS
   ${COMPILER_RT_UNWINDER_LINK_LIBS}
   ${COMPILER_RT_CXX_LINK_LIBS})
 
+append_rtti_flag(OFF RTSAN_CFLAGS)
+
 if(APPLE)
   add_compiler_rt_object_libraries(RTRtsan
     OS ${SANITIZER_COMMON_SUPPORTED_OS}
diff --git a/compiler-rt/test/rtsan/basic.cpp b/compiler-rt/test/rtsan/basic.cpp
index 607db90213a30d..4edf32336720f8 100644
--- a/compiler-rt/test/rtsan/basic.cpp
+++ b/compiler-rt/test/rtsan/basic.cpp
@@ -1,5 +1,4 @@
 // RUN: %clangxx -fsanitize=realtime %s -o %t
-// RUN: %clang -fsanitize=realtime %s -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
 // UNSUPPORTED: ios
 
diff --git a/compiler-rt/test/rtsan/sanity_check_pure_c.c b/compiler-rt/test/rtsan/sanity_check_pure_c.c
new file mode 100644
index 00000000000000..bdca6039d9324d
--- /dev/null
+++ b/compiler-rt/test/rtsan/sanity_check_pure_c.c
@@ -0,0 +1,28 @@
+// RUN: %clang -fsanitize=realtime %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: %clang %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NO-SANITIZE
+#ifdef __cplusplus
+#  error "This test must be built in C mode"
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+
+// Check that we can build and run C code.
+
+void nonblocking_function(void) __attribute__((nonblocking));
+
+void nonblocking_function(void) __attribute__((nonblocking)) {
+  void *ptr = malloc(2);
+  printf("ptr: %p\n", ptr); // ensure we don't optimize out the malloc
+}
+
+int main() {
+  nonblocking_function();
+  printf("Done\n");
+  return 0;
+}
+
+// CHECK: ==ERROR: RealtimeSanitizer
+// CHECK-NO-SANITIZE: Done

@cjappl
Copy link
Contributor Author

cjappl commented Sep 14, 2024

CC for review @davidtrevelyan

@davidtrevelyan
Copy link
Contributor

LGTM!

@cjappl cjappl merged commit cb47b45 into llvm:main Sep 18, 2024
10 checks passed
@cjappl cjappl deleted the better_c_tests branch September 18, 2024 11:48
tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants