Skip to content

Commit 8f3357b

Browse files
authored
[flang][runtime] Don't use -1 in I/O API for "default unit" (llvm#76642)
The I/O runtime's API allows -1 to be passed for a unit number in a READ, WRITE, or PRINT statement, where it gets replaced by 5 or 6 as appropriate. This turns out to have been a bad idea, as it prevents the I/O runtime from detecting and reporting a program's invalid attempt to use -1 as an I/O unit number. So just pass 5 or 6 as appropriate.
1 parent 4c1f488 commit 8f3357b

17 files changed

+107
-82
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "flang/Common/uint128.h"
1515
#include "flang/Runtime/entry-names.h"
1616
#include "flang/Runtime/iostat.h"
17+
#include "flang/Runtime/magic-numbers.h"
1718
#include <cinttypes>
1819
#include <cstddef>
1920

@@ -29,7 +30,9 @@ class IoStatementState;
2930
using Cookie = IoStatementState *;
3031
using ExternalUnit = int;
3132
using AsynchronousId = int;
32-
static constexpr ExternalUnit DefaultUnit{-1}; // READ(*), WRITE(*), PRINT
33+
34+
static constexpr ExternalUnit DefaultOutputUnit{FORTRAN_DEFAULT_OUTPUT_UNIT};
35+
static constexpr ExternalUnit DefaultInputUnit{FORTRAN_DEFAULT_INPUT_UNIT};
3336

3437
// INQUIRE specifiers are encoded as simple base-26 packings of
3538
// the spellings of their keywords.
@@ -57,7 +60,8 @@ extern "C" {
5760

5861
// These functions initiate data transfer statements (READ, WRITE, PRINT).
5962
// Example: PRINT *, 666 is implemented as the series of calls:
60-
// Cookie cookie{BeginExternalListOutput(DefaultUnit,__FILE__,__LINE__)};
63+
// Cookie cookie{BeginExternalListOutput(DefaultOutputUnit,
64+
// __FILE__, __LINE__)};
6165
// OutputInteger32(cookie, 666);
6266
// EndIoStatement(cookie);
6367
// Formatted I/O with explicit formats can supply the format as a
@@ -135,19 +139,21 @@ enum Iostat IONAME(CheckUnitNumberInRange128)(common::int128_t unit,
135139
const char *sourceFile = nullptr, int sourceLine = 0);
136140

137141
// External synchronous I/O initiation
138-
Cookie IONAME(BeginExternalListOutput)(ExternalUnit = DefaultUnit,
142+
Cookie IONAME(BeginExternalListOutput)(ExternalUnit = DefaultOutputUnit,
139143
const char *sourceFile = nullptr, int sourceLine = 0);
140-
Cookie IONAME(BeginExternalListInput)(ExternalUnit = DefaultUnit,
144+
Cookie IONAME(BeginExternalListInput)(ExternalUnit = DefaultInputUnit,
141145
const char *sourceFile = nullptr, int sourceLine = 0);
142146
Cookie IONAME(BeginExternalFormattedOutput)(const char *format, std::size_t,
143-
const Descriptor *formatDescriptor = nullptr, ExternalUnit = DefaultUnit,
144-
const char *sourceFile = nullptr, int sourceLine = 0);
147+
const Descriptor *formatDescriptor = nullptr,
148+
ExternalUnit = DefaultOutputUnit, const char *sourceFile = nullptr,
149+
int sourceLine = 0);
145150
Cookie IONAME(BeginExternalFormattedInput)(const char *format, std::size_t,
146-
const Descriptor *formatDescriptor = nullptr, ExternalUnit = DefaultUnit,
147-
const char *sourceFile = nullptr, int sourceLine = 0);
148-
Cookie IONAME(BeginUnformattedOutput)(ExternalUnit = DefaultUnit,
151+
const Descriptor *formatDescriptor = nullptr,
152+
ExternalUnit = DefaultInputUnit, const char *sourceFile = nullptr,
153+
int sourceLine = 0);
154+
Cookie IONAME(BeginUnformattedOutput)(ExternalUnit = DefaultOutputUnit,
149155
const char *sourceFile = nullptr, int sourceLine = 0);
150-
Cookie IONAME(BeginUnformattedInput)(ExternalUnit = DefaultUnit,
156+
Cookie IONAME(BeginUnformattedInput)(ExternalUnit = DefaultInputUnit,
151157
const char *sourceFile = nullptr, int sourceLine = 0);
152158

153159
// WAIT(ID=)
@@ -190,7 +196,7 @@ Cookie IONAME(BeginInquireIoLength)(
190196
// This call makes the runtime library defer those particular error/end
191197
// conditions to the EndIoStatement() call rather than terminating
192198
// the image. E.g., for READ(*,*,END=666) A, B, (C(J),J=1,N)
193-
// Cookie cookie{BeginExternalListInput(DefaultUnit,__FILE__,__LINE__)};
199+
// Cookie cookie{BeginExternalListInput(DefaultInputUnit,__FILE__,__LINE__)};
194200
// EnableHandlers(cookie, false, false, true /*END=*/, false);
195201
// if (InputReal64(cookie, &A)) {
196202
// if (InputReal64(cookie, &B)) {

flang/include/flang/Runtime/magic-numbers.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ start at 100 so as to never conflict with those codes.
2727
#ifndef FORTRAN_RUNTIME_MAGIC_NUMBERS_H_
2828
#define FORTRAN_RUNTIME_MAGIC_NUMBERS_H_
2929

30+
#define FORTRAN_DEFAULT_OUTPUT_UNIT 6
31+
#define FORTRAN_DEFAULT_INPUT_UNIT 5
32+
#define FORTRAN_ERROR_UNIT 0
33+
3034
#define FORTRAN_RUNTIME_IOSTAT_END (-1)
3135
#define FORTRAN_RUNTIME_IOSTAT_EOR (-2)
3236
#define FORTRAN_RUNTIME_IOSTAT_FLUSH (-3)

flang/lib/Lower/IO.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,24 +1850,25 @@ static mlir::Value genIOUnit(Fortran::lower::AbstractConverter &converter,
18501850
mlir::Location loc,
18511851
const Fortran::parser::IoUnit *iounit,
18521852
mlir::Type ty, ConditionSpecInfo &csi,
1853-
Fortran::lower::StatementContext &stmtCtx) {
1853+
Fortran::lower::StatementContext &stmtCtx,
1854+
int defaultUnitNumber) {
18541855
auto &builder = converter.getFirOpBuilder();
18551856
if (iounit)
18561857
if (auto *e = std::get_if<Fortran::parser::FileUnitNumber>(&iounit->u))
18571858
return genIOUnitNumber(converter, loc, Fortran::semantics::GetExpr(*e),
18581859
ty, csi, stmtCtx);
18591860
return builder.create<mlir::arith::ConstantOp>(
1860-
loc, builder.getIntegerAttr(ty, Fortran::runtime::io::DefaultUnit));
1861+
loc, builder.getIntegerAttr(ty, defaultUnitNumber));
18611862
}
18621863

18631864
template <typename A>
1864-
static mlir::Value getIOUnit(Fortran::lower::AbstractConverter &converter,
1865-
mlir::Location loc, const A &stmt, mlir::Type ty,
1866-
ConditionSpecInfo &csi,
1867-
Fortran::lower::StatementContext &stmtCtx) {
1865+
static mlir::Value
1866+
getIOUnit(Fortran::lower::AbstractConverter &converter, mlir::Location loc,
1867+
const A &stmt, mlir::Type ty, ConditionSpecInfo &csi,
1868+
Fortran::lower::StatementContext &stmtCtx, int defaultUnitNumber) {
18681869
const Fortran::parser::IoUnit *iounit =
18691870
stmt.iounit ? &*stmt.iounit : getIOControl<Fortran::parser::IoUnit>(stmt);
1870-
return genIOUnit(converter, loc, iounit, ty, csi, stmtCtx);
1871+
return genIOUnit(converter, loc, iounit, ty, csi, stmtCtx, defaultUnitNumber);
18711872
}
18721873
//===----------------------------------------------------------------------===//
18731874
// Generators for each IO statement type.
@@ -2091,7 +2092,7 @@ getBeginDataTransferFunc(mlir::Location loc, fir::FirOpBuilder &builder,
20912092
}
20922093

20932094
/// Generate the arguments of a begin data transfer statement call.
2094-
template <bool hasIOCtrl, typename A>
2095+
template <bool hasIOCtrl, int defaultUnitNumber, typename A>
20952096
void genBeginDataTransferCallArgs(
20962097
llvm::SmallVectorImpl<mlir::Value> &ioArgs,
20972098
Fortran::lower::AbstractConverter &converter, mlir::Location loc,
@@ -2149,14 +2150,14 @@ void genBeginDataTransferCallArgs(
21492150
TODO(loc, "asynchronous");
21502151
maybeGetFormatArgs();
21512152
ioArgs.push_back(getIOUnit(converter, loc, stmt,
2152-
ioFuncTy.getInput(ioArgs.size()), csi,
2153-
stmtCtx));
2153+
ioFuncTy.getInput(ioArgs.size()), csi, stmtCtx,
2154+
defaultUnitNumber));
21542155
}
21552156
} else { // PRINT - maybe explicit format; default unit
21562157
maybeGetFormatArgs();
21572158
ioArgs.push_back(builder.create<mlir::arith::ConstantOp>(
21582159
loc, builder.getIntegerAttr(ioFuncTy.getInput(ioArgs.size()),
2159-
Fortran::runtime::io::DefaultUnit)));
2160+
defaultUnitNumber)));
21602161
}
21612162
// File name and line number are always the last two arguments.
21622163
ioArgs.push_back(
@@ -2193,7 +2194,9 @@ genDataTransferStmt(Fortran::lower::AbstractConverter &converter,
21932194
loc, builder, isFormatted, isList || isNml, isInternal,
21942195
isInternalWithDesc, isAsync);
21952196
llvm::SmallVector<mlir::Value> ioArgs;
2196-
genBeginDataTransferCallArgs<hasIOCtrl>(
2197+
genBeginDataTransferCallArgs<
2198+
hasIOCtrl, isInput ? Fortran::runtime::io::DefaultInputUnit
2199+
: Fortran::runtime::io::DefaultOutputUnit>(
21972200
ioArgs, converter, loc, stmt, ioFunc.getFunctionType(), isFormatted,
21982201
isList || isNml, isInternal, isAsync, descRef, csi, stmtCtx);
21992202
mlir::Value cookie =

flang/module/iso_fortran_env.f90

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
! See Fortran 2018, clause 16.10.2
1010
! TODO: These are placeholder values so that some tests can be run.
1111

12-
include '../include/flang/Runtime/magic-numbers.h' ! IOSTAT values
12+
include '../include/flang/Runtime/magic-numbers.h'
1313

1414
module iso_fortran_env
1515

@@ -130,8 +130,9 @@ module iso_fortran_env
130130

131131
integer, parameter :: current_team = -1, initial_team = -2, parent_team = -3
132132

133-
integer, parameter :: input_unit = 5, output_unit = 6
134-
integer, parameter :: error_unit = 0
133+
integer, parameter :: output_unit = FORTRAN_DEFAULT_OUTPUT_UNIT
134+
integer, parameter :: input_unit = FORTRAN_DEFAULT_INPUT_UNIT
135+
integer, parameter :: error_unit = FORTRAN_ERROR_UNIT
135136
integer, parameter :: iostat_end = FORTRAN_RUNTIME_IOSTAT_END
136137
integer, parameter :: iostat_eor = FORTRAN_RUNTIME_IOSTAT_EOR
137138
integer, parameter :: iostat_inquire_internal_unit = &

flang/runtime/io-api.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,6 @@ template <Direction DIR, template <Direction> class STATE, typename... A>
185185
Cookie BeginExternalListIO(
186186
int unitNumber, const char *sourceFile, int sourceLine, A &&...xs) {
187187
Terminator terminator{sourceFile, sourceLine};
188-
if (unitNumber == DefaultUnit) {
189-
unitNumber = DIR == Direction::Input ? 5 : 6;
190-
}
191188
Cookie errorCookie{nullptr};
192189
ExternalFileUnit *unit{GetOrCreateUnit(
193190
unitNumber, DIR, false /*!unformatted*/, terminator, errorCookie)};
@@ -246,9 +243,6 @@ Cookie BeginExternalFormattedIO(const char *format, std::size_t formatLength,
246243
const Descriptor *formatDescriptor, ExternalUnit unitNumber,
247244
const char *sourceFile, int sourceLine) {
248245
Terminator terminator{sourceFile, sourceLine};
249-
if (unitNumber == DefaultUnit) {
250-
unitNumber = DIR == Direction::Input ? 5 : 6;
251-
}
252246
Cookie errorCookie{nullptr};
253247
ExternalFileUnit *unit{GetOrCreateUnit(
254248
unitNumber, DIR, false /*!unformatted*/, terminator, errorCookie)};
@@ -761,7 +755,8 @@ bool IONAME(SetAccess)(Cookie cookie, const char *keyword, std::size_t length) {
761755
IoStatementState &io{*cookie};
762756
auto *open{io.get_if<OpenStatementState>()};
763757
if (!open) {
764-
if (!io.get_if<ErroneousIoStatementState>()) {
758+
if (!io.get_if<NoopStatementState>() &&
759+
!io.get_if<ErroneousIoStatementState>()) {
765760
io.GetIoErrorHandler().Crash(
766761
"SetAccess() called when not in an OPEN statement");
767762
}
@@ -796,7 +791,8 @@ bool IONAME(SetAction)(Cookie cookie, const char *keyword, std::size_t length) {
796791
IoStatementState &io{*cookie};
797792
auto *open{io.get_if<OpenStatementState>()};
798793
if (!open) {
799-
if (!io.get_if<ErroneousIoStatementState>()) {
794+
if (!io.get_if<NoopStatementState>() &&
795+
!io.get_if<ErroneousIoStatementState>()) {
800796
io.GetIoErrorHandler().Crash(
801797
"SetAction() called when not in an OPEN statement");
802798
}
@@ -852,7 +848,8 @@ bool IONAME(SetAsynchronous)(
852848
handler.SignalError(IostatBadAsynchronous);
853849
}
854850
}
855-
} else if (!io.get_if<ErroneousIoStatementState>()) {
851+
} else if (!io.get_if<NoopStatementState>() &&
852+
!io.get_if<ErroneousIoStatementState>()) {
856853
handler.Crash("SetAsynchronous() called when not in an OPEN or external "
857854
"I/O statement");
858855
}
@@ -864,7 +861,8 @@ bool IONAME(SetCarriagecontrol)(
864861
IoStatementState &io{*cookie};
865862
auto *open{io.get_if<OpenStatementState>()};
866863
if (!open) {
867-
if (!io.get_if<ErroneousIoStatementState>()) {
864+
if (!io.get_if<NoopStatementState>() &&
865+
!io.get_if<ErroneousIoStatementState>()) {
868866
io.GetIoErrorHandler().Crash(
869867
"SetCarriageControl() called when not in an OPEN statement");
870868
}
@@ -895,7 +893,8 @@ bool IONAME(SetConvert)(
895893
IoStatementState &io{*cookie};
896894
auto *open{io.get_if<OpenStatementState>()};
897895
if (!open) {
898-
if (!io.get_if<ErroneousIoStatementState>()) {
896+
if (!io.get_if<NoopStatementState>() &&
897+
!io.get_if<ErroneousIoStatementState>()) {
899898
io.GetIoErrorHandler().Crash(
900899
"SetConvert() called when not in an OPEN statement");
901900
}
@@ -919,7 +918,8 @@ bool IONAME(SetEncoding)(
919918
IoStatementState &io{*cookie};
920919
auto *open{io.get_if<OpenStatementState>()};
921920
if (!open) {
922-
if (!io.get_if<ErroneousIoStatementState>()) {
921+
if (!io.get_if<NoopStatementState>() &&
922+
!io.get_if<ErroneousIoStatementState>()) {
923923
io.GetIoErrorHandler().Crash(
924924
"SetEncoding() called when not in an OPEN statement");
925925
}
@@ -949,7 +949,8 @@ bool IONAME(SetForm)(Cookie cookie, const char *keyword, std::size_t length) {
949949
IoStatementState &io{*cookie};
950950
auto *open{io.get_if<OpenStatementState>()};
951951
if (!open) {
952-
if (!io.get_if<ErroneousIoStatementState>()) {
952+
if (!io.get_if<NoopStatementState>() &&
953+
!io.get_if<ErroneousIoStatementState>()) {
953954
io.GetIoErrorHandler().Crash(
954955
"SetForm() called when not in an OPEN statement");
955956
}
@@ -977,7 +978,8 @@ bool IONAME(SetPosition)(
977978
IoStatementState &io{*cookie};
978979
auto *open{io.get_if<OpenStatementState>()};
979980
if (!open) {
980-
if (!io.get_if<ErroneousIoStatementState>()) {
981+
if (!io.get_if<NoopStatementState>() &&
982+
!io.get_if<ErroneousIoStatementState>()) {
981983
io.GetIoErrorHandler().Crash(
982984
"SetPosition() called when not in an OPEN statement");
983985
}
@@ -1008,7 +1010,8 @@ bool IONAME(SetRecl)(Cookie cookie, std::size_t n) {
10081010
IoStatementState &io{*cookie};
10091011
auto *open{io.get_if<OpenStatementState>()};
10101012
if (!open) {
1011-
if (!io.get_if<ErroneousIoStatementState>()) {
1013+
if (!io.get_if<NoopStatementState>() &&
1014+
!io.get_if<ErroneousIoStatementState>()) {
10121015
io.GetIoErrorHandler().Crash(
10131016
"SetRecl() called when not in an OPEN statement");
10141017
}
@@ -1093,7 +1096,8 @@ bool IONAME(SetFile)(Cookie cookie, const char *path, std::size_t chars) {
10931096
}
10941097
open->set_path(path, chars);
10951098
return true;
1096-
} else if (!io.get_if<ErroneousIoStatementState>()) {
1099+
} else if (!io.get_if<NoopStatementState>() &&
1100+
!io.get_if<ErroneousIoStatementState>()) {
10971101
io.GetIoErrorHandler().Crash(
10981102
"SetFile() called when not in an OPEN statement");
10991103
}
@@ -1104,7 +1108,8 @@ bool IONAME(GetNewUnit)(Cookie cookie, int &unit, int kind) {
11041108
IoStatementState &io{*cookie};
11051109
auto *open{io.get_if<OpenStatementState>()};
11061110
if (!open) {
1107-
if (!io.get_if<ErroneousIoStatementState>()) {
1111+
if (!io.get_if<NoopStatementState>() &&
1112+
!io.get_if<ErroneousIoStatementState>()) {
11081113
io.GetIoErrorHandler().Crash(
11091114
"GetNewUnit() called when not in an OPEN statement");
11101115
}
@@ -1361,7 +1366,8 @@ std::size_t IONAME(GetSize)(Cookie cookie) {
13611366
if (const auto *formatted{
13621367
io.get_if<FormattedIoStatementState<Direction::Input>>()}) {
13631368
return formatted->GetEditDescriptorChars();
1364-
} else if (!io.get_if<ErroneousIoStatementState>()) {
1369+
} else if (!io.get_if<NoopStatementState>() &&
1370+
!io.get_if<ErroneousIoStatementState>()) {
13651371
handler.Crash("GetIoSize() called for an I/O statement that is not a "
13661372
"formatted READ()");
13671373
}
@@ -1376,7 +1382,8 @@ std::size_t IONAME(GetIoLength)(Cookie cookie) {
13761382
}
13771383
if (const auto *inq{io.get_if<InquireIOLengthState>()}) {
13781384
return inq->bytes();
1379-
} else if (!io.get_if<ErroneousIoStatementState>()) {
1385+
} else if (!io.get_if<NoopStatementState>() &&
1386+
!io.get_if<ErroneousIoStatementState>()) {
13801387
handler.Crash("GetIoLength() called for an I/O statement that is not "
13811388
"INQUIRE(IOLENGTH=)");
13821389
}

flang/runtime/unit.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "lock.h"
1212
#include "tools.h"
1313
#include "unit-map.h"
14+
#include "flang/Runtime/magic-numbers.h"
1415
#include <cstdio>
1516
#include <limits>
1617
#include <utility>
@@ -220,21 +221,24 @@ UnitMap &ExternalFileUnit::CreateUnitMap() {
220221
UnitMap &newUnitMap{*New<UnitMap>{terminator}().release()};
221222

222223
bool wasExtant{false};
223-
ExternalFileUnit &out{*newUnitMap.LookUpOrCreate(6, terminator, wasExtant)};
224+
ExternalFileUnit &out{*newUnitMap.LookUpOrCreate(
225+
FORTRAN_DEFAULT_OUTPUT_UNIT, terminator, wasExtant)};
224226
RUNTIME_CHECK(terminator, !wasExtant);
225227
out.Predefine(1);
226228
handler.SignalError(out.SetDirection(Direction::Output));
227229
out.isUnformatted = false;
228230
defaultOutput = &out;
229231

230-
ExternalFileUnit &in{*newUnitMap.LookUpOrCreate(5, terminator, wasExtant)};
232+
ExternalFileUnit &in{*newUnitMap.LookUpOrCreate(
233+
FORTRAN_DEFAULT_INPUT_UNIT, terminator, wasExtant)};
231234
RUNTIME_CHECK(terminator, !wasExtant);
232235
in.Predefine(0);
233236
handler.SignalError(in.SetDirection(Direction::Input));
234237
in.isUnformatted = false;
235238
defaultInput = &in;
236239

237-
ExternalFileUnit &error{*newUnitMap.LookUpOrCreate(0, terminator, wasExtant)};
240+
ExternalFileUnit &error{
241+
*newUnitMap.LookUpOrCreate(FORTRAN_ERROR_UNIT, terminator, wasExtant)};
238242
RUNTIME_CHECK(terminator, !wasExtant);
239243
error.Predefine(2);
240244
handler.SignalError(error.SetDirection(Direction::Output));

flang/test/Lower/HLFIR/calls-f77.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ subroutine return_char(n)
156156
end subroutine
157157
! CHECK-LABEL: func.func @_QPreturn_char(
158158
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare {{.*}}n
159-
! CHECK: %[[VAL_2:.*]] = arith.constant -1 : i32
159+
! CHECK: %[[VAL_2:.*]] = arith.constant 6 : i32
160160
! CHECK: %[[VAL_7:.*]] = fir.load %[[VAL_1]]#0 : !fir.ref<i64>
161161
! CHECK: %[[VAL_8:.*]] = fir.convert %[[VAL_7]] : (i64) -> index
162162
! CHECK: %[[VAL_9:.*]] = arith.constant 0 : index

flang/test/Lower/HLFIR/convert-mbox-to-value.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ end subroutine test_int_allocatable
88
! CHECK-LABEL: func.func @_QPtest_int_allocatable(
99
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.heap<i32>>> {fir.bindc_name = "a"}) {
1010
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<allocatable>, uniq_name = "_QFtest_int_allocatableEa"} : (!fir.ref<!fir.box<!fir.heap<i32>>>) -> (!fir.ref<!fir.box<!fir.heap<i32>>>, !fir.ref<!fir.box<!fir.heap<i32>>>)
11-
! CHECK: %[[VAL_2:.*]] = arith.constant -1 : i32
11+
! CHECK: %[[VAL_2:.*]] = arith.constant 6 : i32
1212
! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref<!fir.char<1,{{[0-9]*}}>>
1313
! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.char<1,{{[0-9]*}}>>) -> !fir.ref<i8>
1414
! CHECK: %[[VAL_5:.*]] = arith.constant {{[0-9]*}} : i32
@@ -28,7 +28,7 @@ end subroutine test_int_pointer
2828
! CHECK-LABEL: func.func @_QPtest_int_pointer(
2929
! CHECK-SAME: %[[VAL_0:.*]]: !fir.ref<!fir.box<!fir.ptr<i32>>> {fir.bindc_name = "p"}) {
3030
! CHECK: %[[VAL_1:.*]]:2 = hlfir.declare %[[VAL_0]] {fortran_attrs = #fir.var_attrs<pointer>, uniq_name = "_QFtest_int_pointerEp"} : (!fir.ref<!fir.box<!fir.ptr<i32>>>) -> (!fir.ref<!fir.box<!fir.ptr<i32>>>, !fir.ref<!fir.box<!fir.ptr<i32>>>)
31-
! CHECK: %[[VAL_2:.*]] = arith.constant -1 : i32
31+
! CHECK: %[[VAL_2:.*]] = arith.constant 6 : i32
3232
! CHECK: %[[VAL_3:.*]] = fir.address_of(@_QQclX{{.*}}) : !fir.ref<!fir.char<1,{{[0-9]*}}>>
3333
! CHECK: %[[VAL_4:.*]] = fir.convert %[[VAL_3]] : (!fir.ref<!fir.char<1,{{[0-9]*}}>>) -> !fir.ref<i8>
3434
! CHECK: %[[VAL_5:.*]] = arith.constant {{[0-9]*}} : i32

flang/test/Lower/OpenMP/FIR/parallel-lastprivate-clause-scalar.f90

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313

1414
! Check that we are accessing the clone inside the loop
1515
!CHECK-DAG: omp.wsloop for (%[[INDX_WS:.*]]) : {{.*}} {
16-
!CHECK-DAG: %[[NEG_ONE:.*]] = arith.constant -1 : i32
16+
!CHECK-DAG: %[[UNIT:.*]] = arith.constant 6 : i32
1717
!CHECK-NEXT: %[[ADDR:.*]] = fir.address_of(@_QQclX
1818
!CHECK-NEXT: %[[CVT0:.*]] = fir.convert %[[ADDR]]
1919
!CHECK-NEXT: %[[CNST:.*]] = arith.constant
20-
!CHECK-NEXT: %[[CALL_BEGIN_IO:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[NEG_ONE]], %[[CVT0]], %[[CNST]]) {{.*}}: (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
20+
!CHECK-NEXT: %[[CALL_BEGIN_IO:.*]] = fir.call @_FortranAioBeginExternalListOutput(%[[UNIT]], %[[CVT0]], %[[CNST]]) {{.*}}: (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
2121
!CHECK-NEXT: %[[CVT_0_1:.*]] = fir.convert %[[ARG1_PVT]]
2222
!CHECK-NEXT: %[[CVT_0_2:.*]] = fir.convert %[[FIVE]]
2323
!CHECK-NEXT: %[[CALL_OP_ASCII:.*]] = fir.call @_FortranAioOutputAscii(%[[CALL_BEGIN_IO]], %[[CVT_0_1]], %[[CVT_0_2]])

0 commit comments

Comments
 (0)