* call.c (build_operator_new_call): Update *args if we add the
align_arg.
From-SVN: r255253
+2017-11-29 Jason Merrill <jason@redhat.com>
+
+ PR c++/82760 - memory corruption with aligned new.
+ * call.c (build_operator_new_call): Update *args if we add the
+ align_arg.
+
2017-11-28 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81275
= vec_copy_and_insert (*args, align_arg, 1);
cand = perform_overload_resolution (fns, align_args, &candidates,
&any_viable_p, tf_none);
+ if (cand)
+ *args = align_args;
/* If no aligned allocation function matches, try again without the
alignment. */
}
--- /dev/null
+// PR c++/82760
+// { dg-options -std=c++17 }
+// { dg-do run }
+
+#include <new>
+#include <cstddef>
+
+struct alignas(2 * alignof (std::max_align_t)) aligned_foo {
+ char x[2048];
+
+ ~aligned_foo() { }
+ aligned_foo() { __builtin_memset(x, 0, sizeof(x)); }
+};
+
+int main()
+{
+ aligned_foo * gFoo = new (std::nothrow) aligned_foo[2];
+ delete[] gFoo;
+}