-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[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
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: None (jeanPerier) ChangesDynamic type and element size of the descriptor dummy must match the dummy static type when the dummy is not polymorphic, otherwise IS_CONTIGUOUS, C_SIZEOF.... won't work properly inside the callee. When the actual argument is polymorphic the descriptor of the actual may have a different dynamic type/element size. Hence, the dummy argument cannot simply take or copy the descriptor of the actual argument. Full diff: https://github.com/llvm/llvm-project/pull/95240.diff 2 Files Affected:
diff --git a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
index 2c545d66ebd8e..cb6d6a73eace2 100644
--- a/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
+++ b/flang/lib/Optimizer/Transforms/AssumedRankOpConversion.cpp
@@ -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));
diff --git a/flang/test/Fir/rebox_assumed_rank_codegen.fir b/flang/test/Fir/rebox_assumed_rank_codegen.fir
index 6f9cd6edda31b..3c4de0bef509f 100644
--- a/flang/test/Fir/rebox_assumed_rank_codegen.fir
+++ b/flang/test/Fir/rebox_assumed_rank_codegen.fir
@@ -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>>) {
@@ -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}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…#95240) Dynamic type and element size of the descriptor dummy must match the dummy static type when the dummy is not polymorphic, otherwise IS_CONTIGUOUS, C_SIZEOF.... won't work properly inside the callee. When the actual argument is polymorphic the descriptor of the actual may have a different dynamic type/element size. Hence, the dummy argument cannot simply take or copy the descriptor of the actual argument.
…#95240) Dynamic type and element size of the descriptor dummy must match the dummy static type when the dummy is not polymorphic, otherwise IS_CONTIGUOUS, C_SIZEOF.... won't work properly inside the callee. When the actual argument is polymorphic the descriptor of the actual may have a different dynamic type/element size. Hence, the dummy argument cannot simply take or copy the descriptor of the actual argument.
Dynamic type and element size of the descriptor dummy must match the dummy static type when the dummy is not polymorphic, otherwise IS_CONTIGUOUS, C_SIZEOF.... won't work properly inside the callee.
When the actual argument is polymorphic the descriptor of the actual may have a different dynamic type/element size. Hence, the dummy argument cannot simply take or copy the descriptor of the actual argument.