This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix __builtin_object_size (x, [13])
- From: Richard Guenther <rguenther at suse dot de>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: Richard Henderson <rth at redhat dot com>, gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Sep 2009 10:44:46 +0200 (CEST)
- Subject: Re: [PATCH] Fix __builtin_object_size (x, [13])
- References: <20090901211008.GL2884@tyan-ft48-01.lab.bos.redhat.com>
On Tue, 1 Sep 2009, Jakub Jelinek wrote:
> Hi!
>
> As shown in the testcase below, when handling INDIRECT_REF in an ADDR_EXPR
> base, for __bos (x, 1) or __bos (x, 3) we shouldn't compute the base size
> using the same argument (i.e. considering subobjects), only the last
> ADDR_EXPR should be considered for subobjects, otherwise on the testcase
> below we return 0 (which means e.g. strcpy (t->d, "") would always fail).
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
Ok.
Thanks,
Richard.
> 2009-09-01 Jakub Jelinek <jakub@redhat.com>
>
> * tree-object-size.c (addr_object_size): Always use object_size_type
> 0 or 2 when determining the pointer pointed object size.
>
> * gcc.dg/builtin-object-size-9.c: New test.
>
> --- gcc/tree-object-size.c.jj 2009-07-20 20:42:09.000000000 +0200
> +++ gcc/tree-object-size.c 2009-09-01 19:14:28.000000000 +0200
> @@ -171,9 +171,9 @@ addr_object_size (struct object_size_inf
> {
> unsigned HOST_WIDE_INT sz;
>
> - if (!osi)
> + if (!osi || (object_size_type & 1) != 0)
> sz = compute_builtin_object_size (TREE_OPERAND (pt_var, 0),
> - object_size_type);
> + object_size_type & ~1);
> else
> {
> tree var = TREE_OPERAND (pt_var, 0);
> --- gcc/testsuite/gcc.dg/builtin-object-size-9.c.jj 2009-09-01 19:25:51.000000000 +0200
> +++ gcc/testsuite/gcc.dg/builtin-object-size-9.c 2009-09-01 19:25:38.000000000 +0200
> @@ -0,0 +1,31 @@
> +/* { dg-do run } */
> +/* { dg-options "-O2" } */
> +
> +typedef __SIZE_TYPE__ size_t;
> +extern void *malloc (size_t);
> +extern void free (void *);
> +extern void abort (void);
> +
> +union U
> +{
> + struct S { int a; int b; } s;
> + int t;
> +};
> +
> +struct T
> +{
> + int c;
> + char d[1];
> +};
> +
> +int
> +main (void)
> +{
> + union U *u = malloc (sizeof (struct S) + sizeof (struct T) + 6);
> + struct T *t = (struct T *) (&u->s + 1);
> + if (__builtin_object_size (t->d, 1)
> + != sizeof (struct T) + 6 - __builtin_offsetof (struct T, d))
> + abort ();
> + free (u);
> + return 0;
> +}
>
> Jakub
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex