[flang] Modify right modes for READ/WRITE vs OPEN
authorPeter Klausler <pklausler@nvidia.com>
Mon, 31 Jan 2022 18:06:40 +0000 (10:06 -0800)
committerPeter Klausler <pklausler@nvidia.com>
Wed, 2 Feb 2022 21:47:46 +0000 (13:47 -0800)
When a mode flag is modified (e.g., BLANK='ZERO') in an I/O data transfer
statement, ensure that the right set of mode flags is modified.
There's one set of mode flags that are captured by an OPEN
statement and maintained in the connection, and another that
is maintained in an I/O statement state record for local mutability.
Some I/O API routines were unconditionally modifying the persistent
set of flags.

Differential Revision: https://reviews.llvm.org/D118835

flang/runtime/io-api.cpp

index 8700f7c..8c999ed 100644 (file)
@@ -461,14 +461,13 @@ bool IONAME(SetAdvance)(
 
 bool IONAME(SetBlank)(Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
   static const char *keywords[]{"NULL", "ZERO", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    connection.modes.editingFlags &= ~blankZero;
+    io.mutableModes().editingFlags &= ~blankZero;
     return true;
   case 1:
-    connection.modes.editingFlags |= blankZero;
+    io.mutableModes().editingFlags |= blankZero;
     return true;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -480,14 +479,13 @@ bool IONAME(SetBlank)(Cookie cookie, const char *keyword, std::size_t length) {
 bool IONAME(SetDecimal)(
     Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
   static const char *keywords[]{"COMMA", "POINT", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    connection.modes.editingFlags |= decimalComma;
+    io.mutableModes().editingFlags |= decimalComma;
     return true;
   case 1:
-    connection.modes.editingFlags &= ~decimalComma;
+    io.mutableModes().editingFlags &= ~decimalComma;
     return true;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -498,17 +496,16 @@ bool IONAME(SetDecimal)(
 
 bool IONAME(SetDelim)(Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
   static const char *keywords[]{"APOSTROPHE", "QUOTE", "NONE", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    connection.modes.delim = '\'';
+    io.mutableModes().delim = '\'';
     return true;
   case 1:
-    connection.modes.delim = '"';
+    io.mutableModes().delim = '"';
     return true;
   case 2:
-    connection.modes.delim = '\0';
+    io.mutableModes().delim = '\0';
     return true;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -519,8 +516,7 @@ bool IONAME(SetDelim)(Cookie cookie, const char *keyword, std::size_t length) {
 
 bool IONAME(SetPad)(Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
-  connection.modes.pad =
+  io.mutableModes().pad =
       YesOrNo(keyword, length, "PAD", io.GetIoErrorHandler());
   return true;
 }
@@ -570,27 +566,26 @@ bool IONAME(SetRec)(Cookie cookie, std::int64_t rec) {
 
 bool IONAME(SetRound)(Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
   static const char *keywords[]{"UP", "DOWN", "ZERO", "NEAREST", "COMPATIBLE",
       "PROCESSOR_DEFINED", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    connection.modes.round = decimal::RoundUp;
+    io.mutableModes().round = decimal::RoundUp;
     return true;
   case 1:
-    connection.modes.round = decimal::RoundDown;
+    io.mutableModes().round = decimal::RoundDown;
     return true;
   case 2:
-    connection.modes.round = decimal::RoundToZero;
+    io.mutableModes().round = decimal::RoundToZero;
     return true;
   case 3:
-    connection.modes.round = decimal::RoundNearest;
+    io.mutableModes().round = decimal::RoundNearest;
     return true;
   case 4:
-    connection.modes.round = decimal::RoundCompatible;
+    io.mutableModes().round = decimal::RoundCompatible;
     return true;
   case 5:
-    connection.modes.round = executionEnvironment.defaultOutputRoundingMode;
+    io.mutableModes().round = executionEnvironment.defaultOutputRoundingMode;
     return true;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -601,16 +596,15 @@ bool IONAME(SetRound)(Cookie cookie, const char *keyword, std::size_t length) {
 
 bool IONAME(SetSign)(Cookie cookie, const char *keyword, std::size_t length) {
   IoStatementState &io{*cookie};
-  ConnectionState &connection{io.GetConnectionState()};
   static const char *keywords[]{
       "PLUS", "SUPPRESS", "PROCESSOR_DEFINED", nullptr};
   switch (IdentifyValue(keyword, length, keywords)) {
   case 0:
-    connection.modes.editingFlags |= signPlus;
+    io.mutableModes().editingFlags |= signPlus;
     return true;
   case 1:
   case 2: // processor default is SS
-    connection.modes.editingFlags &= ~signPlus;
+    io.mutableModes().editingFlags &= ~signPlus;
     return true;
   default:
     io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,