]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/79085 (ICE with placement new to unaligned location)
authorJakub Jelinek <jakub@redhat.com>
Fri, 22 Jun 2018 20:43:53 +0000 (22:43 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 22 Jun 2018 20:43:53 +0000 (22:43 +0200)
Backported from mainline
2018-03-15  Jakub Jelinek  <jakub@redhat.com>

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: r261925

gcc/ChangeLog
gcc/calls.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr79085.C [new file with mode: 0644]

index 65c140f5a22bc0e743b3ea4a5b2374a5eb4d4940..53055f1cf83547060f338903926c45beced9e975 100644 (file)
@@ -3,6 +3,10 @@
        Backported from mainline
        2018-03-15  Jakub Jelinek  <jakub@redhat.com>
 
+       PR c++/79085
+       * calls.c (expand_call): For TREE_ADDRESSABLE rettype ignore alignment
+       check and use address of target always.
+
        PR target/84860
        * optabs.c (emit_conditional_move): Pass address of cmode's copy
        rather than address of cmode as last argument to prepare_cmp_insn.
index 31663f4f67b34f310bfda0ee5788e579467b1886..8eec155cf7de1186538a007a113f02dbf275379d 100644 (file)
@@ -3147,9 +3147,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
          {
index 304ec3ac47ee7290fe53b619ebfbcb87d472e67d..073c11d832a98df083991490f8d4951fcf00c411 100644 (file)
@@ -3,6 +3,9 @@
        Backported from mainline
        2018-03-15  Jakub Jelinek  <jakub@redhat.com>
 
+       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 (file)
index 0000000..1d75d6a
--- /dev/null
@@ -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 ());
+}