Skip to content

Commit d3ec96c

Browse files
author
git apple-llvm automerger
committed
Merge commit '928cad49beec' from llvm.org/main into next
2 parents 6ad7ea5 + 4bdb4c3 commit d3ec96c

File tree

6 files changed

+71
-140
lines changed

6 files changed

+71
-140
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
@@ -813,20 +813,12 @@ static void addSanitizers(const Triple &TargetTriple,
813813
PB.registerOptimizerLastEPCallback(SanitizersCallback);
814814
}
815815

816-
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
817-
// Opts.cutoffs: unsigned ints with range [0, 1000000]
818-
auto ScaledCutoffs = CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
819-
820-
// TODO: remove IsRequested()
821-
if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) {
816+
if (LowerAllowCheckPass::IsRequested()) {
822817
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
823818
PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
824819
OptimizationLevel Level,
825820
ThinOrFullLTOPhase Phase) {
826821
LowerAllowCheckPass::Options Opts;
827-
// TODO: after removing IsRequested(), make this unconditional
828-
if (ScaledCutoffs.has_value())
829-
Opts.cutoffs = ScaledCutoffs.value();
830822
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
831823
});
832824
}

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4135,33 +4135,29 @@ void CodeGenFunction::EmitCheck(
41354135
llvm::Value *RecoverableCond = nullptr;
41364136
llvm::Value *TrapCond = nullptr;
41374137
bool NoMerge = false;
4138-
// Expand checks into:
4139-
// (Check1 || !allow_ubsan_check) && (Check2 || !allow_ubsan_check) ...
4140-
// We need separate allow_ubsan_check intrinsics because they have separately
4141-
// specified cutoffs.
4142-
// This expression looks expensive but will be simplified after
4143-
// LowerAllowCheckPass.
41444138
for (auto &[Check, Ord] : Checked) {
4145-
llvm::Value *GuardedCheck = Check;
4146-
if (ClSanitizeGuardChecks ||
4147-
(CGM.getCodeGenOpts().SanitizeSkipHotCutoffs[Ord] > 0)) {
4148-
llvm::Value *Allow = Builder.CreateCall(
4149-
CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
4150-
llvm::ConstantInt::get(CGM.Int8Ty, Ord));
4151-
GuardedCheck = Builder.CreateOr(Check, Builder.CreateNot(Allow));
4152-
}
4153-
41544139
// -fsanitize-trap= overrides -fsanitize-recover=.
41554140
llvm::Value *&Cond = CGM.getCodeGenOpts().SanitizeTrap.has(Ord) ? TrapCond
41564141
: CGM.getCodeGenOpts().SanitizeRecover.has(Ord)
41574142
? RecoverableCond
41584143
: FatalCond;
4159-
Cond = Cond ? Builder.CreateAnd(Cond, GuardedCheck) : GuardedCheck;
4144+
Cond = Cond ? Builder.CreateAnd(Cond, Check) : Check;
41604145

41614146
if (!CGM.getCodeGenOpts().SanitizeMergeHandlers.has(Ord))
41624147
NoMerge = true;
41634148
}
41644149

4150+
if (ClSanitizeGuardChecks) {
4151+
llvm::Value *Allow =
4152+
Builder.CreateCall(CGM.getIntrinsic(llvm::Intrinsic::allow_ubsan_check),
4153+
llvm::ConstantInt::get(CGM.Int8Ty, CheckHandler));
4154+
4155+
for (llvm::Value **Cond : {&FatalCond, &RecoverableCond, &TrapCond}) {
4156+
if (*Cond)
4157+
*Cond = Builder.CreateOr(*Cond, Builder.CreateNot(Allow));
4158+
}
4159+
}
4160+
41654161
if (TrapCond)
41664162
EmitTrapCheck(TrapCond, CheckHandler, NoMerge);
41674163
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)