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

    <tr>
        <th>Summary</th>
        <td>
            Kokkos test with its OpenMPTarget backend fails with clang-18
        </td>
    </tr>

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

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

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

<pre>
    A simple Kokkos test leads to an ICE with clang-18 (thunk) and clang-17. Compiles with clang-16 and below. 
Here is the error message
```shell
fatal error: error in backend: Cannot select: t8: i64,ch = stacksave t7, main.cpp:21:1 @[ main.cpp:20:1 ]
In function: __omp_offloading_d61f715a_c4004632_main_l20
clang++: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 18.0.0 (https://github.com/llvm/llvm-project.git 24c91d443222bdb20205630d300ae61bfa07067e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /global/cfs/cdirs/nstaff/rgayatri/software/llvm/nightly/bin
clang++: note: diagnostic msg:
```
I wrote the equivalent code as is implemented in the OpenMPTarget backend of Kokkos and could still reproduce the issue.
Can someone take a look at it?
Here is the reproducer

```c++
#include <Kokkos_Core.hpp>

int main(int argc, char **argv) {
    Kokkos::initialize();
    {
        using ExecSpace = Kokkos::DefaultExecutionSpace;
        using team_policy = Kokkos::TeamPolicy<ExecSpace>;
        using member_type = typename Kokkos::TeamPolicy<ExecSpace>::member_type;

        using viewDataType = Kokkos::View<int *, ExecSpace>;
        viewDataType v("Vector", 4);

        auto lambda1 = [=]() {
            const int n = omp_get_team_num();
            int out = 0;
            auto lambda2 = [&]() { out += n; };
            lambda2();
        };

#pragma omp target teams thread_limit(32) num_teams(1) map(lambda1)
#pragma omp parallel
        {
            const int blockId = omp_get_team_num();
            const int gridDim = omp_get_num_teams();

            for (int i = blockId; i < 1; i += gridDim) {
                lambda1();
            }
        }
 }
    Kokkos::finalize();
    return 0;
}
```

While some parts of the reproducer seem unnecessary, they are all needed for the ICE to occur. 
I can provide a Makefile too and provide pointers to where Kokkos related code is in its source.
Let me know if the above snippet has any issues. 

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVl2P4jrS_jXmptQocSDABRcMDHpH7x7tkXZ09hJVnErixbGztgPd--tX5UA3nOkZ7YkQieyqp74_MATdWqKtWH4Ry8MMx9g5v_UtvmH0WhazytVv2x0E3Q-G4P_d-ewCRAoRDGEdIDpAC9_2X-GqYwfKoG1f8jUIuY7daM9CbgBtfb9YzWHv-kEbCk8MZSKqyLjrHER2ENnu_8gT6ACxIyDvnYeeQsCWpmtRZtMvdGTMdNZgRDMRi2J349IWKlRnsjWf7dFaFyGQIRX5IK75X5cLIfeqA1EcIERU54AXgrgScg89ajtXwyCKncxFsctBLDKx_PJ0kU0Xy8OkyjcLzWhV1M4y_unk-uHkmsY4rLVtT3WZN6t8iSe1yLJFWcgTg52MzCb-5Bchv_Dvbgp_pHNovLOR2K2u79lzDWpD9eRSetURlKsJVhnHYQwELxeOVCACbS9OYdJLbh5kwYV80M5Cvp5n88TYxTgEUeyEPAp5bHXsxmquXC_k0ZjL_fUyePcvUnHe6ghyoTZ5vVgUUsqqrmQms2VZZHWRZUhlXjWYrbJyRe-yv6NvKQXidV2eysXLaM_WXe2L0XZ8fWnteKPrPGENvavJMPXggn69uzpENIbqg04uYl2Nq9AIeVRN4P9ae34zYdMIebwnuJDH4Jp4RU8fRlnddtG8CXmstP00GtZF4netsbUuRK2gDy176jk1b_rB1btIUyL_e9QXNGRvEcLAKZ6KqycbqeZ0ZcK_D2R_-33yzj1_wTX3Ckwl5UZTQ4jaGPA0eFePapKiQxhpPknfo4XgenKWIOKZAME4dwaMoKMojj8W2zuWv5nzbJS6-WE6lYW2yow1gSj2k3KnvfM077gsvj4iaBtTxQi55k_0reLqUh16EHIn5A59e-GGIVY3eAC4WczOLXba6qjR6P-QkGv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