@@ -248,16 +248,18 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
248248}
249249
250250// Computes the sanitizer mask as:
251- // Default + AlwaysIn + Arguments - AlwaysOut
251+ // Default + Arguments (in or out) + AlwaysIn - AlwaysOut
252252// with arguments parsed from left to right.
253253//
254+ // AlwaysOut is not enforced if AlwaysOutAdvisoryOnly is enabled.
255+ //
254256// Error messages are optionally printed if the AlwaysIn or AlwaysOut
255257// invariants are violated.
256258static SanitizerMask
257259parseSanitizeArgs (const Driver &D, const llvm::opt::ArgList &Args,
258260 bool DiagnoseErrors, SanitizerMask Default,
259261 SanitizerMask AlwaysIn, SanitizerMask AlwaysOut, int OptInID,
260- int OptOutID) {
262+ int OptOutID, bool AlwaysOutAdvisoryOnly ) {
261263 assert (!(AlwaysIn & AlwaysOut) &&
262264 " parseSanitizeArgs called with contradictory in/out requirements" );
263265
@@ -303,7 +305,8 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
303305 }
304306
305307 Output |= AlwaysIn;
306- Output &= ~AlwaysOut;
308+ if (!AlwaysOutAdvisoryOnly)
309+ Output &= ~AlwaysOut;
307310
308311 return Output;
309312}
@@ -314,9 +317,13 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
314317 SanitizerMask AlwaysTrap; // Empty
315318 SanitizerMask NeverTrap = ~(setGroupBits (TrappingSupported));
316319
320+ // AlwaysOutAdvisoryOnly = true is needed to maintain the behavior of
321+ // '-fsanitize=undefined -fsanitize-trap=undefined'
322+ // (clang/test/Driver/fsanitize.c ), which is that vptr is not enabled at all
323+ // (not even in recover mode) in order to avoid the need for a ubsan runtime.
317324 return parseSanitizeArgs (D, Args, DiagnoseErrors, TrappingDefault, AlwaysTrap,
318325 NeverTrap, options::OPT_fsanitize_trap_EQ,
319- options::OPT_fno_sanitize_trap_EQ);
326+ options::OPT_fno_sanitize_trap_EQ, true );
320327}
321328
322329bool SanitizerArgs::needsFuzzerInterceptors () const {
@@ -682,7 +689,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
682689 SanitizerMask RecoverableKinds = parseSanitizeArgs (
683690 D, Args, DiagnoseErrors, RecoverableByDefault, AlwaysRecoverable,
684691 Unrecoverable, options::OPT_fsanitize_recover_EQ,
685- options::OPT_fno_sanitize_recover_EQ);
692+ options::OPT_fno_sanitize_recover_EQ, false );
686693
687694 RecoverableKinds &= Kinds;
688695
0 commit comments