Skip to content

Commit d2fbca8

Browse files
authored
[flang] Allow polymorphic type mismatch for hlfir.eoshift. (#158718)
When the ARRAY has polymorphic type, its element type may not match the element type of BOUNDARY. Fixes #158382.
1 parent 3388d40 commit d2fbca8

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

flang/lib/Optimizer/HLFIR/IR/HLFIROps.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1618,12 +1618,15 @@ static llvm::LogicalResult verifyArrayShift(Op op) {
16181618
if (mlir::Value boundary = op.getBoundary()) {
16191619
mlir::Type boundaryTy =
16201620
hlfir::getFortranElementOrSequenceType(boundary.getType());
1621-
if (auto match = areMatchingTypes(
1622-
op, eleTy, hlfir::getFortranElementType(boundaryTy),
1623-
/*allowCharacterLenMismatch=*/!useStrictIntrinsicVerifier);
1624-
match.failed())
1625-
return op.emitOpError(
1626-
"ARRAY and BOUNDARY operands must have the same element type");
1621+
// In case of polymorphic ARRAY type, the BOUNDARY's element type
1622+
// may not match the ARRAY's element type.
1623+
if (!hlfir::isPolymorphicType(array.getType()))
1624+
if (auto match = areMatchingTypes(
1625+
op, eleTy, hlfir::getFortranElementType(boundaryTy),
1626+
/*allowCharacterLenMismatch=*/!useStrictIntrinsicVerifier);
1627+
match.failed())
1628+
return op.emitOpError(
1629+
"ARRAY and BOUNDARY operands must have the same element type");
16271630
if (failed(verifyOperandTypeShape(boundaryTy, "BOUNDARY")))
16281631
return mlir::failure();
16291632
}

flang/test/Lower/HLFIR/eoshift.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
module eoshift_types
55
type t
66
end type t
7+
type, extends(t) :: t2
8+
end type t2
79
end module eoshift_types
810

911
! 1d shift by scalar
@@ -269,3 +271,12 @@ subroutine eoshift14(array)
269271
! CHECK-DAG: %[[VAL_3]] = arith.constant 1 : i32
270272
! CHECK: %[[VAL_5:.*]] = hlfir.eoshift{{.*}}boundary %[[VAL_4]] : (!fir.box<!fir.array<?xui32>>, i32, ui32) -> !hlfir.expr<?xui32>
271273
end subroutine eoshift14
274+
275+
! CHECK-LABEL: func.func @_QPeoshift15(
276+
subroutine eoshift15(array, boundary)
277+
use eoshift_types
278+
class(t), allocatable :: array(:,:)
279+
type(t) :: boundary(:)
280+
array = eoshift(array, shift=1, boundary=boundary)
281+
! CHECK: hlfir.eoshift %{{.*}} %{{.*}} boundary %{{.*}}#0 : (!fir.class<!fir.heap<!fir.array<?x?x!fir.type<_QMeoshift_typesTt>>>>, i32, !fir.box<!fir.array<?x!fir.type<_QMeoshift_typesTt>>>) -> !hlfir.expr<?x?x!fir.type<_QMeoshift_typesTt>?>
282+
end subroutine eoshift15

0 commit comments

Comments
 (0)