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

    <tr>
        <th>Summary</th>
        <td>
            [flang][OpenMP] Declare Mapper does not map base type members properly
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          jfuchs-kmt
      </td>
    </tr>
</table>

<pre>
    I am using the most recent `flang version 22.0.0git (git@github.com:llvm/llvm-project.git 89f53af3fffed3e41167fbb7bc10d4885cd97c7f)`.

The reproducer below shows that when using a custom `declare mapper` for `real_t`, then even when we specify `t%base_arr` within the mapper, the array is not mapped properly in a target region.

I am compiling this reproducer with `flang -O2 -fopenmp -fopenmp-version=52 -fopenmp-targets=nvptx64-nvidia-cuda main.F90` and run it with `OMP_TARGET_OFFLOAD=mandatory ./a.out`.

```fortran
PROGRAM reproducer
    IMPLICIT NONE

    TYPE, ABSTRACT :: base_t
        REAL, ALLOCATABLE :: base_arr(:)
    END TYPE base_t

    TYPE, EXTENDS(base_t) :: real_t
        REAL, ALLOCATABLE :: real_arr(:)
    END TYPE real_t
 !$omp declare mapper(custommapper: real_t :: t) map(t%base_arr, t%real_arr)

    TYPE(real_t) :: r
    ALLOCATE(r%base_arr(10), source=1.0)
    ALLOCATE(r%real_arr(10), source=1.0)

    PRINT*, "BEFORE TARGET REGION:"
    PRINT*, "base_arr: ", r%base_arr
    PRINT*, "real_arr: ", r%real_arr
    PRINT*, ""

    !$omp target map(tofrom: r)
        r%base_arr = 2.0 ! This write has no effect since base_arr is not mapped properly
        r%real_arr = 3.0 ! This is fine
        !r%real_arr = r%base_arr(1) ! UNCOMMENT THIS --> results in (core dumped) since we read from an unmapped base_arr
    !$omp end target

    PRINT*, "AFTER TARGET REGION:"
    PRINT*, "base_arr: ", r%base_arr ! We would expect "2. ..." here
    PRINT*, "real_arr: ", r%real_arr

 DEALLOCATE(r%real_arr)
    DEALLOCATE(r%base_arr)
END PROGRAM reproducer
```

The error message when reading from `base_arr(1)` by uncommenting the third line in the target region is:
```
"PluginInterface" error: Failure to copy data from device to host. Pointers: host = 0x000064a6f0418ab0, device = 0x00007ac120a00200, size = 40: "unknown or internal error" error in cuMemcpyDtoHAsync: an illegal memory access was encountered
omptarget error: Copying data from device failed.
omptarget error: Call to targetDataEnd failed, abort target.
omptarget error: Failed to process data after launching the kernel.
omptarget error: Consult https://openmp.llvm.org/design/Runtimes.html for debugging options.
omptarget error: Source location information not present. Compile with -g or -gline-tables-only.
omptarget fatal error 1: failure of target construct while offloading is mandatory
Aborted (core dumped)
```

</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJysV92O4joSfhpzUyJyHH6SCy4yDcxpqbtpMax292rkOBXiM4kd2U4z7NOv7AToZqaPVquDWmqI6_erz1UVbq08KsQVmX8h8_WE967WZvVn1YvaTn-0blLo8rx6BN5Cb6U6gqsRWm0dGBSoHJAFrRqujvCGxkqtgLGIRvQoHRCWHqUjM_-j7otI6JYkedO8tYRt_b9pZ_SfKFzkpdOsmie8SqqqwjLBWRwvllVRLAsR03KWpnNRZkuxrAjLyIJGhOaE5ocawWBndNkLNFBgo09ga32y4Gru4FSjGgPnIHrrdOsjLlE03CC0vOvQkAWFSht_YJA33x1ZUMIefKoK8A3VYOaEYDsUsjp7SUfYvOAWv3MTDJykq6Ua4BmsDhaAG8PPIC0o7YajEjqjOzTNGaQCDo6bI3pAj1KrMbGAuNBtJ5sBdWnfJ-q93aCf7hhMK92harvrl-lYEJKs57fj6eDMkmSt3jr3czGbqjdZSj4Vfcmh5VJF24z6jLgqwfQKpLu62z2_fj_k-6-bw_fddvu0y9ckWbdcldxpc4aIsC2PdO9uBfJQhr9KG2e4IjR_3e--7vPnd-kQmgMAPD6_Pj0-PB7gZfeyGdT948O_XzcezPzLt8M-fzgASXKS5BDQd6OQ_-w3-VMQfHraPeSH_MvT5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