Skip to content

Commit 8cf6e94

Browse files
authored
[flang] Remove dead code and update test (NFC) (#73004)
OutputUnformattedBlock and InputUnformattedBlock are not used.
1 parent bed1a5b commit 8cf6e94

File tree

4 files changed

+57
-100
lines changed

4 files changed

+57
-100
lines changed

flang/include/flang/Runtime/io-api.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,6 @@ bool IONAME(SetSign)(Cookie, const char *, std::size_t);
244244
// and avoid the following items when they might crash.
245245
bool IONAME(OutputDescriptor)(Cookie, const Descriptor &);
246246
bool IONAME(InputDescriptor)(Cookie, const Descriptor &);
247-
// Contiguous transfers for unformatted I/O
248-
bool IONAME(OutputUnformattedBlock)(
249-
Cookie, const char *, std::size_t, std::size_t elementBytes);
250-
bool IONAME(InputUnformattedBlock)(
251-
Cookie, char *, std::size_t, std::size_t elementBytes);
252247
// Formatted (including list directed) I/O data items
253248
bool IONAME(OutputInteger8)(Cookie, std::int8_t);
254249
bool IONAME(OutputInteger16)(Cookie, std::int16_t);

flang/lib/Lower/IO.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,19 @@ static constexpr std::tuple<
101101
mkIOKey(InputAscii), mkIOKey(InputComplex32), mkIOKey(InputComplex64),
102102
mkIOKey(InputDerivedType), mkIOKey(InputDescriptor), mkIOKey(InputInteger),
103103
mkIOKey(InputLogical), mkIOKey(InputNamelist), mkIOKey(InputReal32),
104-
mkIOKey(InputReal64), mkIOKey(InputUnformattedBlock),
105-
mkIOKey(InquireCharacter), mkIOKey(InquireInteger64),
104+
mkIOKey(InputReal64), mkIOKey(InquireCharacter), mkIOKey(InquireInteger64),
106105
mkIOKey(InquireLogical), mkIOKey(InquirePendingId), mkIOKey(OutputAscii),
107106
mkIOKey(OutputComplex32), mkIOKey(OutputComplex64),
108107
mkIOKey(OutputDerivedType), mkIOKey(OutputDescriptor),
109108
mkIOKey(OutputInteger8), mkIOKey(OutputInteger16), mkIOKey(OutputInteger32),
110109
mkIOKey(OutputInteger64), mkIOKey(OutputInteger128), mkIOKey(OutputLogical),
111110
mkIOKey(OutputNamelist), mkIOKey(OutputReal32), mkIOKey(OutputReal64),
112-
mkIOKey(OutputUnformattedBlock), mkIOKey(SetAccess), mkIOKey(SetAction),
113-
mkIOKey(SetAdvance), mkIOKey(SetAsynchronous), mkIOKey(SetBlank),
114-
mkIOKey(SetCarriagecontrol), mkIOKey(SetConvert), mkIOKey(SetDecimal),
115-
mkIOKey(SetDelim), mkIOKey(SetEncoding), mkIOKey(SetFile), mkIOKey(SetForm),
116-
mkIOKey(SetPad), mkIOKey(SetPos), mkIOKey(SetPosition), mkIOKey(SetRec),
117-
mkIOKey(SetRecl), mkIOKey(SetRound), mkIOKey(SetSign), mkIOKey(SetStatus)>
111+
mkIOKey(SetAccess), mkIOKey(SetAction), mkIOKey(SetAdvance),
112+
mkIOKey(SetAsynchronous), mkIOKey(SetBlank), mkIOKey(SetCarriagecontrol),
113+
mkIOKey(SetConvert), mkIOKey(SetDecimal), mkIOKey(SetDelim),
114+
mkIOKey(SetEncoding), mkIOKey(SetFile), mkIOKey(SetForm), mkIOKey(SetPad),
115+
mkIOKey(SetPos), mkIOKey(SetPosition), mkIOKey(SetRec), mkIOKey(SetRecl),
116+
mkIOKey(SetRound), mkIOKey(SetSign), mkIOKey(SetStatus)>
118117
newIOTable;
119118
} // namespace Fortran::lower
120119

flang/runtime/io-api.cpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,39 +1135,6 @@ bool IONAME(InputDescriptor)(Cookie cookie, const Descriptor &descriptor) {
11351135
return descr::DescriptorIO<Direction::Input>(*cookie, descriptor);
11361136
}
11371137

1138-
bool IONAME(OutputUnformattedBlock)(Cookie cookie, const char *x,
1139-
std::size_t length, std::size_t elementBytes) {
1140-
IoStatementState &io{*cookie};
1141-
if (auto *unf{io.get_if<
1142-
ExternalUnformattedIoStatementState<Direction::Output>>()}) {
1143-
return unf->Emit(x, length, elementBytes);
1144-
} else if (auto *inq{io.get_if<InquireIOLengthState>()}) {
1145-
return inq->Emit(x, length, elementBytes);
1146-
} else if (!io.get_if<ErroneousIoStatementState>()) {
1147-
io.GetIoErrorHandler().Crash("OutputUnformattedBlock() called for an I/O "
1148-
"statement that is not unformatted output");
1149-
}
1150-
return false;
1151-
}
1152-
1153-
bool IONAME(InputUnformattedBlock)(
1154-
Cookie cookie, char *x, std::size_t length, std::size_t elementBytes) {
1155-
IoStatementState &io{*cookie};
1156-
IoErrorHandler &handler{io.GetIoErrorHandler()};
1157-
io.BeginReadingRecord();
1158-
if (handler.InError()) {
1159-
return false;
1160-
}
1161-
if (auto *unf{
1162-
io.get_if<ExternalUnformattedIoStatementState<Direction::Input>>()}) {
1163-
return unf->Receive(x, length, elementBytes);
1164-
} else if (!io.get_if<ErroneousIoStatementState>()) {
1165-
handler.Crash("InputUnformattedBlock() called for an I/O statement that is "
1166-
"not unformatted input");
1167-
}
1168-
return false;
1169-
}
1170-
11711138
bool IONAME(OutputInteger8)(Cookie cookie, std::int8_t n) {
11721139
if (!cookie->CheckFormattedStmtType<Direction::Output>("OutputInteger8")) {
11731140
return false;

flang/unittests/Runtime/ExternalIOTest.cpp

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,15 @@ TEST(ExternalIOTests, TestDirectUnformatted) {
4343
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
4444
<< "EndIoStatement() for OpenNewUnit";
4545

46+
StaticDescriptor<0> staticDescriptor;
47+
Descriptor &desc{staticDescriptor.descriptor()};
48+
desc.Establish(TypeCode{CFI_type_int8_t}, recl, &buffer, 0);
49+
desc.Check();
50+
4651
// INQUIRE(IOLENGTH=) j
4752
io = IONAME(BeginInquireIoLength)(__FILE__, __LINE__);
48-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
49-
io, reinterpret_cast<const char *>(&buffer), recl, 1))
50-
<< "OutputUnformattedBlock() for InquireIoLength";
53+
ASSERT_TRUE(IONAME(OutputDescriptor)(io, desc))
54+
<< "OutputDescriptor() for InquireIoLength";
5155
ASSERT_EQ(IONAME(GetIoLength)(io), recl) << "GetIoLength";
5256
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
5357
<< "EndIoStatement() for InquireIoLength";
@@ -59,24 +63,23 @@ TEST(ExternalIOTests, TestDirectUnformatted) {
5963
ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
6064

6165
buffer = j;
62-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
63-
io, reinterpret_cast<const char *>(&buffer), 1, recl))
64-
<< "OutputUnformattedBlock()";
66+
ASSERT_TRUE(IONAME(OutputDescriptor)(io, desc))
67+
<< "OutputDescriptor() for Write";
6568

6669
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
67-
<< "EndIoStatement() for OutputUnformattedBlock";
70+
<< "EndIoStatement() for Write";
6871
}
6972

7073
for (int j{records}; j >= 1; --j) {
74+
buffer = -1;
7175
// READ(UNIT=unit,REC=j) n
7276
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
7377
ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
74-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(
75-
io, reinterpret_cast<char *>(&buffer), 1, recl))
76-
<< "InputUnformattedBlock()";
78+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc))
79+
<< "InputDescriptor() for Read";
7780

7881
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
79-
<< "EndIoStatement() for InputUnformattedBlock";
82+
<< "EndIoStatement() for Read";
8083

8184
ASSERT_EQ(buffer, j) << "Read back " << buffer
8285
<< " from direct unformatted record " << j
@@ -108,17 +111,21 @@ TEST(ExternalIOTests, TestDirectUnformattedSwapped) {
108111
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
109112
<< "EndIoStatement() for OpenNewUnit";
110113

114+
StaticDescriptor<0> staticDescriptor;
115+
Descriptor &desc{staticDescriptor.descriptor()};
116+
desc.Establish(TypeCode{CFI_type_int64_t}, recl, &buffer, 0);
117+
desc.Check();
118+
111119
static constexpr int records{10};
112120
for (int j{1}; j <= records; ++j) {
113121
// WRITE(UNIT=unit,REC=j) j
114122
io = IONAME(BeginUnformattedOutput)(unit, __FILE__, __LINE__);
115123
ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
116124
buffer = j;
117-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
118-
io, reinterpret_cast<const char *>(&buffer), recl, recl))
119-
<< "OutputUnformattedBlock()";
125+
ASSERT_TRUE(IONAME(OutputDescriptor)(io, desc))
126+
<< "OutputDescriptor() for Write";
120127
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
121-
<< "EndIoStatement() for OutputUnformattedBlock";
128+
<< "EndIoStatement() for Write";
122129
}
123130

124131
// OPEN(UNIT=unit,STATUS='OLD',CONVERT='SWAP')
@@ -132,11 +139,10 @@ TEST(ExternalIOTests, TestDirectUnformattedSwapped) {
132139
// READ(UNIT=unit,REC=j) n
133140
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
134141
ASSERT_TRUE(IONAME(SetRec)(io, j)) << "SetRec(" << j << ')';
135-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(
136-
io, reinterpret_cast<char *>(&buffer), recl, recl))
137-
<< "InputUnformattedBlock()";
142+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc))
143+
<< "InputDescriptor() for Read";
138144
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
139-
<< "EndIoStatement() for InputUnformattedBlock";
145+
<< "EndIoStatement() for Read";
140146
ASSERT_EQ(buffer >> 56, j)
141147
<< "Read back " << (buffer >> 56) << " from direct unformatted record "
142148
<< j << ", expected " << j << '\n';
@@ -169,17 +175,6 @@ TEST(ExternalIOTests, TestSequentialFixedUnformatted) {
169175
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
170176
<< "EndIoStatement() for OpenNewUnit";
171177

172-
// INQUIRE(IOLENGTH=) j, ...
173-
io = IONAME(BeginInquireIoLength)(__FILE__, __LINE__);
174-
for (int j{1}; j <= 3; ++j) {
175-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
176-
io, reinterpret_cast<const char *>(&buffer), recl, 1))
177-
<< "OutputUnformattedBlock() for InquireIoLength";
178-
}
179-
ASSERT_EQ(IONAME(GetIoLength)(io), 3 * recl) << "GetIoLength";
180-
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
181-
<< "EndIoStatement() for InquireIoLength";
182-
183178
// INQUIRE(IOLENGTH=) j, ...
184179
StaticDescriptor<0> staticDescriptor;
185180
Descriptor &desc{staticDescriptor.descriptor()};
@@ -200,11 +195,10 @@ TEST(ExternalIOTests, TestSequentialFixedUnformatted) {
200195
// DO J=1,RECORDS; WRITE(UNIT=unit) j; END DO
201196
io = IONAME(BeginUnformattedOutput)(unit, __FILE__, __LINE__);
202197
buffer = j;
203-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(
204-
io, reinterpret_cast<const char *>(&buffer), recl, recl))
205-
<< "OutputUnformattedBlock()";
198+
ASSERT_TRUE(IONAME(OutputDescriptor)(io, desc))
199+
<< "OutputDescriptor() for Write";
206200
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
207-
<< "EndIoStatement() for OutputUnformattedBlock";
201+
<< "EndIoStatement() for WRITE";
208202
}
209203

210204
// REWIND(UNIT=unit)
@@ -215,11 +209,10 @@ TEST(ExternalIOTests, TestSequentialFixedUnformatted) {
215209
for (int j{1}; j <= records; ++j) {
216210
// DO J=1,RECORDS; READ(UNIT=unit) n; check n; END DO
217211
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
218-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(
219-
io, reinterpret_cast<char *>(&buffer), recl, recl))
220-
<< "InputUnformattedBlock()";
212+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc))
213+
<< "InputDescriptor() for Read";
221214
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
222-
<< "EndIoStatement() for InputUnformattedBlock";
215+
<< "EndIoStatement() for Read";
223216
ASSERT_EQ(buffer, j) << "Read back " << buffer
224217
<< " from sequential fixed unformatted record " << j
225218
<< ", expected " << j << '\n';
@@ -232,11 +225,10 @@ TEST(ExternalIOTests, TestSequentialFixedUnformatted) {
232225
<< "EndIoStatement() for Backspace (before read)";
233226
// READ(UNIT=unit) n
234227
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
235-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(
236-
io, reinterpret_cast<char *>(&buffer), recl, recl))
237-
<< "InputUnformattedBlock()";
228+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc))
229+
<< "InputDescriptor() for Read";
238230
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
239-
<< "EndIoStatement() for InputUnformattedBlock";
231+
<< "EndIoStatement() for Read";
240232
ASSERT_EQ(buffer, j) << "Read back " << buffer
241233
<< " from sequential fixed unformatted record " << j
242234
<< " after backspacing, expected " << j << '\n';
@@ -275,15 +267,18 @@ TEST(ExternalIOTests, TestSequentialVariableUnformatted) {
275267
buffer[j] = j;
276268
}
277269

270+
StaticDescriptor<0> staticDescriptor;
271+
Descriptor &desc{staticDescriptor.descriptor()};
272+
278273
for (int j{1}; j <= records; ++j) {
279274
// DO J=1,RECORDS; WRITE(UNIT=unit) BUFFER(0:j); END DO
280275
io = IONAME(BeginUnformattedOutput)(unit, __FILE__, __LINE__);
281-
ASSERT_TRUE(IONAME(OutputUnformattedBlock)(io,
282-
reinterpret_cast<const char *>(&buffer), j * sizeof *buffer,
283-
sizeof *buffer))
284-
<< "OutputUnformattedBlock()";
276+
desc.Establish(TypeCode{sizeof *buffer}, j * sizeof *buffer, buffer, 0);
277+
desc.Check();
278+
ASSERT_TRUE(IONAME(OutputDescriptor)(io, desc))
279+
<< "OutputDescriptor() for Write";
285280
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
286-
<< "EndIoStatement() for OutputUnformattedBlock";
281+
<< "EndIoStatement() for Write";
287282
}
288283

289284
// REWIND(UNIT=unit)
@@ -293,11 +288,12 @@ TEST(ExternalIOTests, TestSequentialVariableUnformatted) {
293288
for (int j{1}; j <= records; ++j) {
294289
// DO J=1,RECORDS; READ(UNIT=unit) n; check n; END DO
295290
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
296-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(io,
297-
reinterpret_cast<char *>(&buffer), j * sizeof *buffer, sizeof *buffer))
298-
<< "InputUnformattedBlock()";
291+
desc.Establish(TypeCode{sizeof *buffer}, j * sizeof *buffer, buffer, 0);
292+
desc.Check();
293+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc))
294+
<< "InputDescriptor() for Read";
299295
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
300-
<< "EndIoStatement() for InputUnformattedBlock";
296+
<< "EndIoStatement() for Read";
301297
for (int k{0}; k < j; ++k) {
302298
ASSERT_EQ(buffer[k], k) << "Read back [" << k << "]=" << buffer[k]
303299
<< " from direct unformatted record " << j
@@ -312,9 +308,9 @@ TEST(ExternalIOTests, TestSequentialVariableUnformatted) {
312308
<< "EndIoStatement() for Backspace (before read)";
313309
// READ(unit=unit) n; check
314310
io = IONAME(BeginUnformattedInput)(unit, __FILE__, __LINE__);
315-
ASSERT_TRUE(IONAME(InputUnformattedBlock)(io,
316-
reinterpret_cast<char *>(&buffer), j * sizeof *buffer, sizeof *buffer))
317-
<< "InputUnformattedBlock()";
311+
desc.Establish(TypeCode{sizeof *buffer}, j * sizeof *buffer, buffer, 0);
312+
desc.Check();
313+
ASSERT_TRUE(IONAME(InputDescriptor)(io, desc)) << "InputDescriptor()";
318314
ASSERT_EQ(IONAME(EndIoStatement)(io), IostatOk)
319315
<< "EndIoStatement() for InputUnformattedBlock";
320316
for (int k{0}; k < j; ++k) {

0 commit comments

Comments
 (0)