[flang] Correctly lower optional assumed type dummy
authorValentin Clement <clementval@gmail.com>
Tue, 4 Apr 2023 15:39:37 +0000 (08:39 -0700)
committerValentin Clement <clementval@gmail.com>
Tue, 4 Apr 2023 15:40:53 +0000 (08:40 -0700)
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

flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/assumed-type.f90

index 9bb158d..c06fcc2 100644 (file)
@@ -1838,6 +1838,15 @@ public:
     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());
index b877a16..856129d 100644 (file)
@@ -39,4 +39,13 @@ contains
 ! 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