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

    <tr>
        <th>Summary</th>
        <td>
            Clang assertion failure "Trying to aggregate-copy a type without a trivial copy/move constructor or assignment operator" in clang::CodeGen::CodeGenFunction::EmitAggregateCopy
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

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

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

<pre>
    Some of our code exposes an assertion failure in Clang. I've reduced the example to this snippet:
```
template <class T>
class __attribute__((__trivial_abi__)) shared_ptr {
 public:
  shared_ptr(const shared_ptr&);
  shared_ptr& operator=(const shared_ptr&);
};
class V {
 shared_ptr<int> impl_;
};
V v();
void f() {
  (void)+[] { return v(); };
}
```
The assertion failure is reproducible way back to Clang 7.

```
clang++: /root/llvm-project/llvm/tools/clang/lib/CodeGen/CGExprAgg.cpp:2297: void clang::CodeGen::CodeGenFunction::EmitAggregateCopy(clang::CodeGen::LValue, clang::CodeGen::LValue, clang::QualType, clang::CodeGen::AggValueSlot::Overlap_t, bool): Assertion `(Record->hasTrivialCopyConstructor() || Record->hasTrivialCopyAssignment() || Record->hasTrivialMoveConstructor() || Record->hasTrivialMoveAssignment() || Record->hasAttr<TrivialABIAttr>() || Record->isUnion()) && "Trying to aggregate-copy a type without a trivial copy/move " "constructor or assignment operator"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics <source>
1.      <eof> parser at end of file
2.      Per-file LLVM IR generation
3.      <source>:12:10: Generating code for declaration 'f()::(anonymous class)::__invoke'
 #0 0x0000000003fac638 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fac638)
 #1 0x0000000003faa2c4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3faa2c4)
 #2 0x0000000003eeeef8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000070d14b042520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000070d14b0969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000070d14b042476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000070d14b0287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000070d14b02871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000070d14b039e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000004323dc2 clang::CodeGen::CodeGenFunction::EmitAggregateCopy(clang::CodeGen::LValue, clang::CodeGen::LValue, clang::QualType, clang::CodeGen::AggValueSlot::Overlap_t, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4323dc2)
#10 0x000000000447f638 clang::CodeGen::CodeGenFunction::EmitReturnOfRValue(clang::CodeGen::RValue, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x447f638)
#11 0x00000000048826b2 clang::CodeGen::CodeGenFunction::EmitForwardingCallToLambda(clang::CXXMethodDecl const*, clang::CodeGen::CallArgList&, clang::CodeGen::CGFunctionInfo const*, llvm::Constant*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48826b2)
#12 0x00000000048834a6 clang::CodeGen::CodeGenFunction::EmitLambdaDelegatingInvokeBody(clang::CXXMethodDecl const*, clang::CodeGen::CallArgList&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48834a6)
#13 0x0000000004883903 clang::CodeGen::CodeGenFunction::EmitLambdaStaticInvokeBody(clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4883903)
#14 0x000000000450f0ba clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x450f0ba)
#15 0x00000000045784ad clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45784ad)
#16 0x0000000004573634 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4573634)
#17 0x000000000457fe2c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457fe2c)
#18 0x000000000457fd48 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x457fd48)
#19 0x00000000045823b3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x45823b3)
#20 0x000000000495d6ce (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#21 0x0000000004959b05 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4959b05)
#22 0x000000000664a7fc clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x664a7fc)
#23 0x000000000495a298 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x495a298)
#24 0x0000000004c52cf5 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c52cf5)
#25 0x0000000004bd10fe clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bd10fe)
#26 0x0000000004d44d19 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4d44d19)
#27 0x0000000000dae7af cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdae7af)
#28 0x0000000000da53ca ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x00000000049c13a9 void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::'lambda'()>(long) Job.cpp:0:0
#30 0x0000000003eef394 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3eef394)
#31 0x00000000049c19bf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x000000000498378d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x498378d)
#33 0x000000000498481e clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x498481e)
#34 0x000000000498cb05 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x498cb05)
#35 0x0000000000daacbf clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdaacbf)
#36 0x0000000000c304c4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc304c4)
#37 0x000070d14b029d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x000070d14b029e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000da4e75 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xda4e75)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkWltv27iX_zTKC-FAomRdHvKgOEm3gxbTbTLFvBkUdSRzS5MCSbnOt1-QlCNLubTuxIPF_geTwqJ4Dn_nx3OTRKI1awXAVbC8DpY3F6Q3G6muCId9s7moZP14dS-3gGSDZK8QlTUg2HdSg0ZEIKI1KMOkQA1hvFeAmEArTkR7iT4GONsBUlD3FGpkNlaSbDsOyEhkNkwjLVjXgQniMgjLIA2H_8PSwLbjxAAK4hXlRGv0EMS3QVj6i_WaGKNY1RtYrwOcBzhfr41iO0b4mlTMDhYBLpDeEAX1ujMKBdl1EJao6yvOqF8RHd0PcE6l0GYylFo18fWzqSmSHShipArim59IBtmN_-GhfzsAOZodr5gwQXyL2Lbj65nYN7RzFg7qdpLVqPEjB1UowLkdd0Zf-52095AC0ytxpAA9qbU_ppw_bOCl_dRIQadk3VNWcUA_yCOqCP1u99BtNMouraKpLmrvWCz4OohLFOA7JaUJ8B3nu-2iU_J_gB4uA3xnpOQ6wHeD2B1nVYDvVrKGDyDsrw-3-06VbXtJuy6IS4yLzOp1ZHihuAzi8iBxfHHXC2ot8oO3W2bKtlXQEgMr2T3a3XtFwadvhPcQ4NWrS7w44797wh8euzcFy7Z1ovdcGj_y5w4UJ93aWLFKSu42rETl045YZnH-FahU9SKIbzdEP3iXt3asrAuqnlqfPDjHKshW6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