-
Notifications
You must be signed in to change notification settings - Fork 15.2k
Revert "[clang][analyzer] Make per-entry-point metric rows uniquely identifiable" #161857
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…dentifiable" This reverts commit cf86ef9.
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-static-analyzer-1 Author: Balazs Benics (steakhal) ChangesReverts llvm/llvm-project#161663 See the comment
Full diff: https://github.com/llvm/llvm-project/pull/161857.diff 4 Files Affected:
diff --git a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h
index 448e40269ca2d..633fb7aa8f72d 100644
--- a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h
+++ b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h
@@ -25,7 +25,7 @@ class EntryPointStat {
public:
llvm::StringLiteral name() const { return Name; }
- static void lockRegistry(llvm::StringRef CPPFileName);
+ static void lockRegistry();
static void takeSnapshot(const Decl *EntryPoint);
static void dumpStatsAsCSV(llvm::raw_ostream &OS);
diff --git a/clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp b/clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp
index 62ae62f2f2154..b7f9044f65308 100644
--- a/clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp
+++ b/clang/lib/StaticAnalyzer/Core/EntryPointStats.cpp
@@ -9,9 +9,7 @@
#include "clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h"
#include "clang/AST/DeclBase.h"
#include "clang/Analysis/AnalysisDeclContext.h"
-#include "clang/Index/USRGeneration.h"
#include "llvm/ADT/STLExtras.h"
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/FileSystem.h"
@@ -40,7 +38,6 @@ struct Registry {
};
std::vector<Snapshot> Snapshots;
- std::string EscapedCPPFileName;
};
} // namespace
@@ -72,7 +69,7 @@ static void checkStatName(const EntryPointStat *M) {
}
}
-void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
+void EntryPointStat::lockRegistry() {
auto CmpByNames = [](const EntryPointStat *L, const EntryPointStat *R) {
return L->name() < R->name();
};
@@ -81,8 +78,6 @@ void EntryPointStat::lockRegistry(llvm::StringRef CPPFileName) {
enumerateStatVectors(
[](const auto &Stats) { llvm::for_each(Stats, checkStatName); });
StatsRegistry->IsLocked = true;
- llvm::raw_string_ostream OS(StatsRegistry->EscapedCPPFileName);
- llvm::printEscapedString(CPPFileName, OS);
}
[[maybe_unused]] static bool isRegistered(llvm::StringLiteral Name) {
@@ -149,27 +144,15 @@ static std::vector<llvm::StringLiteral> getStatNames() {
return Ret;
}
-static std::string getUSR(const Decl *D) {
- llvm::SmallVector<char> Buf;
- if (index::generateUSRForDecl(D, Buf)) {
- assert(false && "This should never fail");
- return AnalysisDeclContext::getFunctionName(D);
- }
- return llvm::toStringRef(Buf).str();
-}
-
void Registry::Snapshot::dumpAsCSV(llvm::raw_ostream &OS) const {
OS << '"';
- llvm::printEscapedString(getUSR(EntryPoint), OS);
- OS << "\",\"";
- OS << StatsRegistry->EscapedCPPFileName << "\",\"";
llvm::printEscapedString(
clang::AnalysisDeclContext::getFunctionName(EntryPoint), OS);
- OS << "\",";
+ OS << "\", ";
auto PrintAsBool = [&OS](bool B) { OS << (B ? "true" : "false"); };
- llvm::interleave(BoolStatValues, OS, PrintAsBool, ",");
- OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ",");
- llvm::interleave(UnsignedStatValues, OS, [&OS](unsigned U) { OS << U; }, ",");
+ llvm::interleaveComma(BoolStatValues, OS, PrintAsBool);
+ OS << ((BoolStatValues.empty() || UnsignedStatValues.empty()) ? "" : ", ");
+ llvm::interleaveComma(UnsignedStatValues, OS);
}
static std::vector<bool> consumeBoolStats() {
@@ -198,8 +181,8 @@ void EntryPointStat::dumpStatsAsCSV(llvm::StringRef FileName) {
}
void EntryPointStat::dumpStatsAsCSV(llvm::raw_ostream &OS) {
- OS << "USR,File,DebugName,";
- llvm::interleave(getStatNames(), OS, [&OS](const auto &a) { OS << a; }, ",");
+ OS << "EntryPoint, ";
+ llvm::interleaveComma(getStatNames(), OS);
OS << "\n";
std::vector<std::string> Rows;
diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
index cf01e2f37c662..3f296aae0ae5f 100644
--- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
+++ b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
@@ -68,15 +68,6 @@ STAT_MAX(MaxCFGSize, "The maximum number of basic blocks in a function.");
namespace {
-StringRef getMainFileName(const CompilerInvocation &Invocation) {
- if (!Invocation.getFrontendOpts().Inputs.empty()) {
- const FrontendInputFile &Input = Invocation.getFrontendOpts().Inputs[0];
- return Input.isFile() ? Input.getFile()
- : Input.getBuffer().getBufferIdentifier();
- }
- return "<no input>";
-}
-
class AnalysisConsumer : public AnalysisASTConsumer,
public DynamicRecursiveASTVisitor {
enum {
@@ -137,8 +128,7 @@ class AnalysisConsumer : public AnalysisASTConsumer,
PP(CI.getPreprocessor()), OutDir(outdir), Opts(opts), Plugins(plugins),
Injector(std::move(injector)), CTU(CI),
MacroExpansions(CI.getLangOpts()) {
-
- EntryPointStat::lockRegistry(getMainFileName(CI.getInvocation()));
+ EntryPointStat::lockRegistry();
DigestAnalyzerOptions();
if (Opts.AnalyzerDisplayProgress || Opts.PrintStats ||
diff --git a/clang/test/Analysis/analyzer-stats/entry-point-stats.cpp b/clang/test/Analysis/analyzer-stats/entry-point-stats.cpp
index 9cbe04550a8d3..1ff31d114ee99 100644
--- a/clang/test/Analysis/analyzer-stats/entry-point-stats.cpp
+++ b/clang/test/Analysis/analyzer-stats/entry-point-stats.cpp
@@ -5,9 +5,7 @@
// RUN: %csv2json "%t.csv" | FileCheck --check-prefix=CHECK %s
//
// CHECK: {
-// CHECK-NEXT: "c:@F@fib#i#": {
-// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
-// CHECK-NEXT: "DebugName": "fib(unsigned int)",
+// CHECK-NEXT: "fib(unsigned int)": {
// CHECK-NEXT: "NumBlocks": "{{[0-9]+}}",
// CHECK-NEXT: "NumBlocksUnreachable": "{{[0-9]+}}",
// CHECK-NEXT: "NumCTUSteps": "{{[0-9]+}}",
@@ -42,9 +40,7 @@
// CHECK-NEXT: "MaxValidBugClassSize": "{{[0-9]+}}",
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}"
// CHECK-NEXT: },
-// CHECK-NEXT: "c:@F@main#I#**C#": {
-// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
-// CHECK-NEXT: "DebugName": "main(int, char **)",
+// CHECK-NEXT: "main(int, char **)": {
// CHECK-NEXT: "NumBlocks": "{{[0-9]+}}",
// CHECK-NEXT: "NumBlocksUnreachable": "{{[0-9]+}}",
// CHECK-NEXT: "NumCTUSteps": "{{[0-9]+}}",
|
Auto-merging. |
I can submit a quick fix if needed.
|
I just pushed my fix. |
Awesome. Im away at the moment. Could you submit a patch and merge that please? |
Reverts #161663
https://lab.llvm.org/buildbot/#/builders/206/builds/7031/steps/7/logs/stdio
See the comment
#161663 (comment)