|
11 | 11 | namespace Fortran::evaluate {
|
12 | 12 | bool CheckReductionDIM(std::optional<int> &dim, FoldingContext &context,
|
13 | 13 | ActualArguments &arg, std::optional<int> dimIndex, int rank) {
|
14 |
| - if (dimIndex && static_cast<std::size_t>(*dimIndex) < arg.size()) { |
15 |
| - if (auto *dimConst{ |
16 |
| - Folder<SubscriptInteger>{context}.Folding(arg[*dimIndex])}) { |
17 |
| - if (auto dimScalar{dimConst->GetScalarValue()}) { |
18 |
| - auto dimVal{dimScalar->ToInt64()}; |
19 |
| - if (dimVal >= 1 && dimVal <= rank) { |
20 |
| - dim = dimVal; |
21 |
| - } else { |
22 |
| - context.messages().Say( |
23 |
| - "DIM=%jd is not valid for an array of rank %d"_err_en_US, |
24 |
| - static_cast<std::intmax_t>(dimVal), rank); |
25 |
| - return false; |
26 |
| - } |
| 14 | + if (!dimIndex || static_cast<std::size_t>(*dimIndex) >= arg.size() || |
| 15 | + !arg[*dimIndex]) { |
| 16 | + dim.reset(); |
| 17 | + return true; // no DIM= argument |
| 18 | + } |
| 19 | + if (auto *dimConst{ |
| 20 | + Folder<SubscriptInteger>{context}.Folding(arg[*dimIndex])}) { |
| 21 | + if (auto dimScalar{dimConst->GetScalarValue()}) { |
| 22 | + auto dimVal{dimScalar->ToInt64()}; |
| 23 | + if (dimVal >= 1 && dimVal <= rank) { |
| 24 | + dim = dimVal; |
| 25 | + return true; // DIM= exists and is a valid constant |
| 26 | + } else { |
| 27 | + context.messages().Say( |
| 28 | + "DIM=%jd is not valid for an array of rank %d"_err_en_US, |
| 29 | + static_cast<std::intmax_t>(dimVal), rank); |
27 | 30 | }
|
28 | 31 | }
|
29 | 32 | }
|
30 |
| - return true; |
| 33 | + return false; // DIM= bad or not scalar constant |
31 | 34 | }
|
32 | 35 |
|
33 | 36 | Constant<LogicalResult> *GetReductionMASK(
|
|
0 commit comments