[flang-commits] [flang] 7f5928e - [flang] Avoid cascading error in subscript triplet
Tim Keith via flang-commits
flang-commits at lists.llvm.org
Mon Aug 10 11:44:27 PDT 2020
Author: Tim Keith
Date: 2020-08-10T11:44:08-07:00
New Revision: 7f5928ef5a5743ee7e65c6c9d1e1c9bc6af03063
URL: https://github.com/llvm/llvm-project/commit/7f5928ef5a5743ee7e65c6c9d1e1c9bc6af03063
DIFF: https://github.com/llvm/llvm-project/commit/7f5928ef5a5743ee7e65c6c9d1e1c9bc6af03063.diff
LOG: [flang] Avoid cascading error in subscript triplet
If a bound of a subscript triplet is present but fails to analyze
due to an error, return nullopt rather than returning a Triplet with
that bound missing. This is so we can distinguish an absent bound from
an erroneous one and avoid spurious errors.
Differential Revision: https://reviews.llvm.org/D85672
Added:
Modified:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/assign04.f90
Removed:
################################################################################
diff --git a/flang/lib/Semantics/expression.cpp b/flang/lib/Semantics/expression.cpp
index 64ccb3b98786..9b6531cdbd6d 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -871,21 +871,28 @@ std::optional<Expr<SubscriptInteger>> ExpressionAnalyzer::TripletPart(
std::optional<Subscript> ExpressionAnalyzer::AnalyzeSectionSubscript(
const parser::SectionSubscript &ss) {
- return std::visit(common::visitors{
- [&](const parser::SubscriptTriplet &t) {
- return std::make_optional<Subscript>(
- Triplet{TripletPart(std::get<0>(t.t)),
- TripletPart(std::get<1>(t.t)),
- TripletPart(std::get<2>(t.t))});
- },
- [&](const auto &s) -> std::optional<Subscript> {
- if (auto subscriptExpr{AsSubscript(Analyze(s))}) {
- return Subscript{std::move(*subscriptExpr)};
- } else {
- return std::nullopt;
- }
- },
- },
+ return std::visit(
+ common::visitors{
+ [&](const parser::SubscriptTriplet &t) -> std::optional<Subscript> {
+ const auto &lower{std::get<0>(t.t)};
+ const auto &upper{std::get<1>(t.t)};
+ const auto &stride{std::get<2>(t.t)};
+ auto result{Triplet{
+ TripletPart(lower), TripletPart(upper), TripletPart(stride)}};
+ if ((lower && !result.lower()) || (upper && !result.upper())) {
+ return std::nullopt;
+ } else {
+ return std::make_optional<Subscript>(result);
+ }
+ },
+ [&](const auto &s) -> std::optional<Subscript> {
+ if (auto subscriptExpr{AsSubscript(Analyze(s))}) {
+ return Subscript{std::move(*subscriptExpr)};
+ } else {
+ return std::nullopt;
+ }
+ },
+ },
ss.u);
}
diff --git a/flang/test/Semantics/assign04.f90 b/flang/test/Semantics/assign04.f90
index a37896aa7aa1..99f4901b2050 100644
--- a/flang/test/Semantics/assign04.f90
+++ b/flang/test/Semantics/assign04.f90
@@ -125,3 +125,10 @@ real function f9() result(r)
!ERROR: Assignment to subprogram 'f9' is not allowed
f9 = 1.0
end
+
+!ERROR: No explicit type declared for 'n'
+subroutine s10(a, n)
+ implicit none
+ real a(n)
+ a(1:n) = 0.0 ! should not get a second error here
+end
More information about the flang-commits
mailing list