! Test loop variables increment ! RUN: %flang_fc1 -emit-hlfir -o - %s | FileCheck %s module test_loop_var implicit none integer, pointer:: i_pointer integer, allocatable :: i_allocatable real, pointer :: x_pointer real, allocatable :: x_allocatable contains ! CHECK-LABEL: func.func @_QMtest_loop_varPtest_pointer subroutine test_pointer() do i_pointer=1,10 enddo ! CHECK: %[[PTR:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QMtest_loop_varEi_pointer"} ! CHECK: %[[BOX:.*]] = fir.load %[[PTR]]#0 : !fir.ref>> ! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box>) -> !fir.ptr ! CHECK: %[[LOOP:.*]] = fir.do_loop ! CHECK: fir.store %{{.*}} to %[[ADDR]] : !fir.ptr ! CHECK: fir.store %[[LOOP]] to %[[ADDR]] : !fir.ptr end subroutine ! CHECK-LABEL: func.func @_QMtest_loop_varPtest_allocatable subroutine test_allocatable() do i_allocatable=1,10 enddo ! CHECK: %[[ALLOC:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QMtest_loop_varEi_allocatable"} ! CHECK: %[[BOX:.*]] = fir.load %[[ALLOC]]#0 : !fir.ref>> ! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box>) -> !fir.heap ! CHECK: %[[LOOP:.*]] = fir.do_loop ! CHECK: fir.store %{{.*}} to %[[ADDR]] : !fir.heap ! CHECK: fir.store %[[LOOP]] to %[[ADDR]] : !fir.heap end subroutine ! CHECK-LABEL: func.func @_QMtest_loop_varPtest_real_pointer subroutine test_real_pointer() do x_pointer=1,10 enddo ! CHECK: %[[COUNT:.*]] = fir.alloca index ! CHECK: %[[PTR:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QMtest_loop_varEx_pointer"} ! CHECK: %[[BOX:.*]] = fir.load %[[PTR]]#0 : !fir.ref>> ! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box>) -> !fir.ptr ! CHECK: fir.store %{{.*}} to %[[ADDR]] : !fir.ptr ! CHECK: cf.br ^bb1 ! CHECK: ^bb1: ! CHECK: cf.cond_br ! CHECK: ^bb2: ! CHECK: %[[VAL:.*]] = fir.load %[[ADDR]] : !fir.ptr ! CHECK: %[[NEXT:.*]] = arith.addf %[[VAL]], %{{.*}} fastmath : f32 ! CHECK: fir.store %[[NEXT]] to %[[ADDR]] : !fir.ptr end subroutine ! CHECK-LABEL: func.func @_QMtest_loop_varPtest_real_allocatable subroutine test_real_allocatable() do x_allocatable=1,10 enddo ! CHECK: %[[COUNT:.*]] = fir.alloca index ! CHECK: %[[ALLOC:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QMtest_loop_varEx_allocatable"} ! CHECK: %[[BOX:.*]] = fir.load %[[ALLOC]]#0 : !fir.ref>> ! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box>) -> !fir.heap ! CHECK: fir.store %{{.*}} to %[[ADDR]] : !fir.heap ! CHECK: cf.br ^bb1 ! CHECK: ^bb1: ! CHECK: cf.cond_br ! CHECK: ^bb2: ! CHECK: %[[VAL:.*]] = fir.load %[[ADDR]] : !fir.heap ! CHECK: %[[NEXT:.*]] = arith.addf %[[VAL]], %{{.*}} fastmath : f32 ! CHECK: fir.store %[[NEXT]] to %[[ADDR]] : !fir.heap end subroutine ! CHECK-LABEL: func.func @_QMtest_loop_varPtest_pointer_unstructured_loop() subroutine test_pointer_unstructured_loop() do i_pointer=1,10 if (i_pointer .gt. 5) exit enddo ! CHECK: %[[PTR:.*]]:2 = hlfir.declare %{{.*}} {fortran_attrs = #fir.var_attrs, uniq_name = "_QMtest_loop_varEi_pointer"} ! CHECK: %[[BOX:.*]] = fir.load %[[PTR]]#0 : !fir.ref>> ! CHECK: %[[ADDR:.*]] = fir.box_addr %[[BOX]] : (!fir.box>) -> !fir.ptr ! CHECK: fir.store %{{.*}} to %[[ADDR]] : !fir.ptr ! CHECK: cf.br ^bb1 ! CHECK: ^bb1: ! CHECK: cf.cond_br ! CHECK: ^bb2: ! CHECK: cf.cond_br ! CHECK: ^bb3: ! CHECK: cf.br ^bb5 ! CHECK: ^bb4: ! CHECK: %[[VAL:.*]] = fir.load %[[ADDR]] : !fir.ptr ! CHECK: %[[NEXT:.*]] = arith.addi %[[VAL]], %{{.*}} overflow : i32 ! CHECK: fir.store %[[NEXT]] to %[[ADDR]] : !fir.ptr end subroutine end module use test_loop_var implicit none integer, target :: i_target = -1 real, target :: x_target = -1. i_pointer => i_target allocate(i_allocatable) i_allocatable = -1 x_pointer => x_target allocate(x_allocatable) x_allocatable = -1. call test_pointer() call test_allocatable() call test_real_pointer() call test_real_allocatable() ! Expect 11 everywhere print *, i_target print *, i_allocatable print *, x_target print *, x_allocatable call test_pointer_unstructured_loop() call test_allocatable_unstructured_loop() ! Expect 6 everywhere print *, i_target end