Skip to content

Commit

Permalink
[Driver] Automatically disable incompatible default sanitizers
Browse files Browse the repository at this point in the history
When a sanitizer incompatible with one of the default sanitizers
is explicitly enabled, automatically disable all the conflicting
default sanitizers.

Differential Revision: https://reviews.llvm.org/D44064

llvm-svn: 326860
  • Loading branch information
petrhosek committed Mar 7, 2018
1 parent a0db2eb commit a14b460
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions clang/lib/Driver/SanitizerArgs.cpp
Expand Up @@ -332,8 +332,30 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}
}

std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
std::make_pair(Address, Thread | Memory),
std::make_pair(Thread, Memory),
std::make_pair(Leak, Thread | Memory),
std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
KernelAddress),
std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
KernelAddress | Efficiency),
std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
KernelAddress | Efficiency)};

// Enable toolchain specific default sanitizers if not explicitly disabled.
Kinds |= TC.getDefaultSanitizers() & ~AllRemove;
SanitizerMask Default = TC.getDefaultSanitizers() & ~AllRemove;

// Disable default sanitizers that are incompatible with the default ones.
for (auto G : IncompatibleGroups) {
SanitizerMask Group = G.first;
if ((Default & Group) && (Kinds & G.second))
Default &= ~Group;
}

Kinds |= Default;

// We disable the vptr sanitizer if it was enabled by group expansion but RTTI
// is disabled.
Expand Down Expand Up @@ -369,18 +391,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
}

// Warn about incompatible groups of sanitizers.
std::pair<SanitizerMask, SanitizerMask> IncompatibleGroups[] = {
std::make_pair(Address, Thread | Memory),
std::make_pair(Thread, Memory),
std::make_pair(Leak, Thread | Memory),
std::make_pair(KernelAddress, Address | Leak | Thread | Memory),
std::make_pair(HWAddress, Address | Thread | Memory | KernelAddress),
std::make_pair(Efficiency, Address | HWAddress | Leak | Thread | Memory |
KernelAddress),
std::make_pair(Scudo, Address | HWAddress | Leak | Thread | Memory |
KernelAddress | Efficiency),
std::make_pair(SafeStack, Address | HWAddress | Leak | Thread | Memory |
KernelAddress | Efficiency)};
for (auto G : IncompatibleGroups) {
SanitizerMask Group = G.first;
if (Kinds & Group) {
Expand Down

0 comments on commit a14b460

Please sign in to comment.