Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OpenMP] OpenMPOpt miscompiles sprintf function from the GPU implementation #94643

Open
jhuber6 opened this issue Jun 6, 2024 · 1 comment
Open
Labels

Comments

@jhuber6
Copy link
Contributor

jhuber6 commented Jun 6, 2024

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.

#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.

$ 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.

@llvmbot
Copy link
Collaborator

llvmbot commented Jun 6, 2024

@llvm/issue-subscribers-openmp

Author: Joseph Huber (jhuber6)

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.
#include &lt;stdio.h&gt;

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.

$ 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants