summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/builtin-object-size-9.c31
-rw-r--r--gcc/tree-object-size.c4
4 files changed, 42 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index a35edee60a1..f623607af83 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3e331d98ed8..4f8f0cd6bd9 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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.
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-9.c b/gcc/testsuite/gcc.dg/builtin-object-size-9.c
new file mode 100644
index 00000000000..f134aaca0d6
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-9.c
@@ -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;
+}
diff --git a/gcc/tree-object-size.c b/gcc/tree-object-size.c
index 5b9fe38e96b..443f2808c2d 100644
--- a/gcc/tree-object-size.c
+++ b/gcc/tree-object-size.c
@@ -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);