Skip to content

Commit e050aee

Browse files
authored
Revert "[clang][analyzer] Make per-entry-point metric rows uniquely identifiable"
This reverts commit cf86ef9.
1 parent 78739ff commit e050aee

File tree

4 files changed

+11
-42
lines changed

4 files changed

+11
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class EntryPointStat {
2525
public:
2626
llvm::StringLiteral name() const { return Name; }
2727

28-
static void lockRegistry(llvm::StringRef CPPFileName);
28+
static void lockRegistry();
2929

3030
static void takeSnapshot(const Decl *EntryPoint);
3131
static void dumpStatsAsCSV(llvm::raw_ostream &OS);

clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
#include "clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h"
1010
#include "clang/AST/DeclBase.h"
1111
#include "clang/Analysis/AnalysisDeclContext.h"
12-
#include "clang/Index/USRGeneration.h"
1312
#include "llvm/ADT/STLExtras.h"
14-
#include "llvm/ADT/SmallVector.h"
1513
#include "llvm/ADT/StringExtras.h"
1614
#include "llvm/ADT/StringRef.h"
1715
#include "llvm/Support/FileSystem.h"
@@ -40,7 +38,6 @@ struct Registry {
4038
};
4139

4240
std::vector<Snapshot> Snapshots;
43-
std::string EscapedCPPFileName;
4441
};
4542
} // namespace
4643

@@ -72,7 +69,7 @@ static void checkStatName(const EntryPointStat *M) {
7269
}
7370
}
7471

75-
void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
72+
void EntryPointStat::lockRegistry() {
7673
auto CmpByNames = [](const EntryPointStat *L, const EntryPointStat *R) {
7774
return L->name() < R->name();
7875
};
@@ -81,8 +78,6 @@ void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
8178
enumerateStatVectors(
8279
[](const auto &Stats) { llvm::for_each(Stats, checkStatName); });
8380
StatsRegistry->IsLocked = true;
84-
llvm::raw_string_ostream OS(StatsRegistry->EscapedCPPFileName);
85-
llvm::printEscapedString(CPPFileName, OS);
8681
}
8782

8883
[[maybe_unused]] static bool isRegistered(llvm::StringLiteral Name) {
@@ -149,27 +144,15 @@ static std::vector<llvm::StringLiteral> getStatNames() {
149144
return Ret;
150145
}
151146

152-
static std::string getUSR(const Decl *D) {
153-
llvm::SmallVector<char> Buf;
154-
if (index::generateUSRForDecl(D, Buf)) {
155-
assert(false && "This should never fail");
156-
return AnalysisDeclContext::getFunctionName(D);
157-
}
158-
return llvm::toStringRef(Buf).str();
159-
}
160-
161147
void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &OS) const {
162148
OS << '"';
163-
llvm::printEscapedString(getUSR(EntryPoint), OS);
164-
OS << "\",\"";
165-
OS << StatsRegistry->EscapedCPPFileName << "\",\"";
166149
llvm::printEscapedString(
167150
clang::AnalysisDeclContext::getFunctionName(EntryPoint), OS);
168-
OS << "\",";
151+
OS << "\", ";
169152
auto PrintAsBool = [&OS](bool B) { OS << (B ? "true" : "false"); };
170-
llvm::interleave(BoolStatValues, OS, PrintAsBool, ",");
171-
OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ",");
172-
llvm::interleave(UnsignedStatValues, OS, [&OS](unsigned U) { OS << U; }, ",");
153+
llvm::interleaveComma(BoolStatValues, OS, PrintAsBool);
154+
OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ", ");
155+
llvm::interleaveComma(UnsignedStatValues, OS);
173156
}
174157

175158
static std::vector<bool> consumeBoolStats() {
@@ -198,8 +181,8 @@ void EntryPointStat::dumpStatsAsCSV(llvm::StringRef FileName) {
198181
}
199182

200183
void EntryPointStat::dumpStatsAsCSV(llvm::raw_ostream &OS) {
201-
OS << "USR,File,DebugName,";
202-
llvm::interleave(getStatNames(), OS, [&OS](const auto &a) { OS << a; }, ",");
184+
OS << "EntryPoint, ";
185+
llvm::interleaveComma(getStatNames(), OS);
203186
OS << "\n";
204187

205188
std::vector<std::string> Rows;

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ STAT_MAX(MaxCFGSize, "The maximum number of basic blocks in a function.");
6868

6969
namespace {
7070

71-
StringRef getMainFileName(const CompilerInvocation &Invocation) {
72-
if (!Invocation.getFrontendOpts().Inputs.empty()) {
73-
const FrontendInputFile &Input = Invocation.getFrontendOpts().Inputs[0];
74-
return Input.isFile() ? Input.getFile()
75-
: Input.getBuffer().getBufferIdentifier();
76-
}
77-
return "<no input>";
78-
}
79-
8071
class AnalysisConsumer : public AnalysisASTConsumer,
8172
public DynamicRecursiveASTVisitor {
8273
enum {
@@ -137,8 +128,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
137128
PP(CI.getPreprocessor()), OutDir(outdir), Opts(opts), Plugins(plugins),
138129
Injector(std::move(injector)), CTU(CI),
139130
MacroExpansions(CI.getLangOpts()) {
140-
141-
EntryPointStat::lockRegistry(getMainFileName(CI.getInvocation()));
131+
EntryPointStat::lockRegistry();
142132
DigestAnalyzerOptions();
143133

144134
if (Opts.AnalyzerDisplayProgress || Opts.PrintStats ||

clang/test/Analysis/analyzer-stats/entry-point-stats.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
// RUN: %csv2json "%t.csv" | FileCheck --check-prefix=CHECK %s
66
//
77
// CHECK: {
8-
// CHECK-NEXT: "c:@F@fib#i#": {
9-
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
10-
// CHECK-NEXT: "DebugName": "fib(unsigned int)",
8+
// CHECK-NEXT: "fib(unsigned int)": {
119
// CHECK-NEXT: "NumBlocks": "{{[0-9]+}}",
1210
// CHECK-NEXT: "NumBlocksUnreachable": "{{[0-9]+}}",
1311
// CHECK-NEXT: "NumCTUSteps": "{{[0-9]+}}",
@@ -42,9 +40,7 @@
4240
// CHECK-NEXT: "MaxValidBugClassSize": "{{[0-9]+}}",
4341
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}"
4442
// CHECK-NEXT: },
45-
// CHECK-NEXT: "c:@F@main#I#**C#": {
46-
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
47-
// CHECK-NEXT: "DebugName": "main(int, char **)",
43+
// CHECK-NEXT: "main(int, char **)": {
4844
// CHECK-NEXT: "NumBlocks": "{{[0-9]+}}",
4945
// CHECK-NEXT: "NumBlocksUnreachable": "{{[0-9]+}}",
5046
// CHECK-NEXT: "NumCTUSteps": "{{[0-9]+}}",

0 commit comments

Comments
 (0)