diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp --- a/flang/lib/Frontend/FrontendActions.cpp +++ b/flang/lib/Frontend/FrontendActions.cpp @@ -560,6 +560,13 @@ llvmModule = mlir::translateModuleToLLVMIR( *mlirModule, *llvmCtx, moduleName ? *moduleName : "FIRModule"); + if (!llvmModule) { + unsigned diagID = ci.getDiagnostics().getCustomDiagID( + clang::DiagnosticsEngine::Error, "failed to create the LLVM module"); + ci.getDiagnostics().Report(diagID); + return; + } + // Set PIC/PIE level LLVM module flags. if (opts.PICLevel > 0) { llvmModule->setPICLevel(static_cast(opts.PICLevel)); @@ -568,12 +575,6 @@ static_cast(opts.PICLevel)); } - if (!llvmModule) { - unsigned diagID = ci.getDiagnostics().getCustomDiagID( - clang::DiagnosticsEngine::Error, "failed to create the LLVM module"); - ci.getDiagnostics().Report(diagID); - return; - } } void CodeGenAction::setUpTargetMachine() {