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

    <tr>
        <th>Summary</th>
        <td>
            Assertion failure (!isLibFunction) during openmp offload compilation
        </td>
    </tr>

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

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

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

<pre>
    Assertion failure message:
llvm-project/llvm/lib/Analysis/LazyCallGraph.cpp:1502: void llvm::LazyCallGraph::removeDeadFunction(llvm::Function&): Assertion `!isLibFunction(F) && "Must not remove lib functions from the call graph!"' failed.

Compile command is:
```
clang++ \
-c \
-O3 \
-fopenmp -fopenmp-targets=nvptx64-nvidia-cuda -fopenmp-offload-mandatory \
test_sort_cmp.cpp
```


The relevant code seems to be acquiring a function pointer address from the device
```
typedef bool (*ompx_sort_cmp_ty)(void *, void *);
template <typename T, typename Cmp> bool cmp_wrapper(void *a, void *b) {
  Cmp c;
  return c(*(T *)a, *(T *)b);
}
template<typename T, typename Cmp> func() {
  ompx_sort_cmp_ty dev_fptr;
// Remove the following two lines, and it compiles w/o assertion
#pragma omp target map(from : dev_fptr)
  { dev_fptr = &cmp_wrapper<T, Cmp>; }
}
```


The assertion happens with the nvptx64 target, but not with the amdgpu target.

The assertion occurs with llvm 16 and mainline.

The full stack is in `out.txt` in the attached file (along with the reproducer and compile command)


[dead_lib_func.tar.gz](https://github.com/llvm/llvm-project/files/11519674/dead_lib_func.tar.gz)


</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVc2O6zYPfRpmQySw5dhJFlnk58u3uUWBYvaBLNGOemVLleRkcp--kJzf22mLAgOPpVCHR4fkMfdetT3RGsotlPsJH8LJuHXH3XdJF9W3k9rI63rjPbmgTI8NV3pwhB15z1uCYgPZHrKN1uduap35nUQAdojL-E_VwA6bnuurV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