Skip to content

Commit 928cad4

Browse files
authored
Revert "[ubsan] Connect -fsanitize-skip-hot-cutoff to LowerAllowCheckPass<cutoffs>" (#125032)
Reverts #124857 due to buildbot breakage (https://lab.llvm.org/buildbot/#/builders/46/builds/11310)
1 parent fd94c85 commit 928cad4

File tree

6 files changed

+71
-141
lines changed

6 files changed

+71
-141
lines changed

clang/include/clang/Basic/Sanitizers.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ class SanitizerMaskCutoffs {
162162

163163
void set(SanitizerMask K, double V);
164164
void clear(SanitizerMask K = SanitizerKind::All);
165-
166-
// Returns nullopt if all the values are zero.
167-
// Otherwise, return value contains a vector of all the scaled values.
168-
std::optional<std::vector<unsigned>> getAllScaled(unsigned ScalingFactor) const;
169165
};
170166

171167
struct SanitizerSet {

clang/lib/Basic/Sanitizers.cpp

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include "llvm/Support/MathExtras.h"
1919
#include "llvm/Support/raw_ostream.h"
2020
#include <algorithm>
21-
#include <cmath>
2221
#include <optional>
2322

2423
using namespace clang;
@@ -44,27 +43,6 @@ std::optional<double> SanitizerMaskCutoffs::operator[](unsigned Kind) const {
4443

4544
void SanitizerMaskCutoffs::clear(SanitizerMask K) { set(K, 0); }
4645

47-
std::optional<std::vector<unsigned>>
48-
SanitizerMaskCutoffs::getAllScaled(unsigned ScalingFactor) const {
49-
std::vector<unsigned> ScaledCutoffs;
50-
51-
bool AnyCutoff = false;
52-
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
53-
auto C = (*this)[i];
54-
if (C.has_value()) {
55-
ScaledCutoffs.push_back(lround(std::clamp(*C, 0.0, 1.0) * ScalingFactor));
56-
AnyCutoff = true;
57-
} else {
58-
ScaledCutoffs.push_back(0);
59-
}
60-
}
61-
62-
if (AnyCutoff)
63-
return ScaledCutoffs;
64-
65-
return std::nullopt;
66-
}
67-
6846
// Once LLVM switches to C++17, the constexpr variables can be inline and we
6947
// won't need this.
7048
#define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -795,20 +795,12 @@ static void addSanitizers(const Triple &TargetTriple,
795795
PB.registerOptimizerLastEPCallback(SanitizersCallback);
796796
}
797797

798-
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
799-
// Opts.cutoffs: unsigned ints with range [0, 1000000]
800-
auto ScaledCutoffs = CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
801-
802-
// TODO: remove IsRequested()
803-
if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) {
798+
if (LowerAllowCheckPass::IsRequested()) {
804799
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
805800
PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
806801
OptimizationLevel Level,
807802
ThinOrFullLTOPhase Phase) {
808803
LowerAllowCheckPass::Options Opts;
809-
// TODO: after removing IsRequested(), make this unconditional
810-
if (ScaledCutoffs.has_value())
811-
Opts.cutoffs = ScaledCutoffs.value();
812804
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
813805
});
814806
}

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3614,33 +3614,29 @@ void CodeGenFunction::EmitCheck(
36143614
llvm::Value *RecoverableCond = nullptr;
36153615
llvm::Value *TrapCond = nullptr;
36163616
bool NoMerge = false;
3617-
// Expand checks into:
3618-
// (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ...
3619-
// We need separate allow_ubsan_check intrinsics because they have separately
3620-
// specified cutoffs.
3621-
// This expression looks expensive but will be simplified after
3622-
// LowerAllowCheckPass.
36233617
for (auto &[Check, Ord] : Checked) {
3624-
llvm::Value *GuardedCheck = Check;
3625-
if (ClSanitizeGuardChecks ||
3626-
(CGM.getCodeGenOpts().SanitizeSkipHotCutoffs[Ord] > 0)) {
3627-
llvm::Value *Allow = Builder.CreateCall(
3628-
CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
3629-
llvm::ConstantInt::get(CGM.Int8Ty, Ord));
3630-
GuardedCheck = Builder.CreateOr(Check, Builder.CreateNot(Allow));
3631-
}
3632-
36333618
// -fsanitize-trap= overrides -fsanitize-recover=.
36343619
llvm::Value *&Cond = CGM.getCodeGenOpts().SanitizeTrap.has(Ord) ? TrapCond
36353620
: CGM.getCodeGenOpts().SanitizeRecover.has(Ord)
36363621
? RecoverableCond
36373622
: FatalCond;
3638-
Cond = Cond ? Builder.CreateAnd(Cond, GuardedCheck) : GuardedCheck;
3623+
Cond = Cond ? Builder.CreateAnd(Cond, Check) : Check;
36393624

36403625
if (!CGM.getCodeGenOpts().SanitizeMergeHandlers.has(Ord))
36413626
NoMerge = true;
36423627
}
36433628

3629+
if (ClSanitizeGuardChecks) {
3630+
llvm::Value *Allow =
3631+
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
3632+
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandler));
3633+
3634+
for (llvm::Value **Cond : {&FatalCond, &RecoverableCond, &TrapCond}) {
3635+
if (*Cond)
3636+
*Cond = Builder.CreateOr(*Cond, Builder.CreateNot(Allow));
3637+
}
3638+
}
3639+
36443640
if (TrapCond)
36453641
EmitTrapCheck(TrapCond, CheckHandler, NoMerge);
36463642
if (!FatalCond && !RecoverableCond)

clang/test/CodeGen/allow-ubsan-check-inline.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s -fsanitize=signed-integer-overflow -fsanitize-skip-hot-cutoff=signed-integer-overflow=0.000001 -O3 -mllvm -lower-allow-check-random-rate=1 -Rpass=lower-allow-check -Rpass-missed=lower-allow-check -fno-inline 2>&1 | FileCheck %s --check-prefixes=NOINL --implicit-check-not="remark:"
2-
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s -fsanitize=signed-integer-overflow -fsanitize-skip-hot-cutoff=signed-integer-overflow=0.000001 -O3 -mllvm -lower-allow-check-random-rate=1 -Rpass=lower-allow-check -Rpass-missed=lower-allow-check 2>&1 | FileCheck %s --check-prefixes=INLINE --implicit-check-not="remark:"
3-
//
4-
// -ubsan-guard-checks is deprecated and will be removed in the future;
5-
// use -fsanitize-skip-hot-cutoff, as shown above.
61
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s -fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks -O3 -mllvm -lower-allow-check-random-rate=1 -Rpass=lower-allow-check -Rpass-missed=lower-allow-check -fno-inline 2>&1 | FileCheck %s --check-prefixes=NOINL --implicit-check-not="remark:"
72
// RUN: %clang_cc1 -triple x86_64-pc-linux-gnu -emit-llvm -o - %s -fsanitize=signed-integer-overflow -mllvm -ubsan-guard-checks -O3 -mllvm -lower-allow-check-random-rate=1 -Rpass=lower-allow-check -Rpass-missed=lower-allow-check 2>&1 | FileCheck %s --check-prefixes=INLINE --implicit-check-not="remark:"
83

0 commit comments

Comments
 (0)