summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-17 18:07:45 +0000
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>2018-01-17 18:07:45 +0000
commite1afa6615f79c8ed214271040ab48e6db72be408 (patch)
tree827b99f0647d2236de0ac00e0c5a7c1c99a345bf
parentcb36f3d1200fec5c6cc02f1748128a5d8b4aa1a8 (diff)
PR c++/82760 - memory corruption with aligned new.
* call.c (build_operator_new_call): Update *args if we add the align_arg. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@256806 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/call.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp1z/aligned-new8.C19
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 99b594717d2b..bbe31ec76931 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,9 @@
+2018-01-17 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.
+
2018-01-02 Jakub Jelinek <jakub@redhat.com>
PR c++/83556
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 09279555b65c..56f6b93230b3 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4344,6 +4344,8 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
= 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. */
}
diff --git a/gcc/testsuite/g++.dg/cpp1z/aligned-new8.C b/gcc/testsuite/g++.dg/cpp1z/aligned-new8.C
new file mode 100644
index 000000000000..11dd45722b78
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1z/aligned-new8.C
@@ -0,0 +1,19 @@
+// 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;
+}