<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67533>67533</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
clang-cuda: ICE when trying to take the address of a pure virtual function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
miscco
</td>
</tr>
</table>
<pre>
This is most coming from a standard library test that tested https://cplusplus.github.io/LWG/lwg-defects.html#2767
The -reduced- code in question is:
```cpp
template<class Fun>
struct not_fn_t {
Fun fun_;
template<class Arg>
__host__ __device__ bool operator()(Arg&& arg) noexcept {
return !fun_(static_cast<Arg&&>(arg));
}
};
__host__ __device__
void test_lwg2767() {
// See https://cplusplus.github.io/LWG/lwg-defects.html#2767
struct Abstract { __host__ __device__ virtual void f() const = 0; };
struct Derived : public Abstract { __host__ __device__ void f() const {} };
struct F { __host__ __device__ bool operator()(Abstract&&) { return false; } };
{
Derived d;
Abstract &a = d;
not_fn_t <F>{F{}}(static_cast<Abstract&&>(a));
}
}
int main(int, char**)
{
test_lwg2767();
return 0;
}
```
Compiling this with lit in our test hardness via:
```bash
lit: /home/coder/cccl/libcudacxx/utils/libcudacxx/test/config.py:218: note: Using warnings: ['-D_LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code']
lit: /home/coder/cccl/libcudacxx/utils/libcudacxx/test/config.py:219: note: Using link flags: ['-L/usr/local/cuda/lib64', '-lcuda', '-lcudart', '-lm', '-lgcc_s', '-lgcc', '-lpthread', '-lrt', '-lc', '-lgcc_s', '-lgcc']
lit: /home/coder/cccl/libcudacxx/utils/libcudacxx/test/config.py:221: note: Using available_features: ['glibc-2', 'c++filesystem-disabled', 'clang', 'fdelayed-template-parsing', 'libc++', 'dylib-has-no-filesystem', '-faligned-allocation', 'no_execute', 'locale.en_US.UTF-8', 'libcpp-no-rtti', 'clang-16.0', 'long_tests', 'modules-support', 'diagnose-if-support', '-fsized-deallocation', 'pre-sm-90', 'linux', 'c++17', 'glibc', 'clang-16.0.6', 'libcpp-no-exceptions', 'glibc-2.35', 'clang-16']
lit: /home/coder/cccl/libcudacxx/utils/libcudacxx/test/config.py:227: note: Adding environment variables: {}
FAIL: libcu++ :: std/utilities/function.objects/func.not_fn/not_fn.pass.cpp (1 of 1)
******************** TEST 'libcu++ :: std/utilities/function.objects/func.not_fn/not_fn.pass.cpp' FAILED ********************
Command: ['/usr/bin/sccache', '/usr/bin/clang++', '-o', '/home/coder/cccl/build/test/std/utilities/function.objects/func.not_fn/Output/not_fn.pass.cpp.o', '-x', 'cu', '/home/coder/cccl/libcudacxx/.upstream-tests/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp', '-c', '-std=c++17', '-include', '/home/coder/cccl/libcudacxx/test/support/nasty_macros.h', '-I/home/coder/cccl/libcudacxx/include', '-D__STDC_FORMAT_MACROS', '-D__STDC_LIMIT_MACROS', '-D__STDC_CONSTANT_MACROS', '-fno-exceptions', '-fno-rtti', '-D_LIBCUDACXX_NO_RTTI', '-I/home/coder/cccl/libcudacxx/test/support', '-Xclang', '-fcuda-allow-variadic-functions', '-Xclang', '-Wno-unused-parameter', '-Wno-unknown-cuda-version', '--cuda-gpu-arch=sm_86', '-D_LIBCUDACXX_DISABLE_PRAGMA_GCC_SYSTEM_HEADER', '-Wall', '-Wextra', '-Werror', '-Wuser-defined-warnings', '-Wshadow', '-Wno-unused-command-line-argument', '-Wno-attributes', '-Wno-pessimizing-move', '-Wno-c++11-extensions', '-Wno-user-defined-literals', '-Wno-noexcept-type', '-Wsign-compare', '-Wunused-variable', '-Wunused-parameter', '-Wunreachable-code', '-c']
Exit Code: 1
Standard Error:
--
ptxas fatal : Cannot take address of function '__cxa_pure_virtual'
clang: error: ptxas command failed with exit code 255 (use -v to see invocation)
Ubuntu clang version 16.0.6 (++20230710042027+7cbf1a259152-1~exp1~20230710162048.105)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang: note: diagnostic msg:
********************
```
The preprocessed files are given here
[reproducer.zip](https://github.com/llvm/llvm-project/files/12736745/reproducer.zip)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWN1v2zgS_2uYF4KGTcWW85AHf8R7AdLtoXGxvSeBIkcSrxSpIynH6cP-7QfqI5Zst9dudw844AK3tmbI-fxxZkTmnMw1wD2ar9F8e8NqXxh7X0rHublJjXi93xfSYelwaZzH3JRS5zizpsQMO8-0YFZgJVPL7Cv24Dz2BfPNLxC48L5yKFohukN0xytVu_Bvkktf1OlEGkR3T7_9guhOveREQAbcu0nhS4VoRONFjKZbNF21_-8LwMSCqDkIgrkRgKXG_6rBeWk0lo2idv1i2n54VbUUD2WlmAcUbbhizuFdrVH00DKdtzX3WBufZDrxGMXrloExDgtxVusEReuhMYF1IXRl8zehYUGSFMb5JMFJIuAgOSQJTo1R2FRgmTcW0SWid4guw066QHSBWfh1h7WBI4fqzJjwZ8HXVmNEZ41ZdOk885InnDmPos2bpGAJXbbiwicayEHxtnMm3p45dsXmlnEwUjR5TdRL3uSmMX5sYJto_AzwZ-U-SO0StEqdt4w3Mbka24O0vmYKN6ZmnX3caOcxirZ4iqI1Hno8kL0FKw8gMIpWuKpTJfl3qLuiJl6jePs1JbuvivoKKjoLuoS2we4BkDHloPNorPACMr1zYmRU-Dv5SBesCdLlmtO5iDa7gKp4vWv9DJ8L_I1tbkH4nyA4wJ_UHpdMakSXUntEN5gXzCK6aj53_Z43SZeIvDipXcCmJ8abyr5QDDdsTFlJFeqcD7XvRfoCK-lDsTG1bYtcwazQ4Bw-SHZZdlLmipakpA-I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