Skip to content

Commit afacf0e

Browse files
committed
More reviewer feedback
1 parent d5af843 commit afacf0e

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

clang/lib/Basic/Sanitizers.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ void SanitizerMaskCutoffs::clear(SanitizerMask K) { set(K, 0); }
4646

4747
std::optional<std::vector<int>>
4848
SanitizerMaskCutoffs::getAllScaled(int ScalingFactor) const {
49-
std::vector<int> scaledCutoffs;
49+
std::vector<int> ScaledCutoffs;
5050

51-
bool anyNonZero = false;
51+
bool AnyCutoff = false;
5252
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
53-
int scaled = round((operator[](i)).value_or(0) * ScalingFactor);
54-
scaledCutoffs.push_back(scaled);
55-
anyNonZero |= (scaled != 0);
53+
auto C = (*this)[i];
54+
ScaledCutoffs.push_back(C.has_value() ? lround(ScalingFactor * *C) : 0);
55+
AnyCutoff |= C.has_value();
5656
}
5757

58-
if (anyNonZero)
59-
return scaledCutoffs;
58+
if (AnyCutoff)
59+
return ScaledCutoffs;
6060

6161
return std::nullopt;
6262
}

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -797,27 +797,22 @@ static void addSanitizers(const Triple &TargetTriple,
797797

798798
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
799799
// Opts.cutoffs: ints with range [0, 1000000]
800-
std::optional<std::vector<int>> scaledCutoffs =
800+
std::optional<std::vector<int>> ScaledCutoffs =
801801
CodeGenOpts.SanitizeSkipHotCutoffs.getAllScaled(1000000);
802802

803803
// TODO: remove IsRequested()
804-
if (LowerAllowCheckPass::IsRequested() || scaledCutoffs.has_value()) {
804+
if (LowerAllowCheckPass::IsRequested() || ScaledCutoffs.has_value()) {
805805
// We want to call it after inline, which is about OptimizerEarlyEPCallback.
806806
PB.registerOptimizerEarlyEPCallback([&](ModulePassManager &MPM,
807807
OptimizationLevel Level,
808808
ThinOrFullLTOPhase Phase) {
809809
LowerAllowCheckPass::Options Opts;
810810

811-
// TODO: after removing IsRequested(), the if case will be unconditional
812-
if (scaledCutoffs.has_value()) {
811+
// TODO: after removing IsRequested(), make this unconditional
812+
if (ScaledCutoffs.has_value())
813813
// Copy from std::vector<int> to std::vector<unsigned int>
814-
Opts.cutoffs = {scaledCutoffs.value().begin(),
815-
scaledCutoffs.value().end()};
816-
} else {
817-
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
818-
Opts.cutoffs.push_back(0);
819-
}
820-
}
814+
Opts.cutoffs = {ScaledCutoffs.value().begin(),
815+
ScaledCutoffs.value().end()};
821816

822817
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));
823818
});

0 commit comments

Comments
 (0)