Skip to content

[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

Merged
merged 2 commits into from
Mar 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,8 @@ Miscellaneous Bug Fixes
Miscellaneous Clang Crashes Fixed
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

- Fixed crash when ``-print-stats`` is enabled in compiling IR files. (#GH131608)

OpenACC Specific Changes
------------------------

Expand Down
12 changes: 8 additions & 4 deletions clang/lib/Frontend/FrontendAction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

Expand Down
20 changes: 20 additions & 0 deletions clang/test/Frontend/print-stats.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
// RUN: -emit-llvm -x ir /dev/null -o - 2>&1 | FileCheck %s --check-prefix=CHECK-IR
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -print-stats \
// RUN: -emit-llvm -x c /dev/null -o - 2>&1 | FileCheck %s --check-prefix=CHECK-C

// CHECK-IR: *** Source Manager Stats
// CHECK-IR: *** File Manager Stats
// CHECK-IR: *** Virtual File System Stats

// CHECK-C: *** Semantic Analysis Stats
// CHECK-C: *** Analysis Based Warnings Stats
// CHECK-C: *** AST Context Stats
// CHECK-C: *** Decl Stats
// CHECK-C: *** Stmt/Expr Stats
// CHECK-C: *** Preprocessor Stats
// CHECK-C: *** Identifier Table Stats
// CHECK-C: *** HeaderSearch Stats
// CHECK-C: *** Source Manager Stats
// CHECK-C: *** File Manager Stats
// CHECK-C: *** Virtual File System Stats