[flang-commits] [flang] [flang] Fix seg fault `CodeGenAction::executeAction()` (PR #78269)

Kareem Ergawy via flang-commits flang-commits at lists.llvm.org
Tue Jan 16 04:59:39 PST 2024


https://github.com/ergawy created https://github.com/llvm/llvm-project/pull/78269

If `generateLLVMIR()` fails, we still continue using the module we failed to generate which causes a seg fault if LLVM code-gen failed for some reason or another. This commit fixes this issue.

>From 7cdb5588154e1714ad14e229dfb16af2072e9f2e Mon Sep 17 00:00:00 2001
From: ergawy <kareem.ergawy at amd.com>
Date: Tue, 16 Jan 2024 06:56:23 -0600
Subject: [PATCH] [flang] Fix seg fault `CodeGenAction::executeAction()`

If `generateLLVMIR()` fails, we still continue using the module we
failed to generate which causes a seg fault if LLVM code-gen failed for
some reason or another. This commit fixes this issue.
---
 flang/lib/Frontend/FrontendActions.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/flang/lib/Frontend/FrontendActions.cpp b/flang/lib/Frontend/FrontendActions.cpp
index 74e3992d5ab62ba..65c4df7388f97b2 100644
--- a/flang/lib/Frontend/FrontendActions.cpp
+++ b/flang/lib/Frontend/FrontendActions.cpp
@@ -1202,6 +1202,11 @@ void CodeGenAction::executeAction() {
   if (!llvmModule)
     generateLLVMIR();
 
+  // If generating the LLVM module failed, abort! No need for further error
+  // reporting since generateLLVMIR() does this already.
+  if (!llvmModule)
+    return;
+
   // Set the triple based on the targetmachine (this comes compiler invocation
   // and the command-line target option if specified, or the default if not
   // given on the command-line).



More information about the flang-commits mailing list