[flang-commits] [PATCH] D127735: [flang] Support PDT declaration with initial comp value in internal procedure

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Jun 14 03:35:56 PDT 2022


jeanPerier created this revision.
jeanPerier added reviewers: clementval, peixin.
jeanPerier added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

Lowering was crashing with "fatal internal error: node has not been analyzed"
if a PDT with initial component value was defined inside an internal
procedure. This is because the related expression cannot be analyzed
without the component values (which happens at the instatiation).
These expression do not need to be visited (the instantiations, if any
will be). Use the form of GetExpr that tolerates the parse tree expression
to not be analyzed into an evaluate::Expr when looking through the
symbols used in an internal procedure.

Note that the PDTs TODO will then fire (it happens after the PFT
analysis) as expected if the derived type is used.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D127735

Files:
  flang/lib/Lower/PFTBuilder.cpp
  flang/test/Lower/host-associated.f90


Index: flang/test/Lower/host-associated.f90
===================================================================
--- flang/test/Lower/host-associated.f90
+++ flang/test/Lower/host-associated.f90
@@ -661,3 +661,25 @@
   external test_11b
   call test_11c(test_11b, 3)
 end subroutine test_11a
+
+subroutine test_PDT_with_init_do_not_crash_host_symbol_analysis()
+  integer :: i
+  call sub()
+contains
+  subroutine sub()
+    ! PDT definition symbols maps to un-analyzed expression,
+    ! check this does not crash the visit of the internal procedure
+    ! parse-tree to get the list of captured host variables.
+    type type1 (k)
+      integer, KIND :: k
+      integer :: x = k
+    end type
+    type type2 (k, l)
+      integer, KIND :: k = 4
+      integer, LEN :: l = 2
+      integer :: x = 10
+      real :: y = 20
+    end type
+    print *, i
+  end subroutine
+end subroutine
Index: flang/lib/Lower/PFTBuilder.cpp
===================================================================
--- flang/lib/Lower/PFTBuilder.cpp
+++ flang/lib/Lower/PFTBuilder.cpp
@@ -1768,7 +1768,9 @@
   template <typename A>
   bool Pre(const A &x) {
     if constexpr (Fortran::parser::HasTypedExpr<A>::value)
-      if (const auto *expr = Fortran::semantics::GetExpr(x))
+      // Some parse tree Expr may legitimately be un-analyzed after semantics
+      // (for instance PDT component initial value in the PDT definition body).
+      if (const auto *expr = Fortran::semantics::GetExpr(nullptr, x))
         visitExpr(*expr);
     return true;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D127735.436727.patch
Type: text/x-patch
Size: 1542 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220614/2213a7c5/attachment-0001.bin>


More information about the flang-commits mailing list