1 ! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | fir-opt --array-value-copy | fir-opt --stack-arrays | FileCheck %s
3 ! In order to verify the whole MLIR pipeline, make the driver generate LLVM IR.
4 ! This is only to check that -fstack-arrays enables the stack-arrays pass so
5 ! only check the first example
6 ! RUN: %flang_fc1 -emit-llvm -flang-deprecated-no-hlfir -o - -fstack-arrays %s | FileCheck --check-prefix=LLVM-IR %s
8 ! check simple array value copy case
9 subroutine array_value_copy_simple(arr
)
10 integer, intent(inout
) :: arr(4)
13 ! CHECK-LABEL: func.func @_QParray_value_copy_simple(%arg0: !fir.ref<!fir.array<4xi32>>
14 ! CHECK-NOT: fir.allocmem
15 ! CHECK-NOT: fir.freemem
16 ! CHECK: fir.alloca !fir.array<4xi32>
17 ! CHECK-NOT: fir.allocmem
18 ! CHECK-NOT: fir.freemem
22 ! LLVM-IR: array_value_copy_simple
25 ! LLVM-IR: alloca [4 x i32]
31 ! check complex array value copy case
33 type DerivedWithAllocatable
34 integer, dimension(:), allocatable
:: dat
38 subroutine array_value_copy_complex(arr
)
39 type(DerivedWithAllocatable
), intent(inout
) :: arr(:)
44 ! CHECK-SAME: array_value_copy_complex
45 ! CHECK-NOT: fir.allocmem
46 ! CHECK-NOT: fir.freemem
47 ! CHECK: fir.alloca !fir.array<?x!fir.type<_QMstuffTderivedwithallocatable
48 ! CHECK-NOT: fir.allocmem
49 ! CHECK-NOT: fir.freemem
53 subroutine parameter_array_init
54 integer, parameter :: p(100) = 42
58 ! CHECK-SAME: parameter_array_init
59 ! CHECK-NOT: fir.allocmem
60 ! CHECK-NOT: fir.freemem
61 ! CHECK: fir.alloca !fir.array<100xi32>
62 ! CHECK-NOT: fir.allocmem
63 ! CHECK-NOT: fir.freemem
67 subroutine test_vector_subscripted_section_to_box(v
, x
)
69 subroutine takes_box(y
)
79 ! CHECK-SAME: test_vector_subscripted_section_to_box
80 ! CHECK-NOT: fir.allocmem
81 ! CHECK: fir.alloca !fir.array<?xf32>
82 ! CHECK-NOT: fir.allocmem
83 ! CHECK: fir.call @_QPtakes_box
84 ! CHECK-NOT: fir.freemem
88 subroutine call_parenthesized_arg(x
)
93 ! CHECK-SAME: call_parenthesized_arg
94 ! CHECK-NOT: fir.allocmem
95 ! CHECK: fir.alloca !fir.array<100xi32>
96 ! CHECK-NOT: fir.allocmem
97 ! CHECK: fir.call @_QPbar
98 ! CHECK-NOT: fir.freemem
102 subroutine where_allocatable_assignments(a
, b
)
104 integer, allocatable
:: b(:)
111 ! TODO: broken: passing allocation through fir.result
113 ! CHECK-SAME: where_allocatable_assignments
117 subroutine array_constructor(a
, b
)
120 a
= [f(b
), f(b
+1), f(b
+2), f(b
+5), f(b
+11)]
122 ! TODO: broken: realloc
124 ! CHECK-SAME: array_constructor
128 subroutine sequence(seq
, n
)
132 ! TODO: broken: realloc
134 ! CHECK-SAME: sequence
138 subroutine CFGLoop(x
)
139 integer, parameter :: k
= 100, m
=1000000, n
= k
*m
144 x(k
*i
+1:k
*(i
+1)) = x(k
*(i
+1):k
*i
+1:-1)
145 if (has_error(x
, k
)) stop
149 ! CHECK-SAME: cfgloop
150 ! CHECK-NEXT: %[[MEM:.*]] = fir.alloca !fir.array<100000000xi32>
151 ! CHECK-NOT: fir.allocmem
152 ! CHECK-NOT: fir.freemem