[flang-commits] [flang] 8735e69 - [flang] OPTIONAL char dummy has no defining op; add null check (#182582)

via flang-commits flang-commits at lists.llvm.org
Fri Feb 20 12:22:23 PST 2026


Author: tedj
Date: 2026-02-20T20:22:18Z
New Revision: 8735e69f1e9fe196e6dd47449112235387c56e4c

URL: https://github.com/llvm/llvm-project/commit/8735e69f1e9fe196e6dd47449112235387c56e4c
DIFF: https://github.com/llvm/llvm-project/commit/8735e69f1e9fe196e6dd47449112235387c56e4c.diff

LOG: [flang] OPTIONAL char dummy has no defining op; add null check (#182582)

size.getDefiningOp() returns nullptr for block arguments when a OPTIONAL
character length generated the conditional "fir.if". Check for a nullptr
before calling mlir::isa<> to avoid the crash.

Addresses: https://github.com/llvm/llvm-project/issues/182436
Passes check-flang, check-flang-rt, and llvm-test-suite (x86_64)

---------

Co-authored-by: Valentin Clement (バレンタイン クレメン) <clementval at gmail.com>

Added: 
    

Modified: 
    flang/lib/Optimizer/CodeGen/CodeGen.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 93f3806b18648..1c5cc3cc1b306 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -319,7 +319,9 @@ struct AllocaOpConversion : public fir::FIROpConversion<fir::AllocaOp> {
     unsigned allocaAs = getAllocaAddressSpace(rewriter);
     unsigned programAs = getProgramAddressSpace(rewriter);
 
-    if (mlir::isa<mlir::LLVM::ConstantOp>(size.getDefiningOp())) {
+    // A value defined by a block arg, such as fir.if for a
+    // optional assumed character dummy len, doesn't have a defining op.
+    if (mlir::isa_and_nonnull<mlir::LLVM::ConstantOp>(size.getDefiningOp())) {
       // Set the Block in which the llvm alloca should be inserted.
       mlir::Operation *parentOp = rewriter.getInsertionBlock()->getParentOp();
       mlir::Region *parentRegion = rewriter.getInsertionBlock()->getParent();


        


More information about the flang-commits mailing list