aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Frontend/FrontendActions.cpp
diff options
context:
space:
mode:
authorDmitriy Chestnykh <dm.chestnykh@gmail.com>2024-07-11 11:48:58 +0300
committerGitHub <noreply@github.com>2024-07-11 16:48:58 +0800
commitbf4167fd1d06ff68da2cbea210a4ccfa045694d3 (patch)
tree76b2f1d21a938ac3e24fb527e16c259b5b77855c /clang/lib/Frontend/FrontendActions.cpp
parentd4e46f0e864e37085da0c5e56e4f6f278e2f7aee (diff)
downloadllvm-bf4167fd1d06ff68da2cbea210a4ccfa045694d3.zip
llvm-bf4167fd1d06ff68da2cbea210a4ccfa045694d3.tar.gz
llvm-bf4167fd1d06ff68da2cbea210a4ccfa045694d3.tar.bz2
[Clang] Don't crash if input file is not a module. (#98439)
Currently clang crashes with `-module-file-info` and input file which is not a module Emit error instead of segfaulting. Fix #98365
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r--clang/lib/Frontend/FrontendActions.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp
index 4f06432..e70210d 100644
--- a/clang/lib/Frontend/FrontendActions.cpp
+++ b/clang/lib/Frontend/FrontendActions.cpp
@@ -841,9 +841,16 @@ static StringRef ModuleKindName(Module::ModuleKind MK) {
}
void DumpModuleInfoAction::ExecuteAction() {
- assert(isCurrentFileAST() && "dumping non-AST?");
- // Set up the output file.
CompilerInstance &CI = getCompilerInstance();
+
+ // Don't process files of type other than module to avoid crash
+ if (!isCurrentFileAST()) {
+ CI.getDiagnostics().Report(diag::err_file_is_not_module)
+ << getCurrentFile();
+ return;
+ }
+
+ // Set up the output file.
StringRef OutputFileName = CI.getFrontendOpts().OutputFile;
if (!OutputFileName.empty() && OutputFileName != "-") {
std::error_code EC;