[clang] [Clang] Check PP presence when printing stats (PR #131608)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Mar 17 05:55:13 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Qiu Chaofan (ecnelises)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/131608.diff
2 Files Affected:
- (modified) clang/lib/Frontend/FrontendAction.cpp (+8-4)
- (added) clang/test/Frontend/print-stats.ll (+6)
``````````diff
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp
index 9f789f093f55d..a750953393759 100644
--- a/clang/lib/Frontend/FrontendAction.cpp
+++ b/clang/lib/Frontend/FrontendAction.cpp
@@ -1120,10 +1120,14 @@ void FrontendAction::EndSourceFile() {
if (CI.getFrontendOpts().ShowStats) {
llvm::errs() << "\nSTATISTICS FOR '" << getCurrentFileOrBufferName() << "':\n";
- CI.getPreprocessor().PrintStats();
- CI.getPreprocessor().getIdentifierTable().PrintStats();
- CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
- CI.getSourceManager().PrintStats();
+ if (CI.hasPreprocessor()) {
+ CI.getPreprocessor().PrintStats();
+ CI.getPreprocessor().getIdentifierTable().PrintStats();
+ CI.getPreprocessor().getHeaderSearchInfo().PrintStats();
+ }
+ if (CI.hasSourceManager()) {
+ CI.getSourceManager().PrintStats();
+ }
llvm::errs() << "\n";
}
diff --git a/clang/test/Frontend/print-stats.ll b/clang/test/Frontend/print-stats.ll
new file mode 100644
index 0000000000000..6fd094470ba95
--- /dev/null
+++ b/clang/test/Frontend/print-stats.ll
@@ -0,0 +1,6 @@
+; RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
+; RUN: -emit-llvm -x ir %s -o - 2>&1 | FileCheck %s
+
+; CHECK: *** Source Manager Stats
+; CHECK: *** File Manager Stats
+; CHECK: *** Virtual File System Stats
``````````
</details>
https://github.com/llvm/llvm-project/pull/131608
More information about the cfe-commits
mailing list