Skip to content

Commit 2b0b9b2

Browse files
committed
[flang] Modify right modes for READ/WRITE vs OPEN
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
1 parent 1d67909 commit 2b0b9b2

File tree

1 file changed

+16
-22
lines changed

1 file changed

+16
-22
lines changed

flang/runtime/io-api.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,13 @@ bool IONAME(SetAdvance)(
461461

462462
bool IONAME(SetBlank)(Cookie cookie, const char *keyword, std::size_t length) {
463463
IoStatementState &io{*cookie};
464-
ConnectionState &connection{io.GetConnectionState()};
465464
static const char *keywords[]{"NULL", "ZERO", nullptr};
466465
switch (IdentifyValue(keyword, length, keywords)) {
467466
case 0:
468-
connection.modes.editingFlags &= ~blankZero;
467+
io.mutableModes().editingFlags &= ~blankZero;
469468
return true;
470469
case 1:
471-
connection.modes.editingFlags |= blankZero;
470+
io.mutableModes().editingFlags |= blankZero;
472471
return true;
473472
default:
474473
io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -480,14 +479,13 @@ bool IONAME(SetBlank)(Cookie cookie, const char *keyword, std::size_t length) {
480479
bool IONAME(SetDecimal)(
481480
Cookie cookie, const char *keyword, std::size_t length) {
482481
IoStatementState &io{*cookie};
483-
ConnectionState &connection{io.GetConnectionState()};
484482
static const char *keywords[]{"COMMA", "POINT", nullptr};
485483
switch (IdentifyValue(keyword, length, keywords)) {
486484
case 0:
487-
connection.modes.editingFlags |= decimalComma;
485+
io.mutableModes().editingFlags |= decimalComma;
488486
return true;
489487
case 1:
490-
connection.modes.editingFlags &= ~decimalComma;
488+
io.mutableModes().editingFlags &= ~decimalComma;
491489
return true;
492490
default:
493491
io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -498,17 +496,16 @@ bool IONAME(SetDecimal)(
498496

499497
bool IONAME(SetDelim)(Cookie cookie, const char *keyword, std::size_t length) {
500498
IoStatementState &io{*cookie};
501-
ConnectionState &connection{io.GetConnectionState()};
502499
static const char *keywords[]{"APOSTROPHE", "QUOTE", "NONE", nullptr};
503500
switch (IdentifyValue(keyword, length, keywords)) {
504501
case 0:
505-
connection.modes.delim = '\'';
502+
io.mutableModes().delim = '\'';
506503
return true;
507504
case 1:
508-
connection.modes.delim = '"';
505+
io.mutableModes().delim = '"';
509506
return true;
510507
case 2:
511-
connection.modes.delim = '\0';
508+
io.mutableModes().delim = '\0';
512509
return true;
513510
default:
514511
io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -519,8 +516,7 @@ bool IONAME(SetDelim)(Cookie cookie, const char *keyword, std::size_t length) {
519516

520517
bool IONAME(SetPad)(Cookie cookie, const char *keyword, std::size_t length) {
521518
IoStatementState &io{*cookie};
522-
ConnectionState &connection{io.GetConnectionState()};
523-
connection.modes.pad =
519+
io.mutableModes().pad =
524520
YesOrNo(keyword, length, "PAD", io.GetIoErrorHandler());
525521
return true;
526522
}
@@ -570,27 +566,26 @@ bool IONAME(SetRec)(Cookie cookie, std::int64_t rec) {
570566

571567
bool IONAME(SetRound)(Cookie cookie, const char *keyword, std::size_t length) {
572568
IoStatementState &io{*cookie};
573-
ConnectionState &connection{io.GetConnectionState()};
574569
static const char *keywords[]{"UP", "DOWN", "ZERO", "NEAREST", "COMPATIBLE",
575570
"PROCESSOR_DEFINED", nullptr};
576571
switch (IdentifyValue(keyword, length, keywords)) {
577572
case 0:
578-
connection.modes.round = decimal::RoundUp;
573+
io.mutableModes().round = decimal::RoundUp;
579574
return true;
580575
case 1:
581-
connection.modes.round = decimal::RoundDown;
576+
io.mutableModes().round = decimal::RoundDown;
582577
return true;
583578
case 2:
584-
connection.modes.round = decimal::RoundToZero;
579+
io.mutableModes().round = decimal::RoundToZero;
585580
return true;
586581
case 3:
587-
connection.modes.round = decimal::RoundNearest;
582+
io.mutableModes().round = decimal::RoundNearest;
588583
return true;
589584
case 4:
590-
connection.modes.round = decimal::RoundCompatible;
585+
io.mutableModes().round = decimal::RoundCompatible;
591586
return true;
592587
case 5:
593-
connection.modes.round = executionEnvironment.defaultOutputRoundingMode;
588+
io.mutableModes().round = executionEnvironment.defaultOutputRoundingMode;
594589
return true;
595590
default:
596591
io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,
@@ -601,16 +596,15 @@ bool IONAME(SetRound)(Cookie cookie, const char *keyword, std::size_t length) {
601596

602597
bool IONAME(SetSign)(Cookie cookie, const char *keyword, std::size_t length) {
603598
IoStatementState &io{*cookie};
604-
ConnectionState &connection{io.GetConnectionState()};
605599
static const char *keywords[]{
606600
"PLUS", "SUPPRESS", "PROCESSOR_DEFINED", nullptr};
607601
switch (IdentifyValue(keyword, length, keywords)) {
608602
case 0:
609-
connection.modes.editingFlags |= signPlus;
603+
io.mutableModes().editingFlags |= signPlus;
610604
return true;
611605
case 1:
612606
case 2: // processor default is SS
613-
connection.modes.editingFlags &= ~signPlus;
607+
io.mutableModes().editingFlags &= ~signPlus;
614608
return true;
615609
default:
616610
io.GetIoErrorHandler().SignalError(IostatErrorInKeyword,

0 commit comments

Comments
 (0)