[flang-commits] [flang] 081e202 - [flang] Fix DATA-like default component initialization (#82784)

via flang-commits flang-commits at lists.llvm.org
Fri Mar 1 15:34:02 PST 2024


Author: Peter Klausler
Date: 2024-03-01T15:33:58-08:00
New Revision: 081e202c8e124780cf77fea461c16f58b26d8d34

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

LOG: [flang] Fix DATA-like default component initialization (#82784)

Ensure that the values in a DATA-like default component initialization
pass through expression analysis.

Fixes https://github.com/llvm/llvm-project/issues/81097.

Added: 
    flang/test/Semantics/data21.f90

Modified: 
    flang/include/flang/Semantics/expression.h

Removed: 
    


################################################################################
diff  --git a/flang/include/flang/Semantics/expression.h b/flang/include/flang/Semantics/expression.h
index a330e241c2cdaa..a224b08da21da7 100644
--- a/flang/include/flang/Semantics/expression.h
+++ b/flang/include/flang/Semantics/expression.h
@@ -506,9 +506,18 @@ class ExprChecker {
   }
 
   bool Pre(const parser::ComponentDefStmt &) {
-    // Already analyzed in name resolution and PDT instantiation;
-    // do not attempt to re-analyze now without type parameters.
-    return false;
+    inComponentDefStmt_ = true;
+    return true;
+  }
+  void Post(const parser::ComponentDefStmt &) { inComponentDefStmt_ = false; }
+  bool Pre(const parser::Initialization &x) {
+    // Default component initialization expressions (but not DATA-like ones
+    // as in DEC STRUCTUREs) were already analyzed in name resolution
+    // and PDT instantiation; do not attempt to re-analyze them without
+    // type parameters.
+    return !inComponentDefStmt_ ||
+        std::holds_alternative<
+            std::list<common::Indirection<parser::DataStmtValue>>>(x.u);
   }
 
   template <typename A> bool Pre(const parser::Scalar<A> &x) {
@@ -538,6 +547,7 @@ class ExprChecker {
   SemanticsContext &context_;
   evaluate::ExpressionAnalyzer exprAnalyzer_{context_};
   int whereDepth_{0}; // nesting of WHERE statements & constructs
+  bool inComponentDefStmt_{false};
 };
 } // namespace Fortran::semantics
 #endif // FORTRAN_SEMANTICS_EXPRESSION_H_

diff  --git a/flang/test/Semantics/data21.f90 b/flang/test/Semantics/data21.f90
new file mode 100644
index 00000000000000..639f78440840a8
--- /dev/null
+++ b/flang/test/Semantics/data21.f90
@@ -0,0 +1,7 @@
+! RUN: %flang_fc1 -fdebug-dump-symbols %s 2>&1 | FileCheck %s
+! Ensure that DATA-like default component initializers work.
+! CHECK: j (InDataStmt) size=4 offset=0: ObjectEntity type: INTEGER(4) init:123_4
+type t
+  integer j/123/
+end type
+end


        


More information about the flang-commits mailing list