diff options
author | Naveen Seth Hanig <naveen.hanig@outlook.com> | 2025-04-29 05:22:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-29 11:22:34 +0800 |
commit | 7ce0f5a9cc37345fee801736bded83081b61571b (patch) | |
tree | b9d7374ab9f6009ae1c1e9a02e8d8bf87b95a985 /clang/lib/Frontend/FrontendActions.cpp | |
parent | a37e475efc223bae903dc80373b0e36317f4bc7e (diff) | |
download | llvm-7ce0f5a9cc37345fee801736bded83081b61571b.zip llvm-7ce0f5a9cc37345fee801736bded83081b61571b.tar.gz llvm-7ce0f5a9cc37345fee801736bded83081b61571b.tar.bz2 |
[clang][modules] Validate input file format for GenerateModuleInterfaceAction (#132692) (#137711)
Fixes #132692.
`clang -cc1` crashes when generating a module interface with
`emit-module-interface` or `emit-reduced-module-interface` using an
input file which is already a precompiled module (`.pcm`) file.
This commit adds validation for the input file format and Clang will now
emit an error message instead of crashing.
Diffstat (limited to 'clang/lib/Frontend/FrontendActions.cpp')
-rw-r--r-- | clang/lib/Frontend/FrontendActions.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/Frontend/FrontendActions.cpp b/clang/lib/Frontend/FrontendActions.cpp index e6c7b9f..51e9f2c 100644 --- a/clang/lib/Frontend/FrontendActions.cpp +++ b/clang/lib/Frontend/FrontendActions.cpp @@ -263,6 +263,20 @@ GenerateModuleFromModuleMapAction::CreateOutputFile(CompilerInstance &CI, /*ForceUseTemporary=*/true); } +bool GenerateModuleInterfaceAction::PrepareToExecuteAction( + CompilerInstance &CI) { + for (const auto &FIF : CI.getFrontendOpts().Inputs) { + if (const auto InputFormat = FIF.getKind().getFormat(); + InputFormat != InputKind::Format::Source) { + CI.getDiagnostics().Report( + diag::err_frontend_action_unsupported_input_format) + << "module interface compilation" << FIF.getFile() << InputFormat; + return false; + } + } + return GenerateModuleAction::PrepareToExecuteAction(CI); +} + bool GenerateModuleInterfaceAction::BeginSourceFileAction( CompilerInstance &CI) { CI.getLangOpts().setCompilingModule(LangOptions::CMK_ModuleInterface); |