Skip to content

Commit 8466750

Browse files
authored
[flang][coarray] Fix error fir.store mismatch memory reference type in genCoBounds llvm#193131 (llvm#194870)
The error mentioned in issue llvm#193131 occurs when the lower bound of a coarray is specified and its corank is 1. A conversion operation was missing. I noticed that the hasStat argument wasn't being taken into account in Allocatable.cpp
1 parent 2359e77 commit 8466750

3 files changed

Lines changed: 19 additions & 3 deletions

File tree

flang/lib/Lower/Allocatable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ class AllocateStmtHelper {
502502
if (alloc.hasCoarraySpec()) {
503503
stat = Fortran::lower::genAllocateCoarray(
504504
converter, loc, alloc.getSymbol(), box.getAddr(),
505-
alloc.getCoarraySpec(), errorManager.errMsgAddr);
505+
alloc.getCoarraySpec(), errorManager.errMsgAddr,
506+
errorManager.hasStatSpec());
506507
} else if (!isCudaAllocate) {
507508
stat = genRuntimeAllocate(builder, loc, box, errorManager);
508509
setPinnedToFalse();
@@ -649,7 +650,8 @@ class AllocateStmtHelper {
649650
if (alloc.hasCoarraySpec()) {
650651
stat = Fortran::lower::genAllocateCoarray(
651652
converter, loc, alloc.getSymbol(), box.getAddr(),
652-
alloc.getCoarraySpec(), errorManager.errMsgAddr);
653+
alloc.getCoarraySpec(), errorManager.errMsgAddr,
654+
errorManager.hasStatSpec());
653655
} else if (Fortran::semantics::HasCUDAAttr(alloc.getSymbol()) ||
654656
sourceIsDevice) {
655657
stat =

flang/lib/Lower/MultiImageFortran.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ genCoBounds(Fortran::lower::AbstractConverter &converter, mlir::Location loc,
410410
std::get<1>(allocSpec.t)) {
411411
auto expr = Fortran::semantics::GetExpr(*lastCobound);
412412
lb = fir::getBase(converter.genExprValue(loc, expr, stmtCtx));
413+
lb = fir::ConvertOp::create(builder, loc, i64Ty, lb);
413414
}
414415
mlir::Value index =
415416
builder.createIntegerConstant(loc, builder.getIndexType(), i);

flang/test/Lower/MIF/coarray_allocation.f90

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,17 @@ program alloc_test
6060
! CHECK: mif.dealloc_coarray %[[VAL_14]] stat %[[STAT:.*]] errmsg %[[ERRMSG:.*]] : (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<i32>, !fir.box<none>) -> ()
6161
deallocate(d%z%co)
6262

63-
end program
63+
end program
64+
65+
! CHECK-LABEL: func.func @_QPtest_alloc2()
66+
subroutine test_alloc2
67+
class(*),allocatable :: a[:]
68+
class(*),allocatable :: b[:]
69+
integer :: ierr
70+
71+
! CHECK: mif.alloc_coarray %[[VAL_1:.*]]#0 lcobounds %[[LCOBOUNDS:.*]] ucobounds %[[UCOBOUNDS:.*]] errmsg %[[ERRMSG:.*]] {uniq_name = "_QFtest_alloc2Ea"} : (!fir.ref<!fir.class<!fir.heap<none>>>, !fir.box<!fir.array<1xi64>>, !fir.box<!fir.array<0xi64>>, !fir.box<none>) -> ()
72+
allocate(real::a[1:*])
73+
74+
! CHECK: mif.alloc_coarray %[[VAL_2:.*]]#0 lcobounds %[[LCOBOUNDS2:.*]] ucobounds %[[UCOBOUNDS2:.*]] stat %[[STAT:.*]] errmsg %[[ERRMSG2:.*]] {uniq_name = "_QFtest_alloc2Eb"} : (!fir.ref<!fir.class<!fir.heap<none>>>, !fir.box<!fir.array<1xi64>>, !fir.box<!fir.array<0xi64>>, !fir.ref<i32>, !fir.box<none>) -> ()
75+
allocate(real::b[2:*], STAT=ierr)
76+
end subroutine

0 commit comments

Comments
 (0)