[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 20:34:34 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd8713523a2f5: [flang] Improve message for assignment to subprogram (authored by tskeith).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85483/new/
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.283801.patch
Type: text/x-patch
Size: 1677 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/4add86a8/attachment.bin>
More information about the llvm-commits
mailing list