https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93153
Bug ID: 93153
Summary: Wrong optimization while devirtualizing after
placement new over local var
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ch3root at openwall dot com
Target Milestone: ---
It seems gcc doesn't account for a possible type change of local variables due
to storage reuse while devirtualizing method calls (seems to happen in ccp1):
----------------------------------------------------------------------
#include <stdio.h>
#include <new>
struct Y {
virtual void foo() { puts("Y"); }
};
struct X : Y {
virtual void foo() { puts("X"); }
};
static_assert(sizeof(X) == sizeof(Y));
int main()
{
Y y;
Y *p = new (&y) X;
p->foo();
}
----------------------------------------------------------------------
$ g++ -std=c++2a -pedantic -Wall -Wextra test.cc && ./a.out
X
$ g++ -std=c++2a -pedantic -Wall -Wextra -O3 test.cc && ./a.out
Y
----------------------------------------------------------------------
gcc x86-64 version: g++ (GCC) 10.0.0 20200104 (experimental)
----------------------------------------------------------------------