Skip to content

Commit 60b1e16

Browse files
committed
[Clang] Check PP presence when printing stats
1 parent 5d8e8e8 commit 60b1e16

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

clang/lib/Frontend/FrontendAction.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,10 +1120,14 @@ void FrontendAction::EndSourceFile() {
11201120

11211121
if (CI.getFrontendOpts().ShowStats) {
11221122
llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFileOrBufferName() << "':\n";
1123-
CI.getPreprocessor().PrintStats();
1124-
CI.getPreprocessor().getIdentifierTable().PrintStats();
1125-
CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
1126-
CI.getSourceManager().PrintStats();
1123+
if (CI.hasPreprocessor()) {
1124+
CI.getPreprocessor().PrintStats();
1125+
CI.getPreprocessor().getIdentifierTable().PrintStats();
1126+
CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
1127+
}
1128+
if (CI.hasSourceManager()) {
1129+
CI.getSourceManager().PrintStats();
1130+
}
11271131
llvm::errs() << "\n";
11281132
}
11291133

clang/test/Frontend/print-stats.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
2+
// RUN: -emit-llvm -x ir /dev/null -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IR
3+
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
4+
// RUN: -emit-llvm -x c /dev/null -o - 2>&1 | FileCheck %s --check-prefix=CHECK-C
5+
6+
// CHECK-IR: *** Source Manager Stats
7+
// CHECK-IR: *** File Manager Stats
8+
// CHECK-IR: *** Virtual File System Stats
9+
10+
// CHECK-C: *** Semantic Analysis Stats
11+
// CHECK-C: *** Analysis Based Warnings Stats
12+
// CHECK-C: *** AST Context Stats
13+
// CHECK-C: *** Decl Stats
14+
// CHECK-C: *** Stmt/Expr Stats
15+
// CHECK-C: *** Preprocessor Stats
16+
// CHECK-C: *** Identifier Table Stats
17+
// CHECK-C: *** HeaderSearch Stats
18+
// CHECK-C: *** Source Manager Stats
19+
// CHECK-C: *** File Manager Stats
20+
// CHECK-C: *** Virtual File System Stats

0 commit comments

Comments
 (0)