[Bug tree-optimization/45734] [4.6 Regression] Devirtualization results in wrong-code
--- Comment #3 from rguenth at gcc dot gnu dot org 2010-09-21 10:12 --- The following is miscompiled since ever (and also ICC miscompiles it), so I'm not sure if it is valid to use 'f' to refer to the Bar object. namespace std { typedef __SIZE_TYPE__ size_t; } inline void* operator new(std::size_t, void* __p) throw() { return __p; } extern "C" void abort (void); class Foo { public: virtual void test (void) { abort (); } }; class Bar : public Foo { public: virtual void test (void) { } }; int main() { Foo f; new (&f) Bar(); f.test(); return 0; } A variant with using a pointer of type Bar * like int main() { Foo f; static_cast(new (&f) Bar())->test(); return 0; } only breaks on recent trunk. int main() { Foo f; new (&f) Bar(); (&f)->test(); return 0; } also breaks always. While int main() { Foo f, *p; p = new (&f) Bar(); p->test(); return 0; } works. int main() { Foo f, *p; new (&f) Bar(); ((Foo *)(void *)&f)->test(); return 0; } also works. Fun. -- rguenth at gcc dot gnu dot org changed: What|Removed |Added CC||jason at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45734
[Bug tree-optimization/45734] [4.6 Regression] Devirtualization results in wrong-code
--- Comment #2 from rguenth at gcc dot gnu dot org 2010-09-20 15:46 --- Of course it is ;) Before pointer-conversions became useless we didn't propagate the invariant address into the OBJ_TYPE_REF expression. We still have useful function-pointer conversions as well, because dropping them would wreck CALL_EXPRs, too (we need to preserve the original function type, similar to the alias-type on MEM_REFs). I suppose we could do the same for OBJ_TYPE_REFs that I plan(ned) for CALL_EXPRs - store the pointed-to type via a MEM_REF - thus a dereferenced address. You'd then have CALL_EXPR (MEM [fnptr], args ...) OBJ_TYPE_REF (MEM [fnptr], MEM [objptr], index) where both TREE_TYPE of the function and the object are kept like the FE specified them. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45734
[Bug tree-optimization/45734] [4.6 Regression] Devirtualization results in wrong-code
--- Comment #1 from hjl dot tools at gmail dot com 2010-09-20 15:27 --- It is caused by revision 161655: http://gcc.gnu.org/ml/gcc-cvs/2010-07/msg6.html -- hjl dot tools at gmail dot com changed: What|Removed |Added Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Last reconfirmed|-00-00 00:00:00 |2010-09-20 15:27:10 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45734
[Bug tree-optimization/45734] [4.6 Regression] Devirtualization results in wrong-code
-- rguenth at gcc dot gnu dot org changed: What|Removed |Added CC||hubicka at gcc dot gnu dot ||org, jamborm at gcc dot gnu ||dot org Target Milestone|--- |4.6.0 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45734