public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-7855] c++: low -faligned-new [PR102071] Date: Mon, 28 Mar 2022 13:37:43 +0000 (GMT) [thread overview] Message-ID: <20220328133743.C3BC73857827@sourceware.org> (raw) https://gcc.gnu.org/g:19b87a06482756739087283cd8b884cb3de693f9 commit r12-7855-g19b87a06482756739087283cd8b884cb3de693f9 Author: Jason Merrill <jason@redhat.com> Date: Sun Mar 27 12:36:13 2022 -0400 c++: low -faligned-new [PR102071] This test ICEd after the constexpr new patch (r10-3661) because alloc_call had a NOP_EXPR around it; fixed by moving the NOP_EXPR to alloc_expr. And the PR pointed out that the size_t cookie might need more alignment, so I fix that as well. PR c++/102071 gcc/cp/ChangeLog: * init.cc (build_new_1): Include cookie in alignment. Omit constexpr wrapper from alloc_call. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/aligned-new9.C: New test. Diff: --- gcc/cp/init.cc | 15 +++++++++++---- gcc/testsuite/g++.dg/cpp1z/aligned-new9.C | 26 ++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc index 08767679dd4..91b5c2c0f69 100644 --- a/gcc/cp/init.cc +++ b/gcc/cp/init.cc @@ -3284,7 +3284,13 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, tree align_arg = NULL_TREE; if (type_has_new_extended_alignment (elt_type)) - align_arg = build_int_cst (align_type_node, TYPE_ALIGN_UNIT (elt_type)); + { + unsigned align = TYPE_ALIGN_UNIT (elt_type); + /* Also consider the alignment of the cookie, if any. */ + if (TYPE_VEC_NEW_USES_COOKIE (elt_type)) + align = MAX (align, TYPE_ALIGN_UNIT (size_type_node)); + align_arg = build_int_cst (align_type_node, align); + } alloc_fn = NULL_TREE; @@ -3473,18 +3479,19 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts, } } + alloc_expr = alloc_call; if (cookie_size) - alloc_call = maybe_wrap_new_for_constexpr (alloc_call, type, + alloc_expr = maybe_wrap_new_for_constexpr (alloc_expr, type, cookie_size); /* In the simple case, we can stop now. */ pointer_type = build_pointer_type (type); if (!cookie_size && !is_initialized && !member_delete_p) - return build_nop (pointer_type, alloc_call); + return build_nop (pointer_type, alloc_expr); /* Store the result of the allocation call in a variable so that we can use it more than once. */ - alloc_expr = get_target_expr (alloc_call); + alloc_expr = get_target_expr (alloc_expr); alloc_node = TARGET_EXPR_SLOT (alloc_expr); /* Strip any COMPOUND_EXPRs from ALLOC_CALL. */ diff --git a/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C b/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C new file mode 100644 index 00000000000..7854299419a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C @@ -0,0 +1,26 @@ +// PR c++/102071 +// { dg-do run { target c++17 } } +// { dg-additional-options -faligned-new=2 } + +#include <new> + +int nalign; +void *operator new (std::size_t s, std::align_val_t a) +{ + nalign = (int)a; + return operator new (s); +} + +struct X { ~X(); int c; }; + +int align = (alignof (X) > alignof (std::size_t) + ? alignof (X) : alignof (std::size_t)); + +int n = 4; + +int main() +{ + X *p = new X[n]; + if (nalign != align) + __builtin_abort (); +}
reply other threads:[~2022-03-28 13:37 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=20220328133743.C3BC73857827@sourceware.org \ --to=jason@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).