https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93153
--- Comment #3 from ZhuoYang <logicyangz at gmail dot com> --- Created attachment 66180 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=66180&action=edit GCC 16.2.0 reproducer bundle: full ccp1 dump, preprocessed source, and compiler version I reproduced the behavior described in this PR with Homebrew GCC 16.2.0 on aarch64-apple-darwin25. The second call uses the pointer returned by placement new, converted to A* when passed to call(). Reduced testcase (repro.cc): #include <cstdio> #include <new> struct A { virtual int func() { return 1; } }; struct B : A { int func() override { return 2; } }; int call(A* a) { return a->func(); } int main() { A a; static_assert(sizeof(B) <= sizeof(A) && alignof(B) <= alignof(A)); int x = call(&a); B* b = ::new (&a) B; int y = call(b); std::printf("%d %d\n", x, y); } g++-16 -std=c++23 -O3 -fdump-tree-ccp1-details=ccp1.txt repro.cc -o repro ./repro Expected output: 1 2 Actual output at -O3: 1 1 GCC 16.2.0 prints 1 2 at -O0 and with -O3 -fno-devirtualize -fno-devirtualize-speculatively. In early_objsz, the second call is still an OBJ_TYPE_REF. The ccp1 dump shows: Folding statement: _28 = OBJ_TYPE_REF(_27;b_16->0B) (b_16); repro.cc:5:32: optimized: folding virtual function call to virtual int A::func() Folded into: _28 = A::func (&a); The GIMPLE after ccp1 still contains the store of B's vtable before the second call.
