https://gcc.gnu.org/g:7da47d53d716b689784eaad20ebe26fdbb33982a
commit r17-2157-g7da47d53d716b689784eaad20ebe26fdbb33982a Author: Jakub Jelinek <[email protected]> Date: Sun Jul 5 16:47:47 2026 +0200 testsuite: Add C++ testcase for the recent PTA bug On Wed, Jul 01, 2026 at 09:47:46AM +0200, Eric Botcazou wrote: > this is a regression present on mainline, 16, 15 and 14 branches introduced by > the fix for PR tree-optimization/112653 (PTA and return). What happens is > that DSE incorrectly eliminates a call to __builtin_memcpy, whose destination > is obtained from (an equivalent of) malloc and is ultimately returned from the > function. But this happens only when the dynamic allocation is conditional. For us Ada illiterate, here is a C++ testcase which got fixed by this too. 2026-07-05 Jakub Jelinek <[email protected]> * g++.dg/opt/20260703-1.C: New test. Reviewed-by: Richard Biener <[email protected]> Diff: --- gcc/testsuite/g++.dg/opt/20260703-1.C | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/gcc/testsuite/g++.dg/opt/20260703-1.C b/gcc/testsuite/g++.dg/opt/20260703-1.C new file mode 100644 index 000000000000..007f3d2f1127 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/20260703-1.C @@ -0,0 +1,46 @@ +// This started to be miscompiled with r15-579 or in a larger +// test with r15-3956 and got fixed with r17-2039. +// DSE would optimize away the store of 42. +// { dg-do run { target c++11 } } +// { dg-options "-O2" } + +struct B { }; + +void *volatile g; + +template <typename T> +struct D { T foo (void) const { return (T) g; } }; + +struct G : public B +{ + virtual B *bar (int); + struct H : public B { H () : h (42) {} int h; }; + struct I : public B {}; + D <I *> g; +}; + +struct H : public G { virtual B *bar (int) { return nullptr; } }; + +B * +G::bar (int x) +{ + if (x == 0) + return new H (); + I *y = g.foo (); + return y; +} + +[[gnu::noipa]] B * +baz (G *x, int y) +{ + return x->bar (y); +} + +int +main () +{ + G g; + G::H *h = (G::H *) baz (&g, 0); + if (h->h != 42) + __builtin_abort (); +}
