[flang-commits] [flang] [flang] OPTIONAL char dummy has no defining op; add null check (PR #182582)
via flang-commits
flang-commits at lists.llvm.org
Fri Feb 20 11:56:52 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-flang-fir-hlfir
Author: tedj (tmjbios)
<details>
<summary>Changes</summary>
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)
---
Full diff: https://github.com/llvm/llvm-project/pull/182582.diff
1 Files Affected:
- (modified) flang/lib/Optimizer/CodeGen/CodeGen.cpp (+4-1)
``````````diff
diff --git a/flang/lib/Optimizer/CodeGen/CodeGen.cpp b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
index 93f3806b18648..dc4f11d8ada8c 100644
--- a/flang/lib/Optimizer/CodeGen/CodeGen.cpp
+++ b/flang/lib/Optimizer/CodeGen/CodeGen.cpp
@@ -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())) {
// Set the Block in which the llvm alloca should be inserted.
mlir::Operation *parentOp = rewriter.getInsertionBlock()->getParentOp();
mlir::Region *parentRegion = rewriter.getInsertionBlock()->getParent();
``````````
</details>
https://github.com/llvm/llvm-project/pull/182582
More information about the flang-commits
mailing list