From f57f53d3a5a0b18fdf5cef76247aed5f4b1e5610 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 13 Jun 2016 07:34:45 +0000 Subject: [PATCH] re PR middle-end/64516 (arm: wrong unaligned load generated) 2016-06-13 Richard Biener 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 | 6 ++++++ gcc/fold-const.c | 2 ++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/align-3.c | 11 +++++++++++ 4 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/gcc.dg/align-3.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 3ea7a014f5a..690bd02469d 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-06-13 Richard Biener + + 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 PR sanitizer/71458 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 7f8803ca57d..1a464ec8366 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f3245154d77..a596a54e275 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-06-13 Richard Biener + + PR middle-end/64516 + * gcc.dg/align-3.c: New testcase. + 2016-06-13 Martin Liska * 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 index 00000000000..5c97d5ac3cc --- /dev/null +++ b/gcc/testsuite/gcc.dg/align-3.c @@ -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" } } */ -- 2.30.2