https://bugs.llvm.org/show_bug.cgi?id=44869

            Bug ID: 44869
           Summary: clang11 does not generate code for
                    `shared_ptr_emplace`
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangb...@nondot.org
          Reporter: vittorio.ro...@outlook.com
                CC: blitzrak...@gmail.com, erik.pilking...@gmail.com,
                    llvm-bugs@lists.llvm.org, richard-l...@metafoo.co.uk

Created attachment 23119
  --> https://bugs.llvm.org/attachment.cgi?id=23119&action=edit
Reproducible example

Description:

When creating a `std::shared_ptr` of a variadic template class inside a
coroutine, the compiler fails to generate the methods of the template class 
`__shared_ptr_emplace`, and linking fails.



Links to reproducible example:
https://gcc.godbolt.org/z/GpqoYi
https://wandbox.org/permlink/NRmkf9cnb0eJHgqj



Resulting error:

/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x10):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::~__shared_ptr_emplace()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x18):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::~__shared_ptr_emplace()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x20):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::__on_zero_shared()'
/tmp/prog-e218f2.o:(.rodata._ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE[_ZTVNSt3__120__shared_ptr_emplaceI1AIiENS_9allocatorIS2_EEEE]+0x30):
undefined reference to `std::__1::__shared_ptr_emplace<A<int>,
std::__1::allocator<A<int> > >::__on_zero_shared_weak()'
clang-11: error: linker command failed with exit code 1 (use -v to see
invocation)



How to reproduce:

Compile the code below with the following line:

/usr/bin/clang++-11 -std=gnu++2a -fcoroutines-ts -stdlib=libc++ -nostdinc++
-isystem/usr/lib/llvm-11/include/c++/v1/ -L/usr/lib/llvm-11/lib/
-Wl,-rpath,/usr/lib/llvm-11/lib test.cpp

Code:

#include <experimental/coroutine>
#include <tuple>

struct task
{
struct promise_type
{
task get_return_object() { return task{}; }
void return_void() {}
std::experimental::suspend_always initial_suspend() { return {}; }
void unhandled_exception() noexcept { std::terminate(); }
std::experimental::suspend_never final_suspend() { return {}; }
};
};

// removing the template fixes the linker error
template<typename Args>
struct A {};

int main()
{
// Using a regular function instead of a coroutine fixes the linker error
#ifdef FIX_1
auto coro = [](auto&& int2dbl) {
std::make_shared<A<int>>();
};
#else
auto coro = [](auto&& int2dbl) -> task {
std::make_shared<A<int>>();
co_return;
};
#endif

// Calling the coroutine directly fixes the linker error
#ifdef FIX_2
coro(A<int>());
#else
auto As = std::make_tuple(10);
std::apply([&](auto& wrapper) { return coro(wrapper); }, As);
#endif
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to