[flang-commits] [flang] cd31948 - [flang][lowering] Do not instantiate component symbols used in spec expr

Jean Perier via flang-commits flang-commits at lists.llvm.org
Thu Apr 27 09:38:29 PDT 2023


Author: Jean Perier
Date: 2023-04-27T18:36:53+02:00
New Revision: cd319489e9118a0c93a88fc6e7a200ec3f161922

URL: https://github.com/llvm/llvm-project/commit/cd319489e9118a0c93a88fc6e7a200ec3f161922
DIFF: https://github.com/llvm/llvm-project/commit/cd319489e9118a0c93a88fc6e7a200ec3f161922.diff

LOG: [flang][lowering] Do not instantiate component symbols used in spec expr

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index 2c63852ce95ee..ec4c7218b58f6 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -1451,6 +1451,14 @@ struct SymbolDependenceAnalysis {
     // 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>()) {

diff  --git a/flang/test/Lower/HLFIR/convert-variable.f90 b/flang/test/Lower/HLFIR/convert-variable.f90
index ab9425afe3f1e..2bb1674895626 100644
--- a/flang/test/Lower/HLFIR/convert-variable.f90
+++ b/flang/test/Lower/HLFIR/convert-variable.f90
@@ -95,3 +95,16 @@ subroutine scalar_numeric_parameter()
 ! 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


        


More information about the flang-commits mailing list