public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-5748] gimple: Return fnspec only for replaceable new/delete operators called from new/delete [PR98130] Date: Fri, 4 Dec 2020 18:11:50 +0000 (GMT) [thread overview] Message-ID: <20201204181150.6C2713850418@sourceware.org> (raw) https://gcc.gnu.org/g:78c4a9feceaccf487516aa1eff417e0741556e10 commit r11-5748-g78c4a9feceaccf487516aa1eff417e0741556e10 Author: Jakub Jelinek <jakub@redhat.com> Date: Fri Dec 4 19:10:56 2020 +0100 gimple: Return fnspec only for replaceable new/delete operators called from new/delete [PR98130] As mentioned in the PR, we shouldn't treat non-replaceable operator new/delete (e.g. with the placement new) as replaceable ones. There is some pending discussion that perhaps operator delete called from delete if not replaceable should return some other fnspec, but can we handle that incrementally, fix this wrong-code and then deal with a missed optimization? I really don't know what exactly should be returned. 2020-12-04 Jakub Jelinek <jakub@redhat.com> PR c++/98130 * gimple.c (gimple_call_fnspec): Only return ".co " for replaceable operator delete or ".mC" for replaceable operator new called from new/delete. * g++.dg/opt/pr98130.C: New test. Diff: --- gcc/gimple.c | 3 ++- gcc/testsuite/g++.dg/opt/pr98130.C | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/gcc/gimple.c b/gcc/gimple.c index e8246b72cc9..bb1345875c2 100644 --- a/gcc/gimple.c +++ b/gcc/gimple.c @@ -1514,11 +1514,12 @@ gimple_call_fnspec (const gcall *stmt) such operator, then we can treat it as free. */ if (fndecl && DECL_IS_OPERATOR_DELETE_P (fndecl) + && DECL_IS_REPLACEABLE_OPERATOR (fndecl) && gimple_call_from_new_or_delete (stmt)) return ".co "; /* Similarly operator new can be treated as malloc. */ if (fndecl - && DECL_IS_OPERATOR_NEW_P (fndecl) + && DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) && gimple_call_from_new_or_delete (stmt)) return "mC"; return ""; diff --git a/gcc/testsuite/g++.dg/opt/pr98130.C b/gcc/testsuite/g++.dg/opt/pr98130.C new file mode 100644 index 00000000000..0af55ef0444 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr98130.C @@ -0,0 +1,25 @@ +// PR c++/98130 +// { dg-do run { target c++11 } } +// { dg-options "-O2" } + +#include <new> + +typedef int *T; + +static unsigned char storage[sizeof (T)] alignas (T); +static T *p = (T *) storage; + +static inline __attribute__((__always_inline__)) void +foo (T value) +{ + new (p) T(value); +} + +int +main () +{ + int a; + foo (&a); + if (!*p) + __builtin_abort (); +}
reply other threads:[~2020-12-04 18:11 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=20201204181150.6C2713850418@sourceware.org \ --to=jakub@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).