[flang] Fix test failure, clean up for merging

Original-commit: flang-compiler/f18@77bad27366
Reviewed-on: https://github.com/flang-compiler/f18/pull/611
This commit is contained in:
peter klausler 2019-08-02 10:17:10 -07:00
parent 61fdf0a93e
commit c940fb6641
5 changed files with 47 additions and 37 deletions

View File

@ -6,9 +6,9 @@ Copyright (c) 2018-2019, NVIDIA CORPORATION. All rights reserved.
* Use *clang-format* on all C++ source and header files before
every merge to master. All code layout should be determined
by means of clang-format.
* Where [LLVM's C++ style guide](https://llvm.org/docs/CodingStandards.html#style-issues)
* Where a clear precedent exists in the project, follow it.
* Otherwise, where [LLVM's C++ style guide](https://llvm.org/docs/CodingStandards.html#style-issues)
is clear on usage, follow it.
* Otherwise, where a clear precedent exists in the project, follow it.
* Otherwise, where a good public C++ style guide is relevant and clear,
follow it. [Google's](https://google.github.io/styleguide/cppguide.html)
is pretty good and comes with lots of justifications for its rules.
@ -39,10 +39,12 @@ headers, also alphabetically; then C and system headers.
1. Don't use `#include <iostream>`. If you need it for temporary debugging,
remove the inclusion before committing.
### Naming
1. C++ names that correspond to well-known interfaces from the STL and LLVM
1. C++ names that correspond to well-known interfaces from the STL, LLVM,
and Fortran standard
can and should look like their models when the reader can safely assume that
they mean the same thing -- e.g., `clear()` and `size()` member functions
in a class that implements an STL-ish container.
Fortran intrinsic function names are conventionally in ALL CAPS.
1. Non-public data members should be named with leading miniscule (lower-case)
letters, internal camelCase capitalization, and a trailing underscore,
e.g. `DoubleEntryBookkeepingSystem myLedger_;`. POD structures with

View File

@ -409,19 +409,21 @@ Expr<Type<TypeCategory::Integer, KIND>> LBOUND(FoldingContext &context,
ActualArguments &args{funcRef.arguments()};
if (const auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
if (int rank{array->Rank()}; rank > 0) {
std::optional<std::int64_t> dim;
std::optional<int> dim;
if (args[1].has_value()) {
// Optional DIM= argument is present: return a scalar.
dim = GetInt64Arg(args[1]);
if (!dim.has_value()) {
// Optional DIM= argument is present: result is scalar.
if (auto dim64{GetInt64Arg(args[1])}) {
if (*dim64 < 1 || *dim64 > rank) {
context.messages().Say("DIM=%jd dimension is out of range for "
"rank-%d array"_en_US,
static_cast<std::intmax_t>(*dim64), rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
} else {
dim = *dim64 - 1; // 1-based to 0-based
}
} else {
// DIM= is present but not constant
return Expr<T>{std::move(funcRef)};
} else if (*dim < 1 || *dim > rank) {
context.messages().Say(
"LBOUND(array,dim=%jd) dimension is out of range for "
"rank-%d array"_en_US,
static_cast<std::intmax_t>(*dim), rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
}
}
bool lowerBoundsAreOne{true};
@ -431,8 +433,7 @@ Expr<Type<TypeCategory::Integer, KIND>> LBOUND(FoldingContext &context,
lowerBoundsAreOne = false;
if (dim.has_value()) {
return Fold(context,
ConvertToType<T>(
GetLowerBound(context, *named, static_cast<int>(*dim))));
ConvertToType<T>(GetLowerBound(context, *named, *dim)));
} else if (auto extents{
AsExtentArrayExpr(GetLowerBounds(context, *named))}) {
return Fold(context,
@ -463,19 +464,21 @@ Expr<Type<TypeCategory::Integer, KIND>> UBOUND(FoldingContext &context,
ActualArguments &args{funcRef.arguments()};
if (auto *array{UnwrapExpr<Expr<SomeType>>(args[0])}) {
if (int rank{array->Rank()}; rank > 0) {
std::optional<std::int64_t> dim;
std::optional<int> dim;
if (args[1].has_value()) {
// Optional DIM= argument is present: return a scalar.
dim = GetInt64Arg(args[1]);
if (!dim.has_value()) {
// Optional DIM= argument is present: result is scalar.
if (auto dim64{GetInt64Arg(args[1])}) {
if (*dim64 < 1 || *dim64 > rank) {
context.messages().Say("DIM=%jd dimension is out of range for "
"rank-%d array"_en_US,
static_cast<std::intmax_t>(*dim64), rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
} else {
dim = *dim64 - 1; // 1-based to 0-based
}
} else {
// DIM= is present but not constant
return Expr<T>{std::move(funcRef)};
} else if (*dim < 1 || *dim > rank) {
context.messages().Say(
"UBOUND(array,dim=%jd) dimension is out of range for "
"rank-%d array"_en_US,
static_cast<std::intmax_t>(*dim), rank);
return MakeInvalidIntrinsic<T>(std::move(funcRef));
}
}
bool takeBoundsFromShape{true};
@ -486,8 +489,7 @@ Expr<Type<TypeCategory::Integer, KIND>> UBOUND(FoldingContext &context,
if (dim.has_value()) {
if (semantics::IsAssumedSizeArray(symbol) && *dim == rank) {
return Expr<T>{-1};
} else if (auto ub{GetUpperBound(
context, *named, static_cast<int>(*dim))}) {
} else if (auto ub{GetUpperBound(context, *named, *dim)}) {
return Fold(context, ConvertToType<T>(std::move(*ub)));
}
} else {
@ -1262,8 +1264,9 @@ static std::optional<Constant<SubscriptInteger>> GetConstantSubscript(
lower = GetLowerBound(context, base, dim);
}
if (!upper.has_value()) {
upper = GetUpperBound(context, GetLowerBound(context, base, dim),
GetExtent(context, base, dim));
upper =
ComputeUpperBound(context, GetLowerBound(context, base, dim),
GetExtent(context, base, dim));
}
auto lbi{ToInt64(lower)}, ubi{ToInt64(upper)};
if (lbi.has_value() && ubi.has_value() && stride.has_value() &&

View File

@ -302,7 +302,7 @@ MaybeExtentExpr GetExtent(FoldingContext &context, const Subscript &subscript,
subscript.u);
}
MaybeExtentExpr GetUpperBound(
MaybeExtentExpr ComputeUpperBound(
FoldingContext &context, ExtentExpr &&lower, MaybeExtentExpr &&extent) {
if (extent.has_value()) {
return Fold(context, std::move(*extent) - std::move(lower) + ExtentExpr{1});
@ -323,7 +323,8 @@ MaybeExtentExpr GetUpperBound(
} else if (details->IsAssumedSize() && dimension + 1 == symbol.Rank()) {
break;
} else {
return GetUpperBound(context, GetLowerBound(context, base, dimension),
return ComputeUpperBound(context,
GetLowerBound(context, base, dimension),
GetExtent(context, base, dimension));
}
}
@ -344,7 +345,7 @@ Shape GetUpperBounds(FoldingContext &context, const NamedEntity &base) {
CHECK(dim + 1 == base.Rank());
result.emplace_back(std::nullopt); // UBOUND folding replaces with -1
} else {
result.emplace_back(GetUpperBound(context,
result.emplace_back(ComputeUpperBound(context,
GetLowerBound(context, base, dim), GetExtent(context, base, dim)));
}
++dim;

View File

@ -62,15 +62,15 @@ inline int GetRank(const Shape &s) { return static_cast<int>(s.size()); }
// The dimension argument to these inquiries is zero-based,
// unlike the DIM= arguments to many intrinsics.
ExtentExpr GetLowerBound(FoldingContext &, const NamedEntity &, int dimension);
MaybeExtentExpr GetUpperBound(
FoldingContext &, const NamedEntity &, int dimension);
MaybeExtentExpr ComputeUpperBound(
FoldingContext &, ExtentExpr &&lower, MaybeExtentExpr &&extent);
Shape GetLowerBounds(FoldingContext &, const NamedEntity &);
Shape GetUpperBounds(FoldingContext &, const NamedEntity &);
MaybeExtentExpr GetExtent(FoldingContext &, const NamedEntity &, int dimension);
MaybeExtentExpr GetExtent(
FoldingContext &, const Subscript &, const NamedEntity &, int dimension);
MaybeExtentExpr GetUpperBound(
FoldingContext &, ExtentExpr &&lower, MaybeExtentExpr &&extent);
MaybeExtentExpr GetUpperBound(
FoldingContext &, const NamedEntity &, int dimension);
Shape GetUpperBounds(FoldingContext &, const NamedEntity &);
// Compute an element count for a triplet or trip count for a DO.
ExtentExpr CountTrips(

View File

@ -34,6 +34,10 @@ module m
logical, parameter :: test_lba2 = all(lba2 == [0])
integer, parameter :: uba2(:) = ubound(a2)
logical, parameter :: test_uba2 = all(uba2 == [-1])
integer, parameter :: lbtadim(:) = lbound(ta,1)
logical, parameter :: test_lbtadim = lbtadim == 0
integer, parameter :: ubtadim(:) = ubound(ta,1)
logical, parameter :: test_ubtadim = ubtadim == 2
integer, parameter :: lbta1(:) = lbound(ta)
logical, parameter :: test_lbta1 = all(lbta1 == [0])
integer, parameter :: ubta1(:) = ubound(ta)