[compiler-rt] r223314 - [msan] allow -fsanitize-coverage=N together with -fsanitize=memory, compiler-rt part
Kostya Serebryany
kcc at google.com
Wed Dec 3 15:29:14 PST 2014
Author: kcc
Date: Wed Dec 3 17:29:14 2014
New Revision: 223314
URL: http://llvm.org/viewvc/llvm-project?rev=223314&view=rev
Log:
[msan] allow -fsanitize-coverage=N together with -fsanitize=memory, compiler-rt part
Added:
compiler-rt/trunk/test/msan/coverage-levels.cc
Modified:
compiler-rt/trunk/lib/msan/msan.cc
compiler-rt/trunk/lib/msan/msan_linux.cc
Modified: compiler-rt/trunk/lib/msan/msan.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan.cc?rev=223314&r1=223313&r2=223314&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan.cc (original)
+++ compiler-rt/trunk/lib/msan/msan.cc Wed Dec 3 17:29:14 2014
@@ -372,6 +372,11 @@ void __msan_init() {
Symbolizer::GetOrInit()->AddHooks(EnterSymbolizer, ExitSymbolizer);
+ if (common_flags()->coverage) {
+ __sanitizer_cov_init();
+ Atexit(__sanitizer_cov_dump);
+ }
+
MsanTSDInit(MsanTSDDtor);
MsanThread *main_thread = MsanThread::Create(0, 0);
Modified: compiler-rt/trunk/lib/msan/msan_linux.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/msan/msan_linux.cc?rev=223314&r1=223313&r2=223314&view=diff
==============================================================================
--- compiler-rt/trunk/lib/msan/msan_linux.cc (original)
+++ compiler-rt/trunk/lib/msan/msan_linux.cc Wed Dec 3 17:29:14 2014
@@ -133,6 +133,8 @@ bool InitShadow(bool map_shadow, bool in
}
void MsanDie() {
+ if (common_flags()->coverage)
+ __sanitizer_cov_dump();
if (death_callback)
death_callback();
_exit(flags()->exit_code);
Added: compiler-rt/trunk/test/msan/coverage-levels.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/test/msan/coverage-levels.cc?rev=223314&view=auto
==============================================================================
--- compiler-rt/trunk/test/msan/coverage-levels.cc (added)
+++ compiler-rt/trunk/test/msan/coverage-levels.cc Wed Dec 3 17:29:14 2014
@@ -0,0 +1,27 @@
+// Test various levels of coverage
+//
+// RUN: %clangxx_msan -DINIT_VAR=1 -O1 -fsanitize-coverage=1 %s -o %t
+// RUN: MSAN_OPTIONS=coverage=1:verbosity=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
+// RUN: %clangxx_msan -O1 -fsanitize-coverage=1 %s -o %t
+// RUN: MSAN_OPTIONS=coverage=1:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN
+// RUN: %clangxx_msan -O1 -fsanitize-coverage=2 %s -o %t
+// RUN: MSAN_OPTIONS=coverage=1:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN
+// RUN: %clangxx_msan -O1 -fsanitize-coverage=3 %s -o %t
+// RUN: MSAN_OPTIONS=coverage=1:verbosity=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN
+//
+volatile int sink;
+int main(int argc, char **argv) {
+ int var;
+#if INIT_VAR
+ var = 0;
+#endif
+ if (argc == 0)
+ sink = 0;
+ return *(volatile int*)&var;
+}
+
+// CHECK_WARN: WARNING: MemorySanitizer: use-of-uninitialized-value
+// CHECK_NOWARN-NOT: ERROR
+// CHECK1: 1 PCs written
+// CHECK2: 2 PCs written
+// CHECK3: 3 PCs written
More information about the llvm-commits
mailing list