From 51a2ac645f4efde053175e7cc8f7882d1ea0e14d Mon Sep 17 00:00:00 2001 From: jeanPerier Date: Wed, 18 Oct 2023 08:47:15 +0200 Subject: [PATCH] [flang] Fold IS_CONTIGUOUS of component refs with non-contiguous base (#69327) --- flang/lib/Evaluate/check-expression.cpp | 9 +++++++-- flang/test/Evaluate/folding09.f90 | 9 +++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp index 29bd6eaa466bbc..531fc5ccc56c85 100644 --- a/flang/lib/Evaluate/check-expression.cpp +++ b/flang/lib/Evaluate/check-expression.cpp @@ -821,8 +821,13 @@ class IsContiguousHelper if (x.base().Rank() == 0) { return (*this)(x.GetLastSymbol()); } else { - // TODO could be true if base contiguous and this is only component, or - // if base has only one element? + if (Result baseIsContiguous{(*this)(x.base())}) { + if (!*baseIsContiguous) { + return false; + } + // TODO could be true if base contiguous and this is only component, or + // if base has only one element? + } return std::nullopt; } } diff --git a/flang/test/Evaluate/folding09.f90 b/flang/test/Evaluate/folding09.f90 index e796ed3d5169ba..863b5e873a1e5b 100644 --- a/flang/test/Evaluate/folding09.f90 +++ b/flang/test/Evaluate/folding09.f90 @@ -56,4 +56,13 @@ subroutine test(arr1, arr2, arr3, mat, alloc) end block end associate end subroutine + subroutine test2(x, vec) + type t + integer :: i + end type + type(t) :: x(100) + integer(8) :: vec(10) + integer(kind=merge(1,-1, .not. is_contiguous(x(1:50:2)%i))) t01 + integer(kind=merge(1,-1, .not. is_contiguous(x(vec)%i))) t02 + end subroutine end module