[flang-commits] [flang] fd26eee - [flang] Allow pointer association between derived-type pointer and unlimited polymorphic target
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Jan 19 08:34:40 PST 2023
Author: Valentin Clement
Date: 2023-01-19T17:34:34+01:00
New Revision: fd26eee486ed81a2477e28d069fb68072fd7b2a2
URL: https://github.com/llvm/llvm-project/commit/fd26eee486ed81a2477e28d069fb68072fd7b2a2
DIFF: https://github.com/llvm/llvm-project/commit/fd26eee486ed81a2477e28d069fb68072fd7b2a2.diff
LOG: [flang] Allow pointer association between derived-type pointer and unlimited polymorphic target
Pointer association to unlimited polymorphic target is allowed for
unlimited polymorphic pointer and non-extensible derived-type.
This is checked by the semantic and this patch allows it in the
fir.rebox operation.
Reviewed By: jeanPerier, PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D142104
Added:
Modified:
flang/lib/Optimizer/Dialect/FIROps.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp
index b093f693b08f3..dcedff6aae1cb 100644
--- a/flang/lib/Optimizer/Dialect/FIROps.cpp
+++ b/flang/lib/Optimizer/Dialect/FIROps.cpp
@@ -2322,6 +2322,7 @@ mlir::LogicalResult fir::ReboxOp::verify() {
// character type.
const bool typeCanMismatch =
inputEleTy.isa<fir::RecordType>() || outEleTy.isa<mlir::NoneType>() ||
+ (inputEleTy.isa<mlir::NoneType>() && outEleTy.isa<fir::RecordType>()) ||
(getSlice() && inputEleTy.isa<fir::CharacterType>()) ||
areCompatibleCharacterTypes(inputEleTy, outEleTy);
if (!typeCanMismatch)
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 8caa6ce9603f6..da843a2ca59ac 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -44,6 +44,11 @@ module polymorphic_test
type(p1) :: inner
end type
+ type non_extensible
+ sequence
+ integer :: d
+ end type
+
contains
elemental subroutine assign_p1_int(lhs, rhs)
@@ -749,6 +754,19 @@ subroutine test_polymorphic_intentout(a)
! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none>
! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box<none>, !fir.ref<i8>, i32) -> none
+ subroutine rebox_up_to_record_type(p)
+ class(*), allocatable, target :: p(:,:)
+ type(non_extensible), pointer :: t(:,:)
+ t => p
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPrebox_up_to_record_type(
+! CHECK-SAME: %[[P:.*]]: !fir.ref<!fir.class<!fir.heap<!fir.array<?x?xnone>>>> {fir.bindc_name = "p", fir.target}) {
+! CHECK: %[[T:.*]] = fir.alloca !fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>> {bindc_name = "t", uniq_name = "_QMpolymorphic_testFrebox_up_to_record_typeEt"}
+! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref<!fir.class<!fir.heap<!fir.array<?x?xnone>>>>
+! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]](%{{.*}}) : (!fir.class<!fir.heap<!fir.array<?x?xnone>>>, !fir.shift<2>) -> !fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>>
+! CHECK: fir.store %[[REBOX]] to %[[T]] : !fir.ref<!fir.box<!fir.ptr<!fir.array<?x?x!fir.type<_QMpolymorphic_testTnon_extensible{d:i32}>>>>>
+
end module
program test
More information about the flang-commits
mailing list