Skip to content

Commit 20cd74a

Browse files
authored
[sanitizer] Apply AlwaysIn/Out in parseSanitizeArgs (#129405)
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.
1 parent 69b9ddc commit 20cd74a

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
@@ -262,11 +262,8 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
262262
}
263263

264264
// Computes the sanitizer mask as:
265-
// Default + Arguments (in or out)
265+
// Default + Arguments (in or out) + AlwaysIn - AlwaysOut
266266
// with arguments parsed from left to right.
267-
//
268-
// Error messages are printed if the AlwaysIn or AlwaysOut invariants are
269-
// violated, but the caller must enforce these invariants themselves.
270267
static SanitizerMask
271268
parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
272269
bool DiagnoseErrors, SanitizerMask Default,
@@ -316,6 +313,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
316313
}
317314
}
318315

316+
Output |= AlwaysIn;
317+
Output &= ~AlwaysOut;
318+
319319
return Output;
320320
}
321321

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

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

734728
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)