Skip to content

Commit c7d48ef

Browse files
committed
[Clang] Check PP presence when printing stats
1 parent 4fde8c3 commit c7d48ef

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-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.ll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
; RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
2+
; RUN: -emit-llvm -x ir %s -o - 2>&1 | FileCheck %s
3+
4+
; CHECK: *** Source Manager Stats
5+
; CHECK: *** File Manager Stats
6+
; CHECK: *** Virtual File System Stats

0 commit comments

Comments
 (0)