[flang-commits] [flang] 723cd2e - Fix potential crash in Flang generateLLVMIR() when MLIR fails to translate to LLVM
Mehdi Amini via flang-commits
flang-commits at lists.llvm.org
Sun Feb 19 08:56:34 PST 2023
Author: Mehdi Amini
Date: 2023-02-19T08:55:46-08:00
New Revision: 723cd2e953d245ca9d6df6c4f3852d3ebbe0b253
URL: https://github.com/llvm/llvm-project/commit/723cd2e953d245ca9d6df6c4f3852d3ebbe0b253
DIFF: https://github.com/llvm/llvm-project/commit/723cd2e953d245ca9d6df6c4f3852d3ebbe0b253.diff
LOG: Fix potential crash in Flang generateLLVMIR() when MLIR fails to translate to LLVM
This is pure code motion, to ensure that the check if we have a valid llvmModule
comes before trying to set option on this module.
Differential Revision: https://reviews.llvm.org/D144342
Added:
Modified:
flang/lib/Frontend/FrontendActions.cpp
Removed:
################################################################################
diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 79183c6e8f14a..eba5515c975fb 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -560,6 +560,13 @@ void CodeGenAction::generateLLVMIR() {
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<llvm::PICLevel::Level>(opts.PICLevel));
@@ -568,12 +575,6 @@ void CodeGenAction::generateLLVMIR() {
static_cast<llvm::PIELevel::Level>(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() {
More information about the flang-commits
mailing list