https://gcc.gnu.org/bugzilla/show_bug.cgi?id=124182
Bug ID: 124182
Summary: gcc-16 optimization regression with
-fdevirtualize-speculatively
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: frank.mehnert at googlemail dot com
Target Milestone: ---
Using gcc-16 from Debian/experimental:
$ gcc-16 --version
16-20260208-1) 16.0.1 20260208 (experimental) [trunk r16-7394-gd93c8a679b2]
...
Compiling the L4Re code we get undefined references to extern objects with
g++16. The same code works without any problem with g++15.
Reduced example below. Compiling with gcc-16:
$ g++-16 -O3 -c reduced.cc -o reduced.o && objdump -tC reduced.o|grep marker
0000000000000000 *UND* 0000000000000000 marker
$ g++-15 -O3 -c reduced.cc -o reduced.o && objdump -tC reduced.o|grep marker
$ g++-16 -O3 -c reduced.cc -o reduced.o -fno-devirtualize-speculatively &&
objdump -tC reduced.o|grep marker
Here is the code:
#include <cstdio>
extern unsigned long marker;
struct Logger
{
unsigned long _mask;
void log() const
{
if (marker & _mask)
printf("foo bar\n");
}
};
struct Base
{
virtual void work() noexcept = 0;
virtual ~Base() = default;
};
struct DerivedA : Base
{
void work() noexcept override {}
};
struct DerivedB final : Base
{
Logger *_dbg;
void work() noexcept override
{
_dbg->log();
}
};
DerivedA local_obj;
Base *ptr = &local_obj;
void func()
{
ptr->work();
}