[flang-commits] [flang] d871352 - [flang] Improve message for assignment to subprogram
Tim Keith via flang-commits
flang-commits at lists.llvm.org
Thu Aug 6 20:34:30 PDT 2020
Author: Tim Keith
Date: 2020-08-06T20:34:00-07:00
New Revision: d8713523a2f5847ca69c8ef172578a915c129fe8
URL: https://github.com/llvm/llvm-project/commit/d8713523a2f5847ca69c8ef172578a915c129fe8
DIFF: https://github.com/llvm/llvm-project/commit/d8713523a2f5847ca69c8ef172578a915c129fe8.diff
LOG: [flang] Improve message for assignment to subprogram
In the example below we were producing the error message
"Assignment to constant 'f' is not allowed":
```
function f() result(r)
f = 1.0
end
```
This changes it to a more helpful message when the LHS is a subprogram
name and also mentions the function result name when it's a function.
Differential Revision: https://reviews.llvm.org/D85483
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 0a6e448e98a2..64ccb3b98786 100644
--- a/flang/lib/Semantics/expression.cpp
+++ b/flang/lib/Semantics/expression.cpp
@@ -2704,10 +2704,22 @@ void ArgumentAnalyzer::Analyze(const parser::Variable &x) {
actuals_.emplace_back(std::move(*expr));
return;
}
- const Symbol *symbol{GetFirstSymbol(*expr)};
- context_.Say(x.GetSource(),
- "Assignment to constant '%s' is not allowed"_err_en_US,
- symbol ? symbol->name() : x.GetSource());
+ const Symbol *symbol{GetLastSymbol(*expr)};
+ if (!symbol) {
+ context_.SayAt(x, "Assignment to constant '%s' is not allowed"_err_en_US,
+ x.GetSource());
+ } else if (auto *subp{symbol->detailsIf<semantics::SubprogramDetails>()}) {
+ auto *msg{context_.SayAt(x,
+ "Assignment to subprogram '%s' is not allowed"_err_en_US,
+ symbol->name())};
+ if (subp->isFunction()) {
+ const auto &result{subp->result().name()};
+ msg->Attach(result, "Function result is '%s'"_err_en_US, result);
+ }
+ } else {
+ context_.SayAt(x, "Assignment to constant '%s' is not allowed"_err_en_US,
+ symbol->name());
+ }
}
fatalErrors_ = true;
}
diff --git a/flang/test/Semantics/assign04.f90 b/flang/test/Semantics/assign04.f90
index 03e8f6cef7dc..a37896aa7aa1 100644
--- a/flang/test/Semantics/assign04.f90
+++ b/flang/test/Semantics/assign04.f90
@@ -115,3 +115,13 @@ subroutine s7
integer :: a(10), v(10)
a(v(:)) = 1 ! vector subscript is ok
end
+
+subroutine s8
+ !ERROR: Assignment to subprogram 's8' is not allowed
+ s8 = 1.0
+end
+
+real function f9() result(r)
+ !ERROR: Assignment to subprogram 'f9' is not allowed
+ f9 = 1.0
+end
More information about the flang-commits
mailing list