1 /* { dg-do compile { target i?86-*-linux* i?86-*-gnu* x86_64-*-linux* } } */
2 /* { dg-options "-O2" } */
3 
4 typedef __SIZE_TYPE__ size_t;
5 extern void abort (void);
6 extern char buf[0x40000000];
7 
8 void
test1(size_t x)9 test1 (size_t x)
10 {
11   char *p = &buf[8];
12   size_t i;
13 
14   for (i = 0; i < x; ++i)
15     p = p + 4;
16   if (__builtin_object_size (p, 0) != sizeof (buf) - 8)
17     abort ();
18 }
19 
20 void
test2(size_t x)21 test2 (size_t x)
22 {
23   char *p = &buf[8];
24   size_t i;
25 
26   for (i = 0; i < x; ++i)
27     p = p + 4;
28   if (__builtin_object_size (p, 1) != sizeof (buf) - 8)
29     abort ();
30 }
31 
32 void
test3(size_t x)33 test3 (size_t x)
34 {
35   char *p = &buf[8];
36   size_t i;
37 
38   for (i = 0; i < x; ++i)
39     p = p + 4;
40   if (__builtin_object_size (p, 2) != 0)
41     abort ();
42 }
43 
44 void
test4(size_t x)45 test4 (size_t x)
46 {
47   char *p = &buf[8];
48   size_t i;
49 
50   for (i = 0; i < x; ++i)
51     p = p + 4;
52   if (__builtin_object_size (p, 3) != 0)
53     abort ();
54 }
55 
56 /* { dg-final { scan-assembler-not "abort" } } */
57