Skip to content

Commit e297184

Browse files
authored
[clang][analyzer] Remove boolean per-entry-point metrics (llvm#162817)
The complexity of maintaining an extra kind of metrics have not justified itself, as it is not used upstream, and we have only a single use of boolean stats per entrypoint downstream. As I will do downstream, you can use an unsigned statistic type with values 0 and 1 to model a boolean flag. -- CPP-7097
1 parent 167c00e commit e297184

File tree

3 files changed

+3
-40
lines changed

3 files changed

+3
-40
lines changed

clang/docs/analyzer/developer-docs/Statistics.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ However, note that with ``LLVM_ENABLE_STATS`` disabled, only storage of the valu
2222
If you want to define a statistic only for entry point, EntryPointStats.h has four classes at your disposal:
2323

2424

25-
- ``BoolEPStat`` - a boolean value assigned at most once per entry point. For example: "has the inline limit been reached".
2625
- ``UnsignedEPStat`` - an unsigned value assigned at most once per entry point. For example: "the number of source characters in an entry-point body".
2726
- ``CounterEPStat`` - an additive statistic. It starts with 0 and you can add to it as many times as needed. For example: "the number of bugs discovered".
2827
- ``UnsignedMaxEPStat`` - a maximizing statistic. It starts with 0 and when you join it with a value, it picks the maximum of the previous value and the new one. For example, "the longest execution path of a bug".

clang/include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,6 @@ class EntryPointStat {
4242
llvm::StringLiteral Name;
4343
};
4444

45-
class BoolEPStat : public EntryPointStat {
46-
std::optional<bool> Value = {};
47-
48-
public:
49-
explicit BoolEPStat(llvm::StringLiteral Name);
50-
unsigned value() const { return Value && *Value; }
51-
void set(bool V) {
52-
assert(!Value.has_value());
53-
Value = V;
54-
}
55-
void reset() { Value = {}; }
56-
};
57-
5845
// used by CounterEntryPointTranslationUnitStat
5946
class CounterEPStat : public EntryPointStat {
6047
using EntryPointStat::EntryPointStat;

clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ using namespace ento;
2424

2525
namespace {
2626
struct Registry {
27-
std::vector<BoolEPStat *> BoolStats;
2827
std::vector<CounterEPStat *> CounterStats;
2928
std::vector<UnsignedMaxEPStat *> UnsignedMaxStats;
3029
std::vector<UnsignedEPStat *> UnsignedStats;
@@ -33,7 +32,6 @@ struct Registry {
3332

3433
struct Snapshot {
3534
const Decl *EntryPoint;
36-
std::vector<bool> BoolStatValues;
3735
std::vector<unsigned> UnsignedStatValues;
3836

3937
void dumpAsCSV(llvm::raw_ostream &OS) const;
@@ -48,7 +46,6 @@ static llvm::ManagedStatic<Registry> StatsRegistry;
4846

4947
namespace {
5048
template <typename Callback> void enumerateStatVectors(const Callback &Fn) {
51-
Fn(StatsRegistry->BoolStats);
5249
Fn(StatsRegistry->CounterStats);
5350
Fn(StatsRegistry->UnsignedMaxStats);
5451
Fn(StatsRegistry->UnsignedStats);
@@ -94,12 +91,6 @@ void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
9491
return Result;
9592
}
9693

97-
BoolEPStat::BoolEPStat(llvm::StringLiteral Name) : EntryPointStat(Name) {
98-
assert(!StatsRegistry->IsLocked);
99-
assert(!isRegistered(Name));
100-
StatsRegistry->BoolStats.push_back(this);
101-
}
102-
10394
CounterEPStat::CounterEPStat(llvm::StringLiteral Name) : EntryPointStat(Name) {
10495
assert(!StatsRegistry->IsLocked);
10596
assert(!isRegistered(Name));
@@ -165,28 +156,14 @@ void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &OS) const {
165156
OS << StatsRegistry->EscapedCPPFileName << "\",\"";
166157
llvm::printEscapedString(
167158
clang::AnalysisDeclContext::getFunctionName(EntryPoint), OS);
168-
OS << "\",";
169-
auto PrintAsBool = [&OS](bool B) { OS << (B ? "true" : "false"); };
170-
llvm::interleave(BoolStatValues, OS, PrintAsBool, ",");
171-
OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ",");
159+
OS << "\"";
160+
OS << (UnsignedStatValues.empty() ? "" : ",");
172161
llvm::interleave(UnsignedStatValues, OS, [&OS](unsigned U) { OS << U; }, ",");
173162
}
174163

175-
static std::vector<bool> consumeBoolStats() {
176-
std::vector<bool> Result;
177-
Result.reserve(StatsRegistry->BoolStats.size());
178-
for (auto *M : StatsRegistry->BoolStats) {
179-
Result.push_back(M->value());
180-
M->reset();
181-
}
182-
return Result;
183-
}
184-
185164
void EntryPointStat::takeSnapshot(const Decl *EntryPoint) {
186-
auto BoolValues = consumeBoolStats();
187165
auto UnsignedValues = consumeUnsignedStats();
188-
StatsRegistry->Snapshots.push_back(
189-
{EntryPoint, std::move(BoolValues), std::move(UnsignedValues)});
166+
StatsRegistry->Snapshots.push_back({EntryPoint, std::move(UnsignedValues)});
190167
}
191168

192169
void EntryPointStat::dumpStatsAsCSV(llvm::StringRef FileName) {

0 commit comments

Comments
 (0)