[msan] allow -fsanitize-coverage=N together with -fsanitize=memory, compiler-rt part
authorKostya Serebryany <kcc@google.com>
Wed, 3 Dec 2014 23:29:14 +0000 (23:29 +0000)
committerKostya Serebryany <kcc@google.com>
Wed, 3 Dec 2014 23:29:14 +0000 (23:29 +0000)
llvm-svn: 223314

compiler-rt/lib/msan/msan.cc
compiler-rt/lib/msan/msan_linux.cc
compiler-rt/test/msan/coverage-levels.cc [new file with mode: 0644]

index af42176..853e448 100644 (file)
@@ -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);
index 29acfc4..0b67b53 100644 (file)
@@ -133,6 +133,8 @@ bool InitShadow(bool map_shadow, bool init_origins) {
 }
 
 void MsanDie() {
+  if (common_flags()->coverage)
+    __sanitizer_cov_dump();
   if (death_callback)
     death_callback();
   _exit(flags()->exit_code);
diff --git a/compiler-rt/test/msan/coverage-levels.cc b/compiler-rt/test/msan/coverage-levels.cc
new file mode 100644 (file)
index 0000000..60d41c8
--- /dev/null
@@ -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