Description
Consider the following bit of code:
void _Adjust_manually_vector_aligned()
{}
template <size_t>
constexpr void _Deallocate() {
_Adjust_manually_vector_aligned();
}
struct basic_string {
constexpr ~basic_string() {
_Deallocate<8>();
}
};
template <class Var_t>
class E {
virtual ~E() = default;
basic_string _name;
};
template class E<float>;
Including this into a CUDA file (you don't even have to use the class in a device-side function or variable) leads to errors like ptxas fatal : Unresolved extern function '_Z31_Adjust_manually_vector_alignedv'
or, when compiling with -fgpu-rdc
, corresponding errors from nvlink
. The resulting PTX contains unreferenced .weak .func
s of the defaulted virtual destructor. This bears some similarity to #98151, but the circumstances under which the extraneous symbol is emitted differ.
The code for basic_string
and the functions it calls was reduced from https://github.com/microsoft/STL/blob/vs-2022-17.0/stl/inc/xstring and https://github.com/microsoft/STL/blob/vs-2022-17.0/stl/inc/xmemory. The current issue makes it impossible to use std::string
in template classes with defaulted virtual destructors when using CUDA on Windows in C++20 mode.
Godbolt: https://godbolt.org/z/7MTda4Kq4
NVCC does not show this issue, it never generates .weak .func
symbols for host-side destructors. Clang appears to only be generating these extraneous .weak .func
symbols for code that exactly follows the above pattern; eliminating the templates, the virtual
, the default
, or the constexpr
s makes the problem go away.
Metadata
Metadata
Type
Projects
Status