[clang] [clang] Report an invalid -mllvm or -mmlir argument instead of exiting (PR #229781)
Chen Miao via cfe-commits
cfe-commits at lists.llvm.org
Sun Nov 8 18:39:15 PST 2026
================
@@ -1143,10 +1143,13 @@ void CompilerInstance::parseLLVMArgs() {
for (unsigned i = 0; i != NumArgs; ++i)
Args[i + 1] = getFrontendOpts().LLVMArgs[i].c_str();
Args[NumArgs + 1] = nullptr;
- llvm::cl::parseCommandLineOptions(LibraryOptions,
- ArrayRef(Args.get(), NumArgs + 1),
- /*Overview=*/"", /*Errs=*/nullptr,
- /*VFS=*/&getVirtualFileSystem());
+ // With no stream to report to, the parser calls exit(), which ends the
+ // process that embeds clang. Keep its output where it already went.
+ if (!llvm::cl::parseCommandLineOptions(
+ LibraryOptions, ArrayRef(Args.get(), NumArgs + 1),
+ /*Overview=*/"", /*Errs=*/&llvm::errs(),
+ /*VFS=*/&getVirtualFileSystem()))
+ getDiagnostics().Report(diag::err_fe_invalid_forwarded_option) << 0;
----------------
ChenMiaoi wrote:
I think we also need to stop the current invocation and return failure here, preserving the failure behavior of the original `exit()`.
https://github.com/llvm/llvm-project/pull/229781
More information about the cfe-commits
mailing list