public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94314] New: [10 Regression] Optimizing mismatched new/delete pairs
@ 2020-03-24 21:59 glisse at gcc dot gnu.org
  2020-03-24 22:29 ` [Bug c++/94314] " jason at gcc dot gnu.org
                   ` (15 more replies)
  0 siblings, 16 replies; 17+ messages in thread
From: glisse at gcc dot gnu.org @ 2020-03-24 21:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94314

            Bug ID: 94314
           Summary: [10 Regression] Optimizing mismatched new/delete pairs
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Keywords: wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org
  Target Milestone: ---

(originally posted at
https://gcc.gnu.org/legacy-ml/gcc-patches/2019-08/msg00276.html , I don't know
if we will do something about it, but it seems worth documenting it in
bugzilla)

Now that we optimize class-specific operator new/delete pairs (but you could do
the same with the global replacable ones as well):

#include <stdio.h>
int count = 0;
struct A {
  __attribute__((malloc,noinline))
  static void* operator new(unsigned long sz){++count;return ::operator
new(sz);}
  static void operator delete(void* ptr){--count;::operator delete(ptr);}
};
int main(){
  delete new A;
  printf("%d\n",count); // Should print 0.
}

If we do not inline anything, we can remove the pair and nothing touches count.
If we inline both new and delete, we can then remove the inner pair instead,
count increases and decreases, fine. If we inline only one of them, and DCE the
mismatched pair new/delete, we get something inconsistent (count is -1).

This seems to indicate we should check that the new and delete match somehow...

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2020-04-17  7:02 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-24 21:59 [Bug c++/94314] New: [10 Regression] Optimizing mismatched new/delete pairs glisse at gcc dot gnu.org
2020-03-24 22:29 ` [Bug c++/94314] " jason at gcc dot gnu.org
2020-03-25  7:55 ` rguenth at gcc dot gnu.org
2020-03-25 10:08 ` [Bug c++/94314] [10 Regression] Optimizing mismatched new/delete pairs since r10-2106-g6343b6bf3bb83c87 marxin at gcc dot gnu.org
2020-03-25 10:44 ` rguenth at gcc dot gnu.org
2020-03-25 11:24 ` glisse at gcc dot gnu.org
2020-03-27 21:43 ` jason at gcc dot gnu.org
2020-03-30  7:57 ` marxin at gcc dot gnu.org
2020-04-01  7:48 ` rguenth at gcc dot gnu.org
2020-04-08 15:17 ` cvs-commit at gcc dot gnu.org
2020-04-08 15:18 ` marxin at gcc dot gnu.org
2020-04-08 16:02 ` glisse at gcc dot gnu.org
2020-04-08 18:04 ` cvs-commit at gcc dot gnu.org
2020-04-09 13:55 ` marxin at gcc dot gnu.org
2020-04-16 13:40 ` cvs-commit at gcc dot gnu.org
2020-04-16 13:41 ` marxin at gcc dot gnu.org
2020-04-17  7:02 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).