[flang-commits] [PATCH] D144655: [flang] Do not include dangling ac-implied-do-index in folded shape inquiry

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Thu Feb 23 09:58:50 PST 2023


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

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D144655

Files:
  flang/include/flang/Evaluate/shape.h
  flang/test/Evaluate/rewrite01.f90


Index: flang/test/Evaluate/rewrite01.f90
===================================================================
--- flang/test/Evaluate/rewrite01.f90
+++ flang/test/Evaluate/rewrite01.f90
@@ -195,4 +195,14 @@
   end associate
 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
Index: flang/include/flang/Evaluate/shape.h
===================================================================
--- flang/include/flang/Evaluate/shape.h
+++ flang/include/flang/Evaluate/shape.h
@@ -183,8 +183,10 @@
                   !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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D144655.499905.patch
Type: text/x-patch
Size: 1470 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230223/2cdee775/attachment.bin>


More information about the flang-commits mailing list