[flang-commits] [PATCH] D91375: [flang] Include source information in an invalid file-unit-number message
Peter Klausler via Phabricator via flang-commits
flang-commits at lists.llvm.org
Thu Nov 12 12:00:13 PST 2020
klausler created this revision.
klausler added a reviewer: tskeith.
klausler added a project: Flang.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.
klausler requested review of this revision.
An io-unit that is an internal-file-variable is syntactically identical
to a file-unit-number expression that is a variable reference. An
ambiguous unit is initially parsed as an internal-file-variable. If
semantic analysis determines that the unit is not of character type,
it is rewritten as an internal-file-variable. This modification must
retain source coordinate information.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91375
Files:
flang/lib/Semantics/rewrite-parse-tree.cpp
flang/test/Semantics/io04.f90
Index: flang/test/Semantics/io04.f90
===================================================================
--- flang/test/Semantics/io04.f90
+++ flang/test/Semantics/io04.f90
@@ -87,6 +87,9 @@
!ERROR: If UNIT=* appears, REC must not appear
write(*, rec=13) 'Ok'
+ !ERROR: Must have INTEGER type, but is REAL(4)
+ write(unit, *) 'Ok'
+
!ERROR: If ADVANCE appears, UNIT=internal-file must not appear
write(internal_file, advance='yes', fmt=1) 'Ok'
Index: flang/lib/Semantics/rewrite-parse-tree.cpp
===================================================================
--- flang/lib/Semantics/rewrite-parse-tree.cpp
+++ flang/lib/Semantics/rewrite-parse-tree.cpp
@@ -110,6 +110,8 @@
return true;
}
+// Convert a syntactically ambiguous io-unit internal-file-variable to a
+// file-unit-number.
void RewriteMutator::Post(parser::IoUnit &x) {
if (auto *var{std::get_if<parser::Variable>(&x.u)}) {
const parser::Name &last{parser::GetLastName(*var)};
@@ -118,11 +120,13 @@
// If the Variable is not known to be character (any kind), transform
// the I/O unit in situ to a FileUnitNumber so that automatic expression
// constraint checking will be applied.
+ auto source{var->GetSource()};
auto expr{std::visit(
[](auto &&indirection) {
return parser::Expr{std::move(indirection)};
},
std::move(var->u))};
+ expr.source = source;
x.u = parser::FileUnitNumber{
parser::ScalarIntExpr{parser::IntExpr{std::move(expr)}}};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91375.304926.patch
Type: text/x-patch
Size: 1549 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20201112/75d8a900/attachment.bin>
More information about the flang-commits
mailing list