<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 - Consteval returning struct/class causes frontend error."
   href="https://bugs.llvm.org/show_bug.cgi?id=51484">51484</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Consteval returning struct/class causes frontend error.
          </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>Linux
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

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

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

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

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

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=25134" name="attach_25134" title="Contains the Source Code and Crash Report.">attachment 25134</a> <a href="attachment.cgi?id=25134&action=edit" title="Contains the Source Code and Crash Report.">[details]</a></span>
Contains the Source Code and Crash Report.

I was experimenting with C++20 Clang on Compiler Explorer (godbolt.org) and I
ran into a bizarre case which caused the Clang frontend to seemingly crash.

I have simplified my source code to the smallest it could be while still
causing the crash, and experimented around with what did and didn't cause it.

I will include the Source File and the Crash Report (with the -v command line
option) as an attachment.

I will also include a link to the source on Compiler Explorer for easy
verification and experimentation.

For the record, I was using "x86-64 clang (trunk)" but this issue seems to
occur with any version of Clang starting from 11.0.0 and onwards, as it does
not crash on Clang 10.0.0 or 10.0.1.

The only compiler flags used were -std=c++20 (and -v for the crash report).

I have verified all of this information to be true as of 8/15/2021.


The crash occurs under specific circumstances when a Consteval function is
returning a struct/class.

If you call that function and discard the result, it seems to always cause a
crash. If you store the result in a variable (constexpr or not) or pass it to a
function, the crash does not occur.

Additionally, if the struct/class being returned inherits from another
struct/class and you call the Consteval function in the return statement of
another function, this will cause a crash only if the base class has 2 or more
members. (Very strangely specific, but this is how I encountered the bug in the
first place)

None of these issues seem to occur when using constexpr instead of consteval.

If you look at the submitted source code, the comments will likely make this
description more clear.


Compiler Explorer link:
<a href="https://godbolt.org/z/oMT1vWbMY">https://godbolt.org/z/oMT1vWbMY</a></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>