From: Jakub Jelinek Date: Mon, 25 Jun 2018 17:32:55 +0000 (+0200) Subject: backport: re PR c++/79085 (ICE with placement new to unaligned location) X-Git-Tag: releases/gcc-6.5.0~208 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a4b178f3d6569620cb1c0422d4a867de455e9474;p=thirdparty%2Fgcc.git backport: re PR c++/79085 (ICE with placement new to unaligned location) Backported from mainline 2018-03-15 Jakub Jelinek PR c++/79085 * calls.c (expand_call): For TREE_ADDRESSABLE rettype ignore alignment check and use address of target always. * g++.dg/opt/pr79085.C: New test. From-SVN: r262076 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 6923e64fbde2..070fee57a60b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,12 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-03-15 Jakub Jelinek + + PR c++/79085 + * calls.c (expand_call): For TREE_ADDRESSABLE rettype ignore alignment + check and use address of target always. + 2018-03-09 Jakub Jelinek PR target/84772 diff --git a/gcc/calls.c b/gcc/calls.c index c78059fb5199..30c74ec961f8 100644 --- a/gcc/calls.c +++ b/gcc/calls.c @@ -2557,9 +2557,14 @@ expand_call (tree exp, rtx target, int ignore) if (CALL_EXPR_RETURN_SLOT_OPT (exp) && target && MEM_P (target) - && !(MEM_ALIGN (target) < TYPE_ALIGN (rettype) - && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype), - MEM_ALIGN (target)))) + /* If rettype is addressable, we may not create a temporary. + If target is properly aligned at runtime and the compiler + just doesn't know about it, it will work fine, otherwise it + will be UB. */ + && (TREE_ADDRESSABLE (rettype) + || !(MEM_ALIGN (target) < TYPE_ALIGN (rettype) + && SLOW_UNALIGNED_ACCESS (TYPE_MODE (rettype), + MEM_ALIGN (target))))) structure_value_addr = XEXP (target, 0); else { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 8f9eb960f9d2..818d6b60c4c2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -3,6 +3,9 @@ Backported from mainline 2018-03-15 Jakub Jelinek + PR c++/79085 + * g++.dg/opt/pr79085.C: New test. + PR c++/84222 * g++.dg/warn/deprecated.C (T::member3): Change dg-warning to dg-bogus. * g++.dg/warn/deprecated-6.C (T::member3): Likewise. diff --git a/gcc/testsuite/g++.dg/opt/pr79085.C b/gcc/testsuite/g++.dg/opt/pr79085.C new file mode 100644 index 000000000000..1d75d6a73009 --- /dev/null +++ b/gcc/testsuite/g++.dg/opt/pr79085.C @@ -0,0 +1,24 @@ +// PR c++/79085 +// { dg-do compile } +// { dg-options "-Os" } +// { dg-additional-options "-mstrict-align" { target { aarch64*-*-* powerpc*-*-linux* powerpc*-*-elf* } } } + +void *operator new (__SIZE_TYPE__, void *p) { return p; } + +struct S +{ + S (); + S (const S &); + ~S (void); + int i; +}; + +S foo (); + +static char buf [sizeof (S) + 1]; + +S * +bar () +{ + return new (buf + 1) S (foo ()); +}