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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] Attached host pointer is overwritten
        </td>
    </tr>

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

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

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

<pre>
    When the kernel is done we overwrite `ptr1` with the device value which causes the printf to segfault.

```
#include <stdio.h>

#include <omp.h>

#define N 10

 

int main()

{

  int *ptr1;

  ptr1 = (int *)malloc(sizeof(int)*N);

 

  for (int i=0; i<N; i++) ptr1[i]=100;

 

  #pragma omp target map(ptr1,ptr1[1:N-1])

  {

     for (int i=1; i<N-1; i++)

     { ptr1[i] = i; }

  }

 

  for (int i=0; i<N; i++) printf(" %d %d\n",i,ptr1[i]);

 

   return 0;

}
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysVE2TozgM_TXiokrKyHweOCRhc9vs3ubsgAjuAZuyTVIzv34KOj3dSU_1aapc_kDS09OzkfJeXwxzBeke0jpSc-itq15ay65jF6KzbX9U33o2GHrG7-wMD6g9ttYw3hjtld3N6cAImZiCiyETeNOhX_1bvuqG8aqGmfHW66bHRs2e_WqdnDahw2DR86VT8xC2IGoQu_ucift4PZLUphnmlhHkwYdW220P8p-HkAcfO05_8mi504bxhLH4aMGPB20CjkoboAKofADI9w9RuLgC7dba5ZNt-YggawQq7n5A5aiGwTZAhdc_2XavtiUN7U7L8oTyCNlZ94amQdYC5H7ZHE6vG9qvo1xTQ7rXkNYg61iIr2GB5OTUZVRoxwmDchdeFJiAihWJDnfAGOTutIkX2EdhED9Jg5_oxr_pbuJHwp8iId9_LGKVUS8xkNfPeeu_Idj6GtcLJwRK23WC9GCACOig3zXQ9-q_VBQdh9kZfBb-ne3b-47aSralLFXEVZzlqUyKUqZRX0kqMnVOMxnnWZc2eZc1JRdp2yVJk6skj3RFgqQgQXGSUJxuizzPCtlQcT43ZSMKSASPSg_bYbiOW-sukfZ-5ioTSV5Ggzrz4Nd_n8hObMZpqTWtI1ctAZvzfPGQiEH74N8hgg7D2jH-m9j8-_9yObsQVNNzi731ASerTWC39Im3_hDYRLMbqj6EyYPcAR2Bjhcd-vm8bewIdFzw78tmcvaFmwB0XPl6oONK-VcAAAD__1BvRSA">