From ce8dbe3c253147b6229a34899d2adc5bc705157c Mon Sep 17 00:00:00 2001 From: Jean Perier Date: Fri, 24 Feb 2023 09:07:25 +0100 Subject: [PATCH] [flang] Do not include dangling ac-implied-do-index in folded shape inquiry The current code was replacing inquiry to array constructor whose ac-value shape depends on ac-implied-do-index with an expression using the ac-implied-do-index without the implied-do (folding the first case added in the test as in the second case with a regular symbol). Differential Revision: https://reviews.llvm.org/D144655 --- flang/include/flang/Evaluate/shape.h | 6 ++++-- flang/test/Evaluate/rewrite01.f90 | 10 ++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/flang/include/flang/Evaluate/shape.h b/flang/include/flang/Evaluate/shape.h index 0539d8f..dce24b7 100644 --- a/flang/include/flang/Evaluate/shape.h +++ b/flang/include/flang/Evaluate/shape.h @@ -184,8 +184,10 @@ private: !ContainsAnyImpliedDoIndex(ido.upper()) && !ContainsAnyImpliedDoIndex(ido.stride())) { if (auto nValues{GetArrayConstructorExtent(ido.values())}) { - return std::move(*nValues) * - CountTrips(ido.lower(), ido.upper(), ido.stride()); + if (!ContainsAnyImpliedDoIndex(*nValues)) { + return std::move(*nValues) * + CountTrips(ido.lower(), ido.upper(), ido.stride()); + } } } return std::nullopt; diff --git a/flang/test/Evaluate/rewrite01.f90 b/flang/test/Evaluate/rewrite01.f90 index e971ff2..3f7f954 100644 --- a/flang/test/Evaluate/rewrite01.f90 +++ b/flang/test/Evaluate/rewrite01.f90 @@ -206,4 +206,14 @@ subroutine array_constructor() print *, size([return_allocatable(), return_allocatable()]) end subroutine +!CHECK-LABEL: array_ctor_implied_do_index +subroutine array_ctor_implied_do_index(x, j) + integer :: x(:) + integer(8) :: j + !CHECK: PRINT *, size([INTEGER(4)::(x(1_8:i:1_8),INTEGER(8)::i=1_8,2_8,1_8)]) + print *, size([(x(1:i), integer(8)::i=1,2)]) + !CHECK: PRINT *, int(0_8+2_8*(0_8+max((j-1_8+1_8)/1_8,0_8)),kind=4) + print *, size([(x(1:j), integer(8)::i=1,2)]) +end subroutine + end module -- 2.7.4