[Bug tree-optimization/107066] New: Field initialized before ctor is mis-optimized away by DSE
fxue at os dot amperecomputing.com
gcc-bugzilla@gcc.gnu.org
Wed Sep 28 10:55:52 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107066
Bug ID: 107066
Summary: Field initialized before ctor is mis-optimized away by
DSE
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: fxue at os dot amperecomputing.com
Target Milestone: ---
By means of user-defined new operator, it is possible that a field is
initialized before constructor.
#include <stddef.h>
class A {
public:
int f1;
int f2;
A() : f2(2) { }
void *operator new(size_t size)
{
void *mem = ::operator new(size);
A *obj = static_cast<A *>(mem);
obj->f1 = 1;
return obj;
}
};
A* foo ()
{
return new A();
}
The original gimple code of foo() is:
struct A * foo ()
{
void * D.2444;
void * _9;
<bb 2> :
_9 = operator new (8);
MEM[(struct A *)_9].f1 = 1;
MEM[(struct A *)_9] ={v} {CLOBBER};
MEM[(struct A *)_9].f2 = 2;
return _9;
}
In gimple, there exists a pseudo clobber statement marking beginning of
constructor code. Although the statement is of no side effect, it is regarded
as normal store by DSE when determining store redundancy. Consequently, DSE
thought that "MEM[(struct A *)_9].f1 = 1" was killed by "MEM[(struct A *)_9]
={v} {CLOBBER}", and removed it. After DSE pass,the foo becomes:
struct A * foo ()
{
void * D.2444;
void * _9;
<bb 2> :
_9 = operator new (8);
MEM[(struct A *)_9] ={v} {CLOBBER};
MEM[(struct A *)_9].f2 = 2;
return _9;
}
More information about the Gcc-bugs
mailing list