llvm-project/flang/test/Evaluate/folding09.f90

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

29 lines
1.1 KiB
Fortran
Raw Normal View History

! RUN: %python %S/test_folding.py %s %flang_fc1
! Test folding of IS_CONTIGUOUS on simply contiguous items (9.5.4)
! When IS_CONTIGUOUS() is constant, it's .TRUE.
module m
real, target :: hosted(2)
contains
function f()
real, pointer, contiguous :: f(:)
f => hosted
end function
subroutine test(arr1, arr2, arr3, mat)
real, intent(in) :: arr1(:), arr2(10), mat(10, 10)
real, intent(in), contiguous :: arr3(:)
real :: scalar
[flang] Fix problems with constant arrays with lower bounds that are not 1 There were two problems with constant arrays whose lower bound is not 1. First, when folding the arrays, we were creating the folded array to have lower bounds of 1 but, we were not re-adjusting their lower bounds to the declared values. Second, we were not calculating the extents correctly. Both of these problems led to bogus error messages. I fixed the first problem by adjusting the lower bounds in NonPointerInitializationExpr() in Evaluate/check-expression.cpp. I wrote the class ArrayConstantBoundChanger, which is similar to the existing class ScalarConstantExpander. In the process of implementing and testing it, I found a bug that I fixed in ScalarConstantExpander which caused it to infinitely recurse on parenthesized expressions. I also removed the unrelated class ScalarExpansionVisitor, which was not used. I fixed the second problem by changing the formula that calculates upper bounds in in the function ComputeUpperBound() in Evaluate/shape.cpp. I added tests that trigger the bogus error messages mentioned above along with a constant folding tests that uses array operands with shapes that conform but have different bounds. In the process of adding tests, I discovered that tests in Evaluate/folding09.f90 and folding16.f90 were written incorrectly, and I fixed them. This also revealed a bug in contant folding of the intrinsic "lbounds" which I plan to fix in a later change. Differential Revision: https://reviews.llvm.org/D95449
2021-01-27 00:20:57 +08:00
logical, parameter :: test_isc01 = is_contiguous(0)
logical, parameter :: test_isc02 = is_contiguous(scalar)
logical, parameter :: test_isc03 = is_contiguous(scalar + scalar)
logical, parameter :: test_isc04 = is_contiguous([0, 1, 2])
logical, parameter :: test_isc05 = is_contiguous(arr1 + 1.0)
logical, parameter :: test_isc06 = is_contiguous(arr2)
logical, parameter :: test_isc07 = is_contiguous(mat)
logical, parameter :: test_isc08 = is_contiguous(mat(1:10,1))
logical, parameter :: test_isc09 = is_contiguous(arr2(1:10:1))
logical, parameter :: test_isc10 = is_contiguous(arr3)
logical, parameter :: test_isc11 = is_contiguous(f())
end subroutine
end module