Skip to content

Commit b47313a

Browse files
vdonaldsonschweitzpgi
authored andcommitted
Fix #493 - reading from a default unit (#521)
1 parent 3044a8e commit b47313a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

flang/lib/Lower/IO.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,8 +1200,11 @@ mlir::Value getIOUnit(Fortran::lower::AbstractConverter &converter,
12001200
mlir::Location loc, const A &stmt, mlir::Type ty) {
12011201
if (stmt.iounit)
12021202
return genIOUnit(converter, loc, *stmt.iounit, ty);
1203-
return genIOUnit(converter, loc, *getIOControl<Fortran::parser::IoUnit>(stmt),
1204-
ty);
1203+
if (auto *iounit = getIOControl<Fortran::parser::IoUnit>(stmt))
1204+
return genIOUnit(converter, loc, *iounit, ty);
1205+
auto &builder = converter.getFirOpBuilder();
1206+
return builder.create<mlir::ConstantOp>(
1207+
loc, builder.getIntegerAttr(ty, Fortran::runtime::io::DefaultUnit));
12051208
}
12061209

12071210
//===----------------------------------------------------------------------===//

flang/test/Lower/io-stmt02.f90

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,15 @@ subroutine control1(n) ! I/O condition specifier control flow
8080
dimension c(n), d(n,n), e(n,n), f(n)
8181
read(*,'(F7.2)', iostat=mm, advance='no') a, b, (c(j), (d(k,j), e(k,j), k=1,n), f(j), j=1,n), g
8282
end
83+
84+
! CHECK-LABEL: func @_QPimpliedformat
85+
subroutine impliedformat
86+
! CHECK: BeginExternalListInput(%c-1
87+
! CHECK: InputReal32
88+
! CHECK: EndIoStatement(%3) : (!fir.ref<i8>) -> i32
89+
read*, x
90+
! CHECK: BeginExternalListOutput(%c-1
91+
! CHECK: OutputReal32
92+
! CHECK: EndIoStatement
93+
print*, x
94+
end

0 commit comments

Comments
 (0)