re PR middle-end/64516 (arm: wrong unaligned load generated)
authorRichard Biener <rguenther@suse.de>
Mon, 13 Jun 2016 07:34:45 +0000 (07:34 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Mon, 13 Jun 2016 07:34:45 +0000 (07:34 +0000)
2016-06-13  Richard Biener  <rguenther@suse.de>

PR middle-end/64516
* fold-const.c (fold_unary_loc): Preserve alignment when
folding a VIEW_CONVERT_EXPR into a MEM_REF.

* gcc.dg/align-3.c: New testcase.

From-SVN: r237355

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/align-3.c [new file with mode: 0644]

index 3ea7a014f5a19f2b58871a2f049ee93fd5200a26..690bd02469d2a51ba4a393c0ff1943043f3ce4f3 100644 (file)
@@ -1,3 +1,9 @@
+2016-06-13  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/64516
+       * fold-const.c (fold_unary_loc): Preserve alignment when
+       folding a VIEW_CONVERT_EXPR into a MEM_REF.
+
 2016-06-13  Martin Liska  <mliska@suse.cz>
 
        PR sanitizer/71458
index 7f8803ca57d0982ba8d090720ee652af138faf9c..1a464ec8366126939b3e4fa65c2b5b701eaddd41 100644 (file)
@@ -7975,6 +7975,8 @@ fold_unary_loc (location_t loc, enum tree_code code, tree type, tree op0)
     case VIEW_CONVERT_EXPR:
       if (TREE_CODE (op0) == MEM_REF)
         {
+         if (TYPE_ALIGN (TREE_TYPE (op0)) != TYPE_ALIGN (type))
+           type = build_aligned_type (type, TYPE_ALIGN (TREE_TYPE (op0)));
          tem = fold_build2_loc (loc, MEM_REF, type,
                                 TREE_OPERAND (op0, 0), TREE_OPERAND (op0, 1));
          REF_REVERSE_STORAGE_ORDER (tem) = REF_REVERSE_STORAGE_ORDER (op0);
index f3245154d776311bcabd6700125c2f6ade7f761d..a596a54e2750335f8c3310250850d3dc744ce373 100644 (file)
@@ -1,3 +1,8 @@
+2016-06-13  Richard Biener  <rguenther@suse.de>
+
+       PR middle-end/64516
+       * gcc.dg/align-3.c: New testcase.
+
 2016-06-13  Martin Liska  <mliska@suse.cz>
 
        * gcc.target/i386/pr71458.c: New test.
diff --git a/gcc/testsuite/gcc.dg/align-3.c b/gcc/testsuite/gcc.dg/align-3.c
new file mode 100644 (file)
index 0000000..5c97d5a
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-rtl-expand" } */
+
+typedef struct { char a[2]; } __attribute__((__packed__)) TU2;
+unsigned short get16_unaligned(const void *p) {
+    unsigned short v;
+    *(TU2 *)(void *)(&v) = *(const TU2 *)p;
+    return v;
+}
+
+/* { dg-final { scan-rtl-dump "MEM\[^\n\r\]*A8\\\]" "expand" } } */