public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed] c++: non-array new alignment [PR102071]
@ 2022-04-12 21:08 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2022-04-12 21:08 UTC (permalink / raw)
  To: gcc-patches

While considering the PR102071 patch for backporting, I noticed that I was
considering the alignment of the array new cookie even when there isn't one
because we aren't allocating an array.

Tested x86_64-pc-linux-gnu, applying to trunk.

	PR c++/102071

gcc/cp/ChangeLog:

	* init.cc (build_new_1): Check array_p for alignment.

gcc/testsuite/ChangeLog:

	* g++.dg/cpp1z/aligned-new9.C: Add single-object test.
---
 gcc/cp/init.cc                            | 2 +-
 gcc/testsuite/g++.dg/cpp1z/aligned-new9.C | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/init.cc b/gcc/cp/init.cc
index ce332c7e329..7ce8d3a46e5 100644
--- a/gcc/cp/init.cc
+++ b/gcc/cp/init.cc
@@ -3292,7 +3292,7 @@ build_new_1 (vec<tree, va_gc> **placement, tree type, tree nelts,
     {
       unsigned align = TYPE_ALIGN_UNIT (elt_type);
       /* Also consider the alignment of the cookie, if any.  */
-      if (TYPE_VEC_NEW_USES_COOKIE (elt_type))
+      if (array_p && 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);
     }
diff --git a/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C b/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C
index 7854299419a..3fa0ed996bd 100644
--- a/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C
+++ b/gcc/testsuite/g++.dg/cpp1z/aligned-new9.C
@@ -23,4 +23,8 @@ int main()
   X *p = new X[n];
   if (nalign != align)
     __builtin_abort ();
+
+  X *p2 = new X;
+  if (nalign != alignof (X))
+    __builtin_abort ();
 }

base-commit: aa7874596b9f12b25a3214b0a143b040fafa1f10
-- 
2.27.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2022-04-12 21:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-12 21:08 [pushed] c++: non-array new alignment [PR102071] Jason Merrill

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).