-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Clang] Check PP presence when printing stats #131608
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
@llvm/pr-subscribers-clang Author: Qiu Chaofan (ecnelises) ChangesFull diff: https://github.com/llvm/llvm-project/pull/131608.diff 2 Files Affected:
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
|
Thanks working on this! Can you add some description for this patch? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the fix!
Second, that we need a summary explaining the problem and solution.
Is this linked to a bug report, if it is, then we should mention that bug report as well.
I would also like to see a test showing a case where we successfully print the preprocessor stats as well, if we don't already have one.
c7d48ef
to
60b1e16
Compare
This change needs a release note. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Will you need me to merge this for you?
Done, thanks! |
LGTM! Thanks for the fix |
Front-end option
-print-stats
can be used to print statistics around the compilation process. But clang with this options will crash when input is IR file. This patch fixes the crash by checking preprocessor presence before invoking it.