diff --git a/flang/lib/Lower/Allocatable.cpp b/flang/lib/Lower/Allocatable.cpp --- a/flang/lib/Lower/Allocatable.cpp +++ b/flang/lib/Lower/Allocatable.cpp @@ -220,7 +220,7 @@ : fir::runtime::getRuntimeFunc( loc, builder); llvm::SmallVector args{ - box.getAddr(), fir::getBase(mold), + fir::factory::getMutableIRBox(builder, loc, box), fir::getBase(mold), builder.createIntegerConstant( loc, callee.getFunctionType().getInputs()[2], rank)}; llvm::SmallVector operands; diff --git a/flang/test/Lower/allocate-mold.f90 b/flang/test/Lower/allocate-mold.f90 new file mode 100644 --- /dev/null +++ b/flang/test/Lower/allocate-mold.f90 @@ -0,0 +1,19 @@ +! RUN: bbc -emit-fir %s -o - | FileCheck %s + +! Test lowering of ALLOCATE statement with a MOLD argument for scalars + +subroutine scalar_mold_allocation() + integer, allocatable :: a + allocate(a, mold=9) +end subroutine + +! CHECK-LABEL: func.func @_QPscalar_mold_allocation() { +! CHECK: %[[A:.*]] = fir.alloca !fir.box> {bindc_name = "a", uniq_name = "_QFscalar_mold_allocationEa"} +! CHECK: %[[HEAP_A:.*]] = fir.alloca !fir.heap {uniq_name = "_QFscalar_mold_allocationEa.addr"} +! CHECK: %[[ADDR_A:.*]] = fir.load %[[HEAP_A]] : !fir.ref> +! CHECK: %[[BOX_ADDR_A:.*]] = fir.embox %[[ADDR_A]] : (!fir.heap) -> !fir.box> +! CHECK: fir.store %[[BOX_ADDR_A]] to %[[A]] : !fir.ref>> +! CHECK: %[[A_REF_BOX_NONE1:.*]] = fir.convert %[[A]] : (!fir.ref>>) -> !fir.ref> +! CHECK: %{{.*}} = fir.call @_FortranAAllocatableApplyMold(%[[A_REF_BOX_NONE1]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, !fir.box, i32) -> none +! CHECK: %[[A_REF_BOX_NONE2:.*]] = fir.convert %[[A]] : (!fir.ref>>) -> !fir.ref> +! CHECK: %{{.*}} = fir.call @_FortranAAllocatableAllocate(%[[A_REF_BOX_NONE2]], %{{.*}}, %{{.*}}, %{{.*}}, %{{.*}}) {{.*}} : (!fir.ref>, i1, !fir.box, !fir.ref, i32) -> i32