[flang-commits] [PATCH] D156753: [flang] More compile-time error checking for null implied DO loops in array constructors

Peter Klausler via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 31 16:08:03 PDT 2023


klausler created this revision.
klausler added a reviewer: vzakhari.
klausler added a project: Flang.
Herald added subscribers: sunshaoce, jdoerfert.
Herald added a project: All.
klausler requested review of this revision.

An implied DO loop in an array constructor may not have a type (explicit
or otherwise) with a character length that depends on a value of an
implied DO index or a non-constant expression if the implied DO loop
executes no iterations.  When the iteration count can be known to be
zero at compilation time, catch the case of a non-constant length
expression correctly.


https://reviews.llvm.org/D156753

Files:
  flang/lib/Semantics/expression.cpp
  flang/test/Semantics/array-constr-len.f90


Index: flang/test/Semantics/array-constr-len.f90
===================================================================
--- flang/test/Semantics/array-constr-len.f90
+++ flang/test/Semantics/array-constr-len.f90
@@ -10,5 +10,6 @@
   print *, [(s(1:j),j=1,0)]
   print *, [(s(1:1),j=1,0)] ! ok
   print *, [character(2)::(s(1:n),j=1,0)] ! ok
-  print *, [character(n)::(s(1:n),j=1,0)] ! ok
+  !ERROR: Array constructor implied DO loop has no iterations and indeterminate character length
+  print *, [character(n)::(s(1:n),j=1,0)]
 end
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -1510,8 +1510,8 @@
     return std::nullopt;
   }
   bool NeedLength() const {
-    return !explicitType_ && type_ &&
-        type_->category() == TypeCategory::Character && !LengthIfGood();
+    return type_ && type_->category() == TypeCategory::Character &&
+        !LengthIfGood();
   }
   void Push(MaybeExpr &&);
   void Add(const parser::AcValue::Triplet &);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156753.545847.patch
Type: text/x-patch
Size: 1090 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230731/2808c226/attachment-0001.bin>


More information about the flang-commits mailing list