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,7 +1234,8 @@ [&](mlir::Value value) -> llvm::Optional { if (auto valInt = fir::factory::getIntIfConstant(value)) return valInt; - else if (auto valOp = mlir::dyn_cast(value.getDefiningOp())) + else if (auto valOp = + mlir::dyn_cast_or_null(value.getDefiningOp())) return getConstantValue(valOp.getValue()); return {}; }; diff --git a/flang/test/Lower/getExtentFromTripletFix.f90 b/flang/test/Lower/getExtentFromTripletFix.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/getExtentFromTripletFix.f90 @@ -0,0 +1,16 @@ +! Test that the get_extent_fix function works without crashing +! RUN: bbc -emit-fir %s -o - | FileCheck %s +! RUN: %flang_fc1 -emit-fir %s -o - | FileCheck %s + + +! CHECK-LABEL: func @_QPget_extent_fix +! CHECK: fir.do_loop +! CHECK: fir.call @_FortranAProductInteger +! CHECK: fir.do_loop +! CHECK: fir.array_merge_store + +subroutine get_extent_fix(map) + integer, dimension(:) :: map + integer :: counter + map = (/ (product(map(:counter)), counter = 1, sizeof(map)) /) +end subroutine