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

    <tr>
        <th>Summary</th>
        <td>
            [BUG][OpenMP][runtime]The OpenMP runtime memory mapping table cannot be properly deleted.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    Hello, I’ve encountered an issue with OpenMP in LLVM 17. While testing OpenMP memory mapping, I found that when using multi-level chained pointer access, the runtime mapping table cannot be correctly deleted due to reference counting.

For example, consider the following OpenMP directives:
```
#pragma omp target enter data map(to: s.ps->ps->ps->ps->i)
#pragma omp target exit data map(from: s.ps->ps->ps->ps->i)
```
After the enter data directive, the reference counts of the mapped objects are:
```
s.ps(1) -> ps(2) -> ps(2) -> ps(2) -> i(1)
```
Then, during exit data, the directive reduces the reference counts as follows:
```
s.ps(0) -> ps(1) -> ps(1) -> ps(1) -> i(0)
```
As a result, only the mappings for s.ps and i are deleted, while the intermediate mappings remain, which prevents proper cleanup.


</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVE-PuzYQ_TTmMgoCA0k4cMh2f2kr7ao9bNuzsSfgytjUHpLNt69MSDb75yetFAWMPM_vvfE8EYLuLGLDqgdWPSZiot75ph3-29R5nrROnZvf0BjH-C_wO_vB2TZjdX1EQCvdZAk9KhAWdAgTwklTD3-MaJ__BG3h6envZ8g3KfzTa4NAGEjb7rphwMH5MwxiHLXt5gPg4CargHpBcOrRwhRiwTAZ0iuDRzQge6EtKhidjqeDkBJDiNXUI_jJkh7wCgokWoMghbWOoEWQznuUZM6g0CChAjUhkAOPB_RoZdwSMWyXsmzHst3eecBXMYwG4yHS2aAV-vm0gzPGne4kKR3R9REDK2IxW2fLL9sxXoxedIMAN4xAwndIgLMGJUhEyoxvybFiByEdw4oVPz7_a8brn4K9arrHOng3fA_tjubuQIu6O243XTef39sVwB3m79F3VODaf1FSAOHxsxGRDuPbnPEaIgmYl_ybS72UfgB96dFGcmrysR83K66EbwrAo5okhq9liLA09YsGLryz98zyby71UvrR7gACPIbJUKTqrDnfjNS2i3T83EAQVoGOjl6vbtx_ugxWjzBPw4BKC7qr9jgIbZedsofR4xGj0NG7ET1Ig8JO43LXE9UUqi5qkWCTb6piu-ZZsU76RrVlrXiVi43aliXWdYlVWyle1mvMRCsT3fCMV9mmyLJNVVTr9FC2tayK9Rar7ZpvalZmkYpJjTkOqfNdMidGk1c5r7PEiBZNmFOIc4unS54wzmMo-SYWrdqpC6zMjA4U3mBIk5nj6-GvX1n1yKqHyyxe3pc8YNXjS4_XKb2FxLsA-pQVF4veoiJNJm-anmicLwffM77vNPVTm0o3ML6PnJbHavQujgDj-1lJYHy_SD02_P8AAAD__4UYucA">