public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-9222] middle-end/101480 - overloaded global new/delete Date: Mon, 8 Nov 2021 12:35:27 +0000 (GMT) [thread overview] Message-ID: <20211108123527.CE72A3858401@sourceware.org> (raw) https://gcc.gnu.org/g:19dcea67ac40cfdeb396fa264ebbe04fbe61fdc0 commit r11-9222-g19dcea67ac40cfdeb396fa264ebbe04fbe61fdc0 Author: Richard Biener <rguenther@suse.de> Date: Mon Oct 11 16:06:03 2021 +0200 middle-end/101480 - overloaded global new/delete The following fixes the issue of ignoring side-effects on memory from overloaded global new/delete operators by not marking them as effectively 'const' apart from other explicitely specified side-effects. This will cause FAIL: g++.dg/warn/Warray-bounds-16.C -std=gnu++1? (test for excess errors) because we now no longer statically see the initialization loop never executes because the call to operator new can now clobber 'a.m'. This seems to be an issue with the warning code and/or ranger so I'm leaving this FAIL to be addressed as followup. 2021-10-11 Richard Biener <rguenther@suse.de> PR middle-end/101480 * gimple.c (gimple_call_fnspec): Do not mark operator new/delete as const. * g++.dg/torture/pr10148.C: New testcase. (cherry picked from commit 09a0affdb0598a54835ac4bb0dd6b54122c12916) Diff: --- gcc/gimple.c | 4 +-- gcc/testsuite/g++.dg/torture/pr10148.C | 52 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/gcc/gimple.c b/gcc/gimple.c index c6f7c2d4900..61126cf94b3 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1516,12 +1516,12 @@ gimple_call_fnspec (const gcall *stmt) && DECL_IS_OPERATOR_DELETE_P (fndecl) && DECL_IS_REPLACEABLE_OPERATOR (fndecl) && gimple_call_from_new_or_delete (stmt)) - return ".co "; + return ". o "; /* Similarly operator new can be treated as malloc. */ if (fndecl && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) && gimple_call_from_new_or_delete (stmt)) - return "mC"; + return "m "; return ""; } diff --git a/gcc/testsuite/g++.dg/torture/pr10148.C b/gcc/testsuite/g++.dg/torture/pr10148.C new file mode 100644 index 00000000000..ed278f9f8d8 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr10148.C @@ -0,0 +1,52 @@ +/* { dg-do run } */ + +#include <stdlib.h> +#include <assert.h> + +static bool flag = false; + +class C +{ + bool prev; + +public: + C() : prev(flag) + { + flag = true; + } + + ~C() { + flag = prev; + } +}; + +void* operator new(size_t size) +{ + assert(flag); + return malloc(size); +} + +void operator delete(void *p) +{ + free(p); +} + +void g(int* p) +{ + delete p; +} + +void f() +{ + int* p; + { + C c; + p = new int; + } + g(p); +} + +int main(int, char**) +{ + f(); +}
reply other threads:[~2021-11-08 12:35 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20211108123527.CE72A3858401@sourceware.org \ --to=rguenth@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).