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

    <tr>
        <th>Summary</th>
        <td>
            [Offload][Flang] Compilation hangs for minutes and then fails when not using optimization flag
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          jfuchs-kmt
      </td>
    </tr>
</table>

<pre>
    When compiling the snippet below with the latest flang compiler from the master branch using `flang -fopenmp -fopenmp-targets=nvptx64 main.F90` will hang the compiler for minutes and then output the following error message:
```
>flang -fopenmp -fopenmp-targets=nvptx64 main.F90
nvlink warning : Stack size for entry function '__omp_offloading_10304_8e3c9d__QQmain_l14' cannot be statically determined
nvlink error   : Entry function 'optimizer.__omp_offloading_10304_8e3c9d__QQmain_l14' uses too much data for compiler-generated constants; please recompile with -Xptxas --disable-optimizer-constants
nvlink error   : Undefined reference to 'abort' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
nvlink error   : Undefined reference to 'strlen' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
nvlink error   : Undefined reference to 'memchr' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
nvlink error   : Undefined reference to 'strcmp' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
nvlink error   : Undefined reference to 'toupper' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
nvlink error   : Undefined reference to 'strcpy' in '/tmp/a.out.nvptx64.sm_120-0928e2-8dd2ec.cubin'
/opt/llvm/llvm-project/install/bin/clang-nvlink-wrapper: error: 'nvlink' failed
clang: error: nvlink command failed with exit code 1 (use -v to see invocation)
/opt/llvm/llvm-project/install/bin/clang-linker-wrapper: error: 'clang' failed
flang-22: error: linker command failed with exit code 1 (use -v to see invocation)`
```

```fortran
PROGRAM reproducer
    IMPLICIT NONE

    INTEGER, PARAMETER :: param(4) = [5, 6, 7, 8]
    INTEGER :: non_param(4) = [0, 0, 0, 0]

    !$omp target map(tofrom: non_param)
 non_param(:) = param(:)
    !$omp end target

    PRINT*, non_param
END PROGRAM reproducer
```

But when compiling the snippet with any optimization flag O1, O2 or O3, the program compiles quickly as expected and runs correctly it with `OMP_TARGET_OFFLOAD=mandatory ./a.out`. Then the output is as expected: `5 6 7 8`.

I checked this issue with nvfortran and gfortran - both of them compile and run correctly without and with optimization flags.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzEVkFv2zgT_TX0ZSBDpizFOvig1HYRoIlTf_6wezMoamSxoUgtSdlxf_2ClNIkTXpoC3SBQJHJmXnvkaOZYdaKo0JckvSapKsJ612jzfJL3fPGRg-tm5S6uiz_alAB120npFBHcA2CVaLr0EGJUp_hLFwTliVzaB3Ukqnj6IEGaqPbsN0y69BAaZjiDfTWRyNZPJhHte5Qtd23l8gxc0RnSbJSp849ZnNomVDTTR6TLIazkBIaNhJ6BtMGWqF6hxaYqvymAt27rnfBsNZS6rNHRmO8LVrLjkiSgsQFyeLxLy5Isv4FYnGhTlKoBzgzo4K-pID_OcYfwIqvGOihcuYCda-4E1oBoVeHg267g65rqVkl1PEwi5N4flhgwvPqcPj82cc_yNmc0CvgTCntjx6sY05wJuUFKnRoWqGweqYwCIRAYf0GU3dOtOIrmulPofcWLTitoe15AxVzLGh6Ov_oiAoNc1gB18o6pvw5XUMnkVkEg6PhkDPR3517ZBaiqBKWlRKjb6yiZ_d3Bf1fVVh7vWCwRoOKIzjthbFSG-epiqCT0I1rO0I3bKp7Nx1vbGrbw4zGUZzTBdJoUVUU-ZT3pVDe5ychrTMS1Z_FbLHljfnjOrnH-JOYTvddh_-B0O7y25iEbnTnCN1IeWrHf1Fn9BfkflX4DJeS0E3w2HBfb6KBaHQ2LOhOioGzfyH0atj1zGomZPjcg9sru1Er123ra-BgOXxy-CgccF0h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