testsuite: Skip analyzer tests on AIX.
[official-gcc.git] / gcc / testsuite / c-c++-common / Wstringop-truncation-2.c
blob7b3c182b0fa2971d7b22fa482eb97d291516bb52
1 /* Verify that
2 { dg-do compile }
3 { dg-options "-O2 -Wstringop-truncation -Wno-stringop-overflow -ftrack-macro-expansion=0" } */
5 typedef __SIZE_TYPE__ size_t;
7 #define stpncpy(d, s, n) __builtin_stpncpy ((d), (s), (n))
8 #define strncpy(d, s, n) __builtin_stpncpy ((d), (s), (n))
10 void sink (void*);
12 struct A {
13 char arr[3] __attribute__ ((nonstring));
14 char str[3];
17 struct B { struct A a[3]; int i; };
18 struct C { struct B b[3]; int i; };
20 void stpncpy_arr_1 (struct C *pc, const char *s)
22 stpncpy (pc->b[0].a[0].arr, s, sizeof pc->b[0].a[0].arr);
23 sink (pc->b[0].a[0].arr);
25 stpncpy (pc->b[0].a[1].arr, s, sizeof pc->b[0].a[1].arr);
26 sink (pc->b[0].a[1].arr);
28 stpncpy (pc->b[0].a[2].arr, s, sizeof pc->b[0].a[2].arr);
29 sink (pc->b[0].a[2].arr);
31 stpncpy (pc->b[1].a[0].arr, s, sizeof pc->b[1].a[0].arr);
32 sink (pc->b[1].a[0].arr);
34 stpncpy (pc->b[1].a[1].arr, s, sizeof pc->b[1].a[1].arr);
35 sink (pc->b[1].a[1].arr);
37 stpncpy (pc->b[1].a[2].arr, s, sizeof pc->b[1].a[2].arr);
38 sink (pc->b[1].a[2].arr);
40 stpncpy (pc->b[2].a[0].arr, s, sizeof pc->b[2].a[0].arr);
41 sink (pc->b[2].a[0].arr);
43 stpncpy (pc->b[2].a[1].arr, s, sizeof pc->b[2].a[1].arr);
44 sink (pc->b[2].a[1].arr);
46 stpncpy (pc->b[2].a[2].arr, s, sizeof pc->b[2].a[2].arr);
47 sink (pc->b[2].a[2].arr);
50 void stpncpy_str_nowarn_1 (struct C *pc, const char *s)
52 stpncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str)[-1] = 0; /* { dg-bogus "\\\[-Wstringop-truncation" } */
55 void stpncpy_str_nowarn_2 (struct C *pc, const char *s)
57 *stpncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str - 1) = 0; /* { dg-bogus "\\\[-Wstringop-truncation" } */
60 void stpncpy_str_nowarn_3 (struct C *pc, const char *s)
62 char *d = stpncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str); /* { dg-bogus "\\\[-Wstringop-truncation" } */
64 d[-1] = 0;
67 void stpncpy_str_nowarn_4 (struct C *pc, const char *s)
69 char *d = stpncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str - 1); /* { dg-bogus "\\\[-Wstringop-truncation" } */
71 *d = 0;
74 void strncpy_arr_1 (struct C *pc, const char *s)
76 strncpy (pc->b[0].a[0].arr, s, sizeof pc->b[0].a[0].arr);
77 sink (pc->b[0].a[0].arr);
79 strncpy (pc->b[0].a[1].arr, s, sizeof pc->b[0].a[1].arr);
80 sink (pc->b[0].a[1].arr);
82 strncpy (pc->b[0].a[2].arr, s, sizeof pc->b[0].a[2].arr);
83 sink (pc->b[0].a[2].arr);
86 void strncpy_str_nowarn_1 (struct C *pc, const char *s)
88 strncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str); /* { dg-bogus "\\\[-Wstringop-truncation" } */
90 pc->b[0].a[0].str[sizeof pc->b[0].a[0].str - 1] = 0;
93 void strncpy_str_warn_1 (struct C *pc, const char *s)
95 strncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str); /* { dg-warning "specified bound 3 equals destination size" } */
97 pc->b[1].a[0].str[sizeof pc->b[0].a[0].str - 1] = 0;
100 void strncpy_str_warn_2 (struct C *pc, const char *s)
102 strncpy (pc->b[0].a[0].str, s, sizeof pc->b[0].a[0].str); /* { dg-warning "specified bound 3 equals destination size" } */
104 pc->b[0].a[1].str[sizeof pc->b[0].a[0].str - 1] = 0;