[flang] Relax overindexing error to warning for last dummy dimension (#71725)
Compilation-time subscript value range checking should emit a warning, not an error, when the indexed array is a dummy argument; there's old-school codes out there that should have used assumed-size dummy arguments but didn't.
This commit is contained in:
@@ -403,19 +403,28 @@ void ExpressionAnalyzer::CheckConstantSubscripts(ArrayRef &ref) {
|
||||
}
|
||||
for (int j{0}; j < vals; ++j) {
|
||||
if (val[j]) {
|
||||
std::optional<parser::MessageFixedText> msg;
|
||||
std::optional<ConstantSubscript> bound;
|
||||
if (dimLB && *val[j] < *dimLB) {
|
||||
AttachDeclaration(
|
||||
Say("Subscript %jd is less than lower bound %jd for dimension %d of array"_err_en_US,
|
||||
static_cast<std::intmax_t>(*val[j]),
|
||||
static_cast<std::intmax_t>(*dimLB), dim + 1),
|
||||
ref.base().GetLastSymbol());
|
||||
msg =
|
||||
"Subscript %jd is less than lower bound %jd for dimension %d of array"_err_en_US;
|
||||
bound = *dimLB;
|
||||
} else if (dimUB && *val[j] > *dimUB) {
|
||||
msg =
|
||||
"Subscript %jd is greater than upper bound %jd for dimension %d of array"_err_en_US;
|
||||
bound = *dimUB;
|
||||
if (dim + 1 == arraySymbol.Rank() && IsDummy(arraySymbol) &&
|
||||
*bound == 1) {
|
||||
// Old-school overindexing of a dummy array isn't fatal when
|
||||
// it's on the last dimension and the extent is 1.
|
||||
msg->set_severity(parser::Severity::Warning);
|
||||
}
|
||||
}
|
||||
if (dimUB && *val[j] > *dimUB) {
|
||||
if (msg) {
|
||||
AttachDeclaration(
|
||||
Say("Subscript %jd is greater than upper bound %jd for dimension %d of array"_err_en_US,
|
||||
static_cast<std::intmax_t>(*val[j]),
|
||||
static_cast<std::intmax_t>(*dimUB), dim + 1),
|
||||
ref.base().GetLastSymbol());
|
||||
Say(std::move(*msg), static_cast<std::intmax_t>(*val[j]),
|
||||
static_cast<std::intmax_t>(bound.value()), dim + 1),
|
||||
arraySymbol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user