[compiler-rt] 9360f1a - [Sanitizer] Fix sanitizer tests without reducing optimization levels
Julian Lettner via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 11 15:22:49 PST 2021
Author: Julian Lettner
Date: 2021-02-11T15:22:20-08:00
New Revision: 9360f1a1911edee4c6f4c7d070bdaa1ca26016cc
URL: https://github.com/llvm/llvm-project/commit/9360f1a1911edee4c6f4c7d070bdaa1ca26016cc
DIFF: https://github.com/llvm/llvm-project/commit/9360f1a1911edee4c6f4c7d070bdaa1ca26016cc.diff
LOG: [Sanitizer] Fix sanitizer tests without reducing optimization levels
As discussed, these tests are compiled with optimization to mimic real
sanitizer usage [1].
Let's mark relevant functions with `noinline` so we can continue to
check against the stack traces in the report.
[1] https://reviews.llvm.org/D96198
This reverts commit 04af72c5423eb5ff7c0deba2d08cb46d583bb9d4.
Differential Revision: https://reviews.llvm.org/D96357
Added:
Modified:
compiler-rt/test/tsan/blacklist2.cpp
compiler-rt/test/tsan/free_race.c
compiler-rt/test/tsan/longjmp3.cpp
compiler-rt/test/tsan/longjmp4.cpp
compiler-rt/test/tsan/race_on_heap.cpp
compiler-rt/test/tsan/race_top_suppression.cpp
compiler-rt/test/tsan/simple_stack.c
compiler-rt/test/tsan/sleep_sync.cpp
compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp
Removed:
################################################################################
diff --git a/compiler-rt/test/tsan/blacklist2.cpp b/compiler-rt/test/tsan/blacklist2.cpp
index 31a7bcac2b6b..6442eb0e789d 100644
--- a/compiler-rt/test/tsan/blacklist2.cpp
+++ b/compiler-rt/test/tsan/blacklist2.cpp
@@ -3,7 +3,7 @@
// RUN: echo "fun:*Blacklisted_Thread2*" > %t.blacklist
// RUN: echo "fun:*CallTouchGlobal*" >> %t.blacklist
-// RUN: %clangxx_tsan %s -fsanitize-blacklist=%t.blacklist -o %t
+// RUN: %clangxx_tsan -O1 %s -fsanitize-blacklist=%t.blacklist -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
#include "test.h"
@@ -18,13 +18,13 @@ void *Thread1(void *x) {
return NULL;
}
-void TouchGlobal() {
+void TouchGlobal() __attribute__((noinline)) {
// CHECK: Previous write of size 4
// CHECK: #0 TouchGlobal{{.*}}blacklist2.cpp:[[@LINE+1]]
Global--;
}
-void CallTouchGlobal() {
+void CallTouchGlobal() __attribute__((noinline)) {
// CHECK: #1 CallTouchGlobal{{.*}}blacklist2.cpp:[[@LINE+1]]
TouchGlobal();
}
diff --git a/compiler-rt/test/tsan/free_race.c b/compiler-rt/test/tsan/free_race.c
index 9209c12e22ae..eb66233b8038 100644
--- a/compiler-rt/test/tsan/free_race.c
+++ b/compiler-rt/test/tsan/free_race.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -o %t
+// RUN: %clang_tsan -O1 %s -o %t
// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOZUPP
// RUN: %env_tsan_opts=suppressions='%s.supp':print_suppressions=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPP
@@ -15,7 +15,7 @@ void *Thread1(void *x) {
return NULL;
}
-void *Thread2(void *x) {
+void *Thread2(void *x) __attribute__((noinline)) {
barrier_wait(&barrier);
pthread_mutex_lock(&mtx);
mem[0] = 42;
diff --git a/compiler-rt/test/tsan/longjmp3.cpp b/compiler-rt/test/tsan/longjmp3.cpp
index af23a3c40209..3f5dd0333b5e 100644
--- a/compiler-rt/test/tsan/longjmp3.cpp
+++ b/compiler-rt/test/tsan/longjmp3.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>
@@ -17,14 +17,14 @@ void foo(jmp_buf env) {
x++;
}
-void badguy() {
+void badguy() __attribute__((noinline)) {
pthread_mutex_t mtx;
pthread_mutex_init(&mtx, 0);
pthread_mutex_lock(&mtx);
pthread_mutex_destroy(&mtx);
}
-void mymain() {
+void mymain() __attribute__((noinline)) {
jmp_buf env;
if (setjmp(env) == 42) {
badguy();
diff --git a/compiler-rt/test/tsan/longjmp4.cpp b/compiler-rt/test/tsan/longjmp4.cpp
index d8650764ace7..616ee887f0a3 100644
--- a/compiler-rt/test/tsan/longjmp4.cpp
+++ b/compiler-rt/test/tsan/longjmp4.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdio.h>
@@ -20,14 +20,14 @@ void foo(jmp_buf env) {
x++;
}
-void badguy() {
+void badguy() __attribute__((noinline)) {
pthread_mutex_t mtx;
pthread_mutex_init(&mtx, 0);
pthread_mutex_lock(&mtx);
pthread_mutex_destroy(&mtx);
}
-void mymain() {
+void mymain() __attribute__((noinline)) {
jmp_buf env;
if (setjmp(env) == 42) {
badguy();
diff --git a/compiler-rt/test/tsan/race_on_heap.cpp b/compiler-rt/test/tsan/race_on_heap.cpp
index 9057e9fdc0c2..9a07703a1f8e 100644
--- a/compiler-rt/test/tsan/race_on_heap.cpp
+++ b/compiler-rt/test/tsan/race_on_heap.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
@@ -14,7 +14,7 @@ void *Thread2(void *p) {
return 0;
}
-void *alloc() {
+void *alloc() __attribute__((noinline)) {
return malloc(99);
}
diff --git a/compiler-rt/test/tsan/race_top_suppression.cpp b/compiler-rt/test/tsan/race_top_suppression.cpp
index eeb3ef802cf2..d1c8f72cefde 100644
--- a/compiler-rt/test/tsan/race_top_suppression.cpp
+++ b/compiler-rt/test/tsan/race_top_suppression.cpp
@@ -1,12 +1,12 @@
// RUN: echo "race_top:TopFunction" > %t.supp
-// RUN: %clangxx_tsan %s -o %t
+// RUN: %clangxx_tsan -O1 %s -o %t
// RUN: %env_tsan_opts=suppressions='%t.supp' %run %t 2>&1 | FileCheck %s
// RUN: rm %t.supp
#include "test.h"
int Global;
-void TopFunction(int *p) {
+void TopFunction(int *p) __attribute__((noinline)) {
*p = 1;
}
diff --git a/compiler-rt/test/tsan/simple_stack.c b/compiler-rt/test/tsan/simple_stack.c
index e46ffaa7a046..0c02cbdd0c93 100644
--- a/compiler-rt/test/tsan/simple_stack.c
+++ b/compiler-rt/test/tsan/simple_stack.c
@@ -32,7 +32,7 @@ void *Thread2(void *x) {
return NULL;
}
-void StartThread(pthread_t *t, void *(*f)(void*)) {
+void __attribute__((noinline)) StartThread(pthread_t *t, void *(*f)(void*)) {
pthread_create(t, NULL, f, NULL);
}
@@ -46,14 +46,14 @@ int main() {
return 0;
}
-// RUN: %clang_tsan %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
// Also check that functions instrumentation can be configured by either driver
// or legacy flags:
-// RUN: %clangxx_tsan %s -o %t -fno-sanitize-thread-func-entry-exit && %deflake %run %t 2>&1 \
+// RUN: %clangxx_tsan -O1 %s -o %t -fno-sanitize-thread-func-entry-exit && %deflake %run %t 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-FUNC-ENTRY-EXIT-OFF %s
-// RUN: %clangxx_tsan %s -o %t -mllvm -tsan-instrument-func-entry-exit=0 && %deflake %run %t 2>&1 \
+// RUN: %clangxx_tsan -O1 %s -o %t -mllvm -tsan-instrument-func-entry-exit=0 && %deflake %run %t 2>&1 \
// RUN: | FileCheck --check-prefix=CHECK-FUNC-ENTRY-EXIT-OFF %s
// CHECK: WARNING: ThreadSanitizer: data race
diff --git a/compiler-rt/test/tsan/sleep_sync.cpp b/compiler-rt/test/tsan/sleep_sync.cpp
index 0eee9b67edef..3b2bfd0b3f79 100644
--- a/compiler-rt/test/tsan/sleep_sync.cpp
+++ b/compiler-rt/test/tsan/sleep_sync.cpp
@@ -1,9 +1,9 @@
-// RUN: %clangxx_tsan %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include "test.h"
int X = 0;
-void MySleep() {
+void MySleep() __attribute__((noinline)) {
sleep(1); // the sleep that must appear in the report
}
diff --git a/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp b/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp
index 6b63baa9e819..e8146d6c44b0 100644
--- a/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp
+++ b/compiler-rt/test/ubsan/TestCases/Misc/missing_return.cpp
@@ -1,11 +1,11 @@
-// RUN: %clangxx -fsanitize=return %gmlt %s -o %t
+// RUN: %clangxx -fsanitize=return %gmlt %s -O3 -o %t
// RUN: not %run %t 2>&1 | FileCheck %s
// RUN: %env_ubsan_opts=print_stacktrace=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-STACKTRACE
// Error message does not exact what expected
// XFAIL: openbsd
// CHECK: missing_return.cpp:[[@LINE+1]]:5: runtime error: execution reached the end of a value-returning function without returning a value
-int f() {
+int f() __attribute__((noinline)) {
// CHECK-STACKTRACE: #0 {{.*}}f{{.*}}missing_return.cpp:[[@LINE-1]]
}
More information about the llvm-commits
mailing list