[clang] c8248dc - Change deprecated -fsanitize-recover flag to apply to all sanitizers, not just UBSan.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 17 22:48:46 PDT 2020
Author: Richard Smith
Date: 2020-04-17T22:37:30-07:00
New Revision: c8248dc3bb36bea61ac6d87bd02c39c6a781b011
URL: https://github.com/llvm/llvm-project/commit/c8248dc3bb36bea61ac6d87bd02c39c6a781b011
DIFF: https://github.com/llvm/llvm-project/commit/c8248dc3bb36bea61ac6d87bd02c39c6a781b011.diff
LOG: Change deprecated -fsanitize-recover flag to apply to all sanitizers, not just UBSan.
Summary:
This flag has been deprecated, with an on-by-default warning encouraging
users to explicitly specify whether they mean "all" or ubsan for 5 years
(released in Clang 3.7). Change it to mean what we wanted and
undeprecate it.
Also make the argument to -fsanitize-trap optional, and likewise default
it to 'all', and express the aliases for these flags in the .td file
rather than in code. (Plus documentation updates for the above.)
Reviewers: kcc
Subscribers: cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77753
Added:
Modified:
clang/docs/ReleaseNotes.rst
clang/docs/UndefinedBehaviorSanitizer.rst
clang/docs/UsersManual.rst
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/test/Driver/fsanitize.c
Removed:
################################################################################
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 54deba7bbd0e..6ed00a5be936 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -110,6 +110,11 @@ Modified Compiler Flags
- Duplicate qualifiers on asm statements (ex. `asm volatile volatile ("")`) no
longer produces a warning via -Wduplicate-decl-specifier, but now an error
(this matches GCC's behavior).
+- The deprecated argument ``-f[no-]sanitize-recover`` has changed to mean
+ ``-f[no-]sanitize-recover=all`` instead of
+ ``-f[no-]sanitize-recover=undefined,integer`` and is no longer deprecated.
+- The argument to ``-f[no-]sanitize-trap=...`` is now optional and defaults to
+ ``all``.
New Pragmas in Clang
--------------------
diff --git a/clang/docs/UndefinedBehaviorSanitizer.rst b/clang/docs/UndefinedBehaviorSanitizer.rst
index 0f6a42a2113f..493b9478bdf3 100644
--- a/clang/docs/UndefinedBehaviorSanitizer.rst
+++ b/clang/docs/UndefinedBehaviorSanitizer.rst
@@ -54,6 +54,10 @@ and define the desired behavior for each kind of check:
* ``-fno-sanitize-recover=...``: print a verbose error report and exit the program;
* ``-fsanitize-trap=...``: execute a trap instruction (doesn't require UBSan run-time support).
+Note that the ``trap`` / ``recover`` options do not enable the corresponding
+sanitizer, and in general need to be accompanied by a suitable ``-fsanitize=``
+flag.
+
For example if you compile/link your program as:
.. code-block:: console
diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index f50f8888f477..60319833c901 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1466,7 +1466,7 @@ are listed below.
**-f[no-]sanitize-recover=check1,check2,...**
-**-f[no-]sanitize-recover=all**
+**-f[no-]sanitize-recover[=all]**
Controls which checks enabled by ``-fsanitize=`` flag are non-fatal.
If the check is fatal, program will halt after the first error
@@ -1492,6 +1492,8 @@ are listed below.
**-f[no-]sanitize-trap=check1,check2,...**
+**-f[no-]sanitize-trap[=all]**
+
Controls which checks enabled by the ``-fsanitize=`` flag trap. This
option is intended for use in cases where the sanitizer runtime cannot
be used (for instance, when building libc or a kernel module), or where
@@ -1499,9 +1501,7 @@ are listed below.
This flag is only compatible with :doc:`control flow integrity
<ControlFlowIntegrity>` schemes and :doc:`UndefinedBehaviorSanitizer`
- checks other than ``vptr``. If this flag
- is supplied together with ``-fsanitize=undefined``, the ``vptr`` sanitizer
- will be implicitly disabled.
+ checks other than ``vptr``.
This flag is enabled by default for sanitizers in the ``cfi`` group.
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 226876d84b96..fcfc3a387de8 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1083,27 +1083,35 @@ def fsanitize_hwaddress_abi_EQ
: Joined<["-"], "fsanitize-hwaddress-abi=">,
Group<f_clang_Group>,
HelpText<"Select the HWAddressSanitizer ABI to target (interceptor or platform, default interceptor). This option is currently unused.">;
-def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group<f_clang_Group>;
-def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
- Flags<[CoreOption, DriverOption]>,
- Group<f_clang_Group>;
def fsanitize_recover_EQ : CommaJoined<["-"], "fsanitize-recover=">,
Group<f_clang_Group>,
HelpText<"Enable recovery for specified sanitizers">;
-def fno_sanitize_recover_EQ
- : CommaJoined<["-"], "fno-sanitize-recover=">,
- Group<f_clang_Group>,
- Flags<[CoreOption, DriverOption]>,
- HelpText<"Disable recovery for specified sanitizers">;
+def fno_sanitize_recover_EQ : CommaJoined<["-"], "fno-sanitize-recover=">,
+ Group<f_clang_Group>, Flags<[CoreOption, DriverOption]>,
+ HelpText<"Disable recovery for specified sanitizers">;
+def fsanitize_recover : Flag<["-"], "fsanitize-recover">, Group<f_clang_Group>,
+ Alias<fsanitize_recover_EQ>, AliasArgs<["all"]>;
+def fno_sanitize_recover : Flag<["-"], "fno-sanitize-recover">,
+ Flags<[CoreOption, DriverOption]>, Group<f_clang_Group>,
+ Alias<fno_sanitize_recover_EQ>, AliasArgs<["all"]>;
def fsanitize_trap_EQ : CommaJoined<["-"], "fsanitize-trap=">, Group<f_clang_Group>,
HelpText<"Enable trapping for specified sanitizers">;
def fno_sanitize_trap_EQ : CommaJoined<["-"], "fno-sanitize-trap=">, Group<f_clang_Group>,
Flags<[CoreOption, DriverOption]>,
HelpText<"Disable trapping for specified sanitizers">;
-def fsanitize_undefined_trap_on_error : Flag<["-"], "fsanitize-undefined-trap-on-error">,
- Group<f_clang_Group>;
-def fno_sanitize_undefined_trap_on_error : Flag<["-"], "fno-sanitize-undefined-trap-on-error">,
- Group<f_clang_Group>;
+def fsanitize_trap : Flag<["-"], "fsanitize-trap">, Group<f_clang_Group>,
+ Alias<fsanitize_trap_EQ>, AliasArgs<["all"]>,
+ HelpText<"Enable trapping for all sanitizers">;
+def fno_sanitize_trap : Flag<["-"], "fno-sanitize-trap">, Group<f_clang_Group>,
+ Alias<fno_sanitize_trap_EQ>, AliasArgs<["all"]>,
+ Flags<[CoreOption, DriverOption]>,
+ HelpText<"Disable trapping for all sanitizers">;
+def fsanitize_undefined_trap_on_error
+ : Flag<["-"], "fsanitize-undefined-trap-on-error">, Group<f_clang_Group>,
+ Alias<fsanitize_trap_EQ>, AliasArgs<["undefined"]>;
+def fno_sanitize_undefined_trap_on_error
+ : Flag<["-"], "fno-sanitize-undefined-trap-on-error">, Group<f_clang_Group>,
+ Alias<fno_sanitize_trap_EQ>, AliasArgs<["undefined"]>;
def fsanitize_minimal_runtime : Flag<["-"], "fsanitize-minimal-runtime">,
Group<f_clang_Group>;
def fno_sanitize_minimal_runtime : Flag<["-"], "fno-sanitize-minimal-runtime">,
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 7e05fda4e7bf..78a4d9486562 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -56,8 +56,6 @@ static const SanitizerMask Unrecoverable =
SanitizerKind::Unreachable | SanitizerKind::Return;
static const SanitizerMask AlwaysRecoverable =
SanitizerKind::KernelAddress | SanitizerKind::KernelHWAddress;
-static const SanitizerMask LegacyFsanitizeRecoverMask =
- SanitizerKind::Undefined | SanitizerKind::Integer;
static const SanitizerMask NeedsLTO = SanitizerKind::CFI;
static const SanitizerMask TrappingSupported =
(SanitizerKind::Undefined & ~SanitizerKind::Vptr) |
@@ -221,16 +219,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
} else if (Arg->getOption().matches(options::OPT_fno_sanitize_trap_EQ)) {
Arg->claim();
TrapRemove |= expandSanitizerGroups(parseArgValues(D, Arg, true));
- } else if (Arg->getOption().matches(
- options::OPT_fsanitize_undefined_trap_on_error)) {
- Arg->claim();
- TrappingKinds |=
- expandSanitizerGroups(SanitizerKind::UndefinedGroup & ~TrapRemove) &
- ~TrapRemove;
- } else if (Arg->getOption().matches(
- options::OPT_fno_sanitize_undefined_trap_on_error)) {
- Arg->claim();
- TrapRemove |= expandSanitizerGroups(SanitizerKind::UndefinedGroup);
}
}
@@ -541,18 +529,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
SanitizerMask DiagnosedUnrecoverableKinds;
SanitizerMask DiagnosedAlwaysRecoverableKinds;
for (const auto *Arg : Args) {
- const char *DeprecatedReplacement = nullptr;
- if (Arg->getOption().matches(options::OPT_fsanitize_recover)) {
- DeprecatedReplacement =
- "-fsanitize-recover=undefined,integer' or '-fsanitize-recover=all";
- RecoverableKinds |= expandSanitizerGroups(LegacyFsanitizeRecoverMask);
- Arg->claim();
- } else if (Arg->getOption().matches(options::OPT_fno_sanitize_recover)) {
- DeprecatedReplacement = "-fno-sanitize-recover=undefined,integer' or "
- "'-fno-sanitize-recover=all";
- RecoverableKinds &= ~expandSanitizerGroups(LegacyFsanitizeRecoverMask);
- Arg->claim();
- } else if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
+ if (Arg->getOption().matches(options::OPT_fsanitize_recover_EQ)) {
SanitizerMask Add = parseArgValues(D, Arg, true);
// Report error if user explicitly tries to recover from unrecoverable
// sanitizer.
@@ -581,10 +558,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
RecoverableKinds &= ~expandSanitizerGroups(Remove);
Arg->claim();
}
- if (DeprecatedReplacement) {
- D.Diag(diag::warn_drv_deprecated_arg) << Arg->getAsString(Args)
- << DeprecatedReplacement;
- }
}
RecoverableKinds &= Kinds;
RecoverableKinds &= ~Unrecoverable;
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index f02f94d8c5a8..e7094ef93afc 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -3,6 +3,7 @@
// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
// RUN: %clang -target x86_64-linux-gnu -fsanitize=undefined-trap -fsanitize-undefined-trap-on-error %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
// RUN: %clang -target x86_64-linux-gnu -fsanitize-undefined-trap-on-error -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
+// RUN: %clang -target x86_64-linux-gnu -fsanitize-trap -fsanitize=undefined-trap %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-UNDEFINED-TRAP
// CHECK-UNDEFINED-TRAP-NOT: -fsanitize-recover
// CHECK-UNDEFINED-TRAP: "-fsanitize={{((signed-integer-overflow|integer-divide-by-zero|shift-base|shift-exponent|unreachable|return|vla-bound|alignment|null|pointer-overflow|float-cast-overflow|array-bounds|enum|bool|builtin|returns-nonnull-attribute|nonnull-attribute|function),?){18}"}}
// CHECK-UNDEFINED-TRAP: "-fsanitize-trap=alignment,array-bounds,bool,builtin,enum,float-cast-overflow,function,integer-divide-by-zero,nonnull-attribute,null,pointer-overflow,return,returns-nonnull-attribute,shift-base,shift-exponent,signed-integer-overflow,unreachable,vla-bound"
@@ -366,6 +367,7 @@
// CHECK-PARTIAL-RECOVER: "-fsanitize-recover={{((shift-base),?){1}"}}
// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=address -fsanitize-recover=all -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-ASAN
+// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=address -fsanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-RECOVER-ASAN
// CHECK-RECOVER-ASAN: "-fsanitize-recover=address"
// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover=foobar,object-size,unreachable -### 2>&1 | FileCheck %s --check-prefix=CHECK-DIAG-RECOVER
@@ -373,8 +375,6 @@
// CHECK-DIAG-RECOVER: unsupported argument 'unreachable' to option 'fsanitize-recover='
// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=undefined -fsanitize-recover -fno-sanitize-recover -### 2>&1 | FileCheck %s --check-prefix=CHECK-DEPRECATED-RECOVER
-// CHECK-DEPRECATED-RECOVER: argument '-fsanitize-recover' is deprecated, use '-fsanitize-recover=undefined,integer' or '-fsanitize-recover=all' instead
-// CHECK-DEPRECATED-RECOVER: argument '-fno-sanitize-recover' is deprecated, use '-fno-sanitize-recover=undefined,integer' or '-fno-sanitize-recover=all' instead
// CHECK-DEPRECATED-RECOVER-NOT: is deprecated
// RUN: %clang -target x86_64-linux-gnu %s -fsanitize=kernel-address -fno-sanitize-recover=kernel-address -### 2>&1 | FileCheck %s --check-prefix=CHECK-NO-RECOVER-KASAN
More information about the cfe-commits
mailing list