<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - assertion failure converting lambda returning trivial_abi struct to function pointer"
   href="https://bugs.llvm.org/show_bug.cgi?id=42961">42961</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>assertion failure converting lambda returning trivial_abi struct to function pointer
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>enhancement
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>comexk@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>I think the fix may be to just change the assert in EmitAggregateCopy, as
memcpying a trivial_abi return value should work. 

Test case:

---

struct A {
  A(A &);
  A &operator=(const A &);
} __attribute__((trivial_abi));
A (*f)() = []() -> A {};

---

$ clang -cc1 -triple x86_64-apple-macosx10.14.0 -S test.cpp

Assertion failed: ((Record->hasTrivialCopyConstructor() ||
Record->hasTrivialCopyAssignment() || Record->hasTrivialMoveConstructor() ||
Record->hasTrivialMoveAssignment() || Record->isUnion()) && "Trying to
aggregate-copy a type without a trivial copy/move " "constructor or assignment
operator"), function EmitAggregateCopy, file
/usr/src/llvm/clang/lib/CodeGen/CGExprAgg.cpp, line 1928.

(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
  * frame #0: 0x00007fff77cad2a6 libsystem_kernel.dylib`__pthread_kill + 10
    frame #1: 0x00007fff77d68bf1 libsystem_pthread.dylib`pthread_kill + 284
    frame #2: 0x00007fff77c176a6 libsystem_c.dylib`abort + 127
    frame #3: 0x00007fff77be020d libsystem_c.dylib`__assert_rtn + 324
    frame #4: 0x000000010bdfc13b
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::EmitAggregateCopy(this=0x00007ffeefbf84a8,
Dest=LValue @ 0x00007ffeefbf76b0, Src=LValue @ 0x00007ffeefbf7710, Ty=QualType
@ 0x00007ffeefbf7698, MayOverlap=DoesNotOverlap, isVolatile=false) at
CGExprAgg.cpp:1922:7
    frame #5: 0x000000010c03dd03
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::EmitReturnOfRValue(this=0x00007ffeefbf84a8,
RV=RValue @ 0x00007ffeefbf7a40, Ty=QualType @ 0x00007ffeefbf7a38) at
CGStmt.cpp:1031:5
    frame #6: 0x000000010bcca97a
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::EmitForwardingCallToLambda(this=0x00007ffeefbf84a8,
callOperator=0x0000000124057a20, callArgs=0x00007ffeefbf7cc8) at
CGClass.cpp:2855:5
    frame #7: 0x000000010bccb05d
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::EmitLambdaDelegatingInvokeBody(this=0x00007ffeefbf84a8,
MD=0x0000000124057cc8) at CGClass.cpp:2917:3
    frame #8: 0x000000010bccb1db
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::EmitLambdaStaticInvokeBody(this=0x00007ffeefbf84a8,
MD=0x0000000124057cc8) at CGClass.cpp:2928:3
    frame #9: 0x000000010c0d9179
libclangCodeGen.dylib`clang::CodeGen::CodeGenFunction::GenerateCode(this=0x00007ffeefbf84a8,
GD=GlobalDecl @ 0x00007ffeefbf83b0, Fn=0x0000000122404aa8,
FnInfo=0x00000001224037c0) at CodeGenFunction.cpp:1193:5</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>