[flang-commits] [flang] ac64c7b - [flang] Support PDT declaration with initial comp value in internal procedure

Jean Perier via flang-commits flang-commits at lists.llvm.org
Tue Jun 14 05:46:54 PDT 2022


Author: Jean Perier
Date: 2022-06-14T14:46:12+02:00
New Revision: ac64c7b987f15bcce09b616c1ee0deaf2b7b587e

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

LOG: [flang] Support PDT declaration with initial comp value in internal procedure

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Lower/PFTBuilder.cpp b/flang/lib/Lower/PFTBuilder.cpp
index ca0df8399789..2e2e02488031 100644
--- a/flang/lib/Lower/PFTBuilder.cpp
+++ b/flang/lib/Lower/PFTBuilder.cpp
@@ -1768,7 +1768,9 @@ struct SymbolVisitor {
   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;
   }

diff  --git a/flang/test/Lower/host-associated.f90 b/flang/test/Lower/host-associated.f90
index 5d57304aae5d..aa1f8b022646 100644
--- a/flang/test/Lower/host-associated.f90
+++ b/flang/test/Lower/host-associated.f90
@@ -661,3 +661,25 @@ subroutine test_11a
   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


        


More information about the flang-commits mailing list