diff options
author | Qiu Chaofan <qcf@ecnelises.com> | 2025-03-29 01:54:14 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-03-29 01:54:14 +0800 |
commit | b3f01a6aa45b00240cec1c64286b85d7ba87e2af (patch) | |
tree | a56db37aa87cb9ed2b27750bac0efaa01a73e194 /clang/lib/Frontend/FrontendAction.cpp | |
parent | e70fe9b264b6f98fd3744b514d7166f75dd19872 (diff) | |
download | llvm-b3f01a6aa45b00240cec1c64286b85d7ba87e2af.zip llvm-b3f01a6aa45b00240cec1c64286b85d7ba87e2af.tar.gz llvm-b3f01a6aa45b00240cec1c64286b85d7ba87e2af.tar.bz2 |
[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.
Diffstat (limited to 'clang/lib/Frontend/FrontendAction.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendAction.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/Frontend/FrontendAction.cpp b/clang/lib/Frontend/FrontendAction.cpp index f6ad7c8..2d77f06 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"; } |