[flang-commits] [PATCH] D149328: [flang][lowering] Do not instantiate component symbols used in spec expr

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Apr 27 02:24:51 PDT 2023


jeanPerier created this revision.
jeanPerier added reviewers: vzakhari, Renaud-K.
jeanPerier added a project: Flang.
Herald added subscribers: sunshaoce, mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

Lowering analyse specification expressions in order to create order the
symbol instantiations in the IR (If symbol B is used in the
specification expression of A, symbol B must be instantiated first).

This analysis was mistakenly collecting component symbols used in
component references inside specification expressions, which led
lowering to instantiate component symbols as if they were local
objects.

This patch prevents collecting component symbols during this analysis.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D149328

Files:
  flang/lib/Lower/PFTBuilder.cpp
  flang/test/Lower/HLFIR/convert-variable.f90


Index: flang/test/Lower/HLFIR/convert-variable.f90
===================================================================
--- flang/test/Lower/HLFIR/convert-variable.f90
+++ flang/test/Lower/HLFIR/convert-variable.f90
@@ -95,3 +95,16 @@
 ! CHECK-LABEL: func.func @_QPscalar_numeric_parameter() {
 ! CHECK:  %[[VAL_0:.*]] = fir.address_of(@_QFscalar_numeric_parameterECp) : !fir.ref<i32>
 ! CHECK:  %[[VAL_1:.*]] = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<parameter>, uniq_name = "_QFscalar_numeric_parameterECp"} : (!fir.ref<i32>) -> (!fir.ref<i32>, !fir.ref<i32>)
+
+subroutine test_component_in_spec_expr(x, derived)
+  type t
+    integer :: component
+  end type
+  type(t) :: derived
+  ! Test that we do not try to instantiate "component" just because
+  ! its symbol appears in a specification expression.
+  real :: x(derived%component)
+end subroutine
+! CHECK-LABEL: func.func @_QPtest_component_in_spec_expr(
+! CHECK-NOT: alloca
+! CHECK: return
Index: flang/lib/Lower/PFTBuilder.cpp
===================================================================
--- flang/lib/Lower/PFTBuilder.cpp
+++ flang/lib/Lower/PFTBuilder.cpp
@@ -1451,6 +1451,14 @@
     // in some cases. Non-dummy procedures don't.
     if (semantics::IsProcedure(sym) && !isProcedurePointerOrDummy)
       return 0;
+    // Derived type component symbols may be collected by "CollectSymbols"
+    // below when processing something like "real :: x(derived%component)". The
+    // symbol "component" has "ObjectEntityDetails", but it should not be
+    // instantiated: it is is part of "derived" that should be the only one to
+    // be instantiated.
+    if (sym.owner().IsDerivedType())
+      return 0;
+
     semantics::Symbol ultimate = sym.GetUltimate();
     if (const auto *details =
             ultimate.detailsIf<semantics::NamelistDetails>()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D149328.517495.patch
Type: text/x-patch
Size: 1849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230427/86b7c2ad/attachment.bin>


More information about the flang-commits mailing list