r272717 - [sanitizer] Allow sanitize coverage w/o sanitizers.
Evgeniy Stepanov via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 14 14:33:40 PDT 2016
Author: eugenis
Date: Tue Jun 14 16:33:40 2016
New Revision: 272717
URL: http://llvm.org/viewvc/llvm-project?rev=272717&view=rev
Log:
[sanitizer] Allow sanitize coverage w/o sanitizers.
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.
Modified:
cfe/trunk/docs/SanitizerCoverage.rst
cfe/trunk/lib/Driver/SanitizerArgs.cpp
cfe/trunk/test/Driver/fsanitize-coverage.c
Modified: cfe/trunk/docs/SanitizerCoverage.rst
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/SanitizerCoverage.rst?rev=272717&r1=272716&r2=272717&view=diff
==============================================================================
--- cfe/trunk/docs/SanitizerCoverage.rst (original)
+++ cfe/trunk/docs/SanitizerCoverage.rst Tue Jun 14 16:33:40 2016
@@ -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
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
Modified: cfe/trunk/lib/Driver/SanitizerArgs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/SanitizerArgs.cpp?rev=272717&r1=272716&r2=272717&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp (original)
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp Tue Jun 14 16:33:40 2016
@@ -159,11 +159,10 @@ static SanitizerMask parseSanitizeTrapAr
}
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 ToolC
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;
Modified: cfe/trunk/test/Driver/fsanitize-coverage.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fsanitize-coverage.c?rev=272717&r1=272716&r2=272717&view=diff
==============================================================================
--- cfe/trunk/test/Driver/fsanitize-coverage.c (original)
+++ cfe/trunk/test/Driver/fsanitize-coverage.c Tue Jun 14 16:33:40 2016
@@ -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
More information about the cfe-commits
mailing list