diff --git a/flang/lib/Evaluate/fold-integer.cpp b/flang/lib/Evaluate/fold-integer.cpp --- a/flang/lib/Evaluate/fold-integer.cpp +++ b/flang/lib/Evaluate/fold-integer.cpp @@ -36,8 +36,8 @@ } template ConstantSubscripts GetLbound(const Parentheses &x) { - // Strip off the parentheses - return GetLbound(x.left()); + // Lower bounds for (x) is [1, ..., 1] + return ConstantSubscripts(x.Rank(), ConstantSubscript{1}); } template ConstantSubscripts GetLbound(const Expr &x) { diff --git a/flang/test/Evaluate/folding08.f90 b/flang/test/Evaluate/folding08.f90 --- a/flang/test/Evaluate/folding08.f90 +++ b/flang/test/Evaluate/folding08.f90 @@ -99,4 +99,25 @@ lbound(a4, 2) == 1 .and. & lbound(a4, 3) == 4 end subroutine + subroutine test4_bound_parentheses + ! Exercise with (x) + integer :: a1(1) = 0 + integer :: a2(0:1) = 0 + integer :: a3(-1:-1) = 0 + integer :: a4(-1:-1, 2:4) = 0 + logical, parameter :: test_lba1 = all(lbound((a1)) == [1]) + logical, parameter :: test_lba2 = all(lbound((a2)) == [1]) + logical, parameter :: test_lba3 = all(lbound((a3)) == [1]) + logical, parameter :: test_lba4 = all(lbound((a4)) == [1, 1]) + + integer, parameter :: pa1(1) = 0 + integer, parameter :: pa2(0:1) = 0 + integer, parameter :: pa3(-1:-1) = 0 + ! integer, parameter :: pa4(-1:-1, 2:4) = 0 + logical, parameter :: test_lbpa1 = all(lbound((pa1), 1) == [1]) + logical, parameter :: test_lbpa2 = all(lbound((pa2), 1) == [1]) + logical, parameter :: test_lbpa3 = all(lbound((pa3), 1) == [1]) + ! logical, parameter :: test_lbpa4 = lbound((pa4), 1) == 1 .and. & + ! lbound((pa4), 2) == 1 + end subroutine end diff --git a/flang/test/Evaluate/folding16.f90 b/flang/test/Evaluate/folding16.f90 --- a/flang/test/Evaluate/folding16.f90 +++ b/flang/test/Evaluate/folding16.f90 @@ -7,7 +7,7 @@ integer, parameter :: c(-1:1) = [33, 22, 11] integer, parameter :: d(1:3) = [33, 22, 11] integer, parameter :: e(-2:0) = ([33, 22, 11]) - logical, parameter :: test_1 = lbound((a),1)==-1 .and. lbound(b,1)==-1 .and. & + logical, parameter :: test_1 = lbound((a),1)==1 .and. lbound(b,1)==-1 .and. & lbound(log(a),1)==1 .and. all(b==0) logical, parameter :: test_2 = all(c .eq. d) logical, parameter :: test_3 = all(c .eq. e)