summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKostya Serebryany <kcc@google.com>2015-01-06 01:31:23 +0000
committerKostya Serebryany <kcc@google.com>2015-01-06 01:31:23 +0000
commit45b058e6446157c88516721dd27200eaca54b705 (patch)
tree01c51f282c0d009360273adc2a25e59f669b6df1
parent98db89f5dbbf3e57ce6e5491b036730971806c07 (diff)
downloadcompiler-rt-45b058e6446157c88516721dd27200eaca54b705.tar.gz
[ubsan] partially enable -fsanitize-coverage=N with ubsan. It will work as usual in most cases but will not dump coverage on error with -fno-sanitize-recover (that'll be a separate fix)
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@225234 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/ubsan/ubsan_init.cc1
-rw-r--r--test/ubsan/TestCases/Misc/coverage-levels.cc36
2 files changed, 37 insertions, 0 deletions
diff --git a/lib/ubsan/ubsan_init.cc b/lib/ubsan/ubsan_init.cc
index 6080e304c..dbafbac81 100644
--- a/lib/ubsan/ubsan_init.cc
+++ b/lib/ubsan/ubsan_init.cc
@@ -43,6 +43,7 @@ void __ubsan::InitIfNecessary() {
// Initialize UBSan-specific flags.
InitializeFlags();
SuppressionContext::InitIfNecessary();
+ InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
ubsan_inited = true;
}
diff --git a/test/ubsan/TestCases/Misc/coverage-levels.cc b/test/ubsan/TestCases/Misc/coverage-levels.cc
new file mode 100644
index 000000000..02521722f
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/coverage-levels.cc
@@ -0,0 +1,36 @@
+// Test various levels of coverage
+//
+// RUN: mkdir -p %T/coverage-levels
+// RUN: OPT=coverage=1:verbosity=1:coverage_dir=%T/coverage-levels
+// RUN: %clangxx -fsanitize=shift -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=1 %s -o %t
+// RUN: UBSAN_OPTIONS=$OPT ASAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
+// RUN: %clangxx -fsanitize=undefined -DGOOD_SHIFT=1 -O1 -fsanitize-coverage=1 %s -o %t
+// RUN: UBSAN_OPTIONS=$OPT ASAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_NOWARN
+
+// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=1 %s -o %t
+// RUN: UBSAN_OPTIONS=$OPT ASAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1 --check-prefix=CHECK_WARN
+// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=2 %s -o %t
+// RUN: UBSAN_OPTIONS=$OPT ASAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK2 --check-prefix=CHECK_WARN
+// RUN: %clangxx -fsanitize=shift -O1 -fsanitize-coverage=3 %s -o %t
+// RUN: UBSAN_OPTIONS=$OPT ASAN_OPTIONS=$OPT %run %t 2>&1 | FileCheck %s --check-prefix=CHECK3 --check-prefix=CHECK_WARN
+
+volatile int sink;
+int main(int argc, char **argv) {
+ int shift = argc * 32;
+#if GOOD_SHIFT
+ shift = 3;
+#endif
+ if ((argc << shift) == 16) // False.
+ return 1;
+ return 0;
+}
+
+// CHECK_WARN: shift exponent 32 is too large
+// CHECK_NOWARN-NOT: ERROR
+// FIXME: Currently, coverage instrumentation kicks in after ubsan, so we get
+// more than the minimal number of instrumented blocks.
+// FIXME: Currently, ubsan with -fno-sanitize-recover and w/o asan will fail
+// to dump coverage.
+// CHECK1: 1 PCs written
+// CHECK2: 3 PCs written
+// CHECK3: 4 PCs written