[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL326860: [Driver] Automatically disable incompatible default 
sanitizers (authored by phosek, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44064?vs=136893&id=137302#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44064

Files:
  cfe/trunk/lib/Driver/SanitizerArgs.cpp


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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) {


Index: cfe/trunk/lib/Driver/SanitizerArgs.cpp
===
--- cfe/trunk/lib/Driver/SanitizerArgs.cpp
+++ cfe/trunk/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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,

[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-06 Thread Petr Hosek via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC326860: [Driver] Automatically disable incompatible default 
sanitizers (authored by phosek, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D44064?vs=136893&id=137301#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44064

Files:
  lib/Driver/SanitizerArgs.cpp


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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) {


Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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),
-

[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-05 Thread Petr Hosek via Phabricator via cfe-commits
phosek added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:369
   // Check that LTO is enabled if we need it.
   if ((Kinds & NeedsLTO) && !D.isUsingLTO()) {
 D.Diag(diag::err_drv_argument_only_allowed_with)

vitalybuka wrote:
> Is this change needed to avoid errors at "Kinds & NeedsLTO" and 
> KindsToDiagnose?
> Could you create a test for this change?
It is needed for D44065, if we enable some sanitizers like SafeStack by 
default, user would get an error when they enable some incompatible sanitizer 
like ASan and would require them passing `-fno-sanitizer=safe-stack` to avoid 
that error which is non-intuitive. Instead, with this change the incompatible 
default sanitizers are disabled automatically.


Repository:
  rC Clang

https://reviews.llvm.org/D44064



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-05 Thread Vitaly Buka via Phabricator via cfe-commits
vitalybuka added inline comments.



Comment at: clang/lib/Driver/SanitizerArgs.cpp:369
   // Check that LTO is enabled if we need it.
   if ((Kinds & NeedsLTO) && !D.isUsingLTO()) {
 D.Diag(diag::err_drv_argument_only_allowed_with)

Is this change needed to avoid errors at "Kinds & NeedsLTO" and KindsToDiagnose?
Could you create a test for this change?


Repository:
  rC Clang

https://reviews.llvm.org/D44064



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D44064: [Driver] Automatically disable incompatible default sanitizers

2018-03-02 Thread Petr Hosek via Phabricator via cfe-commits
phosek created this revision.
phosek added reviewers: kcc, vitalybuka, mcgrathr.
Herald added subscribers: cfe-commits, cryptoad.
phosek added a dependent revision: D44065: [Driver] Enable SafeStack by default 
on Fuchsia.

When a sanitizer incompatible with one of the default sanitizers
is explicitly enabled, automatically disable all the conflicting
default sanitizers.


Repository:
  rC Clang

https://reviews.llvm.org/D44064

Files:
  clang/lib/Driver/SanitizerArgs.cpp


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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) {


Index: clang/lib/Driver/SanitizerArgs.cpp
===
--- clang/lib/Driver/SanitizerArgs.cpp
+++ clang/lib/Driver/SanitizerArgs.cpp
@@ -332,8 +332,30 @@
 }
   }
 
+  std::pair 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.
@@ -369,18 +391,6 @@
   }
 
   // Warn about incompatible groups of sanitizers.
-  std::pair 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),
-