diff --git a/flang/lib/Optimizer/Builder/FIRBuilder.cpp b/flang/lib/Optimizer/Builder/FIRBuilder.cpp --- a/flang/lib/Optimizer/Builder/FIRBuilder.cpp +++ b/flang/lib/Optimizer/Builder/FIRBuilder.cpp @@ -1234,8 +1234,11 @@ [&](mlir::Value value) -> llvm::Optional { if (auto valInt = fir::factory::getIntIfConstant(value)) return valInt; - else if (auto valOp = mlir::dyn_cast(value.getDefiningOp())) + auto *definingOp = value.getDefiningOp(); + if (mlir::isa_and_nonnull(definingOp)) { + auto valOp = mlir::dyn_cast(definingOp); return getConstantValue(valOp.getValue()); + } return {}; }; if (auto lbInt = getConstantValue(lb)) { diff --git a/flang/test/Lower/extent_triplets.f90 b/flang/test/Lower/extent_triplets.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/extent_triplets.f90 @@ -0,0 +1,11 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +program test_extent_from_triplet + implicit none + integer, parameter:: n = 3 + INTEGER a(n), b(n), i + a = (/ 1, 2, 3 /) + b = (/ (sum(a(1:i)), i=1, n) /) +end program + +! CHECK: %{{.*}} = fir.embox %{{.*}}(%{{.*}}) [%{{.*}}] : (!fir.ref>, !fir.shape<1>, !fir.slice<1>) -> !fir.box>