https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101370
Bug ID: 101370
Summary: miscompile of self-referential constexpr or constinit
array initializer
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: richard-gccbugzilla at metafoo dot co.uk
Target Milestone: ---
Testcase (reduced from tcmalloc):
struct Elem {
Elem* next_ = this;
Elem* prev_ = this;
};
constinit Elem qs[3];
GCC generates a zero initializer for qs:
qs:
.zero 48
If the `constinit` is removed, GCC instead incorrectly generates a dynamic
initializer, so presumably GCC knows that this variable *should* have a
constant initializer but can't actually form one.
The same problem can be observed without constinit:
constexpr Elem rs[3];
const void *p = rs;
... again results in a zero-initialized global and no dynamic initializer.