[llvm-bugs] [Bug 51484] New: Consteval returning struct/class causes frontend error.

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Aug 15 10:06:37 PDT 2021


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

            Bug ID: 51484
           Summary: Consteval returning struct/class causes frontend
                    error.
           Product: clang
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++2a
          Assignee: unassignedclangbugs at nondot.org
          Reporter: luigilinked at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

Created attachment 25134
  --> https://bugs.llvm.org/attachment.cgi?id=25134&action=edit
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:
https://godbolt.org/z/oMT1vWbMY

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210815/3a32c5f8/attachment-0001.html>


More information about the llvm-bugs mailing list