Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion clang/docs/analyzer/developer-docs/Statistics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ However, note that with ``LLVM_ENABLE_STATS`` disabled, only storage of the valu
If you want to define a statistic only for entry point, EntryPointStats.h has four classes at your disposal:


- ``BoolEPStat`` - a boolean value assigned at most once per entry point. For example: "has the inline limit been reached".
- ``UnsignedEPStat`` - an unsigned value assigned at most once per entry point. For example: "the number of source characters in an entry-point body".
- ``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".
- ``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".
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,6 @@ class EntryPointStat {
llvm::StringLiteral Name;
};

class BoolEPStat : public EntryPointStat {
std::optional<bool> Value = {};

public:
explicit BoolEPStat(llvm::StringLiteral Name);
unsigned value() const { return Value && *Value; }
void set(bool V) {
assert(!Value.has_value());
Value = V;
}
void reset() { Value = {}; }
};

// used by CounterEntryPointTranslationUnitStat
class CounterEPStat : public EntryPointStat {
using EntryPointStat::EntryPointStat;
Expand Down
29 changes: 3 additions & 26 deletions clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ using namespace ento;

namespace {
struct Registry {
std::vector<BoolEPStat *> BoolStats;
std::vector<CounterEPStat *> CounterStats;
std::vector<UnsignedMaxEPStat *> UnsignedMaxStats;
std::vector<UnsignedEPStat *> UnsignedStats;
Expand All @@ -33,7 +32,6 @@ struct Registry {

struct Snapshot {
const Decl *EntryPoint;
std::vector<bool> BoolStatValues;
std::vector<unsigned> UnsignedStatValues;

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

namespace {
template <typename Callback> void enumerateStatVectors(const Callback &Fn) {
Fn(StatsRegistry->BoolStats);
Fn(StatsRegistry->CounterStats);
Fn(StatsRegistry->UnsignedMaxStats);
Fn(StatsRegistry->UnsignedStats);
Expand Down Expand Up @@ -94,12 +91,6 @@ void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
return Result;
}

BoolEPStat::BoolEPStat(llvm::StringLiteral Name) : EntryPointStat(Name) {
assert(!StatsRegistry->IsLocked);
assert(!isRegistered(Name));
StatsRegistry->BoolStats.push_back(this);
}

CounterEPStat::CounterEPStat(llvm::StringLiteral Name) : EntryPointStat(Name) {
assert(!StatsRegistry->IsLocked);
assert(!isRegistered(Name));
Expand Down Expand Up @@ -165,28 +156,14 @@ void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &OS) const {
OS << StatsRegistry->EscapedCPPFileName << "\",\"";
llvm::printEscapedString(
clang::AnalysisDeclContext::getFunctionName(EntryPoint), OS);
OS << "\",";
auto PrintAsBool = [&OS](bool B) { OS << (B ? "true" : "false"); };
llvm::interleave(BoolStatValues, OS, PrintAsBool, ",");
OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ",");
OS << "\"";
OS << (UnsignedStatValues.empty() ? "" : ",");
llvm::interleave(UnsignedStatValues, OS, [&OS](unsigned U) { OS << U; }, ",");
}

static std::vector<bool> consumeBoolStats() {
std::vector<bool> Result;
Result.reserve(StatsRegistry->BoolStats.size());
for (auto *M : StatsRegistry->BoolStats) {
Result.push_back(M->value());
M->reset();
}
return Result;
}

void EntryPointStat::takeSnapshot(const Decl *EntryPoint) {
auto BoolValues = consumeBoolStats();
auto UnsignedValues = consumeUnsignedStats();
StatsRegistry->Snapshots.push_back(
{EntryPoint, std::move(BoolValues), std::move(UnsignedValues)});
StatsRegistry->Snapshots.push_back({EntryPoint, std::move(UnsignedValues)});
}

void EntryPointStat::dumpStatsAsCSV(llvm::StringRef FileName) {
Expand Down