Skip to content

[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

Merged
merged 1 commit into from
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 4 additions & 10 deletions clang/lib/Driver/SanitizerArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -315,6 +312,9 @@ parseSanitizeArgs(const Driver &D, const llvm::opt::ArgList &Args,
}
}

Output |= AlwaysIn;
Output &= ~AlwaysOut;

return Output;
}

Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clang/test/Driver/fsanitize.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 -###

Expand Down