diff options
author | Jason Merrill <jason@redhat.com> | 2017-11-29 16:01:23 -0500 |
---|---|---|
committer | Jason Merrill <jason@gcc.gnu.org> | 2017-11-29 16:01:23 -0500 |
commit | e3704417fa5e3ab896ae766087783b098a2f2f8f (patch) | |
tree | 723e990cac4187a1da2f93888fa2fe98694045f1 /gcc | |
parent | edaa6eb53a331e71fe3e8826fc40f51683d01237 (diff) | |
download | gcc-e3704417fa5e3ab896ae766087783b098a2f2f8f.zip gcc-e3704417fa5e3ab896ae766087783b098a2f2f8f.tar.gz gcc-e3704417fa5e3ab896ae766087783b098a2f2f8f.tar.bz2 |
PR c++/82760 - memory corruption with aligned new.
* call.c (build_operator_new_call): Update *args if we add the
align_arg.
From-SVN: r255253
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/call.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp1z/aligned-new8.C | 19 |
3 files changed, 27 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2cb90b8..1bc4600 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +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 diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 45c811e..e046268 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4372,6 +4372,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 0000000..11dd457 --- /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; +} |