1 /* PR tree-optimization/102238 - missing -Wrestrict on sprintf formatting
2 a struct member into enclosing object
4 { dg-options "-O2 -Wall -Wno-format-overflow" } */
6 extern int sprintf (char*, const char*, ...);
8 extern void sink (void*, ...);
22 enum { B_a2_a_off
= __builtin_offsetof (struct B
, a2
.a
) };
25 void test_warn_src_decl_plus (void)
28 char *s
= (char*)&eb
+ B_a2_a_off
;
30 sprintf (d
, "%s", s
); // { dg-warning "overlaps" }
34 // If strlen (s) > 0 there is overlap with a[1].
35 char *s
= (char*)&eb
+ B_a2_a_off
+ 1;
37 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
41 // strlen (s) must be at most 1 so there can be no overlap with a.
42 char *s
= (char*)&eb
+ B_a2_a_off
+ 2;
44 sprintf (d
, "%s", s
); // { dg-bogus "-Wrestrict" }
48 // strlen (s) must be at most 0 so there can be no overlap with a.
49 char *s
= (char*)&eb
+ B_a2_a_off
+ 3;
51 sprintf (d
, "%s", s
); // { dg-bogus "-Wrestrict" }
56 void test_warn_src_ptr_plus (struct B
*p
)
59 char *s
= (char*)p
+ B_a2_a_off
;
61 sprintf (d
, "%s", s
); // { dg-warning "overlaps" }
65 // If strlen (s) > 0 there is overlap with a[1].
66 char *s
= (char*)p
+ B_a2_a_off
+ 1;
68 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
72 // strlen (s) must be at most 1 so there can be no overlap with a.
73 char *s
= (char*)p
+ B_a2_a_off
+ 2;
75 sprintf (d
, "%s", s
); // { dg-bogus "-Wrestrict" }
79 // strlen (s) must be at most 0 so there can be no overlap with a.
80 char *s
= (char*)p
+ B_a2_a_off
+ 3;
82 sprintf (d
, "%s", s
); // { dg-bogus "-Wrestrict" }
87 void test_warn_dst_decl_plus (void)
91 char *d
= (char*)&eb
+ B_a2_a_off
;
92 sprintf (d
, "%s", s
); // { dg-warning "overlaps" }
96 // If strlen (a) > 0 there is overlap with a[1].
98 char *d
= (char*)&eb
+ B_a2_a_off
+ 1;
99 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
103 // If strlen (a) > 1 there is overlap with a[2].
105 char *d
= (char*)&eb
+ B_a2_a_off
+ 2;
106 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
110 // If strlen (a) > 2 there is overlap with a[3].
112 char *d
= (char*)&eb
+ B_a2_a_off
+ 3;
113 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
118 void test_warn_dst_ptr_plus (struct B
*p
)
122 char *d
= (char*)p
+ B_a2_a_off
;
123 sprintf (d
, "%s", s
); // { dg-warning "overlaps" }
127 // If strlen (a) > 0 there is overlap with a[1].
129 char *d
= (char*)p
+ B_a2_a_off
+ 1;
130 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
134 // If strlen (a) > 1 there is overlap with a[2].
136 char *d
= (char*)p
+ B_a2_a_off
+ 2;
137 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }
141 // If strlen (a) > 2 there is overlap with a[3].
143 char *d
= (char*)p
+ B_a2_a_off
+ 3;
144 sprintf (d
, "%s", s
); // { dg-warning "may overlap" }