tree-object-size.c (addr_object_size): Always use object_size_type 0 or 2 when determining the pointer pointed object size.

* 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.

From-SVN: r151323
This commit is contained in:
Jakub Jelinek 2009-09-02 14:25:14 +02:00 committed by Jakub Jelinek
parent 683ebd7553
commit ded97380f0
4 changed files with 42 additions and 2 deletions

View File

@ -1,3 +1,8 @@
2009-09-02 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.
2009-09-02 Richard Guenther <rguenther@suse.de>
Revert

View File

@ -1,3 +1,7 @@
2009-09-02 Jakub Jelinek <jakub@redhat.com>
* gcc.dg/builtin-object-size-9.c: New test.
2009-09-02 Olivier Hainque <hainque@adacore.com>
* gnat.dg/array7.ad[bs]: Add check for Signed_Integer_Type_Definition.

View File

@ -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;
}

View File

@ -171,9 +171,9 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
{
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);