Commit e3704417 by Jason Merrill Committed by Jason Merrill

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
parent edaa6eb5
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> 2017-11-28 Jakub Jelinek <jakub@redhat.com>
PR sanitizer/81275 PR sanitizer/81275
......
...@@ -4372,6 +4372,8 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args, ...@@ -4372,6 +4372,8 @@ build_operator_new_call (tree fnname, vec<tree, va_gc> **args,
= vec_copy_and_insert (*args, align_arg, 1); = vec_copy_and_insert (*args, align_arg, 1);
cand = perform_overload_resolution (fns, align_args, &candidates, cand = perform_overload_resolution (fns, align_args, &candidates,
&any_viable_p, tf_none); &any_viable_p, tf_none);
if (cand)
*args = align_args;
/* If no aligned allocation function matches, try again without the /* If no aligned allocation function matches, try again without the
alignment. */ alignment. */
} }
......
// 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment