Skip to content

Commit 15dc516

Browse files
committed
[Flang] Enable lowering of CONVERT specifier in OPEN statements
The runtime function was implemented and tested and the specifier was handled, but it seems lowering was never specifically added. Differential Revision: https://reviews.llvm.org/D131814
1 parent f5c8c9d commit 15dc516

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

flang/lib/Lower/IO.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ static constexpr std::tuple<
9999
mkIOKey(SetFile), mkIOKey(GetNewUnit), mkIOKey(GetSize),
100100
mkIOKey(GetIoLength), mkIOKey(GetIoMsg), mkIOKey(InquireCharacter),
101101
mkIOKey(InquireLogical), mkIOKey(InquirePendingId),
102-
mkIOKey(InquireInteger64), mkIOKey(EndIoStatement)>
102+
mkIOKey(InquireInteger64), mkIOKey(EndIoStatement), mkIOKey(SetConvert)>
103103
newIOTable;
104104
} // namespace Fortran::lower
105105

@@ -983,7 +983,8 @@ mlir::Value genIOOption<Fortran::parser::ConnectSpec::CharExpr>(
983983
ioFunc = getIORuntimeFunc<mkIOKey(SetCarriagecontrol)>(loc, builder);
984984
break;
985985
case Fortran::parser::ConnectSpec::CharExpr::Kind::Convert:
986-
TODO(loc, "CONVERT not part of the runtime::io interface");
986+
ioFunc = getIORuntimeFunc<mkIOKey(SetConvert)>(loc, builder);
987+
break;
987988
case Fortran::parser::ConnectSpec::CharExpr::Kind::Dispose:
988989
TODO(loc, "DISPOSE not part of the runtime::io interface");
989990
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
! Test lowering of OPEN statment options
2+
! RUN: bbc %s -emit-fir -o - | FileCheck %s
3+
4+
! CHECK-LABEL: func.func @_QPtest_convert_specifier(
5+
subroutine test_convert_specifier(unit)
6+
integer :: unit
7+
! CHECK: %[[cookie:.*]] = fir.call @_FortranAioBeginOpenUnit(%{{.*}}, %{{.*}}, %{{.*}}) : (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
8+
! CHECK: %[[be_str:.*]] = fir.address_of(@[[be_str_name:.*]]) : !fir.ref<!fir.char<1,10>>
9+
! CHECK: %[[len:.*]] = arith.constant 10 : index
10+
! CHECK: %[[be_str_conv:.*]] = fir.convert %[[be_str]] : (!fir.ref<!fir.char<1,10>>) -> !fir.ref<i8>
11+
! CHECK: %[[len_conv:.*]] = fir.convert %[[len]] : (index) -> i64
12+
! CHECK: %{{.*}} = fir.call @_FortranAioSetConvert(%[[cookie]], %[[be_str_conv]], %[[len_conv]]) : (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
13+
! CHECK: %{{.*}} = fir.call @_FortranAioEndIoStatement(%[[cookie]]) : (!fir.ref<i8>) -> i32
14+
open(unit, form="UNFORMATTED", convert="BIG_ENDIAN")
15+
close(unit)
16+
end subroutine
17+
18+
! CHECK: fir.global linkonce @[[be_str_name]] constant : !fir.char<1,10> {
19+
! CHECK: %[[be_str_lit:.*]] = fir.string_lit "BIG_ENDIAN"(10) : !fir.char<1,10>
20+
! CHECK: fir.has_value %[[be_str_lit]] : !fir.char<1,10>

0 commit comments

Comments
 (0)