-
Notifications
You must be signed in to change notification settings - Fork 13.5k
[sanitizer] Apply AlwaysIn/Out in parseSanitizeArgs #129405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
For backwards compatibility, parseSanitizeArgs had an incomplete refactoring in llvm#119819, in order to accommodate the special case of vptr in -fsanitize=undefined and its interaction with -fsanitize-trap=undefined. Now that vptr is no longer part of UBSan (llvm#121115), this patch changes parseSanitizeArgs to apply the AlwaysIn/Out invariants in parseSanitizeArgs, which allows simplifying calls to parseSanitizeArgs. Note that this does change the error message of -fsanitize-trap=vptr.
@llvm/pr-subscribers-clang Author: Thurston Dang (thurstond) ChangesFor backwards compatibility, This is not quite NFC: it changes the error message of -fsanitize-trap=vptr. Full diff: https://github.com/llvm/llvm-project/pull/129405.diff 2 Files Affected:
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 6e75001585c61..f5b0bc5ce720f 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -261,11 +261,8 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
}
// Computes the sanitizer mask as:
-// Default + Arguments (in or out)
+// Default + Arguments (in or out) + AlwaysIn - AlwaysOut
// with arguments parsed from left to right.
-//
-// Error messages are printed if the AlwaysIn or AlwaysOut invariants are
-// violated, but the caller must enforce these invariants themselves.
static SanitizerMask
parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
bool DiagnoseErrors, SanitizerMask Default,
@@ -315,6 +312,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
}
}
+ Output |= AlwaysIn;
+ Output &= ~AlwaysOut;
+
return Output;
}
@@ -324,10 +324,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
SanitizerMask AlwaysTrap; // Empty
SanitizerMask NeverTrap = ~(setGroupBits(TrappingSupported));
- // N.B. We do *not* enforce NeverTrap. This maintains the behavior of
- // '-fsanitize=undefined -fsanitize-trap=undefined'
- // (clang/test/Driver/fsanitize.c ), which is that vptr is not enabled at all
- // (not even in recover mode) in order to avoid the need for a ubsan runtime.
return parseSanitizeArgs(D, Args, DiagnoseErrors, TrappingDefault, AlwaysTrap,
NeverTrap, options::OPT_fsanitize_trap_EQ,
options::OPT_fno_sanitize_trap_EQ);
@@ -725,8 +721,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
D, Args, DiagnoseErrors, RecoverableByDefault, AlwaysRecoverable,
Unrecoverable, options::OPT_fsanitize_recover_EQ,
options::OPT_fno_sanitize_recover_EQ);
- RecoverableKinds |= AlwaysRecoverable;
- RecoverableKinds &= ~Unrecoverable;
RecoverableKinds &= Kinds;
TrappingKinds &= Kinds;
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 79c936a79ffd2..9eb6579ce30ab 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -149,7 +149,7 @@
// CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent"
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-trap=vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
-// CHECK-VPTR-TRAP-UNDEF: error: invalid argument '-fsanitize=vptr' not allowed with '-fsanitize-trap=undefined'
+// CHECK-VPTR-TRAP-UNDEF: error: unsupported argument 'vptr' to option '-fsanitize-trap='
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-undefined-trap-on-error %s -###
|
@llvm/pr-subscribers-clang-driver Author: Thurston Dang (thurstond) ChangesFor backwards compatibility, This is not quite NFC: it changes the error message of -fsanitize-trap=vptr. Full diff: https://github.com/llvm/llvm-project/pull/129405.diff 2 Files Affected:
diff --git a/clang/lib/Driver/SanitizerArgs.cpp b/clang/lib/Driver/SanitizerArgs.cpp
index 6e75001585c61..f5b0bc5ce720f 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -261,11 +261,8 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
}
// Computes the sanitizer mask as:
-// Default + Arguments (in or out)
+// Default + Arguments (in or out) + AlwaysIn - AlwaysOut
// with arguments parsed from left to right.
-//
-// Error messages are printed if the AlwaysIn or AlwaysOut invariants are
-// violated, but the caller must enforce these invariants themselves.
static SanitizerMask
parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
bool DiagnoseErrors, SanitizerMask Default,
@@ -315,6 +312,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
}
}
+ Output |= AlwaysIn;
+ Output &= ~AlwaysOut;
+
return Output;
}
@@ -324,10 +324,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
SanitizerMask AlwaysTrap; // Empty
SanitizerMask NeverTrap = ~(setGroupBits(TrappingSupported));
- // N.B. We do *not* enforce NeverTrap. This maintains the behavior of
- // '-fsanitize=undefined -fsanitize-trap=undefined'
- // (clang/test/Driver/fsanitize.c ), which is that vptr is not enabled at all
- // (not even in recover mode) in order to avoid the need for a ubsan runtime.
return parseSanitizeArgs(D, Args, DiagnoseErrors, TrappingDefault, AlwaysTrap,
NeverTrap, options::OPT_fsanitize_trap_EQ,
options::OPT_fno_sanitize_trap_EQ);
@@ -725,8 +721,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
D, Args, DiagnoseErrors, RecoverableByDefault, AlwaysRecoverable,
Unrecoverable, options::OPT_fsanitize_recover_EQ,
options::OPT_fno_sanitize_recover_EQ);
- RecoverableKinds |= AlwaysRecoverable;
- RecoverableKinds &= ~Unrecoverable;
RecoverableKinds &= Kinds;
TrappingKinds &= Kinds;
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 79c936a79ffd2..9eb6579ce30ab 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -149,7 +149,7 @@
// CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent"
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-trap=vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
-// CHECK-VPTR-TRAP-UNDEF: error: invalid argument '-fsanitize=vptr' not allowed with '-fsanitize-trap=undefined'
+// CHECK-VPTR-TRAP-UNDEF: error: unsupported argument 'vptr' to option '-fsanitize-trap='
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-undefined-trap-on-error %s -###
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe wait a month or so with landing, in case vptr backfire.
Good idea, noted! |
@vitalybuka Any last objections to landing? |
For backwards compatibility, `parseSanitizeArgs`/`parseSanitizeTrapArgs` had an incomplete refactoring in llvm#119819, in order to accommodate the special case of vptr in -fsanitize=undefined and its interaction with -fsanitize-trap=undefined. Now that vptr is no longer part of -fsanitize=undefined (llvm#121115), this patch changes parseSanitizeArgs to apply the AlwaysIn/Out invariants in parseSanitizeArgs, which allows simplifying calls to parseSanitizeArgs. This is not quite NFC: it changes the error message of -fsanitize-trap=vptr.
For backwards compatibility, `parseSanitizeArgs`/`parseSanitizeTrapArgs` had an incomplete refactoring in llvm#119819, in order to accommodate the special case of vptr in -fsanitize=undefined and its interaction with -fsanitize-trap=undefined. Now that vptr is no longer part of -fsanitize=undefined (llvm#121115), this patch changes parseSanitizeArgs to apply the AlwaysIn/Out invariants in parseSanitizeArgs, which allows simplifying calls to parseSanitizeArgs. This is not quite NFC: it changes the error message of -fsanitize-trap=vptr.
For backwards compatibility,
parseSanitizeArgs
/parseSanitizeTrapArgs
had an incomplete refactoring in #119819, in order to accommodate the special case of vptr in -fsanitize=undefined and its interaction with -fsanitize-trap=undefined. Now that vptr is no longer part of -fsanitize=undefined (#121115), this patch changes parseSanitizeArgs to apply the AlwaysIn/Out invariants in parseSanitizeArgs, which allows simplifying calls to parseSanitizeArgs.This is not quite NFC: it changes the error message of -fsanitize-trap=vptr.