diff options
author | Dmitriy Chestnykh <dm.chestnykh@gmail.com> | 2024-07-11 11:48:58 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-11 16:48:58 +0800 |
commit | bf4167fd1d06ff68da2cbea210a4ccfa045694d3 (patch) | |
tree | 76b2f1d21a938ac3e24fb527e16c259b5b77855c /clang/lib/Frontend/FrontendActions.cpp | |
parent | d4e46f0e864e37085da0c5e56e4f6f278e2f7aee (diff) | |
download | llvm-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.cpp | 11 |
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; |