Skip to content

Commit 58c752b

Browse files
committed
Updates
Lazy vector Epsilon and std::optional
1 parent 99cfdb2 commit 58c752b

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

clang/include/clang/Basic/Sanitizers.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ struct SanitizerKind {
155155
}; // SanitizerKind
156156

157157
class SanitizerMaskCutoffs {
158-
std::array<float, SanitizerKind::SO_Count> cutoffs = {0};
158+
std::vector<double> Cutoffs;
159159

160160
public:
161-
float operator[](int index) const { return cutoffs[index]; }
161+
std::optional<double> operator[](unsigned Kind) const;
162162

163163
void set(SanitizerMask K, float V);
164164
void clear(SanitizerMask K = SanitizerKind::All);

clang/lib/Basic/Sanitizers.cpp

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,27 @@
1616
#include "llvm/ADT/StringSwitch.h"
1717
#include "llvm/Support/MathExtras.h"
1818
#include <algorithm>
19+
#include <optional>
1920

2021
using namespace clang;
2122

23+
static const double SanitizerMaskCutoffsEps = 0.000000001f;
24+
2225
void SanitizerMaskCutoffs::set(SanitizerMask K, float V) {
26+
if (V < SanitizerMaskCutoffsEps && Cutoffs.empty())
27+
return;
2328
for (unsigned int i = 0; i < SanitizerKind::SO_Count; i++)
24-
if (K & SanitizerMask::bitPosToMask(i))
25-
cutoffs[i] = V;
29+
if (K & SanitizerMask::bitPosToMask(i)) {
30+
Cutoffs.resize(SanitizerKind::SO_Count);
31+
Cutoffs[i] = V;
32+
}
33+
}
34+
35+
std::optional<double> SanitizerMaskCutoffs::operator[](unsigned Kind) const {
36+
if (Cutoffs.empty() || Cutoffs[Kind] < SanitizerMaskCutoffsEps)
37+
return std::nullopt;
38+
39+
return Cutoffs[Kind];
2640
}
2741

2842
void SanitizerMaskCutoffs::clear(SanitizerMask K) { set(K, 0); }
@@ -79,9 +93,9 @@ void clang::serializeSanitizerSet(SanitizerSet Set,
7993
void clang::serializeSanitizerMaskCutoffs(
8094
const SanitizerMaskCutoffs &Cutoffs, SmallVectorImpl<std::string> &Values) {
8195
#define SANITIZER(NAME, ID) \
82-
if (Cutoffs[SanitizerKind::SO_##ID]) \
83-
Values.push_back(std::string(NAME "=") + \
84-
std::to_string(Cutoffs[SanitizerKind::SO_##ID]));
96+
if (auto C = Cutoffs[SanitizerKind::SO_##ID]) { \
97+
Values.push_back(std::string(NAME "=") + std::to_string(*C)); \
98+
}
8599
#include "clang/Basic/Sanitizers.def"
86100
}
87101

clang/lib/Driver/SanitizerArgs.cpp

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,16 +1169,9 @@ static std::string toString(const clang::SanitizerSet &Sanitizers) {
11691169
}
11701170

11711171
static std::string toString(const clang::SanitizerMaskCutoffs &Cutoffs) {
1172-
std::string Res;
1173-
#define SANITIZER(NAME, ID) \
1174-
if (Cutoffs[SanitizerKind::SO_##ID]) { \
1175-
if (!Res.empty()) \
1176-
Res += ","; \
1177-
Res += std::string(NAME) + "=" + \
1178-
std::to_string(Cutoffs[SanitizerKind::SO_##ID]); \
1179-
}
1180-
#include "clang/Basic/Sanitizers.def"
1181-
return Res;
1172+
llvm::SmallVector<std::string, 4> Res;
1173+
serializeSanitizerMaskCutoffs(Cutoffs, Res);
1174+
return llvm::join(Res, ",");
11821175
}
11831176

11841177
static void addSpecialCaseListOpt(const llvm::opt::ArgList &Args,

0 commit comments

Comments
 (0)