93 lines
2.9 KiB
Diff
93 lines
2.9 KiB
Diff
|
2009-06-15 Jakub Jelinek <jakub@redhat.com>
|
||
|
|
||
|
* tree-object-size.c (addr_object_size): Fix a pasto in the last
|
||
|
change.
|
||
|
|
||
|
* gcc.dg/builtin-object-size-7.c: New test.
|
||
|
|
||
|
--- gcc/tree-object-size.c.jj 2009-06-12 10:36:08.000000000 +0200
|
||
|
+++ gcc/tree-object-size.c 2009-06-15 18:40:17.000000000 +0200
|
||
|
@@ -316,7 +316,7 @@ addr_object_size (struct object_size_inf
|
||
|
&& tree_int_cst_lt (pt_var_size, bytes2))
|
||
|
bytes2 = size_zero_node;
|
||
|
else
|
||
|
- bytes2 = size_binop (MINUS_EXPR, var_size, bytes2);
|
||
|
+ bytes2 = size_binop (MINUS_EXPR, pt_var_size, bytes2);
|
||
|
bytes = size_binop (MIN_EXPR, bytes, bytes2);
|
||
|
}
|
||
|
}
|
||
|
--- gcc/testsuite/gcc.dg/builtin-object-size-7.c.jj 2009-06-15 18:54:33.000000000 +0200
|
||
|
+++ gcc/testsuite/gcc.dg/builtin-object-size-7.c 2009-06-15 18:55:58.000000000 +0200
|
||
|
@@ -0,0 +1,71 @@
|
||
|
+/* { dg-do run } */
|
||
|
+/* { dg-options "-O2" } */
|
||
|
+
|
||
|
+typedef __SIZE_TYPE__ size_t;
|
||
|
+extern void *malloc (size_t);
|
||
|
+extern void abort (void);
|
||
|
+
|
||
|
+struct A
|
||
|
+{
|
||
|
+ int i, j, k;
|
||
|
+ char buf[255];
|
||
|
+ int l, m, n, o;
|
||
|
+};
|
||
|
+
|
||
|
+int
|
||
|
+main (void)
|
||
|
+{
|
||
|
+ const size_t s = sizeof (struct A);
|
||
|
+ const size_t o = __builtin_offsetof (struct A, buf);
|
||
|
+ struct A *a = malloc (s);
|
||
|
+ struct A *b = malloc (o + 212);
|
||
|
+ if (__builtin_object_size (a->buf, 0) != s - o)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (a->buf, 1) != sizeof (a->buf))
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (a->buf, 2) != s - o)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (a->buf, 3) != sizeof (a->buf))
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[0], 0) != s - o)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[0], 1) != sizeof (a->buf))
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[0], 2) != s - o)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[0], 3) != sizeof (a->buf))
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[6], 0) != s - o - 6)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[6], 1) != sizeof (a->buf) - 6)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[6], 2) != s - o - 6)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&a->buf[6], 3) != sizeof (a->buf) - 6)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (b->buf, 0) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (b->buf, 1) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (b->buf, 2) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (b->buf, 3) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[0], 0) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[0], 1) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[0], 2) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[0], 3) != 212)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[28], 0) != 212 - 28)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[28], 1) != 212 - 28)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[28], 2) != 212 - 28)
|
||
|
+ abort ();
|
||
|
+ if (__builtin_object_size (&b->buf[28], 3) != 212 - 28)
|
||
|
+ abort ();
|
||
|
+ return 0;
|
||
|
+}
|