[compiler-rt] r187885 - [TSan] Let the users suppress use-after-free errors using the "race:" suppressions.
Alexander Potapenko
glider at google.com
Wed Aug 7 05:39:00 PDT 2013
Author: glider
Date: Wed Aug 7 07:39:00 2013
New Revision: 187885
URL: http://llvm.org/viewvc/llvm-project?rev=187885&view=rev
Log:
[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.
Added:
compiler-rt/trunk/lib/tsan/lit_tests/free_race.c.supp
Modified:
compiler-rt/trunk/lib/tsan/lit_tests/free_race.c
compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
Modified: compiler-rt/trunk/lib/tsan/lit_tests/free_race.c
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race.c?rev=187885&r1=187884&r2=187885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/free_race.c (original)
+++ compiler-rt/trunk/lib/tsan/lit_tests/free_race.c Wed Aug 7 07:39:00 2013
@@ -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$
+
Added: compiler-rt/trunk/lib/tsan/lit_tests/free_race.c.supp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/lit_tests/free_race.c.supp?rev=187885&view=auto
==============================================================================
--- compiler-rt/trunk/lib/tsan/lit_tests/free_race.c.supp (added)
+++ compiler-rt/trunk/lib/tsan/lit_tests/free_race.c.supp Wed Aug 7 07:39:00 2013
@@ -0,0 +1,2 @@
+# Suppression for a use-after-free in free_race.c
+race:^Thread2$
Modified: compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc?rev=187885&r1=187884&r2=187885&view=diff
==============================================================================
--- compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc (original)
+++ compiler-rt/trunk/lib/tsan/rtl/tsan_suppressions.cc Wed Aug 7 07:39:00 2013
@@ -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)
More information about the llvm-commits
mailing list