summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Potapenko <glider@google.com>2013-08-07 12:39:00 +0000
committerAlexander Potapenko <glider@google.com>2013-08-07 12:39:00 +0000
commitce3241009768389fd3185e8b1ea1dd4623d0bc61 (patch)
treecd04f2a2ebfb5fcdecd3c2a84fcf9ce54d533baa
parent45c54ad8dcb56e66183b5713716394a457125dd9 (diff)
downloadbcm5719-llvm-ce3241009768389fd3185e8b1ea1dd4623d0bc61.tar.gz
bcm5719-llvm-ce3241009768389fd3185e8b1ea1dd4623d0bc61.zip
[TSan] Let the users suppress use-after-free errors using the "race:" suppressions.
If there's a race between a memory access and a free() call in the client program, it can be reported as a use-after-free (if the access occurs after the free()) or an ordinary race (if free() occurs after the access). We've decided to use a single "race:" prefix for both cases instead of introducing a "use-after-free:" one, because in many cases this allows us to keep a single suppression for both the use-after-free and free-after-use. This may be misleading if the use-after-free occurs in a non-racy way (e.g. in a single-threaded program). But normally such bugs shall not be suppressed. llvm-svn: 187885
-rw-r--r--compiler-rt/lib/tsan/lit_tests/free_race.c24
-rw-r--r--compiler-rt/lib/tsan/lit_tests/free_race.c.supp2
-rw-r--r--compiler-rt/lib/tsan/rtl/tsan_suppressions.cc2
3 files changed, 18 insertions, 10 deletions
diff --git a/compiler-rt/lib/tsan/lit_tests/free_race.c b/compiler-rt/lib/tsan/lit_tests/free_race.c
index a49572cfe8b..f54b628f87c 100644
--- a/compiler-rt/lib/tsan/lit_tests/free_race.c
+++ b/compiler-rt/lib/tsan/lit_tests/free_race.c
@@ -1,4 +1,7 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t || exit 1
+// RUN: not %t 2>&1 | FileCheck %s --check-prefix=NOZUPP
+// RUN: TSAN_OPTIONS="suppressions=%s.supp print_suppressions=1" not %t 2>&1 | FileCheck %s --check-prefix=SUPP
+
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
@@ -34,11 +37,14 @@ int main() {
return 0;
}
-// CHECK: WARNING: ThreadSanitizer: heap-use-after-free
-// CHECK: Write of size 4 at {{.*}} by main thread{{.*}}:
-// CHECK: #0 Thread2
-// CHECK: #1 main
-// CHECK: Previous write of size 8 at {{.*}} by thread T1{{.*}}:
-// CHECK: #0 free
-// CHECK: #{{(1|2)}} Thread1
-// CHECK: SUMMARY: ThreadSanitizer: heap-use-after-free{{.*}}Thread2
+// CHECK-NOZUPP: WARNING: ThreadSanitizer: heap-use-after-free
+// CHECK-NOZUPP: Write of size 4 at {{.*}} by main thread{{.*}}:
+// CHECK-NOZUPP: #0 Thread2
+// CHECK-NOZUPP: #1 main
+// CHECK-NOZUPP: Previous write of size 8 at {{.*}} by thread T1{{.*}}:
+// CHECK-NOZUPP: #0 free
+// CHECK-NOZUPP: #{{(1|2)}} Thread1
+// CHECK-NOZUPP: SUMMARY: ThreadSanitizer: heap-use-after-free{{.*}}Thread2
+// CHECK-SUPP: ThreadSanitizer: Matched 1 suppressions
+// CHECK-SUPP: 1 race:^Thread2$
+
diff --git a/compiler-rt/lib/tsan/lit_tests/free_race.c.supp b/compiler-rt/lib/tsan/lit_tests/free_race.c.supp
new file mode 100644
index 00000000000..f5d6a4969a4
--- /dev/null
+++ b/compiler-rt/lib/tsan/lit_tests/free_race.c.supp
@@ -0,0 +1,2 @@
+# Suppression for a use-after-free in free_race.c
+race:^Thread2$
diff --git a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
index 22e07aadb30..69e616c135e 100644
--- a/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
+++ b/compiler-rt/lib/tsan/rtl/tsan_suppressions.cc
@@ -81,7 +81,7 @@ SuppressionType conv(ReportType typ) {
else if (typ == ReportTypeVptrRace)
return SuppressionRace;
else if (typ == ReportTypeUseAfterFree)
- return SuppressionNone;
+ return SuppressionRace;
else if (typ == ReportTypeThreadLeak)
return SuppressionThread;
else if (typ == ReportTypeMutexDestroyLocked)
OpenPOWER on IntegriCloud