https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92023
Bug ID: 92023
Summary: Miscompilation when inlining operator delete[]
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: bruno-gcc at defraine dot net
Target Milestone: ---
Created attachment 47005
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47005&action=edit
Test case
Consider the example in attachment, where we use a toy allocator implemented in
custom operator new[] and operator delete[] functions.
When compiling this with `g++ -std=c++14 -O2 -Wall` and looking at the
disassembly of function "test", I'm surprised to find the operator delete[]
behavior has been completely removed from "test" ("test" ends with a tail call
to "use"...).
Godbolt link: https://godbolt.org/z/bpalzE
As far as I see, this behavior is new since gcc-7. With gcc-6 versions, the
behavior of operator delete[] is inlined at the end of test. If I disable
inlining with `-fno-inline`, all gcc versions seem to produce correct code
(i.e. two calls to operator delete[] at the end of "test").