[flang] Accept polymorphic component element in storage_size
[llvm-project.git] / flang / test / Lower / io-statement-3.f90
blobc04979e756a140353e1eb9b596b719703c84616c
1 ! Test lowering of IO read SIZE control-spec (12.6.2.15)
2 ! RUN: bbc -emit-fir -o - %s | FileCheck %s
4 ! CHECK-LABEL: func @_QPtest_read_size(
5 ! CHECK-SAME: %[[sizeVar:[^:]+]]: !fir.ref<i32>{{[^,]*}},
6 subroutine test_read_size(size, c1, c2, unit, stat)
7 integer :: unit, size, stat
8 character(*) :: c1, c2
9 ! CHECK: %[[cookie:.*]] = fir.call @_FortranAioBeginExternalFormattedInput(
10 ! CHECK: fir.call @_FortranAioEnableHandlers(
11 ! CHECK: %[[ok1:.*]] = fir.call @_FortranAioSetAdvance(
12 ! CHECK: fir.if %[[ok1]] {
13 ! CHECK: fir.if %[[ok1]] {
14 ! CHECK: %[[ok2:.*]] = fir.call @_FortranAioInputAscii(
15 ! CHECK: fir.if %[[ok2]] {
16 ! CHECK: fir.call @_FortranAioInputAscii(
17 ! CHECK: }
18 ! CHECK: }
19 ! CHECK: }
20 ! CHECK: %[[sizeValue:.*]] = fir.call @_FortranAioGetSize(%[[cookie]]) {{.*}}: (!fir.ref<i8>) -> i64
21 ! CHECK: %[[sizeCast:.*]] = fir.convert %[[sizeValue]] : (i64) -> i32
22 ! CHECK: fir.store %[[sizeCast]] to %[[sizeVar]] : !fir.ref<i32>
23 ! CHECK: fir.call @_FortranAioEndIoStatement(%[[cookie]]) {{.*}}: (!fir.ref<i8>) -> i32
24 READ(unit, '(A)', ADVANCE='NO', SIZE=size, IOSTAT=stat) c1, c2
25 end subroutine
27 ! CHECK: %[[unit:.*]] = fir.alloca i32 {bindc_name = "unit", uniq_name = "_QFEunit"}
28 integer :: unit
29 character(7) :: c1
30 character(4) :: c2
31 integer :: size = 0
32 integer :: stat = 0
33 ! CHECK: %[[cookie:.*]] = fir.call @_FortranAioBeginOpenNewUnit(%{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, i32) -> !fir.ref<i8>
34 ! CHECK: fir.call @_FortranAioSetAccess(%[[cookie]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
35 ! CHECK: fir.call @_FortranAioSetAction(%[[cookie]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
36 ! CHECK: fir.call @_FortranAioSetForm(%[[cookie]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
37 ! CHECK: fir.call @_FortranAioSetStatus(%[[cookie]], %{{.*}}, %{{.*}}) {{.*}}: (!fir.ref<i8>, !fir.ref<i8>, i64) -> i1
38 ! CHECK: %[[kind:.*]] = arith.constant 4 : i32
39 ! CHECK: fir.call @_FortranAioGetNewUnit(%[[cookie]], %[[unit]], %[[kind]]) {{.*}}: (!fir.ref<i8>, !fir.ref<i32>, i32) -> i1
40 ! CHECK: fir.call @_FortranAioEndIoStatement(%[[cookie]]) {{.*}}: (!fir.ref<i8>) -> i32
41 OPEN(NEWUNIT=unit,ACCESS='SEQUENTIAL',ACTION='READWRITE',&
42 FORM='FORMATTED',STATUS='SCRATCH')
43 WRITE(unit, '(A)') "ABCDEF"
44 WRITE(unit, '(A)') "GHIJKL"
45 REWIND(unit)
46 call test_read_size(size, c1, c2, unit, stat)
47 print *, stat, size, c1
48 CLOSE(unit)
49 end