@@ -1,11 +1,7 @@
// { dg-do run }
// { dg-options "-O2" }
-typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
-extern "C" void exit (int);
-extern "C" void *malloc (size_t);
-extern "C" void free (void *);
+#include "../../gcc.dg/builtin-object-size-common.h"
struct A
{
@@ -20,105 +16,105 @@ test1 (A *p)
{
char *c;
if (__builtin_object_size (&p->a, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != 0)
- abort ();
+ FAIL ();
}
void
@@ -129,105 +125,105 @@ test2 (void)
size_t s = 2 * sizeof (A);
A *p = (A *) malloc (2 * sizeof (A));
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
free (p);
}
@@ -239,48 +235,48 @@ test3 (void)
size_t s;
A *p = (A *) malloc (4);
if (__builtin_object_size (&p->a, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 0)
- abort ();
+ FAIL ();
free (p);
s = __builtin_offsetof (A, c) + 4;
p = (A *) malloc (s);
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 4)
- abort ();
+ FAIL ();
free (p);
}
@@ -294,17 +290,17 @@ __attribute__ ((noinline))
test4 (struct B *q, int i)
{
if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
}
struct C
@@ -318,13 +314,13 @@ __attribute__ ((noinline))
test5 (struct C *c)
{
if (__builtin_object_size (&c->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 3) != 1)
- abort ();
+ FAIL ();
}
struct D
@@ -342,13 +338,13 @@ __attribute__ ((noinline))
test6 (struct D *d)
{
if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
}
struct E
@@ -366,21 +362,21 @@ __attribute__ ((noinline))
test7 (struct E *e)
{
if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
- abort ();
+ FAIL ();
}
union F
@@ -398,13 +394,13 @@ __attribute__ ((noinline))
test8 (union F *f)
{
if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 3) != 0)
- abort ();
+ FAIL ();
}
int
@@ -431,5 +427,5 @@ main (void)
union F f, *fp = &f;
__asm ("" : "+r" (fp));
test8 (fp);
- exit (0);
+ DONE ();
}
@@ -1,11 +1,7 @@
// { dg-do run }
// { dg-options "-O2" }
-typedef __SIZE_TYPE__ size_t;
-extern "C" void abort ();
-extern "C" void exit (int);
-extern "C" void *malloc (size_t);
-extern "C" void free (void *);
+#include "../../gcc.dg/builtin-object-size-common.h"
typedef struct A
{
@@ -23,105 +19,105 @@ test1 (A *p)
{
char *c;
if (__builtin_object_size (&p->a, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != 0)
- abort ();
+ FAIL ();
}
void
@@ -132,105 +128,105 @@ test2 (void)
size_t s = 2 * sizeof (A);
A *p = (A *) malloc (2 * sizeof (A));
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != s - __builtin_offsetof (A, c))
- abort ();
+ FAIL ();
free (p);
}
@@ -242,48 +238,48 @@ test3 (void)
size_t s;
A *p = (A *) malloc (4);
if (__builtin_object_size (&p->a, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 0)
- abort ();
+ FAIL ();
free (p);
s = __builtin_offsetof (A, c) + 4;
p = (A *) malloc (s);
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 4)
- abort ();
+ FAIL ();
free (p);
}
@@ -297,17 +293,17 @@ __attribute__ ((noinline))
test4 (struct B *q, int i)
{
if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
}
struct C
@@ -321,13 +317,13 @@ __attribute__ ((noinline))
test5 (struct C *c)
{
if (__builtin_object_size (&c->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 3) != 1)
- abort ();
+ FAIL ();
}
struct D
@@ -345,13 +341,13 @@ __attribute__ ((noinline))
test6 (struct D *d)
{
if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
}
struct E
@@ -369,21 +365,21 @@ __attribute__ ((noinline))
test7 (struct E *e)
{
if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
- abort ();
+ FAIL ();
}
union F
@@ -401,13 +397,13 @@ __attribute__ ((noinline))
test8 (union F *f)
{
if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 3) != 0)
- abort ();
+ FAIL ();
}
int
@@ -434,5 +430,5 @@ main (void)
union F f, *fp = &f;
__asm ("" : "+r" (fp));
test8 (fp);
- exit (0);
+ DONE ();
}
@@ -1,6 +1,8 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
+#include "builtin-object-size-common.h"
+
typedef __SIZE_TYPE__ size_t;
#define abort __builtin_abort
@@ -604,13 +606,6 @@ test_pr105736 (struct TV4 *a)
return &a->v[0];
}
-unsigned nfails = 0;
-
-#define FAIL() ({ \
- __builtin_printf ("Failure at line: %d\n", __LINE__); \
- nfails++; \
-})
-
int
main (int argc, char **argv)
{
@@ -790,8 +785,5 @@ main (int argc, char **argv)
if (test_strndup_min (str, 4) != 1)
FAIL ();
- if (nfails > 0)
- __builtin_abort ();
-
- return 0;
+ DONE ();
}
@@ -2,18 +2,7 @@
/* { dg-options "-O2 -Wno-stringop-overread" } */
/* { dg-require-effective-target alloca } */
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
struct A
{
@@ -39,22 +28,22 @@ test1 (void *q, int x)
r = &a.c[1];
if (__builtin_object_size (p, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a.c[9], 0)
!= sizeof (a) - __builtin_offsetof (struct A, c) - 9)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 0) != (size_t) -1)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0)
!= (x < 0
? sizeof (a) - __builtin_offsetof (struct A, a) - 9
: sizeof (a) - __builtin_offsetof (struct A, c) - 1))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 9)
- abort ();
+ FAIL ();
#endif
if (x < 6)
r = &w[2].a[1];
@@ -62,23 +51,23 @@ test1 (void *q, int x)
r = &a.a[6];
if (__builtin_object_size (&y, 0)
!= sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (w, 0)
!= sizeof (w))
- abort ();
+ FAIL ();
if (__builtin_object_size (&y.b, 0)
!= sizeof (a) - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0)
!= (x < 6
? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
: sizeof (a) - __builtin_offsetof (struct A, a) - 6))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0)
!= 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -86,14 +75,14 @@ test1 (void *q, int x)
r = calloc (2, 16);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 16))
- abort ();
+ FAIL ();
#else
/* We may duplicate this test onto the two exit paths. On one path
the size will be 32, the other it will be 30. If we don't duplicate
this test, then the size will be 32. */
if (__builtin_object_size (r, 0) != 2 * 16
&& __builtin_object_size (r, 0) != 30)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -101,10 +90,10 @@ test1 (void *q, int x)
r = calloc (2, 14);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0) != (x < 20 ? 30 : 2 * 14))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0) != 30)
- abort ();
+ FAIL ();
#endif
if (x < 30)
r = malloc (sizeof (a));
@@ -112,102 +101,102 @@ test1 (void *q, int x)
r = &a.a[3];
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0) != sizeof (a))
- abort ();
+ FAIL ();
#endif
r = memcpy (r, "a", 2);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0) != sizeof (a))
- abort ();
+ FAIL ();
#endif
r = memcpy (r + 2, "b", 2) + 2;
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0)
!= (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0) != sizeof (a) - 4)
- abort ();
+ FAIL ();
#endif
r = &a.a[4];
r = memset (r, 'a', 2);
if (__builtin_object_size (r, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 4)
- abort ();
+ FAIL ();
r = memset (r + 2, 'b', 2) + 2;
if (__builtin_object_size (r, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 8)
- abort ();
+ FAIL ();
r = &a.a[1];
r = strcpy (r, "ab");
if (__builtin_object_size (r, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 1)
- abort ();
+ FAIL ();
r = strcpy (r + 2, "cd") + 2;
if (__builtin_object_size (r, 0)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta + 10, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&exta[5], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (extb, 0) != sizeof (extb))
- abort ();
+ FAIL ();
if (__builtin_object_size (extb + 10, 0) != sizeof (extb) - 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extb[5], 0) != sizeof (extb) - 5)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (var, 0) != x + 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 0) != x)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 0) != x + 5)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (var, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 0) != (size_t) -1)
- abort ();
+ FAIL ();
#endif
if (__builtin_object_size (zerol, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0], 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol[0].a, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].a[0], 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].b, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcdefg", 0) != sizeof ("abcdefg"))
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg", 0) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg", 0) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[0], 0) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[4], 0) != sizeof ("abcd\0efg") - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg" + 5, 0) != sizeof ("abcd\0efg") - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (L"abcdefg", 0) != sizeof (L"abcdefg"))
- abort ();
+ FAIL ();
r = (char *) L"abcd\0efg";
if (__builtin_object_size (r + 2, 0) != sizeof (L"abcd\0efg") - 2)
- abort ();
+ FAIL ();
}
size_t l1 = 1;
@@ -242,19 +231,19 @@ test2 (void)
for (i = 0; i < 4; ++i)
{
if (i == l1 - 1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 1;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 1;
else if (i == l1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
else if (i == l1 + 1)
- res = sizeof (buf3) - 5;
+ res = sizeof (buf3) - 5;
else if (i == l1 + 2)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
}
#else
res = 20;
#endif
if (__builtin_object_size (r, 0) != res)
- abort ();
+ FAIL ();
r = &buf3[20];
for (i = 0; i < 4; ++i)
{
@@ -273,38 +262,38 @@ test2 (void)
for (i = 0; i < 4; ++i)
{
if (i == l1 - 1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 7;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 7;
else if (i == l1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 7;
else if (i == l1 + 1)
- res = sizeof (buf3) - 5;
+ res = sizeof (buf3) - 5;
else if (i == l1 + 2)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
}
if (__builtin_object_size (r, 0) != res)
- abort ();
+ FAIL ();
#else
res = 15;
#endif
if (__builtin_object_size (r, 0) != res)
- abort ();
+ FAIL ();
r += 8;
#ifdef __builtin_object_size
res -= 8;
if (__builtin_object_size (r, 0) != res)
- abort ();
+ FAIL ();
if (res >= 6)
{
if (__builtin_object_size (r + 6, 0) != res - 6)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r + 6, 0) != 0)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 0) != 7)
- abort ();
+ FAIL ();
if (__builtin_object_size (r + 6, 0) != 1)
- abort ();
+ FAIL ();
#endif
r = &buf3[18];
for (i = 0; i < 4; ++i)
@@ -324,24 +313,24 @@ test2 (void)
for (i = 0; i < 4; ++i)
{
if (i == l1 - 1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
else if (i == l1)
- res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 9;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf2) - 9;
else if (i == l1 + 1)
- res = sizeof (buf3) - 5;
+ res = sizeof (buf3) - 5;
else if (i == l1 + 2)
- res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
+ res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
}
if (res >= 12)
{
if (__builtin_object_size (r + 12, 0) != res - 12)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r + 12, 0) != 0)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r + 12, 0) != 4)
- abort ();
+ FAIL ();
#endif
}
@@ -357,103 +346,103 @@ test3 (void)
double *dp;
if (__builtin_object_size (buf4, 0) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4, 0) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[0], 0) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[1], 0) != sizeof (buf4) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x, 0) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a, 0) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0], 0) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a, 0) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[0], 0) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[3], 0) != sizeof (x) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].b, 0)
!= sizeof (x) - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c, 0)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[0], 0)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[3], 0)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b, 0)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a, 0)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[0], 0)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[3], 0)
!= sizeof (x) - __builtin_offsetof (struct B, b) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.b, 0)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c, 0)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[0], 0)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[3], 0)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c, 0)
!= sizeof (x) - __builtin_offsetof (struct B, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[0], 0)
!= sizeof (x) - __builtin_offsetof (struct B, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[1], 0)
!= sizeof (x) - __builtin_offsetof (struct B, c) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.d, 0)
!= sizeof (x) - __builtin_offsetof (struct B, d))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.e, 0)
!= sizeof (x) - __builtin_offsetof (struct B, e))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.f, 0)
!= sizeof (x) - __builtin_offsetof (struct B, f))
- abort ();
+ FAIL ();
dp = &__real__ x.f;
if (__builtin_object_size (dp, 0)
!= sizeof (x) - __builtin_offsetof (struct B, f))
- abort ();
+ FAIL ();
dp = &__imag__ x.f;
if (__builtin_object_size (dp, 0)
!= sizeof (x) - __builtin_offsetof (struct B, f)
- sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &y;
if (__builtin_object_size (dp, 0) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (&z, 0) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__real__ z;
if (__builtin_object_size (dp, 0) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__imag__ z;
if (__builtin_object_size (dp, 0) != sizeof (z) / 2)
- abort ();
+ FAIL ();
}
struct S { unsigned int a; };
@@ -470,7 +459,7 @@ test4 (char *x, int y)
p = (struct A *) x;
x = (char *) &p[1];
if (__builtin_object_size (p, 0) != (size_t) -1)
- abort ();
+ FAIL ();
}
return x;
}
@@ -487,7 +476,7 @@ test5 (size_t x)
p = p + 4;
#ifdef __builtin_object_size
if (__builtin_object_size (p, 0) != sizeof (buf) - 8 - 4 * x)
- abort ();
+ FAIL ();
#else
/* My understanding of ISO C99 6.5.6 is that a conforming
program will not end up with p equal to &buf[0]
@@ -497,7 +486,7 @@ test5 (size_t x)
bytes from p until end of the object is 56, otherwise
it would be 64 (or conservative (size_t) -1 == unknown). */
if (__builtin_object_size (p, 0) != sizeof (buf) - 8)
- abort ();
+ FAIL ();
#endif
memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
}
@@ -514,10 +503,10 @@ test6 (size_t x)
p = p + 4;
#ifdef __builtin_object_size
if (__builtin_object_size (p, 0) != sizeof (t) - 8 - 4 * x)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 0) != sizeof (t) - 8)
- abort ();
+ FAIL ();
#endif
memset (p, ' ', sizeof (t) - 8 - 4 * 4);
}
@@ -531,13 +520,13 @@ test7 (void)
char *p = &buf[64], *q = &t.buf[64];
if (__builtin_object_size (p + 64, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 63, 0) != sizeof (t) - 64 - 63)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 64, 0) != sizeof (t) - 64 - 64)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 256, 0) != 0)
- abort ();
+ FAIL ();
}
void
@@ -548,17 +537,17 @@ test8 (void)
char *p = &t.buf2[-4];
char *q = &t.buf2[0];
if (__builtin_object_size (p, 0) != sizeof (t) - 10 + 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 0) != sizeof (t) - 10)
- abort ();
+ FAIL ();
/* GCC only handles additions, not subtractions. */
q = q - 8;
if (__builtin_object_size (q, 0) != (size_t) -1
&& __builtin_object_size (q, 0) != sizeof (t) - 10 + 8)
- abort ();
+ FAIL ();
p = &t.buf[-4];
if (__builtin_object_size (p, 0) != 0)
- abort ();
+ FAIL ();
}
void
@@ -575,10 +564,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (&p[-4], 0) != (cond ? 6 : 10))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (&p[-4], 0) != 10)
- abort ();
+ FAIL ();
#endif
for (unsigned i = cond; i > 0; i--)
@@ -586,10 +575,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 0) != ((cond ? 2 : 6) + cond))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 0) != 10)
- abort ();
+ FAIL ();
#endif
p = &y.c[8];
@@ -599,10 +588,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 0)
!= sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 0) != sizeof (y))
- abort ();
+ FAIL ();
#endif
}
@@ -620,10 +609,10 @@ test10 (void)
{
#ifdef __builtin_object_size
if (__builtin_object_size (p - 3, 0) != sizeof (buf) - i + 3)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p - 3, 0) != sizeof (buf))
- abort ();
+ FAIL ();
#endif
break;
}
@@ -641,19 +630,19 @@ test11 (void)
const char *ptr = "abcdefghijklmnopqrstuvwxyz";
char *res = strndup (ptr, 21);
if (__builtin_object_size (res, 0) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 32);
if (__builtin_object_size (res, 0) != 27)
- abort ();
+ FAIL ();
free (res);
res = strdup (ptr);
if (__builtin_object_size (res, 0) != 27)
- abort ();
+ FAIL ();
free (res);
@@ -662,19 +651,19 @@ test11 (void)
res = strndup (ptr2, 21);
if (__builtin_object_size (res, 0) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 32);
if (__builtin_object_size (res, 0) != 33)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 128);
if (__builtin_object_size (res, 0) != 64)
- abort ();
+ FAIL ();
free (res);
@@ -684,39 +673,39 @@ test11 (void)
#else
if (__builtin_object_size (res, 0) != (size_t) -1)
#endif
- abort ();
+ FAIL ();
free (res);
free (ptr2);
ptr = "abcd\0efghijklmnopqrstuvwxyz";
res = strdup (ptr);
if (__builtin_object_size (res, 0) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 24);
if (__builtin_object_size (res, 0) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 2);
if (__builtin_object_size (res, 0) != 3)
- abort ();
+ FAIL ();
free (res);
res = strdup (&ptr[4]);
if (__builtin_object_size (res, 0) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 4);
if (__builtin_object_size (res, 0) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 1);
if (__builtin_object_size (res, 0) != 1)
- abort ();
+ FAIL ();
free (res);
}
@@ -736,5 +725,5 @@ main (void)
test9 (1);
test10 ();
test11 ();
- exit (0);
+ DONE ();
}
@@ -1,7 +1,8 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-extern void abort (void);
+#include "builtin-object-size-common.h"
+
struct S {
int len;
char s[0];
@@ -10,10 +11,11 @@ int main()
{
char buf[sizeof (struct S) + 32];
if (__builtin_object_size (((struct S *)&buf[0])->s, 1) != 32)
- abort ();
+ FAIL ();
if (__builtin_object_size (((struct S *)&buf[1])->s, 1) != 31)
- abort ();
+ FAIL ();
if (__builtin_object_size (((struct S *)&buf[64])->s, 0) != 0)
- abort ();
- return 0;
+ FAIL ();
+
+ DONE ();
}
@@ -1,10 +1,7 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void free (void *);
-extern void abort (void);
+#include "builtin-object-size-common.h"
union A
{
@@ -56,13 +53,13 @@ struct H
#define T(X, S0, S1) \
if (__builtin_object_size (X, 0) != (S0)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 1) != (S1)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 2) != (S0)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 3) != (S1)) \
- abort ()
+ FAIL ()
#define TS(X, S0) T(&X, S0, sizeof (X))
#define TA(X, S0, S1) \
T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -347,5 +344,5 @@ main (void)
free (h2);
free (h1);
- return 0;
+ DONE ();
}
@@ -1,7 +1,7 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-extern void abort (void);
+#include "builtin-object-size-common.h"
int
main ()
@@ -9,12 +9,12 @@ main ()
struct A { char buf1[9]; char buf2[1]; } a;
if (__builtin_object_size (a.buf1 + (0 + 4), 1) != 5)
- abort ();
+ FAIL ();
char *p = a.buf1;
p += 1;
p += 3;
if (__builtin_object_size (p, 1) != 5)
- abort ();
+ FAIL ();
p = (char *) &a;
char *q = p + 1;
char *r = q + 3;
@@ -22,6 +22,7 @@ main ()
if (r != (char *) &a + 4)
t = (char *) &a + 1;
if (__builtin_object_size (t, 1) != 6)
- abort ();
- return 0;
+ FAIL ();
+
+ DONE ();
}
@@ -2,18 +2,7 @@
/* { dg-options "-O2 -Wno-stringop-overread" } */
/* { dg-require-effective-target alloca } */
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
struct A
{
@@ -40,39 +29,39 @@ test1 (void *q, int x)
else
r = &a.c[1];
if (__builtin_object_size (p, 1) != sizeof (a.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a.c[9], 1)
!= sizeof (a.c) - 9)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 1) != (size_t) -1)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (x < 0
? __builtin_object_size (r, 1) != sizeof (a.a) - 9
: __builtin_object_size (r, 1) != sizeof (a.c) - 1)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (a.c) - 1)
- abort ();
+ FAIL ();
#endif
if (x < 6)
r = &w[2].a[1];
else
r = &a.a[6];
if (__builtin_object_size (&y, 1) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (w, 1) != sizeof (w))
- abort ();
+ FAIL ();
if (__builtin_object_size (&y.b, 1) != sizeof (a.b))
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (x < 6
? __builtin_object_size (r, 1) != sizeof (a.a) - 1
: __builtin_object_size (r, 1) != sizeof (a.a) - 6)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -80,14 +69,14 @@ test1 (void *q, int x)
r = calloc (2, 16);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 16))
- abort ();
+ FAIL ();
#else
/* We may duplicate this test onto the two exit paths. On one path
the size will be 32, the other it will be 30. If we don't duplicate
this test, then the size will be 32. */
if (__builtin_object_size (r, 1) != 2 * 16
&& __builtin_object_size (r, 1) != 30)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -95,10 +84,10 @@ test1 (void *q, int x)
r = calloc (2, 14);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 1) != (x < 20 ? 30 : 2 * 14))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != 30)
- abort ();
+ FAIL ();
#endif
if (x < 30)
r = malloc (sizeof (a));
@@ -106,132 +95,132 @@ test1 (void *q, int x)
r = &a.a[3];
#ifdef __builtin_object_size
if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (a))
- abort ();
+ FAIL ();
#endif
r = memcpy (r, "a", 2);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 1) != (x < 30 ? sizeof (a) : sizeof (a) - 3))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (a))
- abort ();
+ FAIL ();
#endif
r = memcpy (r + 2, "b", 2) + 2;
#ifdef __builtin_object_size
if (__builtin_object_size (r, 0)
!= (x < 30 ? sizeof (a) - 4 : sizeof (a) - 7))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (a) - 4)
- abort ();
+ FAIL ();
#endif
r = &a.a[4];
r = memset (r, 'a', 2);
if (__builtin_object_size (r, 1) != sizeof (a.a) - 4)
- abort ();
+ FAIL ();
r = memset (r + 2, 'b', 2) + 2;
if (__builtin_object_size (r, 1) != sizeof (a.a) - 8)
- abort ();
+ FAIL ();
r = &a.a[1];
r = strcpy (r, "ab");
if (__builtin_object_size (r, 1) != sizeof (a.a) - 1)
- abort ();
+ FAIL ();
r = strcpy (r + 2, "cd") + 2;
if (__builtin_object_size (r, 1) != sizeof (a.a) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta + 10, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&exta[5], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (extb, 1) != sizeof (extb))
- abort ();
+ FAIL ();
if (__builtin_object_size (extb + 10, 1) != sizeof (extb) - 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extb[5], 1) != sizeof (extb) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (extc, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (extc + 10, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc[5], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc->a, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&(extc + 10)->b, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc[5].c[3], 1) != (size_t) -1)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (var, 1) != x + 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 1) != x)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 1) != x + 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara, 1) != (x + 10) * sizeof (struct A))
- abort ();
+ FAIL ();
if (__builtin_object_size (vara + 10, 1) != x * sizeof (struct A))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5], 1) != (x + 5) * sizeof (struct A))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (var, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara + 10, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5], 1) != (size_t) -1)
- abort ();
+ FAIL ();
#endif
if (__builtin_object_size (&vara[0].a, 1) != sizeof (vara[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[10].a[0], 1) != sizeof (vara[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5].a[4], 1) != sizeof (vara[0].a) - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5].b, 1) != sizeof (vara[0].b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[7].c[7], 1) != sizeof (vara[0].c) - 7)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0], 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol[0].a, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].a[0], 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].b, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcdefg", 1) != sizeof ("abcdefg"))
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg", 1) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg", 1) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[0], 1) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[4], 1) != sizeof ("abcd\0efg") - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg" + 5, 1) != sizeof ("abcd\0efg") - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (L"abcdefg", 1) != sizeof (L"abcdefg"))
- abort ();
+ FAIL ();
r = (char *) L"abcd\0efg";
if (__builtin_object_size (r + 2, 1) != sizeof (L"abcd\0efg") - 2)
- abort ();
+ FAIL ();
}
size_t l1 = 1;
@@ -277,10 +266,10 @@ test2 (void)
dyn_res = sizeof (a.buf1) - 9;
}
if (__builtin_object_size (r, 1) != dyn_res)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (buf3))
- abort ();
+ FAIL ();
#endif
r = &buf3[20];
for (i = 0; i < 4; ++i)
@@ -300,19 +289,19 @@ test2 (void)
for (i = 0; i < 4; ++i)
{
if (i == l1 - 1)
- dyn_res = sizeof (a.buf1) - 7;
+ dyn_res = sizeof (a.buf1) - 7;
else if (i == l1)
- dyn_res = sizeof (a.buf2) - 7;
+ dyn_res = sizeof (a.buf2) - 7;
else if (i == l1 + 1)
- dyn_res = sizeof (buf3) - 5;
+ dyn_res = sizeof (buf3) - 5;
else if (i == l1 + 2)
- dyn_res = sizeof (a.buf1) - 9;
+ dyn_res = sizeof (a.buf1) - 9;
}
if (__builtin_object_size (r, 1) != dyn_res)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (buf3) - 5)
- abort ();
+ FAIL ();
#endif
r += 8;
#ifdef __builtin_object_size
@@ -320,23 +309,23 @@ test2 (void)
{
dyn_res -= 8;
if (__builtin_object_size (r, 1) != dyn_res)
- abort ();
+ FAIL ();
if (dyn_res >= 6)
{
if (__builtin_object_size (r + 6, 1) != dyn_res - 6)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r + 6, 1) != 0)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r, 1) != 0)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 1) != sizeof (buf3) - 13)
- abort ();
+ FAIL ();
if (__builtin_object_size (r + 6, 1) != sizeof (buf3) - 19)
- abort ();
+ FAIL ();
#endif
}
@@ -352,78 +341,78 @@ test3 (void)
double *dp;
if (__builtin_object_size (buf4, 1) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4, 1) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[0], 1) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[1], 1) != sizeof (buf4) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x, 1) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a, 1) != sizeof (x.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0], 1) != sizeof (x.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a, 1) != sizeof (x.a[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[0], 1) != sizeof (x.a[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[3], 1) != sizeof (x.a[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].b, 1) != sizeof (x.a[0].b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c, 1) != sizeof (x.a[1].c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[0], 1) != sizeof (x.a[1].c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[3], 1) != sizeof (x.a[1].c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b, 1) != sizeof (x.b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a, 1) != sizeof (x.b.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[0], 1) != sizeof (x.b.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[3], 1) != sizeof (x.b.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.b, 1) != sizeof (x.b.b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c, 1) != sizeof (x.b.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[0], 1) != sizeof (x.b.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[3], 1) != sizeof (x.b.c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c, 1) != sizeof (x.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[0], 1) != sizeof (x.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[1], 1) != sizeof (x.c) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.d, 1) != sizeof (x.d))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.e, 1) != sizeof (x.e))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.f, 1) != sizeof (x.f))
- abort ();
+ FAIL ();
dp = &__real__ x.f;
if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &__imag__ x.f;
if (__builtin_object_size (dp, 1) != sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &y;
if (__builtin_object_size (dp, 1) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (&z, 1) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__real__ z;
if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
- abort ();
+ FAIL ();
dp = &__imag__ z;
if (__builtin_object_size (dp, 1) != sizeof (z) / 2)
- abort ();
+ FAIL ();
}
struct S { unsigned int a; };
@@ -440,7 +429,7 @@ test4 (char *x, int y)
p = (struct A *) x;
x = (char *) &p[1];
if (__builtin_object_size (p, 1) != (size_t) -1)
- abort ();
+ FAIL ();
}
return x;
}
@@ -457,10 +446,10 @@ test5 (size_t x)
p = p + 4;
#ifdef __builtin_object_size
if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8 - 4 * x)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 1) != sizeof (t.buf) - 8)
- abort ();
+ FAIL ();
#endif
memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
}
@@ -474,11 +463,11 @@ test6 (void)
char *p = &buf[64], *q = &t.buf[64];
if (__builtin_object_size (p + 64, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 0, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 64, 1) != 0)
- abort ();
+ FAIL ();
}
void
@@ -489,18 +478,18 @@ test7 (void)
char *p = &t.buf2[-4];
char *q = &t.buf2[0];
if (__builtin_object_size (p, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 1) != sizeof (t.buf2))
- abort ();
+ FAIL ();
q = &t.buf[10];
if (__builtin_object_size (q, 1) != 0)
- abort ();
+ FAIL ();
q = &t.buf[11];
if (__builtin_object_size (q, 1) != 0)
- abort ();
+ FAIL ();
p = &t.buf[-4];
if (__builtin_object_size (p, 1) != 0)
- abort ();
+ FAIL ();
}
void
@@ -517,10 +506,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (&p[-4], 1) != (cond ? 6 : 10))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (&p[-4], 1) != 10)
- abort ();
+ FAIL ();
#endif
for (unsigned i = cond; i > 0; i--)
@@ -528,10 +517,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 1) != ((cond ? 2 : 6) + cond))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 1) != 10)
- abort ();
+ FAIL ();
#endif
p = &y.c[8];
@@ -540,10 +529,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 1) != sizeof (y.c) - 8 + cond)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 1) != sizeof (y.c))
- abort ();
+ FAIL ();
#endif
}
@@ -555,19 +544,19 @@ test9 (void)
const char *ptr = "abcdefghijklmnopqrstuvwxyz";
char *res = strndup (ptr, 21);
if (__builtin_object_size (res, 1) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 32);
if (__builtin_object_size (res, 1) != 27)
- abort ();
+ FAIL ();
free (res);
res = strdup (ptr);
if (__builtin_object_size (res, 1) != 27)
- abort ();
+ FAIL ();
free (res);
@@ -576,19 +565,19 @@ test9 (void)
res = strndup (ptr2, 21);
if (__builtin_object_size (res, 1) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 32);
if (__builtin_object_size (res, 1) != 33)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 128);
if (__builtin_object_size (res, 1) != 64)
- abort ();
+ FAIL ();
free (res);
@@ -598,7 +587,7 @@ test9 (void)
#else
if (__builtin_object_size (res, 1) != (size_t) -1)
#endif
- abort ();
+ FAIL ();
free (res);
free (ptr2);
@@ -606,32 +595,32 @@ test9 (void)
ptr = "abcd\0efghijklmnopqrstuvwxyz";
res = strdup (ptr);
if (__builtin_object_size (res, 1) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 24);
if (__builtin_object_size (res, 1) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 2);
if (__builtin_object_size (res, 1) != 3)
- abort ();
+ FAIL ();
free (res);
res = strdup (&ptr[4]);
if (__builtin_object_size (res, 1) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 4);
if (__builtin_object_size (res, 1) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 1);
if (__builtin_object_size (res, 1) != 1)
- abort ();
+ FAIL ();
free (res);
}
@@ -649,5 +638,5 @@ main (void)
test7 ();
test8 (1);
test9 ();
- exit (0);
+ DONE ();
}
@@ -2,18 +2,7 @@
/* { dg-options "-O2 -Wno-stringop-overread" } */
/* { dg-require-effective-target alloca } */
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
struct A
{
@@ -39,22 +28,22 @@ test1 (void *q, int x)
r = &a.c[1];
if (__builtin_object_size (p, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a.c[9], 2)
!= sizeof (a) - __builtin_offsetof (struct A, c) - 9)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 2) != 0)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2)
!= (x < 0
? sizeof (a) - __builtin_offsetof (struct A, a) - 9
: sizeof (a) - __builtin_offsetof (struct A, c) - 1))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, c) - 1)
- abort ();
+ FAIL ();
#endif
if (x < 6)
r = &w[2].a[1];
@@ -62,23 +51,23 @@ test1 (void *q, int x)
r = &a.a[6];
if (__builtin_object_size (&y, 2)
!= sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (w, 2)
!= sizeof (w))
- abort ();
+ FAIL ();
if (__builtin_object_size (&y.b, 2)
!= sizeof (a) - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2)
!= (x < 6
? 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1
: sizeof (a) - __builtin_offsetof (struct A, a) - 6))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 6)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -86,10 +75,10 @@ test1 (void *q, int x)
r = calloc (2, 16);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 16))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2) != 30)
- abort ();
+ FAIL ();
#endif
if (x < 20)
r = malloc (30);
@@ -97,10 +86,10 @@ test1 (void *q, int x)
r = calloc (2, 14);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2) != (x < 20 ? 30 : 2 * 14))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2) != 2 * 14)
- abort ();
+ FAIL ();
#endif
if (x < 30)
r = malloc (sizeof (a));
@@ -108,106 +97,106 @@ test1 (void *q, int x)
r = &a.a[3];
#ifdef __builtin_object_size
size_t objsz = (x < 30 ? sizeof (a)
- : sizeof (a) - __builtin_offsetof (struct A, a) - 3);
+ : sizeof (a) - __builtin_offsetof (struct A, a) - 3);
if (__builtin_object_size (r, 2) != objsz)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 3)
- abort ();
+ FAIL ();
#endif
r = memcpy (r, "a", 2);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2) != objsz)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 3)
- abort ();
+ FAIL ();
#endif
r = memcpy (r + 2, "b", 2) + 2;
#ifdef __builtin_object_size
if (__builtin_object_size (r, 2) != objsz - 4)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 3 - 4)
- abort ();
+ FAIL ();
#endif
r = &a.a[4];
r = memset (r, 'a', 2);
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 4)
- abort ();
+ FAIL ();
r = memset (r + 2, 'b', 2) + 2;
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 8)
- abort ();
+ FAIL ();
r = &a.a[1];
r = strcpy (r, "ab");
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 1)
- abort ();
+ FAIL ();
r = strcpy (r + 2, "cd") + 2;
if (__builtin_object_size (r, 2)
!= sizeof (a) - __builtin_offsetof (struct A, a) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta + 10, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&exta[5], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (extb, 2) != sizeof (extb))
- abort ();
+ FAIL ();
if (__builtin_object_size (extb + 10, 2) != sizeof (extb) - 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extb[5], 2) != sizeof (extb) - 5)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (var, 2) != x + 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 2) != x)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 2) != x + 5)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (var, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 2) != 0)
- abort ();
+ FAIL ();
#endif
if (__builtin_object_size (zerol, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol[0].a, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].a[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcdefg", 2) != sizeof ("abcdefg"))
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg", 2) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg", 2) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[0], 2) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[4], 2) != sizeof ("abcd\0efg") - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg" + 5, 2) != sizeof ("abcd\0efg") - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (L"abcdefg", 2) != sizeof (L"abcdefg"))
- abort ();
+ FAIL ();
r = (char *) L"abcd\0efg";
if (__builtin_object_size (r + 2, 2) != sizeof (L"abcd\0efg") - 2)
- abort ();
+ FAIL ();
}
size_t l1 = 1;
@@ -253,10 +242,10 @@ test2 (void)
dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 9;
}
if (__builtin_object_size (r, 2) != dyn_res)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2) != 3)
- abort ();
+ FAIL ();
#endif
r = &buf3[20];
for (i = 0; i < 4; ++i)
@@ -271,7 +260,7 @@ test2 (void)
r = &a.buf1[9];
}
if (__builtin_object_size (r, 2) != 0)
- abort ();
+ FAIL ();
r = &buf3[2];
for (i = 0; i < 4; ++i)
{
@@ -299,28 +288,28 @@ test2 (void)
dyn_res = sizeof (a) - __builtin_offsetof (struct B, buf1) - 4;
}
if (__builtin_object_size (r, 2) != dyn_res)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2) != 15)
- abort ();
+ FAIL ();
#endif
r += 8;
#ifdef __builtin_object_size
dyn_res -= 8;
if (__builtin_object_size (r, 2) != dyn_res)
- abort ();
+ FAIL ();
if (dyn_res >= 6)
{
if (__builtin_object_size (r + 6, 2) != dyn_res - 6)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r + 6, 2) != 0)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 2) != 7)
- abort ();
+ FAIL ();
if (__builtin_object_size (r + 6, 2) != 1)
- abort ();
+ FAIL ();
#endif
r = &buf3[18];
for (i = 0; i < 4; ++i)
@@ -351,13 +340,13 @@ test2 (void)
if (dyn_res >= 12)
{
if (__builtin_object_size (r + 12, 2) != dyn_res - 12)
- abort ();
+ FAIL ();
}
else if (__builtin_object_size (r + 12, 2) != 0)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r + 12, 2) != 0)
- abort ();
+ FAIL ();
#endif
}
@@ -373,103 +362,103 @@ test3 (void)
double *dp;
if (__builtin_object_size (buf4, 2) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4, 2) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[0], 2) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[1], 2) != sizeof (buf4) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x, 2) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a, 2) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0], 2) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a, 2) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[0], 2) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[3], 2) != sizeof (x) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].b, 2)
!= sizeof (x) - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c, 2)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[0], 2)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[3], 2)
!= sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b, 2)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a, 2)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[0], 2)
!= sizeof (x) - __builtin_offsetof (struct B, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[3], 2)
!= sizeof (x) - __builtin_offsetof (struct B, b) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.b, 2)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c, 2)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[0], 2)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[3], 2)
!= sizeof (x) - __builtin_offsetof (struct B, b)
- __builtin_offsetof (struct A, c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c, 2)
!= sizeof (x) - __builtin_offsetof (struct B, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[0], 2)
!= sizeof (x) - __builtin_offsetof (struct B, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[1], 2)
!= sizeof (x) - __builtin_offsetof (struct B, c) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.d, 2)
!= sizeof (x) - __builtin_offsetof (struct B, d))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.e, 2)
!= sizeof (x) - __builtin_offsetof (struct B, e))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.f, 2)
!= sizeof (x) - __builtin_offsetof (struct B, f))
- abort ();
+ FAIL ();
dp = &__real__ x.f;
if (__builtin_object_size (dp, 2)
!= sizeof (x) - __builtin_offsetof (struct B, f))
- abort ();
+ FAIL ();
dp = &__imag__ x.f;
if (__builtin_object_size (dp, 2)
!= sizeof (x) - __builtin_offsetof (struct B, f)
- sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &y;
if (__builtin_object_size (dp, 2) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (&z, 2) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__real__ z;
if (__builtin_object_size (dp, 2) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__imag__ z;
if (__builtin_object_size (dp, 2) != sizeof (z) / 2)
- abort ();
+ FAIL ();
}
struct S { unsigned int a; };
@@ -486,7 +475,7 @@ test4 (char *x, int y)
p = (struct A *) x;
x = (char *) &p[1];
if (__builtin_object_size (p, 2) != 0)
- abort ();
+ FAIL ();
}
return x;
}
@@ -506,7 +495,7 @@ test5 (size_t x)
#else
if (__builtin_object_size (p, 2) != 0)
#endif
- abort ();
+ FAIL ();
memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
}
@@ -525,7 +514,7 @@ test6 (size_t x)
#else
if (__builtin_object_size (p, 2) != 0)
#endif
- abort ();
+ FAIL ();
memset (p, ' ', sizeof (t) - 8 - 4 * 4);
}
@@ -538,13 +527,13 @@ test7 (void)
char *p = &buf[64], *q = &t.buf[64];
if (__builtin_object_size (p + 64, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 63, 2) != sizeof (t) - 64 - 63)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 64, 2) != sizeof (t) - 64 - 64)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 256, 2) != 0)
- abort ();
+ FAIL ();
}
void
@@ -555,17 +544,17 @@ test8 (void)
char *p = &t.buf2[-4];
char *q = &t.buf2[0];
if (__builtin_object_size (p, 2) != sizeof (t) - 10 + 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 2) != sizeof (t) - 10)
- abort ();
+ FAIL ();
/* GCC only handles additions, not subtractions. */
q = q - 8;
if (__builtin_object_size (q, 2) != 0
&& __builtin_object_size (q, 2) != sizeof (t) - 10 + 8)
- abort ();
+ FAIL ();
p = &t.buf[-4];
if (__builtin_object_size (p, 2) != 0)
- abort ();
+ FAIL ();
}
void
@@ -582,10 +571,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (&p[-4], 2) != (cond ? 6 : 10))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (&p[-4], 2) != 0)
- abort ();
+ FAIL ();
#endif
for (unsigned i = cond; i > 0; i--)
@@ -593,10 +582,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 2) != ((cond ? 2 : 6) + cond))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 2) != 0)
- abort ();
+ FAIL ();
#endif
p = &y.c[8];
@@ -606,10 +595,10 @@ test9 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 2)
!= sizeof (y) - __builtin_offsetof (struct A, c) - 8 + cond)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 2) != 0)
- abort ();
+ FAIL ();
#endif
}
@@ -627,10 +616,10 @@ test10 (void)
{
#ifdef __builtin_object_size
if (__builtin_object_size (p - 3, 2) != sizeof (buf) - i + 3)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p - 3, 2) != 0)
- abort ();
+ FAIL ();
#endif
break;
}
@@ -647,19 +636,19 @@ test11 (void)
const char *ptr = "abcdefghijklmnopqrstuvwxyz";
char *res = strndup (ptr, 21);
if (__builtin_object_size (res, 2) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 32);
if (__builtin_object_size (res, 2) != 27)
- abort ();
+ FAIL ();
free (res);
res = strdup (ptr);
if (__builtin_object_size (res, 2) != 27)
- abort ();
+ FAIL ();
free (res);
@@ -668,19 +657,19 @@ test11 (void)
res = strndup (ptr2, 21);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 32);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 128);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
@@ -691,7 +680,7 @@ test11 (void)
#else
if (__builtin_object_size (res, 2) != 1)
#endif
- abort ();
+ FAIL ();
free (res);
free (ptr2);
@@ -699,32 +688,32 @@ test11 (void)
ptr = "abcd\0efghijklmnopqrstuvwxyz";
res = strdup (ptr);
if (__builtin_object_size (res, 2) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 24);
if (__builtin_object_size (res, 2) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 2);
if (__builtin_object_size (res, 2) != 3)
- abort ();
+ FAIL ();
free (res);
res = strdup (&ptr[4]);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 4);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 1);
if (__builtin_object_size (res, 2) != 1)
- abort ();
+ FAIL ();
free (res);
}
@@ -744,5 +733,5 @@ main (void)
test9 (1);
test10 ();
test11 ();
- exit (0);
+ DONE ();
}
@@ -2,18 +2,7 @@
/* { dg-options "-O2 -Wno-stringop-overread" } */
/* { dg-require-effective-target alloca } */
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void *calloc (size_t, size_t);
-extern void free (void *);
-extern void *alloca (size_t);
-extern void *memcpy (void *, const void *, size_t);
-extern void *memset (void *, int, size_t);
-extern char *strcpy (char *, const char *);
-extern char *strdup (const char *);
-extern char *strndup (const char *, size_t);
+#include "builtin-object-size-common.h"
struct A
{
@@ -40,36 +29,36 @@ test1 (void *q, int x)
else
r = &a.c[1];
if (__builtin_object_size (p, 3) != sizeof (a.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a.c[9], 3)
!= sizeof (a.c) - 9)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 3) != 0)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 3)
!= (x < 0 ? sizeof (a.a) - 9 : sizeof (a.c) - 1))
#else
if (__builtin_object_size (r, 3) != sizeof (a.a) - 9)
#endif
- abort ();
+ FAIL ();
if (x < 6)
r = &w[2].a[1];
else
r = &a.a[6];
if (__builtin_object_size (&y, 3) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (w, 3) != sizeof (w))
- abort ();
+ FAIL ();
if (__builtin_object_size (&y.b, 3) != sizeof (a.b))
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (r, 3)
!= (x < 6 ? sizeof (w[2].a) - 1 : sizeof (a.a) - 6))
#else
if (__builtin_object_size (r, 3) != sizeof (a.a) - 6)
#endif
- abort ();
+ FAIL ();
if (x < 20)
r = malloc (30);
else
@@ -79,7 +68,7 @@ test1 (void *q, int x)
#else
if (__builtin_object_size (r, 3) != 30)
#endif
- abort ();
+ FAIL ();
if (x < 20)
r = malloc (30);
else
@@ -89,7 +78,7 @@ test1 (void *q, int x)
#else
if (__builtin_object_size (r, 3) != 2 * 14)
#endif
- abort ();
+ FAIL ();
if (x < 30)
r = malloc (sizeof (a));
else
@@ -100,125 +89,125 @@ test1 (void *q, int x)
#else
if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
#endif
- abort ();
+ FAIL ();
r = memcpy (r, "a", 2);
#ifdef __builtin_object_size
if (__builtin_object_size (r, 3) != objsz)
#else
if (__builtin_object_size (r, 3) != sizeof (a.a) - 3)
#endif
- abort ();
+ FAIL ();
r = memcpy (r + 2, "b", 2) + 2;
#ifdef __builtin_object_size
if (__builtin_object_size (r, 3) != objsz - 4)
#else
if (__builtin_object_size (r, 3) != sizeof (a.a) - 3 - 4)
#endif
- abort ();
+ FAIL ();
r = &a.a[4];
r = memset (r, 'a', 2);
if (__builtin_object_size (r, 3) != sizeof (a.a) - 4)
- abort ();
+ FAIL ();
r = memset (r + 2, 'b', 2) + 2;
if (__builtin_object_size (r, 3) != sizeof (a.a) - 8)
- abort ();
+ FAIL ();
r = &a.a[1];
r = strcpy (r, "ab");
if (__builtin_object_size (r, 3) != sizeof (a.a) - 1)
- abort ();
+ FAIL ();
r = strcpy (r + 2, "cd") + 2;
if (__builtin_object_size (r, 3) != sizeof (a.a) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (exta + 10, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&exta[5], 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (extb, 3) != sizeof (extb))
- abort ();
+ FAIL ();
if (__builtin_object_size (extb + 10, 3) != sizeof (extb) - 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extb[5], 3) != sizeof (extb) - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (extc, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (extc + 10, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc[5], 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc->a, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&(extc + 10)->b, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&extc[5].c[3], 3) != 0)
- abort ();
+ FAIL ();
#ifdef __builtin_object_size
if (__builtin_object_size (var, 3) != x + 10)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 3) != x)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 3) != x + 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara, 3) != (x + 10) * sizeof (struct A))
- abort ();
+ FAIL ();
if (__builtin_object_size (vara + 10, 3) != x * sizeof (struct A))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5], 3) != (x + 5) * sizeof (struct A))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (var, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (var + 10, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&var[5], 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (vara + 10, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5], 3) != 0)
- abort ();
+ FAIL ();
#endif
if (__builtin_object_size (&vara[0].a, 3) != sizeof (vara[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[10].a[0], 3) != sizeof (vara[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5].a[4], 3) != sizeof (vara[0].a) - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[5].b, 3) != sizeof (vara[0].b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&vara[7].c[7], 3) != sizeof (vara[0].c) - 7)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0], 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (zerol[0].a, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].a[0], 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&zerol[0].b, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcdefg", 3) != sizeof ("abcdefg"))
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg", 3) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg", 3) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[0], 3) != sizeof ("abcd\0efg"))
- abort ();
+ FAIL ();
if (__builtin_object_size (&"abcd\0efg"[4], 3) != sizeof ("abcd\0efg") - 4)
- abort ();
+ FAIL ();
if (__builtin_object_size ("abcd\0efg" + 5, 3) != sizeof ("abcd\0efg") - 5)
- abort ();
+ FAIL ();
if (__builtin_object_size (L"abcdefg", 3) != sizeof (L"abcdefg"))
- abort ();
+ FAIL ();
r = (char *) L"abcd\0efg";
if (__builtin_object_size (r + 2, 3) != sizeof (L"abcd\0efg") - 2)
- abort ();
+ FAIL ();
/* Prevent DSE from removing calls that prevent bad combining of
addresses and offsets. */
asm volatile ("" : : "g" (&a));
@@ -253,7 +242,7 @@ test2 (void)
r = &a.buf1[9];
}
if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 9)
- abort ();
+ FAIL ();
r = &buf3[20];
for (i = 0; i < 4; ++i)
{
@@ -267,7 +256,7 @@ test2 (void)
r = &a.buf1[9];
}
if (__builtin_object_size (r, 3) != 0)
- abort ();
+ FAIL ();
r = &buf3[1];
for (i = 0; i < 4; ++i)
{
@@ -286,31 +275,31 @@ test2 (void)
for (i = 0; i < 4; ++i)
{
if (i == l1 - 1)
- dyn_res = sizeof (a.buf1) - 6;
+ dyn_res = sizeof (a.buf1) - 6;
else if (i == l1)
- dyn_res = sizeof (a.buf2) - 4;
+ dyn_res = sizeof (a.buf2) - 4;
else if (i == l1 + 1)
- dyn_res = sizeof (buf3) - 5;
+ dyn_res = sizeof (buf3) - 5;
else if (i == l1 + 2)
- dyn_res = sizeof (a.buf1) - 2;
+ dyn_res = sizeof (a.buf1) - 2;
}
if (__builtin_object_size (r, 3) != dyn_res)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6)
- abort ();
+ FAIL ();
#endif
r += 2;
#ifdef __builtin_object_size
if (__builtin_object_size (r, 3) != dyn_res - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (r + 1, 3) != dyn_res - 3)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (r, 3) != sizeof (a.buf1) - 6 - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (r + 1, 3) != sizeof (a.buf1) - 6 - 3)
- abort ();
+ FAIL ();
#endif
}
@@ -326,78 +315,78 @@ test3 (void)
double *dp;
if (__builtin_object_size (buf4, 3) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4, 3) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[0], 3) != sizeof (buf4))
- abort ();
+ FAIL ();
if (__builtin_object_size (&buf4[1], 3) != sizeof (buf4) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x, 3) != sizeof (x))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a, 3) != sizeof (x.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0], 3) != sizeof (x.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a, 3) != sizeof (x.a[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[0], 3) != sizeof (x.a[0].a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].a[3], 3) != sizeof (x.a[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[0].b, 3) != sizeof (x.a[0].b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c, 3) != sizeof (x.a[1].c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[0], 3) != sizeof (x.a[1].c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.a[1].c[3], 3) != sizeof (x.a[1].c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b, 3) != sizeof (x.b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a, 3) != sizeof (x.b.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[0], 3) != sizeof (x.b.a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.a[3], 3) != sizeof (x.b.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.b, 3) != sizeof (x.b.b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c, 3) != sizeof (x.b.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[0], 3) != sizeof (x.b.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.b.c[3], 3) != sizeof (x.b.c) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c, 3) != sizeof (x.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[0], 3) != sizeof (x.c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.c[1], 3) != sizeof (x.c) - 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.d, 3) != sizeof (x.d))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.e, 3) != sizeof (x.e))
- abort ();
+ FAIL ();
if (__builtin_object_size (&x.f, 3) != sizeof (x.f))
- abort ();
+ FAIL ();
dp = &__real__ x.f;
if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &__imag__ x.f;
if (__builtin_object_size (dp, 3) != sizeof (x.f) / 2)
- abort ();
+ FAIL ();
dp = &y;
if (__builtin_object_size (dp, 3) != sizeof (y))
- abort ();
+ FAIL ();
if (__builtin_object_size (&z, 3) != sizeof (z))
- abort ();
+ FAIL ();
dp = &__real__ z;
if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
- abort ();
+ FAIL ();
dp = &__imag__ z;
if (__builtin_object_size (dp, 3) != sizeof (z) / 2)
- abort ();
+ FAIL ();
}
struct S { unsigned int a; };
@@ -414,7 +403,7 @@ test4 (char *x, int y)
p = (struct A *) x;
x = (char *) &p[1];
if (__builtin_object_size (p, 3) != 0)
- abort ();
+ FAIL ();
}
return x;
}
@@ -434,7 +423,7 @@ test5 (size_t x)
#else
if (__builtin_object_size (p, 3) != 0)
#endif
- abort ();
+ FAIL ();
memset (p, ' ', sizeof (t.buf) - 8 - 4 * 4);
}
@@ -447,11 +436,11 @@ test6 (void)
char *p = &buf[64], *q = &t.buf[64];
if (__builtin_object_size (p + 64, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 0, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q + 64, 3) != 0)
- abort ();
+ FAIL ();
}
void
@@ -462,18 +451,18 @@ test7 (void)
char *p = &t.buf2[-4];
char *q = &t.buf2[0];
if (__builtin_object_size (p, 3) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (q, 3) != sizeof (t.buf2))
- abort ();
+ FAIL ();
q = &t.buf[10];
if (__builtin_object_size (q, 3) != 0)
- abort ();
+ FAIL ();
q = &t.buf[11];
if (__builtin_object_size (q, 3) != 0)
- abort ();
+ FAIL ();
p = &t.buf[-4];
if (__builtin_object_size (p, 3) != 0)
- abort ();
+ FAIL ();
}
void
@@ -490,10 +479,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (&p[-4], 3) != (cond ? 6 : 10))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (&p[-4], 3) != 0)
- abort ();
+ FAIL ();
#endif
for (unsigned i = cond; i > 0; i--)
@@ -501,10 +490,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 3) != ((cond ? 2 : 6) + cond))
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 3) != 0)
- abort ();
+ FAIL ();
#endif
p = &y.c[8];
@@ -513,10 +502,10 @@ test8 (unsigned cond)
#ifdef __builtin_object_size
if (__builtin_object_size (p, 3) != sizeof (y.c) - 8 + cond)
- abort ();
+ FAIL ();
#else
if (__builtin_object_size (p, 3) != 0)
- abort ();
+ FAIL ();
#endif
}
@@ -528,19 +517,19 @@ test9 (void)
const char *ptr = "abcdefghijklmnopqrstuvwxyz";
char *res = strndup (ptr, 21);
if (__builtin_object_size (res, 3) != 22)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 32);
if (__builtin_object_size (res, 3) != 27)
- abort ();
+ FAIL ();
free (res);
res = strdup (ptr);
if (__builtin_object_size (res, 3) != 27)
- abort ();
+ FAIL ();
free (res);
@@ -549,19 +538,19 @@ test9 (void)
res = strndup (ptr2, 21);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 32);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr2, 128);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
@@ -571,7 +560,7 @@ test9 (void)
#else
if (__builtin_object_size (res, 3) != 1)
#endif
- abort ();
+ FAIL ();
free (res);
free (ptr2);
@@ -579,32 +568,32 @@ test9 (void)
ptr = "abcd\0efghijklmnopqrstuvwxyz";
res = strdup (ptr);
if (__builtin_object_size (res, 3) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 24);
if (__builtin_object_size (res, 3) != 5)
- abort ();
+ FAIL ();
free (res);
res = strndup (ptr, 2);
if (__builtin_object_size (res, 3) != 3)
- abort ();
+ FAIL ();
free (res);
res = strdup (&ptr[4]);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 4);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
res = strndup (&ptr[4], 1);
if (__builtin_object_size (res, 3) != 1)
- abort ();
+ FAIL ();
free (res);
}
@@ -622,5 +611,5 @@ main (void)
test7 ();
test8 (1);
test9 ();
- exit (0);
+ DONE ();
}
@@ -1,11 +1,7 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-typedef __SIZE_TYPE__ size_t;
-extern void abort (void);
-extern void exit (int);
-extern void *malloc (size_t);
-extern void free (void *);
+#include "builtin-object-size-common.h"
struct A
{
@@ -20,105 +16,105 @@ test1 (struct A *p)
{
char *c;
if (__builtin_object_size (&p->a, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != 0)
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != 0)
- abort ();
+ FAIL ();
}
void
@@ -129,105 +125,105 @@ test2 (void)
size_t s = 2 * sizeof (struct A);
struct A *p = malloc (2 * sizeof (struct A));
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 0) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 0) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 0) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 1) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 2) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 2) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 2) != s - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 2) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 2) != s)
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 2) != s - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 2) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 3) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 3) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
c = p->a;
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[0];
if (__builtin_object_size (c, 3) != sizeof (p->a))
- abort ();
+ FAIL ();
c = &p->a[3];
if (__builtin_object_size (c, 3) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
c = (char *) &p->b;
if (__builtin_object_size (c, 3) != sizeof (p->b))
- abort ();
+ FAIL ();
c = (char *) &p->c;
if (__builtin_object_size (c, 3) != s - __builtin_offsetof (struct A, c))
- abort ();
+ FAIL ();
free (p);
}
@@ -239,48 +235,48 @@ test3 (void)
size_t s;
struct A *p = malloc (4);
if (__builtin_object_size (&p->a, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 0)
- abort ();
+ FAIL ();
free (p);
s = __builtin_offsetof (struct A, c) + 4;
p = malloc (s);
if (__builtin_object_size (&p->a, 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 0) != s)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 0) != s - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 0) != s - __builtin_offsetof (struct A, b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 0) != 4)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a, 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[0], 1) != sizeof (p->a))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->a[3], 1) != sizeof (p->a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->b, 1) != sizeof (p->b))
- abort ();
+ FAIL ();
if (__builtin_object_size (&p->c, 1) != 4)
- abort ();
+ FAIL ();
free (p);
}
@@ -294,17 +290,17 @@ __attribute__ ((noinline))
test4 (struct B *q, int i)
{
if (__builtin_object_size (&q->a[2].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[2].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[3].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].a[2], 1) != sizeof (q->a[0].a) - 2)
- abort ();
+ FAIL ();
if (__builtin_object_size (&q->a[i].c[2], 1) != sizeof (q->a[0].c) - 2)
- abort ();
+ FAIL ();
}
struct C
@@ -318,13 +314,13 @@ __attribute__ ((noinline))
test5 (struct C *c)
{
if (__builtin_object_size (&c->b, 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 1) != 1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&c->b, 3) != 1)
- abort ();
+ FAIL ();
}
struct D
@@ -342,13 +338,13 @@ __attribute__ ((noinline))
test6 (struct D *d)
{
if (__builtin_object_size (&d->j.a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 1) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&d->j.a[3], 3) != sizeof (d->j.a) - 3)
- abort ();
+ FAIL ();
}
struct E
@@ -366,21 +362,21 @@ __attribute__ ((noinline))
test7 (struct E *e)
{
if (__builtin_object_size (&e->j[0].a[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 1) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&e->j[0].a[3], 3) != sizeof (e->j[0].a) - 3)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size ((char *) &e->j[0], 3) != 0)
- abort ();
+ FAIL ();
}
union F
@@ -398,13 +394,13 @@ __attribute__ ((noinline))
test8 (union F *f)
{
if (__builtin_object_size (&f->d.c[3], 0) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 1) != (size_t) -1)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 2) != 0)
- abort ();
+ FAIL ();
if (__builtin_object_size (&f->d.c[3], 3) != 0)
- abort ();
+ FAIL ();
}
int
@@ -431,5 +427,5 @@ main (void)
union F f, *fp = &f;
__asm ("" : "+r" (fp));
test8 (fp);
- exit (0);
+ DONE ();
}
@@ -1,9 +1,7 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void abort (void);
+#include "builtin-object-size-common.h"
struct A
{
@@ -20,52 +18,52 @@ main (void)
struct A *a = malloc (s);
struct A *b = malloc (o + 212);
if (__builtin_object_size (a->buf, 0) != s - o)
- abort ();
+ FAIL ();
if (__builtin_object_size (a->buf, 1) != sizeof (a->buf))
- abort ();
+ FAIL ();
if (__builtin_object_size (a->buf, 2) != s - o)
- abort ();
+ FAIL ();
if (__builtin_object_size (a->buf, 3) != sizeof (a->buf))
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[0], 0) != s - o)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[0], 1) != sizeof (a->buf))
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[0], 2) != s - o)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[0], 3) != sizeof (a->buf))
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[6], 0) != s - o - 6)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[6], 1) != sizeof (a->buf) - 6)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[6], 2) != s - o - 6)
- abort ();
+ FAIL ();
if (__builtin_object_size (&a->buf[6], 3) != sizeof (a->buf) - 6)
- abort ();
+ FAIL ();
if (__builtin_object_size (b->buf, 0) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (b->buf, 1) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (b->buf, 2) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (b->buf, 3) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[0], 0) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[0], 1) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[0], 2) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[0], 3) != 212)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[28], 0) != 212 - 28)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[28], 1) != 212 - 28)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[28], 2) != 212 - 28)
- abort ();
+ FAIL ();
if (__builtin_object_size (&b->buf[28], 3) != 212 - 28)
- abort ();
- return 0;
+ FAIL ();
+ DONE ();
}
@@ -1,10 +1,7 @@
/* { dg-do run } */
/* { dg-options "-O2" } */
-typedef __SIZE_TYPE__ size_t;
-extern void *malloc (size_t);
-extern void free (void *);
-extern void abort (void);
+#include "builtin-object-size-common.h"
union A
{
@@ -56,13 +53,13 @@ struct H
#define T(X, S0, S1) \
if (__builtin_object_size (X, 0) != (S0)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 1) != (S1)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 2) != (S0)) \
- abort (); \
+ FAIL (); \
if (__builtin_object_size (X, 3) != (S1)) \
- abort ()
+ FAIL ()
#define TS(X, S0) T(&X, S0, sizeof (X))
#define TA(X, S0, S1) \
T(X, S0, S1); T(&X[0], S0, S1); T(&X[1], (S0) - 1, (S1) - 1)
@@ -196,5 +193,5 @@ main (void)
free (h2);
free (h1);
- return 0;
+ DONE ();
}
new file mode 100644
@@ -0,0 +1,32 @@
+typedef __SIZE_TYPE__ size_t;
+#ifdef __cplusplus
+extern "C" {
+#endif
+ extern void exit (int);
+ extern void *malloc (size_t);
+ extern void free (void *);
+ extern void *calloc (size_t, size_t);
+ extern void *alloca (size_t);
+ extern void *memcpy (void *, const void *, size_t);
+ extern void *memset (void *, int, size_t);
+ extern char *strcpy (char *, const char *);
+ extern char *strdup (const char *);
+ extern char *strndup (const char *, size_t);
+#ifdef __cplusplus
+}
+#endif
+
+unsigned nfails = 0;
+
+#define FAIL() \
+ do { \
+ __builtin_printf ("Failure at line: %d\n", __LINE__); \
+ nfails++; \
+ } while (0)
+
+#define DONE() \
+ do { \
+ if (nfails > 0) \
+ __builtin_abort (); \
+ return 0; \
+ } while (0)
@@ -4,16 +4,16 @@
/* { dg-do run } */
/* { dg-options "-O2 -fstrict-flex-arrays" } */
-#include <stdio.h>
+#include "builtin-object-size-common.h"
#define expect(p, _v) do { \
size_t v = _v; \
if (p == v) \
- printf("ok: %s == %zd\n", #p, p); \
+ __builtin_printf("ok: %s == %zd\n", #p, p); \
else \
{ \
- printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
- __builtin_abort (); \
+ __builtin_printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+ FAIL (); \
} \
} while (0);
@@ -56,5 +56,5 @@ int main(int argc, char *argv[])
{
stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
- return 0;
+ DONE ();
}
@@ -4,16 +4,16 @@
/* { dg-do run } */
/* { dg-options "-O2 -fstrict-flex-arrays=0" } */
-#include <stdio.h>
+#include "builtin-object-size-common.h"
#define expect(p, _v) do { \
size_t v = _v; \
if (p == v) \
- printf("ok: %s == %zd\n", #p, p); \
+ __builtin_printf ("ok: %s == %zd\n", #p, p); \
else \
{ \
- printf("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
- __builtin_abort (); \
+ __builtin_printf ("WAT: %s == %zd (expected %zd)\n", #p, p, v); \
+ FAIL (); \
} \
} while (0);
@@ -56,5 +56,5 @@ int main(int argc, char *argv[])
{
stuff((void *)argv[0], (void *)argv[0], (void *)argv[0], (void *)argv[0]);
- return 0;
+ DONE ();
}
Instead of failing on first error, run all __builtin_object_size and __builtin_dynamic_object_size tests to completion and then provide a summary of which tests failed. gcc/testsuite/ChangeLog: * gcc.dg/builtin-dynamic-object-size-0.c: Move FAIL and nfail into... * gcc.dg/builtin-object-size-common.h: ... new file. * g++.dg/ext/builtin-object-size1.C: Include builtin-object-size-common.h. Replace all abort with FAIL. (main): Call DONE. * g++.dg/ext/builtin-object-size2.C: Likewise. * gcc.dg/builtin-object-size-1.c: Likewise. * gcc.dg/builtin-object-size-12.c: Likewise. * gcc.dg/builtin-object-size-13.c: Likewise. * gcc.dg/builtin-object-size-15.c: Likewise. * gcc.dg/builtin-object-size-2.c: Likewise. * gcc.dg/builtin-object-size-3.c: Likewise. * gcc.dg/builtin-object-size-4.c: Likewise. * gcc.dg/builtin-object-size-6.c: Likewise. * gcc.dg/builtin-object-size-7.c: Likewise. * gcc.dg/builtin-object-size-8.c: Likewise. * gcc.dg/pr101836.c: Likewise. * gcc.dg/strict-flex-array-3.c: Likewise. Signed-off-by: Siddhesh Poyarekar <siddhesh@gotplt.org> --- .../g++.dg/ext/builtin-object-size1.C | 260 ++++++++------- .../g++.dg/ext/builtin-object-size2.C | 260 ++++++++------- .../gcc.dg/builtin-dynamic-object-size-0.c | 14 +- gcc/testsuite/gcc.dg/builtin-object-size-1.c | 297 ++++++++--------- gcc/testsuite/gcc.dg/builtin-object-size-12.c | 12 +- gcc/testsuite/gcc.dg/builtin-object-size-13.c | 15 +- gcc/testsuite/gcc.dg/builtin-object-size-15.c | 11 +- gcc/testsuite/gcc.dg/builtin-object-size-2.c | 305 +++++++++--------- gcc/testsuite/gcc.dg/builtin-object-size-3.c | 275 ++++++++-------- gcc/testsuite/gcc.dg/builtin-object-size-4.c | 285 ++++++++-------- gcc/testsuite/gcc.dg/builtin-object-size-6.c | 260 ++++++++------- gcc/testsuite/gcc.dg/builtin-object-size-7.c | 54 ++-- gcc/testsuite/gcc.dg/builtin-object-size-8.c | 15 +- .../gcc.dg/builtin-object-size-common.h | 32 ++ gcc/testsuite/gcc.dg/pr101836.c | 10 +- gcc/testsuite/gcc.dg/strict-flex-array-3.c | 10 +- 16 files changed, 1039 insertions(+), 1076 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/builtin-object-size-common.h