[flang-commits] [flang] 15dc516 - [Flang] Enable lowering of CONVERT specifier in OPEN statements
Jonathon Penix via flang-commits
flang-commits at lists.llvm.org
Wed Aug 24 15:22:32 PDT 2022
Author: Jonathon Penix
Date: 2022-08-24T15:18:11-07:00
New Revision: 15dc516e1f34a175692036b7401de3dbd44e716e
URL: https://github.com/llvm/llvm-project/commit/15dc516e1f34a175692036b7401de3dbd44e716e
DIFF: https://github.com/llvm/llvm-project/commit/15dc516e1f34a175692036b7401de3dbd44e716e.diff
LOG: [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
Added:
flang/test/Lower/io-statement-open-options.f90
Modified:
flang/lib/Lower/IO.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/IO.cpp b/flang/lib/Lower/IO.cpp
index 9a73e1c30c8e..8c534f9b8ba3 100644
--- a/flang/lib/Lower/IO.cpp
+++ b/flang/lib/Lower/IO.cpp
@@ -99,7 +99,7 @@ static constexpr std::tuple<
mkIOKey(SetFile), mkIOKey(GetNewUnit), mkIOKey(GetSize),
mkIOKey(GetIoLength), mkIOKey(GetIoMsg), mkIOKey(InquireCharacter),
mkIOKey(InquireLogical), mkIOKey(InquirePendingId),
- mkIOKey(InquireInteger64), mkIOKey(EndIoStatement)>
+ mkIOKey(InquireInteger64), mkIOKey(EndIoStatement), mkIOKey(SetConvert)>
newIOTable;
} // namespace Fortran::lower
@@ -983,7 +983,8 @@ mlir::Value genIOOption<Fortran::parser::ConnectSpec::CharExpr>(
ioFunc = getIORuntimeFunc<mkIOKey(SetCarriagecontrol)>(loc, builder);
break;
case Fortran::parser::ConnectSpec::CharExpr::Kind::Convert:
- TODO(loc, "CONVERT not part of the runtime::io interface");
+ ioFunc = getIORuntimeFunc<mkIOKey(SetConvert)>(loc, builder);
+ break;
case Fortran::parser::ConnectSpec::CharExpr::Kind::Dispose:
TODO(loc, "DISPOSE not part of the runtime::io interface");
}
diff --git a/flang/test/Lower/io-statement-open-options.f90 b/flang/test/Lower/io-statement-open-options.f90
new file mode 100755
index 000000000000..021b8c7d2fa4
--- /dev/null
+++ b/flang/test/Lower/io-statement-open-options.f90
@@ -0,0 +1,20 @@
+! Test lowering of OPEN statment options
+! RUN: bbc %s -emit-fir -o - | FileCheck %s
+
+! CHECK-LABEL: func.func @_QPtest_convert_specifier(
+subroutine test_convert_specifier(unit)
+ integer :: unit
+ ! CHECK: %[[cookie:.*]] = fir.call @_FortranAioBeginOpenUnit(%{{.*}}, %{{.*}}, %{{.*}}) : (i32, !fir.ref<i8>, i32) -> !fir.ref<i8>
+ ! CHECK: %[[be_str:.*]] = fir.address_of(@[[be_str_name:.*]]) : !fir.ref<!fir.char<1,10>>
+ ! CHECK: %[[len:.*]] = arith.constant 10 : index
+ ! CHECK: %[[be_str_conv:.*]] = fir.convert %[[be_str]] : (!fir.ref<!fir.char<1,10>>) -> !fir.ref<i8>
+ ! CHECK: %[[len_conv:.*]] = fir.convert %[[len]] : (index) -> i64
+ ! CHECK: %{{.*}} = fir.call @_FortranAioSetConvert(%[[cookie]], %[[be_str_conv]], %[[len_conv]]) : (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
+ ! CHECK: %{{.*}} = fir.call @_FortranAioEndIoStatement(%[[cookie]]) : (!fir.ref<i8>) -> i32
+ open(unit, form="UNFORMATTED", convert="BIG_ENDIAN")
+ close(unit)
+end subroutine
+
+! CHECK: fir.global linkonce @[[be_str_name]] constant : !fir.char<1,10> {
+! CHECK: %[[be_str_lit:.*]] = fir.string_lit "BIG_ENDIAN"(10) : !fir.char<1,10>
+! CHECK: fir.has_value %[[be_str_lit]] : !fir.char<1,10>
More information about the flang-commits
mailing list