Skip to content

Commit d39638d

Browse files
committed
Extract ::set
and fix clear
1 parent 9321def commit d39638d

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

clang/include/clang/Basic/Sanitizers.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ class SanitizerMaskCutoffs {
158158
std::array<float, SanitizerKind::SO_Count> cutoffs = {0};
159159

160160
public:
161-
float &operator[](int index) { return cutoffs[index]; }
162161
const float &operator[](int index) const { return cutoffs[index]; }
163162

163+
void set(SanitizerMask K, float V);
164164
void clear(SanitizerMask K = SanitizerKind::All);
165165
};
166166

clang/lib/Basic/Sanitizers.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@
1919

2020
using namespace clang;
2121

22-
void SanitizerMaskCutoffs::clear(SanitizerMask K) {
22+
void SanitizerMaskCutoffs::set(SanitizerMask K, float V) {
2323
for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++)
24-
if (!(K & SanitizerMask::bitPosToMask(i)))
25-
cutoffs[i] = 0;
24+
if (K & SanitizerMask::bitPosToMask(i))
25+
cutoffs[i] = V;
2626
}
2727

28+
void SanitizerMaskCutoffs::clear(SanitizerMask K) { set(K, 0); }
29+
2830
// Once LLVM switches to C++17, the constexpr variables can be inline and we
2931
// won't need this.
3032
#define SANITIZER(NAME, ID) constexpr SanitizerMask SanitizerKind::ID;
@@ -62,10 +64,7 @@ bool clang::parseSanitizerWeightedValue(StringRef Value, bool AllowGroups,
6264
float C = std::clamp(A, 0.0, 1.0);
6365
// AllowGroups is already taken into account for ParsedKind,
6466
// hence we unconditionally expandSanitizerGroups.
65-
SanitizerMask ExpandedKind = expandSanitizerGroups(ParsedKind);
66-
for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++)
67-
if (ExpandedKind & SanitizerMask::bitPosToMask(i))
68-
Cutoffs[i] = C;
67+
Cutoffs.set(expandSanitizerGroups(ParsedKind), C);
6968
return true;
7069
}
7170

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
11531153
MergeHandlers.Mask |= MergeKinds;
11541154

11551155
// Zero out TopHotCutoffs for unused sanitizers
1156-
TopHotCutoffs.clear(Sanitizers.Mask);
1156+
TopHotCutoffs.clear(~Sanitizers.Mask);
11571157
}
11581158

11591159
static std::string toString(const clang::SanitizerSet &Sanitizers) {

0 commit comments

Comments
 (0)