[flang-commits] [flang] 9c446da - [flang] More compile-time error checking for null implied DO loops in array constructors

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Tue Aug 1 09:25:50 PDT 2023


Author: Peter Klausler
Date: 2023-08-01T09:05:41-07:00
New Revision: 9c446da5565f78cedbb7c4830a549ff0543541e5

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

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

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.

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 1bb76c64526661..e4b68a0d1abaf5 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -1510,8 +1510,8 @@ class ArrayConstructorContext {
     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 &);

diff  --git a/flang/test/Semantics/array-constr-len.f90 b/flang/test/Semantics/array-constr-len.f90
index 11460a0244ca26..a785c9e2ece6d0 100644
--- a/flang/test/Semantics/array-constr-len.f90
+++ b/flang/test/Semantics/array-constr-len.f90
@@ -10,5 +10,6 @@ subroutine subr(s,n)
   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


        


More information about the flang-commits mailing list