Skip to content

Commit

Permalink
[flang][lowering] Do not instantiate component symbols used in spec expr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jeanPerier committed Apr 27, 2023
1 parent cf792f6 commit cd31948
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
8 changes: 8 additions & 0 deletions flang/lib/Lower/PFTBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>()) {
Expand Down
13 changes: 13 additions & 0 deletions flang/test/Lower/HLFIR/convert-variable.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit cd31948

Please sign in to comment.