Author: Qiu Chaofan Date: 2025-03-29T01:54:14+08:00 New Revision: b3f01a6aa45b00240cec1c64286b85d7ba87e2af
URL: https://github.com/llvm/llvm-project/commit/b3f01a6aa45b00240cec1c64286b85d7ba87e2af DIFF: https://github.com/llvm/llvm-project/commit/b3f01a6aa45b00240cec1c64286b85d7ba87e2af.diff LOG: [Clang] Check PP presence when printing stats (#131608) 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. Added: clang/test/Frontend/print-stats.c Modified: clang/docs/ReleaseNotes.rst clang/lib/Frontend/FrontendAction.cpp Removed: ################################################################################ diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index eaecead0e6b9d..e409f206f6eae 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -389,6 +389,8 @@ Miscellaneous Bug Fixes Miscellaneous Clang Crashes Fixed ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +- Fixed crash when ``-print-stats`` is enabled in compiling IR files. (#GH131608) + OpenACC Specific Changes ------------------------ diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index f6ad7c8dbd7ca..2d77f06be7446 100644 --- a/clang/lib/Frontend/FrontendAction.cpp +++ b/clang/lib/Frontend/FrontendAction.cpp @@ -1074,10 +1074,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.c b/clang/test/Frontend/print-stats.c new file mode 100644 index 0000000000000..c29717b120fc0 --- /dev/null +++ b/clang/test/Frontend/print-stats.c @@ -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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits