Skip to content

Commit c2e8f04

Browse files
committed
Simplify optional and epsilon handling
1 parent 5a85798 commit c2e8f04

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

clang/lib/CodeGen/BackendUtil.cpp

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

798798
bool lowerAllowCheck = LowerAllowCheckPass::IsRequested();
799799
// Is there a non-zero cutoff?
800-
static const double SanitizerMaskCutoffsEps = 0.000000001f;
800+
static constexpr double SanitizerMaskCutoffsEps = 0.000000001f;
801801
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
802-
std::optional<double> maybeCutoff = CodeGenOpts.SanitizeSkipHotCutoffs[i];
803-
lowerAllowCheck |= (maybeCutoff.has_value() &&
804-
(maybeCutoff.value() > SanitizerMaskCutoffsEps));
802+
lowerAllowCheck |= (CodeGenOpts.SanitizeSkipHotCutoffs[i].value_or(0) > SanitizerMaskCutoffsEps);
805803
}
806804

807805
if (lowerAllowCheck) {
@@ -811,18 +809,11 @@ static void addSanitizers(const Triple &TargetTriple,
811809
ThinOrFullLTOPhase Phase) {
812810
LowerAllowCheckPass::Options Opts;
813811

814-
// SanitizeSkipHotCutoffs stores doubles with range [0, 1]
815-
// Opts.cutoffs wants ints with range [0, 1000000]
812+
// SanitizeSkipHotCutoffs: doubles with range [0, 1]
813+
// Opts.cutoffs: ints with range [0, 1000000]
814+
static_assert(static_cast<int>(SanitizerMaskCutoffsEps * 1000000) == 0);
816815
for (unsigned int i = 0; i < SanitizerKind::SO_Count; ++i) {
817-
std::optional<double> maybeCutoff =
818-
CodeGenOpts.SanitizeSkipHotCutoffs[i];
819-
if (maybeCutoff.has_value() &&
820-
(maybeCutoff.value() > SanitizerMaskCutoffsEps)) {
821-
Opts.cutoffs.push_back(maybeCutoff.value() * 1000000);
822-
} else {
823-
// Default is don't skip the check
824-
Opts.cutoffs.push_back(0);
825-
}
816+
Opts.cutoffs.push_back(CodeGenOpts.SanitizeSkipHotCutoffs[i].value_or(0) * 1000000);
826817
}
827818

828819
MPM.addPass(createModuleToFunctionPassAdaptor(LowerAllowCheckPass(Opts)));

0 commit comments

Comments
 (0)