<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/79770>79770</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [flang][openacc] misplaced acc.declare_action?
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang,
            openacc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          vzakhari
      </td>
    </tr>
</table>

<pre>
    The `acc.declare_action` attachments seem off to me:
```
subroutine acc_create_local_ptr()
  integer :: status
  real, pointer, dimension(:) :: localptr
  !$acc declare create(localptr)
 allocate(localptr(n), stat=status)
  localptr(1) = n
 deallocate(localptr, stat=status)
end subroutine acc_create_local_ptr
```

`bbc -fopenacc --emit-fir ptr_actions.f90 -o - | grep -A 1 -B 1 declare_action`:
```
    %24 = fir.call @_FortranAPointerAllocate(%19, %true, %16, %23, %c5_i32) fastmath<contract> : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
 fir.store %24 to %8 {acc.declare_action = #acc.declare_action<postAlloc = @_QFacc_create_local_ptrElocalptr_acc_declare_update_desc_post_alloc>} : !fir.ref<i32>
    %25 = fir.load %6 : !fir.ref<i32>
--
    fir.store %26 to %30 : !fir.ref<f32>
    %31 = fir.call @_FortranAPointerDeallocate(%19, %true, %16, %23, %c7_i32) fastmath<contract> {acc.declare_action = #acc.declare_action<preDealloc = @_QFacc_create_local_ptrElocalptr_acc_declare_update_desc_pre_dealloc>} : (!fir.ref<!fir.box<none>>, i1, !fir.box<none>, !fir.ref<i8>, i32) -> i32
 fir.store %31 to %8 {acc.declare_action = #acc.declare_action<postDealloc = @_QFacc_create_local_ptrElocalptr_acc_declare_update_desc_post_dealloc>} : !fir.ref<i32>
    acc.declare_exit token(%15) dataOperands(%14 : !fir.ptr<!fir.array<?xf32>>)
```

When the `stat` argument is present we attach some declare actions to the store operations that update the values of the stat variable.

I think we should attach them to the call operations instead.  @clementval, what do you think?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVlGP4yYQ_jXkZeTIBjt2HvKQTS5Sn9pKlfoYYTyO6WFjAd677a-vxibZXDe32-oqVYqUAYZvZr5vAEvv9WVA3LHiiRXHlZxCZ93u-U_5uZNOr2rbvOx-6xDYJpVKrRtURjo8SxW0HdgmBRmCVF2PQ_DgEXuwbQvBQo9M7Fl6ZOmebdL4m4d-qp2dgh4QpFJn5VAGPBurpDmPwTFeMb5dXAH0EPCCDghM7MEHGSZ_XXQoDeMHGC25OTIb3ePgKTde0R6-vW6dAxB-3Mx4xngulYJYFCyZMF7dXG95SENzf1usBnLghzkrJo4xudfk71yzJZMjDHGxwYeY3wPDoYGPiHtE9m2yrhUkrR1xoJKTBHsdklY7GIOLcvp1u00hsZAAKw9wcThCsocMkifI4I3039MXgMgteD7X22q3VtIYYHl6PlkXnBz2vyyC7V8ZYLzIZi4ZL4KbMJrZJhpcREMVZy04sdlKH3oZOiYOyg7BSRWY-ERywwyYUWiHLROHOKjtVyYOgx2QiU_04wfQ2QL8wOF1fkHR1XXPkkBC4cheyiZHH6zDWH2wZFTAyqe3R2fmhnHx4FCJw2h9mLlZvPL0_OvpkeKfrn1zptUrzDQ25NWgV2dCOs-NRqmXx8jOfVGC09I3yhU35YyVDU1t3t-YJK8A39KwiTSI9C1C-za0yD5smuP9wfnnbVN-1Db_XiWHMZcfl8mR8Van_7uLRfaDXfyfEUR9_Iihdzr5Pin8qgME-xmH2DQFld7IIH8e0cmh8XE-v8elS_VGu3ROvtBQnL7GziUet-9cu793OEBYXs_5Wqf30l0mei1BexgdejK_YHxGwdseb-9RvJVJAgJZVLGUb5zvZICFpdnhWZoJPdg2ussAz9JpWRtc36f1E4ROD58prO_sZJpr9NBhf402H7-7YHrwAWWzBtJRGaQanpfn9wvl0Vh4sdOCzMRp1exEsxVbucJdVqabvKyyQqy63baSWBZVWucKRb7haVnzTV6WWYWF4Fm-0jue8jzNeMWznAuxrotcCd7ILM-ztqoylqfYS23Wxjz3a-suK-39hLtyW5bpysgajZ-_ZzhvjRwujHPGD4zz-PjRuDiu3I72J_V08SxPjfbBvyIGHcz8UbQgFEdWPF23F0fotR-NVNjAo84_rSZndl0Io58_QU6Mny46dFO9VrZn_ERh4l8yOvsHqsD4aa7CM36aC_krAAD__2Pi7_k">