gcc-patches@gcc.gnu.org
[Top] [All Lists]

Re: [PATCH] Fix __builtin_object_size (x, 1) regression (PR tree-optim

Subject: Re: [PATCH] Fix __builtin_object_size x, 1) regression (PR tree-optimization/39343
From: Richard Guenther
Date: Tue, 3 Mar 2009 12:06:00 +0100
On Mon, Mar 2, 2009 at 8:33 PM, Jakub Jelinek <jakub@xxxxxxxxxx> wrote:
> Hi!
>
> The
> http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00877.html
> patch broke __builtin_object_size (, 1) when unions are involved.
> When another union member contains a field of the desired non-array type,
> one component ref might be transformed into a different one, for which
> bos will return sizeof that type instead of the possibly much larger array.
>
> The following fixes this, bootstrapped/regtested on x86_64-linux.
> I've looked also where it makes a difference during bootstrap and it seemed
> to trigger just with similar cases with unions, e.g. &t->exp.operands
> is no longer changed into &t->decl_minimal.context (completely unrelated,
> just happens to have the same field offset), etc.
>
> Ok for trunk?

Ok.

Thanks,
Richard.

> 2009-03-02  Jakub Jelinek  <jakub@xxxxxxxxxx>
>
>        PR tree-optimization/39343
>        * tree-ssa-ccp.c (maybe_fold_offset_to_address): Don't check if
>        COMPONENT_REF t has ARRAY_TYPE.
>
>        * gcc.dg/pr39343.c: New test.
>
> --- gcc/tree-ssa-ccp.c.jj       2009-02-20 15:56:54.000000000 +0100
> +++ gcc/tree-ssa-ccp.c  2009-03-02 15:46:34.000000000 +0100
> @@ -1942,8 +1942,7 @@ maybe_fold_offset_to_address (tree addr,
>           || (TREE_CODE (orig) == COMPONENT_REF
>               && TREE_CODE (TREE_TYPE (TREE_OPERAND (orig, 1))) == 
> ARRAY_TYPE))
>          && (TREE_CODE (t) == ARRAY_REF
> -             || (TREE_CODE (t) == COMPONENT_REF
> -                 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 1))) == 
> ARRAY_TYPE))
> +             || TREE_CODE (t) == COMPONENT_REF)
>          && !operand_equal_p (TREE_CODE (orig) == ARRAY_REF
>                               ? TREE_OPERAND (orig, 0) : orig,
>                               TREE_CODE (t) == ARRAY_REF
> --- gcc/testsuite/gcc.dg/pr39343.c.jj   2009-03-02 15:52:00.000000000 +0100
> +++ gcc/testsuite/gcc.dg/pr39343.c      2009-03-02 15:51:25.000000000 +0100
> @@ -0,0 +1,29 @@
> +/* PR tree-optimization/39343 */
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +extern void abort (void);
> +
> +extern inline __attribute__ ((__always_inline__)) int
> +foo (char *dest)
> +{
> +  return __builtin_object_size (dest, 1);
> +}
> +
> +struct S
> +{
> +  union
> +  {
> +    struct { int a, b; char c, d; } f;
> +    struct { struct { int a, b; char c, d[255]; } e; } g;
> +  } u;
> +};
> +
> +int
> +main (void)
> +{
> +  struct S s;
> +  if (foo (s.u.g.e.d) != 255)
> +    abort ();
> +  return 0;
> +}
>
>
>        Jakub
>

<Prev in Thread] Current Thread [Next in Thread>