1! RUN: bbc -emit-fir %s -o - | FileCheck %s
2
3! Test that we are passing the correct length when using character array as
4! Format (Fortran 2018 12.6.2.2 point 3)
5! CHECK-LABEL: func @_QPtest_array_format
6subroutine test_array_format
7  ! CHECK-DAG: %[[c2:.*]] = arith.constant 2 : index
8  ! CHECK-DAG: %[[c10:.*]] = arith.constant 10 : index
9  ! CHECK-DAG: %[[mem:.*]] = fir.alloca !fir.array<2x!fir.char<1,10>>
10  character(10) :: array(2)
11  array(1) ="(15HThis i"
12  array(2) ="s a test.)"
13  ! CHECK-DAG: %[[fmtLen:.*]] = arith.muli %[[c10]], %[[c2]] : index
14  ! CHECK-DAG: %[[scalarFmt:.*]] = fir.convert %[[mem]] : (!fir.ref<!fir.array<2x!fir.char<1,10>>>) -> !fir.ref<!fir.char<1,?>>
15  ! CHECK-DAG: %[[fmtArg:.*]] = fir.convert %[[scalarFmt]] : (!fir.ref<!fir.char<1,?>>) -> !fir.ref<i8>
16  ! CHECK-DAG: %[[fmtLenArg:.*]] = fir.convert %[[fmtLen]] : (index) -> i64
17  ! CHECK: fir.call @_FortranAioBeginExternalFormattedOutput(%[[fmtArg]], %[[fmtLenArg]], {{.*}})
18  write(*, array)
19end subroutine
20
21! A test to check the buffer and it's length.
22! CHECK-LABEL: @_QPsome
23subroutine some()
24  character(LEN=255):: buffer
25  character(LEN=255):: greeting
2610 format (A255)
27  ! CHECK:  fir.address_of(@_QQcl.636F6D70696C6572) :
28  write (buffer, 10) "compiler"
29  read (buffer, 10) greeting
30end
31! CHECK-LABEL: fir.global linkonce @_QQcl.636F6D70696C6572
32! CHECK: %[[lit:.*]] = fir.string_lit "compiler"(8) : !fir.char<1,8>
33! CHECK: fir.has_value %[[lit]] : !fir.char<1,8>
34! CHECK: }
35