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

    <tr>
        <th>Summary</th>
        <td>
            [OpenMP] Compilation error at O0 for OpenMP GPU offloading with NVIDIA GPU and LLVM 20
        </td>
    </tr>

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

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

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

<pre>
    Given the following OpenMP C code, at O0 there is a compilation error. O1-3 works fine. The issue occurs in LLVM 20 but not the main branch (LLVM 21).
```c
#include <stdio.h>

void foo() {
  int sum = 10000;
#pragma omp target teams distribute parallel for map(tofrom: sum) num_teams(256) num_threads(1024) reduction(+ : sum)
  for (int i = 1; i <= 100; i++)
    sum += i;

  printf("sum = %d\n", sum);
}

int main(int argc, char **argv) {

  foo();

  return 0;
}
```

```bash
$ clang -v
clang version 20.1.2 (https://github.com/llvm/llvm-project 3f957cc67cff4e337f56fa2dbfdb037d3a997baf)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/ouankou/Projects/llvm-20/llvm_install/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /opt/nvidia/hpc_sdk/Linux_x86_64/24.3/cuda/12.3, version 12.3

$ clang -fopenmp -fopenmp-targets=nvptx64 -O0 test.c
nvlink error   : Undefined reference to 'IsSPMDMode' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
nvlink error   : Undefined reference to '_ZN4ompx5state9TeamStateE' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
nvlink error   : Undefined reference to '_ZN4ompx5state12ThreadStatesE' in '/tmp/a.out.nvptx64.sm_86-a57cc1-8872c3.cubin'
/home/ouankou/Projects/llvm-20/llvm_install/bin/clang-nvlink-wrapper: error: 'nvlink' failed
clang: error: nvlink command failed with exit code 1 (use -v to see invocation)
/home/ouankou/Projects/llvm-20/llvm_install/bin/clang-linker-wrapper: error: 'clang' failed
clang: error: linker command failed with exit code 1 (use -v to see invocation)
```

The setup is LLVM 20 built from source, NVIDIA HPC SDK 24.3 (CUDA 12.3), NVIDIA RTX A3000 Laptop GPU (sm86). The full error log is attached. Please let me know if any other information is needed. Thanks!

[error.log](https://github.com/user-attachments/files/19412964/error.log)
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVl1v47oR_TX0y8CCNJIs6cEP_rjaBk3uBk32ouhLQFMjm41ECiTl5P77gqSS7Ba9Cyx2gQIGLErDmTMzh8PDrZVnRbRl5Z6VxxWf3UWbrZ65etbz6qS7P7ef5JUUuAtBr4dBv0h1hs8Tqbt7OIDQHTE8AHfwOfVGhkBa4CD0OMmBO6kVkDHaJPA5W-fwos2zhV4qSuDx4o3tTKCFmI0FqeD29o87wBROswOlXYg7cqngZLgSF2BYR5OMYZOwdMc2afwJv8BcKjHMHQHLD9Z1UicXlv_mP6W7q5Yd9FozrBk2wKo9S3cAUjmw8wgsP0KWpmnK8n30NRl-HjnocQLHzZkcOOKjhU5aZ-RpdgQTN3wYaIBeGxj5xLB2ujd6ZPnOe_WB1Dw-hY0Mayw3768uhnjnX2YpFv6toW4WvmQB4R4-fASgPgTD2uOVES3L9-HxsGAPa4b78IubIOaGe28il9T8h8lI5foQCd_SZ1h2rDwohui7usSOe6pj3OnD-44sSLg5C28rLtyj2zHccXO-fhR4gb5U_SsAhtxsFKTf-H_rZjR6X564vYSeFCAGrs6wvrJ0Fx-vZKynGaZJlqCv0MW5ybJ8x7Bl2J6lu8ynROiRYTsM17e_9WT0v0k4yPumrITYVKLvC8rzqi83Pcfu1HenNK-6nDdNdeJ9LOljYIJvzWu9edoU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