This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Fix __builtin_object_size


On 5/3/07, Jan Hubicka <jh@suse.cz> wrote:
Hi,
we now fail to return proper __builtin_object_size for:

/* { dg-do run } */
/* { dg-options "-O2" } */

typedef __SIZE_TYPE__ size_t;

struct A
{
  char a[10];
  int b;
  char c[10];
} y, w[4];

extern struct A extc[];

void
__attribute__ ((noinline))
test1 (void *q, int x)
{
  if (__builtin_object_size (&(extc + 10)->b, 1) != (size_t) -1)
    abort ();
}

int
main (void)
{
  test1 (main, 6);
}

The testcase expects -1, we however return -somebignumber.
The reason is that code processing push_expr is not special casing the
-1, value used to indicate unknown size and simply subtracts the offset.

We worked originally, because we used to produce
(void *)((int *)&expr+200), but now we do (void *)(&expr+200) (ie fold away the extra cast).
Analyzis used to stop earlier on the (int *), but now it proceeds to &expr.

This is ok, if tested properly.


Richard.

Honza

        * tree-object-size.c (plus_expr_object_size): When operand size is unknown,
        return unknown.
Index: tree-object-size.c
===================================================================
*** tree-object-size.c  (revision 124378)
--- tree-object-size.c  (working copy)
*************** plus_expr_object_size (struct object_siz
*** 588,594 ****
          unsigned HOST_WIDE_INT off = tree_low_cst (op1, 1);

          bytes = compute_builtin_object_size (op0, object_size_type);
!         if (off > offset_limit)
            bytes = unknown[object_size_type];
          else if (off > bytes)
            bytes = 0;
--- 588,596 ----
          unsigned HOST_WIDE_INT off = tree_low_cst (op1, 1);

          bytes = compute_builtin_object_size (op0, object_size_type);
!         if (bytes == unknown[object_size_type])
!           ;
!         else if (off > offset_limit)
            bytes = unknown[object_size_type];
          else if (off > bytes)
            bytes = 0;



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]