Skip to content

Commit a08b094

Browse files
authored
[clang][analyzer] Record entry-point CFG size in per-entry-point metrics (#163351)
MaxCFGSize does not make sense in the context of per-entry-point metric. Moreover, it gets polluted by the syntax-only checks that run before path-sensitive analysis: the first entry point analized by path-sensitive analysis will have MaxCFGSize set to the max CFG across all syntax-only-analyzed entry points, which has little meaning. This change unbundles the per-TU statistic MaxCFGSize and per-EP statistic CFGSize. -- CPP-7099
1 parent 7bbb4a5 commit a08b094

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ ALWAYS_ENABLED_STATISTIC(
6262
"The # of visited basic blocks in the analyzed functions.");
6363
ALWAYS_ENABLED_STATISTIC(PercentReachableBlocks,
6464
"The % of reachable basic blocks.");
65-
STAT_MAX(MaxCFGSize, "The maximum number of basic blocks in a function.");
65+
ALWAYS_ENABLED_STATISTIC(MaxCFGSize,
66+
"The maximum number of basic blocks in a function.");
67+
static UnsignedEPStat CFGSize("CFGSize");
6668
//===----------------------------------------------------------------------===//
6769
// AnalysisConsumer declaration.
6870
//===----------------------------------------------------------------------===//
@@ -783,15 +785,19 @@ void AnalysisConsumer::HandleCode(Decl *D, AnalysisMode Mode,
783785
void AnalysisConsumer::RunPathSensitiveChecks(Decl *D,
784786
ExprEngine::InliningModes IMode,
785787
SetOfConstDecls *VisitedCallees) {
788+
auto *CFG = Mgr->getCFG(D);
789+
786790
// Construct the analysis engine. First check if the CFG is valid.
787791
// FIXME: Inter-procedural analysis will need to handle invalid CFGs.
788-
if (!Mgr->getCFG(D))
792+
if (!CFG)
789793
return;
790794

791795
// See if the LiveVariables analysis scales.
792796
if (!Mgr->getAnalysisDeclContext(D)->getAnalysis<RelaxedLiveVariables>())
793797
return;
794798

799+
CFGSize.set(CFG->size());
800+
795801
ExprEngine Eng(CTU, *Mgr, VisitedCallees, &FunctionSummaries, IMode);
796802

797803
// Execute the worklist algorithm.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
// CHECK-NEXT: "c:@F@fib#i#": {
99
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
1010
// CHECK-NEXT: "DebugName": "fib(unsigned int)",
11+
// CHECK-NEXT: "CFGSize": "5",
1112
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}",
1213
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
13-
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
1414
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
1515
// CHECK-NEXT: "MaxReachableSize": "{{[0-9]+}}",
1616
// CHECK-NEXT: "MaxTimeSpentSolvingZ3Queries": "{{[0-9]+}}",
@@ -45,9 +45,9 @@
4545
// CHECK-NEXT: "c:@F@main#I#**C#": {
4646
// CHECK-NEXT: "File": "{{.*}}entry-point-stats.cpp",
4747
// CHECK-NEXT: "DebugName": "main(int, char **)",
48+
// CHECK-NEXT: "CFGSize": "3",
4849
// CHECK-NEXT: "PathRunningTime": "{{[0-9]+}}",
4950
// CHECK-NEXT: "MaxBugClassSize": "{{[0-9]+}}",
50-
// CHECK-NEXT: "MaxCFGSize": "{{[0-9]+}}",
5151
// CHECK-NEXT: "MaxQueueSize": "{{[0-9]+}}",
5252
// CHECK-NEXT: "MaxReachableSize": "{{[0-9]+}}",
5353
// CHECK-NEXT: "MaxTimeSpentSolvingZ3Queries": "{{[0-9]+}}",

0 commit comments

Comments
 (0)