https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92023
Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Component|c++ |middle-end Known to fail| |11.2.0, 7.1.0 Summary|Miscompilation when |[9/10/11/12 Regression] |inlining operator delete[] |Miscompilation when | |inlining operator delete[] Known to work| |6.4.0 Target Milestone|--- |9.5 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- here is a runtime testcase: #include <cstddef> #include <cstdio> #include <new> int t = 0; void use(int* p) __attribute__((noipa,noinline,noclone)); void use(int*){} void report(int) __attribute__((noipa,noinline,noclone)); void report(int a) {printf("%d\n",a);t++;} const int N = 5; const size_t S = 512; char objs[N][S]; bool taken[N] = {}; void* operator new[](size_t size) { if (size <= S) { for (int i = 0; i < N; i++) { if (!taken[i]) { report(2000 + i); taken[i] = true; return &objs[i]; } } } throw std::bad_alloc(); } void operator delete[](void* ptr) noexcept { for (int i = 0; i < N; i++) { if (ptr == &objs[i]) { report(-2000 - i); taken[i] = false; } } } int n = 10; void test() __attribute__((noinline)); void test() { int* a = new int[n]; int* b = new int[n]; use(a); use(b); delete[] b; delete[] a; } int main(void) { test(); if (t != 4) __builtin_abort(); }