[flang] Keep the extended value for assumed-type optional
authorValentin Clement <clementval@gmail.com>
Wed, 5 Apr 2023 20:34:23 +0000 (13:34 -0700)
committerValentin Clement <clementval@gmail.com>
Wed, 5 Apr 2023 20:35:24 +0000 (13:35 -0700)
Keep the extended value when lowering optional assumed type
dummy argument. The extended value is needed to lower correctly the
rest of the code.

Reviewed By: PeteSteinfeld, jeanPerier

Differential Revision: https://reviews.llvm.org/D147575

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

index c06fcc2..f6a6e70 100644 (file)
@@ -1844,7 +1844,8 @@ public:
         const Fortran::evaluate::Symbol *assumedTypeSym =
             arg.value()->GetAssumedTypeDummy();
         auto symBox = symMap.lookupSymbol(*assumedTypeSym);
-        operands.emplace_back(symBox.getAddr());
+        operands.emplace_back(
+            converter.getSymbolExtendedValue(*assumedTypeSym, &symMap));
         continue;
       }
       if (!expr) {
index 856129d..c050779 100644 (file)
@@ -48,4 +48,14 @@ contains
 ! 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
 
+  subroutine assumed_type_lbound(a)
+    type(*), optional :: a(:,:)
+    print*,lbound(a,dim=1)
+  end subroutine
+
+! CHECK-LABEL: func.func @_QMassumed_type_testPassumed_type_lbound(
+! CHECK-SAME: %[[ARG0:.*]]: !fir.box<!fir.array<?x?xnone>> {fir.bindc_name = "a", fir.optional}) {
+! CHECK: %[[C1:.*]] = arith.constant 1 : i32
+! CHECK: %{{.*}} = fir.call @_FortranAioOutputInteger32(%{{.*}}, %[[C1]]) {{.*}} : (!fir.ref<i8>, i32) -> i1
+
 end module