]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: non-array new alignment [PR102071]
authorJason Merrill <jason@redhat.com>
Tue, 12 Apr 2022 20:06:18 +0000 (16:06 -0400)
committerJason Merrill <jason@redhat.com>
Tue, 12 Apr 2022 20:45:41 +0000 (16:45 -0400)
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.

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
gcc/testsuite/g++.dg/cpp1z/aligned-new9.C

index ce332c7e3292915bf42fe1ad3624bedd5e1332df..7ce8d3a46e5b0156a766d0e80a7de5a7f1cfad94 100644 (file)
@@ -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);
     }
index 7854299419a17803b725d5f3327e7afb2a81237c..3fa0ed996bd321ae3cffce16fdf7a9820cbd11d7 100644 (file)
@@ -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 ();
 }