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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] OpenMPOpt miscompiles `sprintf` function from the GPU implementation
        </td>
    </tr>

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

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

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

<pre>
    The OpenMPOpt pass currently miscompiles trivial uses of the `sprintf` function. This was recently enabled with the AMDGPU support of varargs. The following example prints an empty string with `openmp-opt` enabled, and `1` with it disabled.

```c
#include <stdio.h>

int main() {
  char str[256];
#pragma omp target
 {
    snprintf(str, 255, "%d\n", 1);
  }
  fputs(str, stdout);
}
```
This can be compiled with the GPU libc using the following, with the disabled version printing `1` as expected.
```console
$ clang sprintf.c -fopenmp --offload-arch=gfx1030 -O1
$ clang sprintf.c -fopenmp --offload-arch=gfx1030 -O1 -mllvm -openmp-opt-disable
```

The output before the offending `openmp-opt` pass is available here https://godbolt.org/z/ecEjEKvv3.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVMuOqzgQ_RqzKYHABpIsWHQnnVmMrvou7nyAMWVwy9iWbdLd8_UjE_KY0d2NFIVH-ZyqOqcoHoIaDWJHmlfSnDK-xMn67mNaevRt1tvhu_s1Ibw7ND9-vrsIjocAYvEeTdTfMKsg7OyUxgDRq4viGpaAAayEOCGQtgzOKxMlaUuQixFRWVPAr0kF-OQBPIorExreaxzgU8Vphb78OP3x8y8Ii3PWx0R44Z77MSQ0grRa209lRsAvPjuNsOYJwA3g7OI3hOhTeCUkbWkdmtnl1sVUypaO0CNwM6R4lV6vh1WEQYU1XpDyRMqX7b8trz-xPVOmjNDLgEDYMcRB2WIi7O0Zo0yEmStD6J7QA5Dd6_U9gJi4TzWS5pU2LWlOhL3eeZ3n48zBzg4i9yPGDfWEBwhmk5buEw89Am2adCGUEtoMpDma9fYIFaGHOz8A2Z1ut9ItMTwYQhzsEp9P38_e278-rhYKbqBH2Gbgyb1knVa9gCUkE-KzYynP_eBNabigD8qaq40Jc_OEB8AvhyI-7LgbYU2wGm-y1SA0NyNsI1cIyOXVdshzK6W2fMi5FxNhp1F-VSUrIX-v_icc8lnrywz5Y8LyravfCneTD8Eu0S0RepTW46qGlRLNsHX_74ldvzwVgF-40okcJvQIU4wuEPZC6JnQ82iH3upYWD8Sev6b0DOKt4-3Py8XVmRDx4YDO_AMu2pX7doDK0uWTR2lDd0L2tblvqqFaA4DL2XVs0Hu6172LFMdLWldtmVbtU1bs2Jf7-pDIwSTFOm-bUhd4syVLpIQKXmmQliwO9RtzTLNe9Rh3TGUGvyENZgmszllvkuYvF_GQOpSqxDDgyWqqNfldF1ApDk9raLn3fP7PQPS2_k-jiptiRlN5CmWLV53_xFPxWnpC2FnQs-phu2SO28_UERCz2vlgdDztbNLR_8JAAD__-itpkI">