[flang] Do not replace format with namelist if there is no unit (avoiding accidental...
authorpeter klausler <pklausler@nvidia.com>
Wed, 10 Apr 2019 00:14:29 +0000 (17:14 -0700)
committerpeter klausler <pklausler@nvidia.com>
Wed, 10 Apr 2019 15:52:46 +0000 (08:52 -0700)
Original-commit: flang-compiler/f18@08562d9b861bf6cb2d7e262b5f47fa58ca686134
Reviewed-on: https://github.com/flang-compiler/f18/pull/394

flang/lib/parser/parse-tree.h
flang/lib/semantics/rewrite-parse-tree.cc

index cfe0e45..f172437 100644 (file)
@@ -2610,10 +2610,11 @@ struct ReadStmt {
       std::list<IoControlSpec> &&cs, std::list<InputItem> &&its)
     : iounit{std::move(i)}, format{std::move(f)}, controls(std::move(cs)),
       items(std::move(its)) {}
-  std::optional<IoUnit> iounit;  // if first in controls without UNIT=
-  std::optional<Format> format;  // if second in controls without FMT=, or
+  std::optional<IoUnit> iounit;  // if first in controls without UNIT= &/or
+                                 // followed by untagged format/namelist
+  std::optional<Format> format;  // if second in controls without FMT=/NML=, or
                                  // no (io-control-spec-list); might be
-                                 // an untagged namelist group name, too
+                                 // an untagged namelist group name
   std::list<IoControlSpec> controls;
   std::list<InputItem> items;
 };
@@ -2631,8 +2632,9 @@ struct WriteStmt {
       std::list<IoControlSpec> &&cs, std::list<OutputItem> &&its)
     : iounit{std::move(i)}, format{std::move(f)}, controls(std::move(cs)),
       items(std::move(its)) {}
-  std::optional<IoUnit> iounit;  // if first in controls without UNIT=
-  std::optional<Format> format;  // if second in controls without FMT=;
+  std::optional<IoUnit> iounit;  // if first in controls without UNIT= &/or
+                                 // followed by untagged format/namelist
+  std::optional<Format> format;  // if second in controls without FMT=/NML=;
                                  // might be an untagged namelist group, too
   std::list<IoControlSpec> controls;
   std::list<OutputItem> items;
index cd87829..a2712c7 100644 (file)
@@ -110,7 +110,7 @@ bool RewriteMutator::Pre(parser::ExecutionPart &x) {
 // name had appeared with NML=.
 template<typename READ_OR_WRITE>
 void FixMisparsedUntaggedNamelistName(READ_OR_WRITE &x) {
-  if (x.format.has_value()) {
+  if (x.iounit.has_value() && x.format.has_value()) {
     if (auto *charExpr{
             std::get_if<parser::DefaultCharExpr>(&x.format.value().u)}) {
       parser::Expr &expr{charExpr->thing.value()};