Skip to content

[flang][fir] handle poly to non poly case in rebox_assumed_rank #95240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ class ReboxAssumedRankConv
auto oldBoxType = mlir::cast<fir::BaseBoxType>(
fir::unwrapRefType(rebox.getBox().getType()));
auto newDerivedType = mlir::dyn_cast<fir::RecordType>(newEleType);
if (newDerivedType && (newEleType != oldBoxType.unwrapInnerType()) &&
if (newDerivedType && !fir::isPolymorphicType(newBoxType) &&
(fir::isPolymorphicType(oldBoxType) ||
(newEleType != oldBoxType.unwrapInnerType())) &&
!fir::isPolymorphicType(newBoxType)) {
newDtype = builder.create<fir::TypeDescOp>(
loc, mlir::TypeAttr::get(newDerivedType));
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Fir/rebox_assumed_rank_codegen.fir
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,18 @@ func.func @test_new_dtype(%arg0: !fir.box<!fir.array<*:!t2>> ) {
return
}

!sometype = !fir.type<sometype{i:i32}>
func.func @test_poly_to_nonepoly(%arg0: !fir.class<!fir.array<*:!sometype>>) {
%1 = fir.rebox_assumed_rank %arg0 lbs ones : (!fir.class<!fir.array<*:!sometype>>) -> !fir.box<!fir.array<*:!sometype>>
fir.call @takes_assumed_rank_t(%1) : (!fir.box<!fir.array<*:!sometype>>) -> ()
return
}

func.func private @somefunc(!fir.box<!fir.array<*:f32>>)
func.func private @somefuncalloc(!fir.box<!fir.heap<!fir.array<*:f32>>>)
func.func private @somefuncpointer(!fir.box<!fir.ptr<!fir.array<*:f32>>>)
func.func private @somefunct1(!fir.box<!fir.array<*:!t1>>)
func.func private @takes_assumed_rank_t(!fir.box<!fir.array<*:!sometype>>)

// CHECK-LABEL: func.func @test_simple(
// CHECK-SAME: %[[VAL_0:.*]]: !fir.box<!fir.array<*:f32>>) {
Expand Down Expand Up @@ -108,4 +116,9 @@ func.func private @somefunct1(!fir.box<!fir.array<*:!t1>>)
// CHECK: return
// CHECK: }

// CHECK-LABEL: func.func @test_poly_to_nonepoly(
// CHECK: %[[VAL_4:.*]] = fir.type_desc !fir.type<sometype{i:i32}>
// CHECK: %[[VAL_7:.*]] = fir.convert %[[VAL_4]] : (!fir.tdesc<!fir.type<sometype{i:i32}>>) -> !fir.ref<none>
// CHECK: %[[VAL_8:.*]] = fir.call @_FortranACopyAndUpdateDescriptor(%{{.*}}, %{{.*}}, %[[VAL_7]],

// CHECK: func.func private @_FortranACopyAndUpdateDescriptor(!fir.ref<!fir.box<none>> {llvm.nocapture}, !fir.box<none> {llvm.nocapture}, !fir.ref<none>, i8, i32) -> none attributes {fir.runtime}
Loading