From 017a49990189cc9513ff088eebbeeb1f54e3ff93 Mon Sep 17 00:00:00 2001 From: David Spickett Date: Fri, 12 Jul 2024 11:34:32 +0100 Subject: [PATCH] =?UTF-8?q?Revert=20"[flang]=20Adjust=20semantics=20of=20t?= =?UTF-8?q?he=20char=20length=20of=20an=20array=20constructor=20(=E2=80=A6?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 2d7e136fc0e31207b962397250bc1581203c8d59. --- flang/lib/Semantics/expression.cpp | 3 +-- flang/test/Lower/HLFIR/array-ctor-character.f90 | 9 ++++----- flang/test/Semantics/array-constr-len.f90 | 1 + 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp index 844ffd44604bac..90900d9acb6ad0 100644 --- a/flang/lib/Semantics/expression.cpp +++ b/flang/lib/Semantics/expression.cpp @@ -1584,8 +1584,7 @@ class ArrayConstructorContext { std::optional> LengthIfGood() const { if (type_) { auto len{type_->LEN()}; - if (explicitType_ || - (len && IsConstantExpr(*len) && !ContainsAnyImpliedDoIndex(*len))) { + if (len && IsConstantExpr(*len) && !ContainsAnyImpliedDoIndex(*len)) { return len; } } diff --git a/flang/test/Lower/HLFIR/array-ctor-character.f90 b/flang/test/Lower/HLFIR/array-ctor-character.f90 index 881085b370ffef..85e6ed27fe0774 100644 --- a/flang/test/Lower/HLFIR/array-ctor-character.f90 +++ b/flang/test/Lower/HLFIR/array-ctor-character.f90 @@ -93,11 +93,10 @@ subroutine test_set_length_sanitize(i, c1) call takes_char([character(len=i):: c1]) end subroutine ! CHECK-LABEL: func.func @_QPtest_set_length_sanitize( -! CHECK: %[[VAL_2:.*]]:2 = hlfir.declare {{.*}}Ec1 -! CHECK: %[[VAL_3:.*]]:2 = hlfir.declare %arg0 -! CHECK: %[[VAL_4:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref -! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_3]]#0 : !fir.ref +! CHECK: %[[VAL_6:.*]]:2 = hlfir.declare {{.*}}Ec1 +! CHECK: %[[VAL_9:.*]]:2 = hlfir.declare {{.*}}Ei +! CHECK: %[[VAL_25:.*]] = fir.load %[[VAL_9]]#0 : !fir.ref ! CHECK: %[[VAL_26:.*]] = arith.constant 0 : i64 ! CHECK: %[[VAL_27:.*]] = arith.cmpi sgt, %[[VAL_25]], %[[VAL_26]] : i64 ! CHECK: %[[VAL_28:.*]] = arith.select %[[VAL_27]], %[[VAL_25]], %[[VAL_26]] : i64 -! CHECK: %[[VAL_29:.*]] = hlfir.set_length %[[VAL_2]]#0 len %[[VAL_28]] : (!fir.boxchar<1>, i64) -> !hlfir.expr> +! CHECK: %[[VAL_29:.*]] = hlfir.set_length %[[VAL_6]]#0 len %[[VAL_28]] : (!fir.boxchar<1>, i64) -> !hlfir.expr> diff --git a/flang/test/Semantics/array-constr-len.f90 b/flang/test/Semantics/array-constr-len.f90 index 4de9c76c7041c2..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 + !ERROR: Array constructor implied DO loop has no iterations and indeterminate character length print *, [character(n)::(s(1:n),j=1,0)] end