From: Valentin Clement Date: Thu, 19 Jan 2023 16:34:01 +0000 (+0100) Subject: [flang] Allow pointer association between derived-type pointer and unlimited polymorp... X-Git-Tag: upstream/17.0.6~20416 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fd26eee486ed81a2477e28d069fb68072fd7b2a2;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index b093f69..dcedff6 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() || outEleTy.isa() || + (inputEleTy.isa() && outEleTy.isa()) || (getSlice() && inputEleTy.isa()) || areCompatibleCharacterTypes(inputEleTy, outEleTy); if (!typeCanMismatch) diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90 index 8caa6ce..da843a2 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 @@ module polymorphic_test ! CHECK: %[[BOX_NONE:.*]] = fir.convert %[[ARG0]] : (!fir.class>) -> !fir.box ! CHECK: %{{.*}} = fir.call @_FortranAInitialize(%[[BOX_NONE]], %{{.*}}, %{{.*}}) {{.*}} : (!fir.box, !fir.ref, 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.bindc_name = "p", fir.target}) { +! CHECK: %[[T:.*]] = fir.alloca !fir.box>>> {bindc_name = "t", uniq_name = "_QMpolymorphic_testFrebox_up_to_record_typeEt"} +! CHECK: %[[LOAD_P:.*]] = fir.load %[[P]] : !fir.ref>>> +! CHECK: %[[REBOX:.*]] = fir.rebox %[[LOAD_P]](%{{.*}}) : (!fir.class>>, !fir.shift<2>) -> !fir.box>>> +! CHECK: fir.store %[[REBOX]] to %[[T]] : !fir.ref>>>> + end module program test