====================
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%
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
}
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 {
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;
// 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