From: Richard Guenther Date: Thu, 1 May 2008 11:15:32 +0000 (+0000) Subject: re PR middle-end/36093 (__align__ produces incorrect results in certain cases) X-Git-Tag: prereleases/gcc-4.2.4-rc1~15 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4824acdd9fc6d9e06603b70d82232153efb0f8f3;p=thirdparty%2Fgcc.git re PR middle-end/36093 (__align__ produces incorrect results in certain cases) 2008-05-01 Richard Guenther PR middle-end/36093 Backport from mainline 2007-04-12 Richard Guenther * gimplify.c (canonicalize_addr_expr): To be consistent with gimplify_compound_lval only set operands two and three of ARRAY_REFs if they are not gimple_min_invariant. This makes it never at this place. * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise. * gcc.c-torture/execute/pr36093.c: New testcase. From-SVN: r134849 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 0815f0aeb1c7..f0f12a657e7b 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,15 @@ +2008-05-01 Richard Guenther + + PR middle-end/36093 + Backport from mainline + 2007-04-12 Richard Guenther + + * gimplify.c (canonicalize_addr_expr): To be consistent with + gimplify_compound_lval only set operands two and three of + ARRAY_REFs if they are not gimple_min_invariant. This makes + it never at this place. + * tree-ssa-ccp.c (maybe_fold_offset_to_array_ref): Likewise. + 2008-04-17 Volker Reichelt PR c/35744 diff --git a/gcc/gimplify.c b/gcc/gimplify.c index 4acaae2936e2..fa2035bc39c9 100644 --- a/gcc/gimplify.c +++ b/gcc/gimplify.c @@ -1600,9 +1600,7 @@ canonicalize_addr_expr (tree *expr_p) /* All checks succeeded. Build a new node to merge the cast. */ *expr_p = build4 (ARRAY_REF, dctype, obj_expr, TYPE_MIN_VALUE (TYPE_DOMAIN (datype)), - TYPE_MIN_VALUE (TYPE_DOMAIN (datype)), - size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (dctype), - size_int (TYPE_ALIGN_UNIT (dctype)))); + NULL_TREE, NULL_TREE); *expr_p = build1 (ADDR_EXPR, ctype, *expr_p); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 372b94b51f6e..fd3820e0ef48 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-05-01 Richard Guenther + + PR middle-end/36093 + * gcc.c-torture/execute/pr36093.c: New testcase. + 2008-04-17 Volker Reichelt PR c/35744 diff --git a/gcc/testsuite/gcc.c-torture/execute/pr36093.c b/gcc/testsuite/gcc.c-torture/execute/pr36093.c new file mode 100644 index 000000000000..9549bc306b96 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/execute/pr36093.c @@ -0,0 +1,28 @@ +extern void abort (void); + +typedef struct Bar { + char c[129]; +} Bar __attribute__((__aligned__(128))); + +typedef struct Foo { + Bar bar[4]; +} Foo; + +Foo foo[4]; + +int main() +{ + int i, j; + Foo *foop = &foo[0]; + + for (i=0; i < 4; i++) { + Bar *bar = &foop->bar[i]; + for (j=0; j < 129; j++) { + bar->c[j] = 'a' + i; + } + } + + if (foo[0].bar[3].c[128] != 'd') + abort (); + return 0; +} diff --git a/gcc/tree-ssa-ccp.c b/gcc/tree-ssa-ccp.c index f485b02e4cf2..162191b87751 100644 --- a/gcc/tree-ssa-ccp.c +++ b/gcc/tree-ssa-ccp.c @@ -1620,9 +1620,7 @@ maybe_fold_offset_to_array_ref (tree base, tree offset, tree orig_type) if (!integer_zerop (elt_offset)) idx = int_const_binop (PLUS_EXPR, idx, elt_offset, 0); - return build4 (ARRAY_REF, orig_type, base, idx, min_idx, - size_int (tree_low_cst (elt_size, 1) - / (TYPE_ALIGN_UNIT (elt_type)))); + return build4 (ARRAY_REF, orig_type, base, idx, NULL_TREE, NULL_TREE); }