[flang-commits] [flang] 8ef9109 - [flang] Correctly lower optional assumed type dummy
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Tue Apr 4 08:41:03 PDT 2023
Author: Valentin Clement
Date: 2023-04-04T08:40:53-07:00
New Revision: 8ef91099f6162b023b467168e208e0843ce6781f
URL: https://github.com/llvm/llvm-project/commit/8ef91099f6162b023b467168e208e0843ce6781f
DIFF: https://github.com/llvm/llvm-project/commit/8ef91099f6162b023b467168e208e0843ce6781f.diff
LOG: [flang] Correctly lower optional assumed type dummy
Assumed type are represented differently in the ActualArgument
class. Correctly handle them in intrinsic arg lowering.
Reviewed By: PeteSteinfeld
Differential Revision: https://reviews.llvm.org/D147487
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/assumed-type.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index 9bb158de7d7d3..c06fcc24e7c22 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -1838,6 +1838,15 @@ class ScalarExprLowering {
for (const auto &arg : llvm::enumerate(procRef.arguments())) {
auto *expr =
Fortran::evaluate::UnwrapExpr<Fortran::lower::SomeExpr>(arg.value());
+
+ if (!expr && arg.value() && arg.value()->GetAssumedTypeDummy()) {
+ // Assumed type optional.
+ const Fortran::evaluate::Symbol *assumedTypeSym =
+ arg.value()->GetAssumedTypeDummy();
+ auto symBox = symMap.lookupSymbol(*assumedTypeSym);
+ operands.emplace_back(symBox.getAddr());
+ continue;
+ }
if (!expr) {
// Absent optional.
operands.emplace_back(fir::getAbsentIntrinsicArgument());
diff --git a/flang/test/Lower/assumed-type.f90 b/flang/test/Lower/assumed-type.f90
index b877a1639b36e..856129d424f8e 100644
--- a/flang/test/Lower/assumed-type.f90
+++ b/flang/test/Lower/assumed-type.f90
@@ -39,4 +39,13 @@ subroutine call_assumed_r()
! CHECK: %[[CONV:.*]] = fir.convert %[[BOX_NONE]] : (!fir.box<!fir.array<10xnone>>) -> !fir.box<!fir.array<?xnone>>
! CHECK: fir.call @_QPassumed_r(%[[CONV]]) {{.*}} : (!fir.box<!fir.array<?xnone>>) -> ()
+ subroutine assumed_type_optional_to_intrinsic(a)
+ type(*), optional :: a(:)
+ if (present(a)) print*, 'present'
+ end subroutine
+
+! CHECK-LABEL: func.func @_QMassumed_type_testPassumed_type_optional_to_intrinsic(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?xnone>> {fir.bindc_name = "a", fir.optional}) {
+! CHECK: %{{.*}} = fir.is_present %[[ARG0]] : (!fir.box<!fir.array<?xnone>>) -> i1
+
end module
More information about the flang-commits
mailing list