[PATCH] D85483: [flang] Improve message for assignment to subprogram
Tim Keith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 15:47:32 PDT 2020
tskeith created this revision.
tskeith added reviewers: klausler, PeteSteinfeld.
tskeith added a project: Flang.
Herald added a reviewer: jdoerfert.
Herald added a reviewer: DavidTruby.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
tskeith requested review of this revision.
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.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D85483
Files:
flang/lib/Semantics/expression.cpp
flang/test/Semantics/assign04.f90
Index: flang/test/Semantics/assign04.f90
===================================================================
--- flang/test/Semantics/assign04.f90
+++ flang/test/Semantics/assign04.f90
@@ -115,3 +115,13 @@
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
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -2704,10 +2704,22 @@
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85483.283755.patch
Type: text/x-patch
Size: 1677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200806/235cc293/attachment.bin>
More information about the llvm-commits
mailing list