Skip to content

Commit 69476cf

Browse files
committed
[sanitizer] Apply AlwaysIn/Out in parseSanitizeArgs
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.
1 parent 872e4a3 commit 69476cf

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,8 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
261261
}
262262

263263
// Computes the sanitizer mask as:
264-
// Default + Arguments (in or out)
264+
// Default + Arguments (in or out) + AlwaysIn - AlwaysOut
265265
// with arguments parsed from left to right.
266-
//
267-
// Error messages are printed if the AlwaysIn or AlwaysOut invariants are
268-
// violated, but the caller must enforce these invariants themselves.
269266
static SanitizerMask
270267
parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
271268
bool DiagnoseErrors, SanitizerMask Default,
@@ -315,6 +312,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
315312
}
316313
}
317314

315+
Output |= AlwaysIn;
316+
Output &= ~AlwaysOut;
317+
318318
return Output;
319319
}
320320

@@ -324,10 +324,6 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
324324
SanitizerMask AlwaysTrap; // Empty
325325
SanitizerMask NeverTrap = ~(setGroupBits(TrappingSupported));
326326

327-
// N.B. We do *not* enforce NeverTrap. This maintains the behavior of
328-
// '-fsanitize=undefined -fsanitize-trap=undefined'
329-
// (clang/test/Driver/fsanitize.c ), which is that vptr is not enabled at all
330-
// (not even in recover mode) in order to avoid the need for a ubsan runtime.
331327
return parseSanitizeArgs(D, Args, DiagnoseErrors, TrappingDefault, AlwaysTrap,
332328
NeverTrap, options::OPT_fsanitize_trap_EQ,
333329
options::OPT_fno_sanitize_trap_EQ);
@@ -725,8 +721,6 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
725721
D, Args, DiagnoseErrors, RecoverableByDefault, AlwaysRecoverable,
726722
Unrecoverable, options::OPT_fsanitize_recover_EQ,
727723
options::OPT_fno_sanitize_recover_EQ);
728-
RecoverableKinds |= AlwaysRecoverable;
729-
RecoverableKinds &= ~Unrecoverable;
730724
RecoverableKinds &= Kinds;
731725

732726
TrappingKinds &= Kinds;

clang/test/Driver/fsanitize.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
// CHECK-FSANITIZE-SHIFT-PARTIAL: "-fsanitize=shift-exponent"
150150

151151
// RUN: not %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-trap=vptr %s -### 2>&1 | FileCheck %s --check-prefix=CHECK-VPTR-TRAP-UNDEF
152-
// CHECK-VPTR-TRAP-UNDEF: error: invalid argument '-fsanitize=vptr' not allowed with '-fsanitize-trap=undefined'
152+
// CHECK-VPTR-TRAP-UNDEF: error: unsupported argument 'vptr' to option '-fsanitize-trap='
153153

154154
// RUN: %clang --target=x86_64-linux-gnu -fsanitize=vptr -fsanitize-undefined-trap-on-error %s -###
155155

0 commit comments

Comments
 (0)