[flang-commits] [flang] 33fbbf8 - [flang] Handle parent component in user function argument
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Mon Mar 13 12:30:47 PDT 2023
Author: Valentin Clement
Date: 2023-03-13T20:30:41+01:00
New Revision: 33fbbf88afe55aaf9b94747074c58f442f37fa00
URL: https://github.com/llvm/llvm-project/commit/33fbbf88afe55aaf9b94747074c58f442f37fa00
DIFF: https://github.com/llvm/llvm-project/commit/33fbbf88afe55aaf9b94747074c58f442f37fa00.diff
LOG: [flang] Handle parent component in user function argument
When the argument is a parent component the box needs to
be updated to reflect the correct type. Use `updateBoxForParentComponent`
to update the argument accordingly.
Depends on D145907
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D145928
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/polymorphic.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 7a60f44d9c4d..a64bc54bd0a7 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -2720,8 +2720,14 @@ class ScalarExprLowering {
builder.create<fir::ReboxOp>(loc, argTy, box, mlir::Value{},
/*slice=*/mlir::Value{});
}
+ } else if (Fortran::lower::isParentComponent(*expr)) {
+ fir::ExtendedValue newExv =
+ Fortran::lower::updateBoxForParentComponent(converter, box,
+ *expr);
+ box = fir::getBase(newExv);
}
}
+
caller.placeInput(arg, box);
}
} else if (arg.passBy == PassBy::AddressAndLength) {
diff --git a/flang/test/Lower/polymorphic.f90 b/flang/test/Lower/polymorphic.f90
index 1681e8425d88..ddd23ffab647 100644
--- a/flang/test/Lower/polymorphic.f90
+++ b/flang/test/Lower/polymorphic.f90
@@ -1055,6 +1055,18 @@ subroutine test_parent_comp_intrinsic(a, b)
! CHECK: %[[BOX_NONE_ARG1:.*]] = fir.convert %[[REBOX_ARG1]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.box<none>
! CHECK: %{{.*}} = fir.call @_FortranASameTypeAs(%[[BOX_NONE_ARG0]], %[[BOX_NONE_ARG1]]) {{.*}} : (!fir.box<none>, !fir.box<none>) -> i1
+ subroutine test_parent_comp_normal(a)
+ class(p2) :: a
+
+ call print(a%p1)
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMpolymorphic_testPtest_parent_comp_normal(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>> {fir.bindc_name = "a"}) {
+! CHECK: %[[REBOX:.*]] = fir.rebox %[[ARG0]] : (!fir.class<!fir.type<_QMpolymorphic_testTp2{a:i32,b:i32,c:f32}>>) -> !fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>
+! CHECK: %[[CONV:.*]] = fir.convert %[[REBOX]] : (!fir.box<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> !fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>
+! CHECK: fir.call @_QMpolymorphic_testPprint(%[[CONV]]) {{.*}} : (!fir.class<!fir.type<_QMpolymorphic_testTp1{a:i32,b:i32}>>) -> ()
+
end module
program test
More information about the flang-commits
mailing list