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

Valentin Clement バレンタイン クレメン via flang-commits flang-commits at lists.llvm.org
Fri Feb 20 12:01:01 PST 2026


================
@@ -319,7 +319,10 @@ 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 (auto *defOp = size.getDefiningOp();
+        defOp && mlir::isa<mlir::LLVM::ConstantOp>(size.getDefiningOp())) {
----------------
clementval wrote:

isa_and_nonnull should do it fine. 
```suggestion
    if (mlir::isa_and_nonnull<mlir::LLVM::ConstantOp>(size.getDefiningOp())) {
```

https://github.com/llvm/llvm-project/pull/182582


More information about the flang-commits mailing list