[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 09:38:32 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGcd319489e911: [flang][lowering] Do not instantiate component symbols used in spec expr (authored by jeanPerier).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D149328/new/

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.517610.patch
Type: text/x-patch
Size: 1849 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230427/96bc9760/attachment-0001.bin>


More information about the flang-commits mailing list