155 lines · plain
1! RUN: %flang_fc1 -emit-fir -flang-deprecated-no-hlfir %s -o - | fir-opt --array-value-copy | fir-opt --stack-arrays | FileCheck %s2 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 so5! only check the first example6! RUN: %flang_fc1 -emit-llvm -flang-deprecated-no-hlfir -o - -fstack-arrays %s | FileCheck --check-prefix=LLVM-IR %s7 8! check simple array value copy case9subroutine array_value_copy_simple(arr)10 integer, intent(inout) :: arr(4)11 arr(3:4) = arr(1:2)12end subroutine13! CHECK-LABEL: func.func @_QParray_value_copy_simple(%arg0: !fir.ref<!fir.array<4xi32>>14! CHECK-NOT: fir.allocmem15! CHECK-NOT: fir.freemem16! CHECK: fir.alloca !fir.array<4xi32>17! CHECK-NOT: fir.allocmem18! CHECK-NOT: fir.freemem19! CHECK: return20! CHECK-NEXT: }21 22! LLVM-IR: array_value_copy_simple23! LLVM-IR-NOT: malloc24! LLVM-IR-NOT: free25! LLVM-IR: alloca [4 x i32]26! LLVM-IR-NOT: malloc27! LLVM-IR-NOT: free28! LLVM-IR: ret void29! LLVM-IR-NEXT: }30 31! check complex array value copy case32module stuff33 type DerivedWithAllocatable34 integer, dimension(:), allocatable :: dat35 end type36 37 contains38 subroutine array_value_copy_complex(arr)39 type(DerivedWithAllocatable), intent(inout) :: arr(:)40 arr(3:4) = arr(1:2)41 end subroutine42end module43! CHECK: func.func44! CHECK-SAME: array_value_copy_complex45! CHECK-NOT: fir.allocmem46! CHECK-NOT: fir.freemem47! CHECK: fir.alloca !fir.array<?x!fir.type<_QMstuffTderivedwithallocatable48! CHECK-NOT: fir.allocmem49! CHECK-NOT: fir.freemem50! CHECK: return51! CHECK-NEXT: }52 53subroutine parameter_array_init54 integer, parameter :: p(100) = 4255 call use_p(p)56end subroutine57! CHECK: func.func58! CHECK-SAME: parameter_array_init59! CHECK-NOT: fir.allocmem60! CHECK-NOT: fir.freemem61! CHECK: fir.alloca !fir.array<100xi32>62! CHECK-NOT: fir.allocmem63! CHECK-NOT: fir.freemem64! CHECK: return65! CHECK-NEXT: }66 67subroutine test_vector_subscripted_section_to_box(v, x)68 interface69 subroutine takes_box(y)70 real :: y(:)71 end subroutine72 end interface73 74 integer :: v(:)75 real :: x(:)76 call takes_box(x(v))77end subroutine78! CHECK: func.func79! CHECK-SAME: test_vector_subscripted_section_to_box80! CHECK-NOT: fir.allocmem81! CHECK: fir.alloca !fir.array<?xf32>82! CHECK-NOT: fir.allocmem83! CHECK: fir.call @_QPtakes_box84! CHECK-NOT: fir.freemem85! CHECK: return86! CHECK-NEXT: }87 88subroutine call_parenthesized_arg(x)89 integer :: x(100)90 call bar((x))91end subroutine92! CHECK: func.func93! CHECK-SAME: call_parenthesized_arg94! CHECK-NOT: fir.allocmem95! CHECK: fir.alloca !fir.array<100xi32>96! CHECK-NOT: fir.allocmem97! CHECK: fir.call @_QPbar98! CHECK-NOT: fir.freemem99! CHECK: return100! CHECK-NEXT: }101 102subroutine where_allocatable_assignments(a, b)103 integer :: a(:)104 integer, allocatable :: b(:)105 where(b > 0)106 b = a107 elsewhere108 b(:) = 0109 end where110end subroutine111! TODO: broken: passing allocation through fir.result112! CHECK: func.func113! CHECK-SAME: where_allocatable_assignments114! CHECK: return115! CHECK-NEXT: }116 117subroutine array_constructor(a, b)118 real :: a(5), b119 real, external :: f120 a = [f(b), f(b+1), f(b+2), f(b+5), f(b+11)]121end subroutine122! TODO: broken: realloc123! CHECK: func.func124! CHECK-SAME: array_constructor125! CHECK: return126! CHECK-NEXT: }127 128subroutine sequence(seq, n)129 integer :: n, seq(n)130 seq = [(i,i=1,n)]131end subroutine132! TODO: broken: realloc133! CHECK: func.func134! CHECK-SAME: sequence135! CHECK: return136! CHECK-NEXT: }137 138subroutine CFGLoop(x)139 integer, parameter :: k = 100, m=1000000, n = k*m140 integer :: x(n)141 logical :: has_error142 143 do i=0,m-1144 x(k*i+1:k*(i+1)) = x(k*(i+1):k*i+1:-1)145 if (has_error(x, k)) stop146 end do147end subroutine148! CHECK: func.func149! CHECK-SAME: cfgloop150! CHECK-NEXT: %[[MEM:.*]] = fir.alloca !fir.array<100000000xi32>151! CHECK-NOT: fir.allocmem152! CHECK-NOT: fir.freemem153! CHECK: return154! CHECK-NEXT: }155