[flang-commits] [PATCH] D156755: [flang] Don't emit false errors on LBOUND/UBOUND of assumed-rank arrays
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Tue Aug 1 11:03:31 PDT 2023
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf9fdd4fdbafb: [flang] Don't emit false errors on LBOUND/UBOUND of assumed-rank arrays (authored by klausler).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D156755/new/
https://reviews.llvm.org/D156755
Files:
flang/lib/Evaluate/fold-integer.cpp
flang/test/Evaluate/errors01.f90
Index: flang/test/Evaluate/errors01.f90
===================================================================
--- flang/test/Evaluate/errors01.f90
+++ flang/test/Evaluate/errors01.f90
@@ -6,8 +6,8 @@
real x
end type t
contains
- subroutine s1(a,b)
- real :: a(*), b(:)
+ subroutine s1(a,b,c)
+ real :: a(*), b(:), c(..)
!CHECK: error: DIM=1 dimension is out of range for rank-1 assumed-size array
integer :: ub1(ubound(a,1))
!CHECK-NOT: error: DIM=1 dimension is out of range for rank-1 assumed-size array
@@ -20,6 +20,10 @@
integer :: lb2(lbound(b,0))
!CHECK: error: DIM=2 dimension is out of range for rank-1 array
integer :: lb3(lbound(b,2))
+ !CHECK: error: DIM=0 dimension must be positive
+ integer :: lb4(lbound(c,0))
+ !CHECK: error: DIM=666 dimension is too large for any array (maximum rank 15)
+ integer :: lb4(lbound(c,666))
end subroutine
subroutine s2
integer, parameter :: array(2,3) = reshape([(j, j=1, 6)], shape(array))
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -156,17 +156,21 @@
using T = Type<TypeCategory::Integer, KIND>;
ActualArguments &args{funcRef.arguments()};
if (const auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
- if (int rank{array->Rank()}; rank > 0 || IsAssumedRank(*array)) {
- std::optional<int> dim;
- if (funcRef.Rank() == 0) {
- // Optional DIM= argument is present: result is scalar.
- if (!CheckDimArg(args[1], *array, context.messages(), true, dim)) {
- return MakeInvalidIntrinsic<T>(std::move(funcRef));
- } else if (!dim) {
- // DIM= is present but not constant, or error
- return Expr<T>{std::move(funcRef)};
- }
+ std::optional<int> dim;
+ if (funcRef.Rank() == 0) {
+ // Optional DIM= argument is present: result is scalar.
+ if (!CheckDimArg(args[1], *array, context.messages(), true, dim)) {
+ return MakeInvalidIntrinsic<T>(std::move(funcRef));
+ } else if (!dim) {
+ // DIM= is present but not constant, or error
+ return Expr<T>{std::move(funcRef)};
}
+ }
+ if (IsAssumedRank(*array)) {
+ // Would like to return 1 if DIM=.. is present, but that would be
+ // hiding a runtime error if the DIM= were too large (including
+ // the case of an assumed-rank argument that's scalar).
+ } else if (int rank{array->Rank()}; rank > 0) {
bool lowerBoundsAreOne{true};
if (auto named{ExtractNamedEntity(*array)}) {
const Symbol &symbol{named->GetLastSymbol()};
@@ -203,17 +207,18 @@
using T = Type<TypeCategory::Integer, KIND>;
ActualArguments &args{funcRef.arguments()};
if (auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
- if (int rank{array->Rank()}; rank > 0 || IsAssumedRank(*array)) {
- std::optional<int> dim;
- if (funcRef.Rank() == 0) {
- // Optional DIM= argument is present: result is scalar.
- if (!CheckDimArg(args[1], *array, context.messages(), false, dim)) {
- return MakeInvalidIntrinsic<T>(std::move(funcRef));
- } else if (!dim) {
- // DIM= is present but not constant
- return Expr<T>{std::move(funcRef)};
- }
+ std::optional<int> dim;
+ if (funcRef.Rank() == 0) {
+ // Optional DIM= argument is present: result is scalar.
+ if (!CheckDimArg(args[1], *array, context.messages(), false, dim)) {
+ return MakeInvalidIntrinsic<T>(std::move(funcRef));
+ } else if (!dim) {
+ // DIM= is present but not constant, or error
+ return Expr<T>{std::move(funcRef)};
}
+ }
+ if (IsAssumedRank(*array)) {
+ } else if (int rank{array->Rank()}; rank > 0) {
bool takeBoundsFromShape{true};
if (auto named{ExtractNamedEntity(*array)}) {
const Symbol &symbol{named->GetLastSymbol()};
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D156755.546154.patch
Type: text/x-patch
Size: 3993 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230801/bd9b9c52/attachment-0001.bin>
More information about the flang-commits
mailing list