Skip to content

[UBSAN][HWASAN] Remove redundant flags #87709

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
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
5 changes: 1 addition & 4 deletions clang/lib/CodeGen/BackendUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,6 @@ using namespace llvm;
namespace llvm {
extern cl::opt<bool> PrintPipelinePasses;

static cl::opt<bool> ClRemoveTraps("clang-remove-traps", cl::Optional,
cl::desc("Insert remove-traps pass."));

// Experiment to move sanitizers earlier.
static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
"sanitizer-early-opt-ep", cl::Optional,
Expand Down Expand Up @@ -750,7 +747,7 @@ static void addSanitizers(const Triple &TargetTriple,
PB.registerOptimizerLastEPCallback(SanitizersCallback);
}

if (ClRemoveTraps) {
if (RemoveTrapsPass::IsRequested()) {
// We can optimize after inliner, and PGO profile matching. The hook below
// is called at the end `buildFunctionSimplificationPipeline`, which called
// from `buildInlinerPipeline`, which called after profile matching.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/CodeGen/remote-traps.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow %s -o - | FileCheck %s
// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -mllvm -clang-remove-traps -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call void @llvm.ubsantrap" --check-prefixes=REMOVE
// RUN: %clang_cc1 -O1 -emit-llvm -fsanitize=signed-integer-overflow -fsanitize-trap=signed-integer-overflow -mllvm -remove-traps-random-rate=1 %s -o - | FileCheck %s --implicit-check-not="call void @llvm.ubsantrap" --check-prefixes=REMOVE

int test(int x) {
return x + 123;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace llvm {
class RemoveTrapsPass : public PassInfoMixin<RemoveTrapsPass> {
public:
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM);

static bool IsRequested();
};

} // namespace llvm
Expand Down
9 changes: 3 additions & 6 deletions llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,6 @@ static cl::opt<bool> ClWithTls(
"platforms that support this"),
cl::Hidden, cl::init(true));

static cl::opt<bool>
CSelectiveInstrumentation("hwasan-selective-instrumentation",
cl::desc("Use selective instrumentation"),
cl::Hidden, cl::init(false));

static cl::opt<int> ClHotPercentileCutoff("hwasan-percentile-cutoff-hot",
cl::desc("Hot percentile cuttoff."));

Expand Down Expand Up @@ -1503,6 +1498,8 @@ bool HWAddressSanitizer::selectiveInstrumentationShouldSkip(
std::bernoulli_distribution D(ClRandomSkipRate);
return (D(*Rng));
}
if (!ClHotPercentileCutoff.getNumOccurrences())
return false;
auto &MAMProxy = FAM.getResult<ModuleAnalysisManagerFunctionProxy>(F);
ProfileSummaryInfo *PSI =
MAMProxy.getCachedResult<ProfileSummaryAnalysis>(*F.getParent());
Expand All @@ -1527,7 +1524,7 @@ void HWAddressSanitizer::sanitizeFunction(Function &F,

NumTotalFuncs++;

if (CSelectiveInstrumentation && selectiveInstrumentationShouldSkip(F, FAM))
if (selectiveInstrumentationShouldSkip(F, FAM))
return;

NumInstrumentedFuncs++;
Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Transforms/Instrumentation/RemoveTrapsPass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ static bool removeUbsanTraps(Function &F, const BlockFrequencyInfo &BFI,
auto ShouldRemove = [&](bool IsHot) {
if (!RandomRate.getNumOccurrences())
return IsHot;
assert(HotPercentileCutoff.getNumOccurrences());
if (!Rng)
Rng = F.getParent()->createRNG(F.getName());
std::bernoulli_distribution D(RandomRate);
Expand Down Expand Up @@ -95,3 +96,8 @@ PreservedAnalyses RemoveTrapsPass::run(Function &F,
return removeUbsanTraps(F, BFI, PSI) ? PreservedAnalyses::none()
: PreservedAnalyses::all();
}

bool RemoveTrapsPass::IsRequested() {
return RandomRate.getNumOccurrences() ||
HotPercentileCutoff.getNumOccurrences();
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S \
; RUN: -hwasan-selective-instrumentation=0 | FileCheck %s --check-prefix=FULL
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S \
; RUN: -hwasan-selective-instrumentation=1 | FileCheck %s --check-prefix=SELSAN
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S | FileCheck %s --check-prefix=FULL
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-percentile-cutoff-hot=990000 | FileCheck %s --check-prefix=SELSAN

; FULL: @not_sanitized
; FULL-NEXT: %x = alloca i8, i64 4
Expand Down
12 changes: 4 additions & 8 deletions llvm/test/Instrumentation/HWAddressSanitizer/pgo-opt-out.ll
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-percentile-cutoff-hot=700000 | FileCheck %s --check-prefix=HOT70
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-percentile-cutoff-hot=990000 | FileCheck %s --check-prefix=HOT99
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-random-skip-rate=0.0 | FileCheck %s --check-prefix=RANDOM0
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-selective-instrumentation=1 \
; RUN: -hwasan-random-skip-rate=1.0 | FileCheck %s --check-prefix=RANDOM1
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-percentile-cutoff-hot=700000 | FileCheck %s --check-prefix=HOT70
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-percentile-cutoff-hot=990000 | FileCheck %s --check-prefix=HOT99
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-random-skip-rate=0.0 | FileCheck %s --check-prefix=RANDOM0
; RUN: opt < %s -passes='require<profile-summary>,hwasan' -S -hwasan-random-skip-rate=1.0 | FileCheck %s --check-prefix=RANDOM1

; HOT70: @sanitized
; HOT70-NEXT: @__hwasan_tls
Expand Down