]> granicus.if.org Git - clang/commitdiff
[sanitizer] Allow sanitize coverage w/o sanitizers.
authorEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Tue, 14 Jun 2016 21:33:40 +0000 (21:33 +0000)
committerEvgeniy Stepanov <eugeni.stepanov@gmail.com>
Tue, 14 Jun 2016 21:33:40 +0000 (21:33 +0000)
The reason is that this (a) seems to work just fine and (b) useful when building stuff with
sanitizer+coverage, but need to exclude the sanitizer for a particular source file.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272717 91177308-0d34-0410-b5e6-96231b3b80d8

docs/SanitizerCoverage.rst
lib/Driver/SanitizerArgs.cpp
test/Driver/fsanitize-coverage.c

index d2dde000273a20d5d2e9362f17e32fd31c00caa9..f7ec65fdd155e9ae2835c898a3e71cbee3687a39 100644 (file)
@@ -16,8 +16,9 @@ How to build and run
 ====================
 
 SanitizerCoverage can be used with :doc:`AddressSanitizer`,
-:doc:`LeakSanitizer`, :doc:`MemorySanitizer`, and UndefinedBehaviorSanitizer.
-In addition to ``-fsanitize=``, pass one of the following compile-time flags:
+:doc:`LeakSanitizer`, :doc:`MemorySanitizer`,
+UndefinedBehaviorSanitizer, or without any sanitizer.  Pass one of the
+following compile-time flags:
 
 * ``-fsanitize-coverage=func`` for function-level coverage (very fast).
 * ``-fsanitize-coverage=bb`` for basic-block-level coverage (may add up to 30%
@@ -27,8 +28,9 @@ In addition to ``-fsanitize=``, pass one of the following compile-time flags:
 You may also specify ``-fsanitize-coverage=indirect-calls`` for
 additional `caller-callee coverage`_.
 
-At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``, ``LSAN_OPTIONS``,
-``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as appropriate.
+At run time, pass ``coverage=1`` in ``ASAN_OPTIONS``,
+``LSAN_OPTIONS``, ``MSAN_OPTIONS`` or ``UBSAN_OPTIONS``, as
+appropriate. For the standalone coverage mode, use ``UBSAN_OPTIONS``.
 
 To get `Coverage counters`_, add ``-fsanitize-coverage=8bit-counters``
 to one of the above compile-time flags. At runtime, use
index d64ac53b69e97d7bdbc82bb048225f3bf2e2effc..4d30a1bc95f75d231b044b3508a97bd35ec0be83 100644 (file)
@@ -159,11 +159,10 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
 }
 
 bool SanitizerArgs::needsUbsanRt() const {
-  return (Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) &&
-         !Sanitizers.has(Address) &&
-         !Sanitizers.has(Memory) &&
-         !Sanitizers.has(Thread) &&
-         !CfiCrossDso;
+  return ((Sanitizers.Mask & NeedsUbsanRt & ~TrapSanitizers.Mask) ||
+          CoverageFeatures) &&
+         !Sanitizers.has(Address) && !Sanitizers.has(Memory) &&
+         !Sanitizers.has(Thread) && !CfiCrossDso;
 }
 
 bool SanitizerArgs::needsCfiRt() const {
@@ -485,10 +484,10 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
         continue;
       }
       CoverageFeatures |= parseCoverageFeatures(D, Arg);
-      // If there is trace-pc, allow it w/o any of the sanitizers.
-      // Otherwise, require that one of the supported sanitizers is present.
-      if ((CoverageFeatures & CoverageTracePC) ||
-          (AllAddedKinds & SupportsCoverage)) {
+
+      // Disable coverage and not claim the flags if there is at least one
+      // non-supporting sanitizer.
+      if (!(AllAddedKinds & ~setGroupBits(SupportsCoverage))) {
         Arg->claim();
       } else {
         CoverageFeatures = 0;
index a13b530f26511daacbf66fab1b94e7437e24428f..16c5dfe09937d1403f78973228d261458061dd43 100644 (file)
@@ -33,7 +33,7 @@
 // CHECK-SANITIZE-COVERAGE-5: error: unsupported argument '5' to option 'fsanitize-coverage='
 
 // RUN: %clang -target x86_64-linux-gnu -fsanitize=thread   -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED
-// RUN: %clang -target x86_64-linux-gnu                     -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-UNUSED
+// RUN: %clang -target x86_64-linux-gnu                     -fsanitize-coverage=func %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-SANITIZE-COVERAGE-FUNC
 // CHECK-SANITIZE-COVERAGE-UNUSED: argument unused during compilation: '-fsanitize-coverage=func'
 // CHECK-SANITIZE-COVERAGE-UNUSED-NOT: -fsanitize-coverage-type=1