Skip to content

[sanitizer] Refactor -f(no-)?sanitize-recover parsing #119819

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

Merged
merged 7 commits into from
Dec 18, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 9 additions & 16 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,16 @@ static SanitizerMask setGroupBits(SanitizerMask Kinds) {
}

// Computes the sanitizer mask as:
// Default + Arguments (in or out) + AlwaysIn - AlwaysOut
// Default + Arguments (in or out)
// with arguments parsed from left to right.
//
// AlwaysOut is not enforced if AlwaysOutAdvisoryOnly is enabled.
//
// Error messages are optionally printed if the AlwaysIn or AlwaysOut
// invariants are violated.
// 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,
SanitizerMask AlwaysIn, SanitizerMask AlwaysOut, int OptInID,
int OptOutID, bool AlwaysOutAdvisoryOnly) {
int OptOutID) {
assert(!(AlwaysIn & AlwaysOut) &&
"parseSanitizeArgs called with contradictory in/out requirements");

Expand Down Expand Up @@ -304,10 +302,6 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
}
}

Output |= AlwaysIn;
if (!AlwaysOutAdvisoryOnly)
Output &= ~AlwaysOut;

return Output;
}

Expand All @@ -317,7 +311,7 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
SanitizerMask AlwaysTrap; // Empty
SanitizerMask NeverTrap = ~(setGroupBits(TrappingSupported));

// AlwaysOutAdvisoryOnly = true is needed to maintain the behavior of
// 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.
Expand All @@ -326,8 +320,7 @@ static SanitizerMask parseSanitizeTrapArgs(const Driver &D,
/* AlwaysIn */ AlwaysTrap,
/* AlwaysOut */ NeverTrap,
/* OptInID */ options::OPT_fsanitize_trap_EQ,
/* OptOutID */ options::OPT_fno_sanitize_trap_EQ,
/* AlwaysOutAdvisoryOnly */ true);
/* OptOutID */ options::OPT_fno_sanitize_trap_EQ);
}

bool SanitizerArgs::needsFuzzerInterceptors() const {
Expand Down Expand Up @@ -696,9 +689,9 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
/* AlwaysIn */ AlwaysRecoverable,
/* AlwaysOut */ Unrecoverable,
/* OptInID */ options::OPT_fsanitize_recover_EQ,
/* OptOutID */ options::OPT_fno_sanitize_recover_EQ,
/* AlwaysOutAdvisoryOnly */ false);

/* OptOutID */ options::OPT_fno_sanitize_recover_EQ);
RecoverableKinds |= AlwaysRecoverable;
RecoverableKinds &= ~Unrecoverable;
RecoverableKinds &= Kinds;

TrappingKinds &= Kinds;
Expand Down