[flang-commits] [PATCH] D132165: [flang] Improve error message for attempted assignment to a procedure
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Aug 18 11:26:51 PDT 2022
klausler created this revision.
klausler added a reviewer: PeteSteinfeld.
klausler added a project: Flang.
Herald added a subscriber: jdoerfert.
Herald added a project: All.
klausler requested review of this revision.
Emit a "Assignment to procedure 'foo' is not allowed" error message
for more cases of 'foo' than just declaraed subprograms, rather than
assuming that those additional cases were named constants.
https://reviews.llvm.org/D132165
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
@@ -117,15 +117,22 @@
end
subroutine s8
- !ERROR: Assignment to subprogram 's8' is not allowed
+ !ERROR: Assignment to procedure 's8' is not allowed
s8 = 1.0
end
real function f9() result(r)
- !ERROR: Assignment to subprogram 'f9' is not allowed
+ !ERROR: Assignment to procedure 'f9' is not allowed
f9 = 1.0
end
+subroutine s9
+ real f9a
+ !ERROR: Assignment to procedure 'f9a' is not allowed
+ f9a = 1.0
+ print *, f9a(1)
+end
+
!ERROR: No explicit type declared for dummy argument 'n'
subroutine s10(a, n)
implicit none
Index: flang/lib/Semantics/expression.cpp
===================================================================
--- flang/lib/Semantics/expression.cpp
+++ flang/lib/Semantics/expression.cpp
@@ -3350,17 +3350,20 @@
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'"_en_US, result);
+ } else if (IsProcedure(*symbol)) {
+ if (auto *msg{context_.SayAt(x,
+ "Assignment to procedure '%s' is not allowed"_err_en_US,
+ symbol->name())}) {
+ if (auto *subp{symbol->detailsIf<semantics::SubprogramDetails>()}) {
+ if (subp->isFunction()) {
+ const auto &result{subp->result().name()};
+ msg->Attach(result, "Function result is '%s'"_en_US, result);
+ }
+ }
}
} else {
- context_.SayAt(x, "Assignment to constant '%s' is not allowed"_err_en_US,
- symbol->name());
+ context_.SayAt(
+ x, "Assignment to '%s' is not allowed"_err_en_US, symbol->name());
}
}
fatalErrors_ = true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132165.453735.patch
Type: text/x-patch
Size: 2173 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220818/74bdb620/attachment.bin>
More information about the flang-commits
mailing list