[PATCH] Introduce -fsanitize-trap= flag.

Alexey Samsonov vonosmas at gmail.com
Tue Jun 16 11:41:38 PDT 2015


================
Comment at: lib/CodeGen/CGExpr.cpp:2306
@@ -2304,2 +2305,3 @@
     llvm::Value *Check = Checked[i].first;
+    // -fsanitize-trap= overrides -fsanitize-recover=.
     llvm::Value *&Cond =
----------------
Should we clarify this behavior in the docs?
We can also handle this case in the driver, so that frontend can assert that each sanitizer check is listed in at most one of `-fsanitize-recover=` and `-fsanitize-trap=` lists. (i.e. intersection of `SanitizeTrap` and `SanitizeRecover` is empty).

Another interesting question is handling the relative order of `-fsanitize-trap=` and `-fsanitize-recover=` flags. Now we parse them completely independently, but this may not be the best solution. Consider global
  CFLAGS='-fsanitize=undefined -fsanitize-trap=undefined'
and now I want to compile a special program, and enable recovery for alignment issues. Using
  clang++ $(CFLAGS) -fsanitize-recover=alignment a.cc
wouldn't work, I would have to write
  clang++ $(CFLAGS) -fno-sanitize-trap=alignment -fsanitize-recover=alignment a.cc
Do you think we should instead parse `-fsanitize-trap` and `-fsanitize-recover` in a single pass, and maintain the recovery setting for each sanitizer kind to be one of
  * diagnosed, recoverable
  * diagnosed, unrecoverable/fatal
  * undiagnosed, trapping.
?


================
Comment at: lib/Driver/SanitizerArgs.cpp:37
@@ -36,1 +36,3 @@
   NeedsLTO = CFI,
+  TrappingSupported = (Undefined & ~Vptr) | UndefinedGroup |
+                      UnsignedIntegerOverflow | LocalBounds,
----------------
Yep, let's use `setGroupBits`. Specifying the groups here manually is error-prone - one can easily forget to change this part if `Sanitizers.def` is re-orrganized.

================
Comment at: lib/Driver/SanitizerArgs.cpp:503
@@ -462,2 +502,3 @@
   RecoverableSanitizers.Mask |= RecoverableKinds;
+  TrapSanitizers.Mask |= TrappingKinds;
 }
----------------
Note that you can also strip out sanitizers which were not enabled eventually from here
  TrappingKinds &= Kinds;
as we do for recoverable sanitizers.

http://reviews.llvm.org/D10464

EMAIL PREFERENCES
  http://reviews.llvm.org/settings/panel/emailpreferences/






More information about the cfe-commits mailing list