summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/builtin-object-size-1.c
diff options
context:
space:
mode:
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-27 12:17:39 +0000
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>2005-06-27 12:17:39 +0000
commit0a39fd5408943300a03d40afe1f6e5b59ae31816 (patch)
treebb3939873bf2cf5cb7bd56f678141658affb0021 /gcc/testsuite/gcc.dg/builtin-object-size-1.c
parentf68ab9c535c26d62063f272878415869effc0ef6 (diff)
downloadgcc-0a39fd5408943300a03d40afe1f6e5b59ae31816.tar.gz
* builtin-attrs.def (DEF_ATTR_FOR_INT): Add for 5 and 6.
(DEF_LIST_INT_INT): Add for 4,0, 4,5, 5,0, 5,6. (ATTR_NOTHROW_NONNULL_4, ATTR_NOTHROW_NONNULL_5): Define. (ATTR_FORMAT_PRINTF_4_0, ATTR_FORMAT_PRINTF_4_5, ATTR_FORMAT_PRINTF_5_0, ATTR_FORMAT_PRINTF_5_6): Define. * builtins.c: Include tree-flow.h. (expand_builtin_mempcpy, expand_builtin_memmove): Comment fixes. (expand_builtin_object_size, expand_builtin_memory_chk, maybe_emit_chk_warning, maybe_emit_sprintf_chk_warning, compute_object_offset, compute_builtin_object_size, fold_builtin_object_size): New functions. (expand_builtin): Handle BUILT_IN_OBJECT_SIZE and BUILT_IN_*_CHK. (fold_builtin_1): Likewise. Handle BUILT_IN_{,V}{,F}PRINTF and BUILT_IN_{,F}PRINTF_UNLOCKED. (fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_strncpy_chk, fold_builtin_strcat_chk, fold_builtin_strncat_chk, fold_builtin_sprintf_chk, fold_builtin_snprintf_chk, fold_builtin_printf, fold_builtin_fprintf): New functions. * builtins.def (BUILT_IN_OBJECT_SIZE, BUILT_IN_MEMCPY_CHK, BUILT_IN_MEMMOVE_CHK, BUILT_IN_MEMPCPY_CHK, BUILT_IN_MEMSET_CHK, BUILT_IN_STPCPY_CHK, BUILT_IN_STRCAT_CHK, BUILT_IN_STRCPY_CHK, BUILT_IN_STRNCAT_CHK, BUILT_IN_STRNCPY_CHK, BUILT_IN_SNPRINTF_CHK, BUILT_IN_SPRINTF_CHK, BUILT_IN_VSNPRINTF_CHK, BUILT_IN_VSPRINTF_CHK, BUILT_IN_FPRINTF_CHK, BUILT_IN_PRINTF_CHK, BUILT_IN_VFPRINTF_CHK, BUILT_IN_VPRINTF_CHK): New builtins. * builtin-types.def (DEF_FUNCTION_TYPE_5, DEF_FUNCTION_TYPE_VAR_4): Document. (BT_FN_SIZE_CONST_PTR_INT, BT_FN_INT_INT_CONST_STRING_VALIST_ARG, BT_FN_PTR_PTR_CONST_PTR_SIZE_SIZE, BT_FN_PTR_PTR_INT_SIZE_SIZE, BT_FN_STRING_STRING_CONST_STRING_SIZE_SIZE, BT_FN_INT_FILEPTR_INT_CONST_STRING_VALIST_ARG, BT_FN_INT_STRING_INT_SIZE_CONST_STRING_VALIST_ARG, BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VALIST_ARG, BT_FN_INT_INT_CONST_STRING_VAR, BT_FN_INT_FILEPTR_INT_CONST_STRING_VAR, BT_FN_INT_STRING_INT_SIZE_CONST_STRING_VAR, BT_FN_INT_STRING_SIZE_INT_SIZE_CONST_STRING_VAR): New types. * c-common.c (DEF_FUNCTION_TYPE_5, DEF_FUNCTION_TYPE_6, DEF_FUNCTION_TYPE_VAR_4, DEF_FUNCTION_TYPE_VAR_5): Define. * Makefile.in (OBJS-common): Add tree-object-size.o. (tree-object-size.o): Add dependencies. * tree-pass.h (pass_object_sizes): Add. * tree-optimize.c (init_tree_optimization_passes): Add pass_object_sizes. * tree-object-size.c: New file. * tree.h (fold_builtin_memory_chk, fold_builtin_stxcpy_chk, fold_builtin_strncpy_chk, fold_builtin_snprintf_chk, compute_builtin_object_size, init_object_sizes, fini_object_sizes): New prototypes. * tree-ssa-ccp.c (get_strlen): Rename to ... (get_maxval_strlen): ...this function. Handle also computing of maximum string length and maximum integral value. (ccp_fold_builtin): Handle BUILT_IN_*_CHK. Use get_maxval_strlen instead of get_strlen. Pass CALLEE and ARGLIST variables to the folding functions instead of computing them again. (execute_fold_all_builtins): Retry ccp_fold_builtin if a builtin changed into some other builtin. * doc/extend.texi (Object Size Checking): Document. * gcc.c-torture/execute/builtins/lib/main.c (abort): Add prototype. * gcc.c-torture/execute/builtins/lib/strncat.c (strncat): Avoid testing uninitialized var. * gcc.c-torture/execute/builtins/chk.h: New. * gcc.c-torture/execute/builtins/lib/chk.c: New. * gcc.c-torture/execute/builtins/memcpy-chk.c: New test. * gcc.c-torture/execute/builtins/memcpy-chk-lib.c: New. * gcc.c-torture/execute/builtins/memmove-chk.c: New test. * gcc.c-torture/execute/builtins/memmove-chk-lib.c: New. * gcc.c-torture/execute/builtins/mempcpy-chk.c: New test. * gcc.c-torture/execute/builtins/mempcpy-chk-lib.c: New. * gcc.c-torture/execute/builtins/memset-chk.c: New test. * gcc.c-torture/execute/builtins/memset-chk-lib.c: New. * gcc.c-torture/execute/builtins/snprintf-chk.c: New test. * gcc.c-torture/execute/builtins/snprintf-chk-lib.c: New. * gcc.c-torture/execute/builtins/sprintf-chk.c: New test. * gcc.c-torture/execute/builtins/sprintf-chk-lib.c: New. * gcc.c-torture/execute/builtins/stpcpy-chk.c: New test. * gcc.c-torture/execute/builtins/stpcpy-chk-lib.c: New. * gcc.c-torture/execute/builtins/strcat-chk.c: New test. * gcc.c-torture/execute/builtins/strcat-chk-lib.c: New. * gcc.c-torture/execute/builtins/strcpy-chk.c: New test. * gcc.c-torture/execute/builtins/strcpy-chk-lib.c: New. * gcc.c-torture/execute/builtins/strncat-chk.c: New test. * gcc.c-torture/execute/builtins/strncat-chk-lib.c: New. * gcc.c-torture/execute/builtins/strncpy-chk.c: New test. * gcc.c-torture/execute/builtins/strncpy-chk-lib.c: New. * gcc.c-torture/execute/builtins/vsnprintf-chk.c: New test. * gcc.c-torture/execute/builtins/vsnprintf-chk-lib.c: New. * gcc.c-torture/execute/builtins/vsprintf-chk.c: New test. * gcc.c-torture/execute/builtins/vsprintf-chk-lib.c: New. * gcc.dg/builtin-object-size-1.c: New test. * gcc.dg/builtin-object-size-2.c: New test. * gcc.dg/builtin-object-size-3.c: New test. * gcc.dg/builtin-object-size-4.c: New test. * gcc.dg/builtin-object-size-5.c: New test. * gcc.dg/builtin-stringop-chk-1.c: New test. * gcc.dg/builtin-stringop-chk-2.c: New test. * gcc.dg/tree-ssa/builtin-fprintf-1.c: New test. * gcc.dg/tree-ssa/builtin-fprintf-chk-1.c: New test. * gcc.dg/tree-ssa/builtin-printf-1.c: New test. * gcc.dg/tree-ssa/builtin-printf-chk-1.c: New test. * gcc.dg/tree-ssa/builtin-vfprintf-1.c: New test. * gcc.dg/tree-ssa/builtin-vfprintf-chk-1.c: New test. * gcc.dg/tree-ssa/builtin-vprintf-1.c: New test. * gcc.dg/tree-ssa/builtin-vprintf-chk-1.c: New test. * gcc.c-torture/execute/printf-1.c: New test. * gcc.c-torture/execute/fprintf-1.c: New test. * gcc.c-torture/execute/vprintf-1.c: New test. * gcc.c-torture/execute/vfprintf-1.c: New test. * gcc.c-torture/execute/printf-chk-1.c: New test. * gcc.c-torture/execute/fprintf-chk-1.c: New test. * gcc.c-torture/execute/vprintf-chk-1.c: New test. * gcc.c-torture/execute/vfprintf-chk-1.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@101352 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/testsuite/gcc.dg/builtin-object-size-1.c')
-rw-r--r--gcc/testsuite/gcc.dg/builtin-object-size-1.c436
1 files changed, 436 insertions, 0 deletions
diff --git a/gcc/testsuite/gcc.dg/builtin-object-size-1.c b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
new file mode 100644
index 00000000000..404b7117f88
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/builtin-object-size-1.c
@@ -0,0 +1,436 @@
+/* { 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 *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 *);
+
+struct A
+{
+ char a[10];
+ int b;
+ char c[10];
+} y, w[4];
+
+extern char exta[];
+extern char extb[30];
+extern struct A zerol[0];
+
+void
+__attribute__ ((noinline))
+test1 (void *q, int x)
+{
+ struct A a;
+ void *p = &a.a[3], *r;
+ char var[x + 10];
+ if (x < 0)
+ r = &a.a[9];
+ else
+ r = &a.c[1];
+ if (__builtin_object_size (p, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 3)
+ abort ();
+ if (__builtin_object_size (&a.c[9], 0)
+ != sizeof (a) - __builtin_offsetof (struct A, c) - 9)
+ abort ();
+ if (__builtin_object_size (q, 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (r, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 9)
+ abort ();
+ if (x < 6)
+ r = &w[2].a[1];
+ else
+ r = &a.a[6];
+ if (__builtin_object_size (&y, 0)
+ != sizeof (y))
+ abort ();
+ if (__builtin_object_size (w, 0)
+ != sizeof (w))
+ abort ();
+ if (__builtin_object_size (&y.b, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, b))
+ abort ();
+ if (__builtin_object_size (r, 0)
+ != 2 * sizeof (w[0]) - __builtin_offsetof (struct A, a) - 1)
+ abort ();
+ if (x < 20)
+ r = malloc (30);
+ else
+ r = calloc (2, 16);
+ if (__builtin_object_size (r, 0) != 2 * 16)
+ abort ();
+ if (x < 20)
+ r = malloc (30);
+ else
+ r = calloc (2, 14);
+ if (__builtin_object_size (r, 0) != 30)
+ abort ();
+ if (x < 30)
+ r = malloc (sizeof (a));
+ else
+ r = &a.a[3];
+ if (__builtin_object_size (r, 0) != sizeof (a))
+ abort ();
+ r = memcpy (r, "a", 2);
+ if (__builtin_object_size (r, 0) != sizeof (a))
+ abort ();
+ r = memcpy (r + 2, "b", 2) + 2;
+ if (__builtin_object_size (r, 0) != sizeof (a) - 4)
+ abort ();
+ r = &a.a[4];
+ r = memset (r, 'a', 2);
+ if (__builtin_object_size (r, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 4)
+ abort ();
+ r = memset (r + 2, 'b', 2) + 2;
+ if (__builtin_object_size (r, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 8)
+ abort ();
+ r = &a.a[1];
+ r = strcpy (r, "ab");
+ if (__builtin_object_size (r, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 1)
+ abort ();
+ r = strcpy (r + 2, "cd") + 2;
+ if (__builtin_object_size (r, 0)
+ != sizeof (a) - __builtin_offsetof (struct A, a) - 5)
+ abort ();
+ if (__builtin_object_size (exta, 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (exta + 10, 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (&exta[5], 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (extb, 0) != sizeof (extb))
+ abort ();
+ if (__builtin_object_size (extb + 10, 0) != sizeof (extb) - 10)
+ abort ();
+ if (__builtin_object_size (&extb[5], 0) != sizeof (extb) - 5)
+ abort ();
+ if (__builtin_object_size (var, 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (var + 10, 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (&var[5], 0) != (size_t) -1)
+ abort ();
+ if (__builtin_object_size (zerol, 0) != 0)
+ abort ();
+ if (__builtin_object_size (&zerol, 0) != 0)
+ abort ();
+ if (__builtin_object_size (&zerol[0], 0) != 0)
+ abort ();
+ if (__builtin_object_size (zerol[0].a, 0) != 0)
+ abort ();
+ if (__builtin_object_size (&zerol[0].a[0], 0) != 0)
+ abort ();
+ if (__builtin_object_size (&zerol[0].b, 0) != 0)
+ abort ();
+ if (__builtin_object_size ("abcdefg", 0) != sizeof ("abcdefg"))
+ abort ();
+ if (__builtin_object_size ("abcd\0efg", 0) != sizeof ("abcd\0efg"))
+ abort ();
+ if (__builtin_object_size (&"abcd\0efg", 0) != sizeof ("abcd\0efg"))
+ abort ();
+ if (__builtin_object_size (&"abcd\0efg"[0], 0) != sizeof ("abcd\0efg"))
+ abort ();
+ if (__builtin_object_size (&"abcd\0efg"[4], 0) != sizeof ("abcd\0efg") - 4)
+ abort ();
+ if (__builtin_object_size ("abcd\0efg" + 5, 0) != sizeof ("abcd\0efg") - 5)
+ abort ();
+ if (__builtin_object_size (L"abcdefg", 0) != sizeof (L"abcdefg"))
+ abort ();
+ r = (char *) L"abcd\0efg";
+ if (__builtin_object_size (r + 2, 0) != sizeof (L"abcd\0efg") - 2)
+ abort ();
+}
+
+size_t l1 = 1;
+
+void
+__attribute__ ((noinline))
+test2 (void)
+{
+ struct B { char buf1[10]; char buf2[10]; } a;
+ char *r, buf3[20];
+ int i;
+
+ if (sizeof (a) != 20)
+ return;
+
+ r = buf3;
+ for (i = 0; i < 4; ++i)
+ {
+ if (i == l1 - 1)
+ r = &a.buf1[1];
+ else if (i == l1)
+ r = &a.buf2[7];
+ else if (i == l1 + 1)
+ r = &buf3[5];
+ else if (i == l1 + 2)
+ r = &a.buf1[9];
+ }
+ if (__builtin_object_size (r, 0) != 20)
+ abort ();
+ r = &buf3[20];
+ for (i = 0; i < 4; ++i)
+ {
+ if (i == l1 - 1)
+ r = &a.buf1[7];
+ else if (i == l1)
+ r = &a.buf2[7];
+ else if (i == l1 + 1)
+ r = &buf3[5];
+ else if (i == l1 + 2)
+ r = &a.buf1[9];
+ }
+ if (__builtin_object_size (r, 0) != 15)
+ abort ();
+ r += 8;
+ if (__builtin_object_size (r, 0) != 7)
+ abort ();
+ if (__builtin_object_size (r + 6, 0) != 1)
+ abort ();
+ r = &buf3[18];
+ for (i = 0; i < 4; ++i)
+ {
+ if (i == l1 - 1)
+ r = &a.buf1[9];
+ else if (i == l1)
+ r = &a.buf2[9];
+ else if (i == l1 + 1)
+ r = &buf3[5];
+ else if (i == l1 + 2)
+ r = &a.buf1[4];
+ }
+ if (__builtin_object_size (r + 12, 0) != 4)
+ abort ();
+}
+
+void
+__attribute__ ((noinline))
+test3 (void)
+{
+ char buf4[10];
+ struct B { struct A a[2]; struct A b; char c[4]; char d; double e;
+ _Complex double f; } x;
+ double y;
+ _Complex double z;
+ double *dp;
+
+ if (__builtin_object_size (buf4, 0) != sizeof (buf4))
+ abort ();
+ if (__builtin_object_size (&buf4, 0) != sizeof (buf4))
+ abort ();
+ if (__builtin_object_size (&buf4[0], 0) != sizeof (buf4))
+ abort ();
+ if (__builtin_object_size (&buf4[1], 0) != sizeof (buf4) - 1)
+ abort ();
+ if (__builtin_object_size (&x, 0) != sizeof (x))
+ abort ();
+ if (__builtin_object_size (&x.a, 0) != sizeof (x))
+ abort ();
+ if (__builtin_object_size (&x.a[0], 0) != sizeof (x))
+ abort ();
+ if (__builtin_object_size (&x.a[0].a, 0) != sizeof (x))
+ abort ();
+ if (__builtin_object_size (&x.a[0].a[0], 0) != sizeof (x))
+ abort ();
+ if (__builtin_object_size (&x.a[0].a[3], 0) != sizeof (x) - 3)
+ abort ();
+ if (__builtin_object_size (&x.a[0].b, 0)
+ != sizeof (x) - __builtin_offsetof (struct A, b))
+ abort ();
+ if (__builtin_object_size (&x.a[1].c, 0)
+ != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
+ abort ();
+ if (__builtin_object_size (&x.a[1].c[0], 0)
+ != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c))
+ abort ();
+ if (__builtin_object_size (&x.a[1].c[3], 0)
+ != sizeof (x) - sizeof (struct A) - __builtin_offsetof (struct A, c) - 3)
+ abort ();
+ if (__builtin_object_size (&x.b, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b))
+ abort ();
+ if (__builtin_object_size (&x.b.a, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b))
+ abort ();
+ if (__builtin_object_size (&x.b.a[0], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b))
+ abort ();
+ if (__builtin_object_size (&x.b.a[3], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b) - 3)
+ abort ();
+ if (__builtin_object_size (&x.b.b, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b)
+ - __builtin_offsetof (struct A, b))
+ abort ();
+ if (__builtin_object_size (&x.b.c, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b)
+ - __builtin_offsetof (struct A, c))
+ abort ();
+ if (__builtin_object_size (&x.b.c[0], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b)
+ - __builtin_offsetof (struct A, c))
+ abort ();
+ if (__builtin_object_size (&x.b.c[3], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, b)
+ - __builtin_offsetof (struct A, c) - 3)
+ abort ();
+ if (__builtin_object_size (&x.c, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, c))
+ abort ();
+ if (__builtin_object_size (&x.c[0], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, c))
+ abort ();
+ if (__builtin_object_size (&x.c[1], 0)
+ != sizeof (x) - __builtin_offsetof (struct B, c) - 1)
+ abort ();
+ if (__builtin_object_size (&x.d, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, d))
+ abort ();
+ if (__builtin_object_size (&x.e, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, e))
+ abort ();
+ if (__builtin_object_size (&x.f, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, f))
+ abort ();
+ dp = &__real__ x.f;
+ if (__builtin_object_size (dp, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, f))
+ abort ();
+ dp = &__imag__ x.f;
+ if (__builtin_object_size (dp, 0)
+ != sizeof (x) - __builtin_offsetof (struct B, f)
+ - sizeof (x.f) / 2)
+ abort ();
+ dp = &y;
+ if (__builtin_object_size (dp, 0) != sizeof (y))
+ abort ();
+ if (__builtin_object_size (&z, 0) != sizeof (z))
+ abort ();
+ dp = &__real__ z;
+ if (__builtin_object_size (dp, 0) != sizeof (z))
+ abort ();
+ dp = &__imag__ z;
+ if (__builtin_object_size (dp, 0) != sizeof (z) / 2)
+ abort ();
+}
+
+struct S { unsigned int a; };
+
+char *
+__attribute__ ((noinline))
+test4 (char *x, int y)
+{
+ register int i;
+ struct A *p;
+
+ for (i = 0; i < y; i++)
+ {
+ p = (struct A *) x;
+ x = (char *) &p[1];
+ if (__builtin_object_size (p, 0) != (size_t) -1)
+ abort ();
+ }
+ return x;
+}
+
+void
+__attribute__ ((noinline))
+test5 (size_t x)
+{
+ char buf[64];
+ char *p = &buf[8];
+ size_t i;
+
+ for (i = 0; i < x; ++i)
+ p = p + 4;
+ /* My understanding of ISO C99 6.5.6 is that a conforming
+ program will not end up with p equal to &buf[0]
+ through &buf[7], i.e. calling this function with say
+ UINTPTR_MAX / 4 results in undefined behaviour.
+ If that's true, then the maximum number of remaining
+ 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 ();
+ memset (p, ' ', sizeof (buf) - 8 - 4 * 4);
+}
+
+void
+__attribute__ ((noinline))
+test6 (size_t x)
+{
+ struct T { char buf[64]; char buf2[64]; } t;
+ char *p = &t.buf[8];
+ size_t i;
+
+ for (i = 0; i < x; ++i)
+ p = p + 4;
+ if (__builtin_object_size (p, 0) != sizeof (t) - 8)
+ abort ();
+ memset (p, ' ', sizeof (t) - 8 - 4 * 4);
+}
+
+void
+__attribute__ ((noinline))
+test7 (void)
+{
+ char buf[64];
+ struct T { char buf[64]; char buf2[64]; } t;
+ char *p = &buf[64], *q = &t.buf[64];
+
+ if (__builtin_object_size (p + 64, 0) != 0)
+ abort ();
+ if (__builtin_object_size (q + 63, 0) != sizeof (t) - 64 - 63)
+ abort ();
+ if (__builtin_object_size (q + 64, 0) != sizeof (t) - 64 - 64)
+ abort ();
+ if (__builtin_object_size (q + 256, 0) != 0)
+ abort ();
+}
+
+void
+__attribute__ ((noinline))
+test8 (void)
+{
+ struct T { char buf[10]; char buf2[10]; } t;
+ char *p = &t.buf2[-4];
+ char *q = &t.buf2[0];
+ if (__builtin_object_size (p, 0) != sizeof (t) - 10 + 4)
+ abort ();
+ if (__builtin_object_size (q, 0) != sizeof (t) - 10)
+ abort ();
+ /* 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 ();
+ p = &t.buf[-4];
+ if (__builtin_object_size (p, 0) != 0)
+ abort ();
+}
+
+int
+main (void)
+{
+ struct S s[10];
+ __asm ("" : "=r" (l1) : "0" (l1));
+ test1 (main, 6);
+ test2 ();
+ test3 ();
+ test4 ((char *) s, 10);
+ test5 (4);
+ test6 (4);
+ test7 ();
+ test8 ();
+ exit (0);
+}