Skip to content

Commit b83242e

Browse files
committed
[flang] Support legacy usage of 'A' edit descriptors for integer & real
The 'A' edit descriptor once served as a form of raw I/O of bytes to/from variables that weren't of type CHARACTER (which itself didn't exist until F'77). This usage was especially common for output of numeric variables that had been initialized with Hollerith. Differential Revision: https://reviews.llvm.org/D112346
1 parent 89a927c commit b83242e

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

flang/runtime/edit-input.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ bool EditIntegerInput(
8383
return EditBOZInput(io, edit, n, 8, kind << 3);
8484
case 'Z':
8585
return EditBOZInput(io, edit, n, 16, kind << 3);
86+
case 'A': // legacy extension
87+
return EditDefaultCharacterInput(
88+
io, edit, reinterpret_cast<char *>(n), kind);
8689
default:
8790
io.GetIoErrorHandler().SignalError(IostatErrorInFormat,
8891
"Data edit descriptor '%c' may not be used with an INTEGER data item",
@@ -323,6 +326,9 @@ bool EditRealInput(IoStatementState &io, const DataEdit &edit, void *n) {
323326
case 'Z':
324327
return EditBOZInput(
325328
io, edit, n, 16, common::BitsForBinaryPrecision(binaryPrecision));
329+
case 'A': // legacy extension
330+
return EditDefaultCharacterInput(
331+
io, edit, reinterpret_cast<char *>(n), KIND);
326332
default:
327333
io.GetIoErrorHandler().SignalError(IostatErrorInFormat,
328334
"Data edit descriptor '%c' may not be used for REAL input",

flang/runtime/edit-output.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ bool EditIntegerOutput(IoStatementState &io, const DataEdit &edit,
5252
*--p = digit >= 10 ? 'A' + (digit - 10) : '0' + digit;
5353
}
5454
break;
55+
case 'A': // legacy extension
56+
return EditDefaultCharacterOutput(
57+
io, edit, reinterpret_cast<char *>(&n), sizeof n);
5558
default:
5659
io.GetIoErrorHandler().Crash(
5760
"Data edit descriptor '%c' may not be used with an INTEGER data item",
@@ -402,6 +405,9 @@ template <int KIND> bool RealOutputEditing<KIND>::Edit(const DataEdit &edit) {
402405
decimal::BinaryFloatingPointNumber<binaryPrecision>{x_}.raw()));
403406
case 'G':
404407
return Edit(EditForGOutput(edit));
408+
case 'A': // legacy extension
409+
return EditDefaultCharacterOutput(
410+
io_, edit, reinterpret_cast<char *>(&x_), sizeof x_);
405411
default:
406412
if (edit.IsListDirected()) {
407413
return EditListDirectedOutput(edit);

flang/unittests/Runtime/RuntimeCrashTest.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ TEST(TestIOCrash, FormatDescriptorWriteMismatchTest) {
5757
static const char *format{"(A4)"};
5858
auto *cookie{IONAME(BeginInternalFormattedOutput)(
5959
buffer, bufferSize, format, std::strlen(format))};
60-
ASSERT_DEATH(IONAME(OutputInteger64)(cookie, 0xfeedface),
61-
"Data edit descriptor 'A' may not be used with an INTEGER data item");
60+
ASSERT_DEATH(IONAME(OutputLogical)(cookie, true),
61+
"Data edit descriptor 'A' may not be used with a LOGICAL data item");
6262
}
6363

6464
TEST(TestIOCrash, InvalidFormatCharacterTest) {

0 commit comments

Comments
 (0)