1 /* PR middle-end/81384 - built-in form of strnlen missing
3 Since the strnlen patch affects the handling for strncmp and other
4 bounded functions, verify that a bound in excess of the maximum
5 object size specified for strncmp is diagnosed regardless of
6 attribute nonstring. Also verify that a bound that's greater than
7 the size of a non-string array is diagnosed, even if it's not in
8 excess of the maximum object size.
11 { dg-options "-O2 -Wall -ftrack-macro-expansion=0" } */
15 extern int strncmp (const char*, const char*, size_t);
17 #define STR /* not non-string */
18 #define NS __attribute__ ((nonstring))
20 #define _CAT(s, n) s ## n
21 #define CAT(s, n) _CAT (s, n)
22 #define UNIQ(n) CAT (n, __LINE__)
26 #define T(at1, N1, at2, N2, bound) \
28 extern at1 char UNIQ (a)[N1]; \
29 extern at2 char UNIQ (b)[N2]; \
30 sink (strncmp (UNIQ (a), UNIQ (b), bound)); \
33 void strncmp_cst (void)
37 T (STR
, /* [] */, STR
, /* [] */, n
);
38 T (STR
, /* [] */, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
40 T (STR
, 1, STR
, /* [] */, 1);
41 T (STR
, 1, STR
, /* [] */, n
);
42 T (STR
, 2, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
44 T (STR
, /* [] */, STR
, 3, 3);
45 T (STR
, /* [] */, STR
, 3, n
);
46 T (STR
, /* [] */, STR
, 4, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
48 T (STR
, /* [] */, NS
, /* [] */, 3);
49 T (STR
, /* [] */, NS
, /* [] */, n
);
50 T (STR
, /* [] */, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
52 T (STR
, 5, NS
, /* [] */, 4);
53 T (STR
, 5, NS
, /* [] */, 5);
54 T (STR
, 5, NS
, /* [] */, 6);
55 T (STR
, 5, NS
, /* [] */, n
);
56 T (STR
, 6, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
58 T (STR
, /* [] */, NS
, 7, n
); /* { dg-warning "argument 2 declared attribute .nonstring. is smaller than the specified bound" } */
60 T (STR
, /* [] */, NS
, 8, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
62 T (NS
, /* [] */, STR
, /* [] */, n
);
63 T (NS
, /* [] */, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
65 T (NS
, 9, STR
, /* [] */, n
); /* { dg-warning "argument 1 declared attribute 'nonstring' is smaller than the specified bound \[0-9\]+" } */
66 T (NS
, 10, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
68 T (NS
, /* [] */, STR
, 11, 11);
69 T (NS
, /* [] */, STR
, 11, n
);
70 T (NS
, /* [] */, STR
, 12, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
72 T (NS
, /* [] */, NS
, /* [] */, n
);
73 T (NS
, /* [] */, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
75 T (NS
, 13, NS
, /* [] */, 13);
76 T (NS
, 13, NS
, /* [] */, n
); /* { dg-warning "argument 1 declared attribute 'nonstring' is smaller than the specified bound \[0-9\]+" } */
77 T (NS
, 14, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
79 T (NS
, /* [] */, NS
, 15, 15);
80 T (NS
, /* [] */, NS
, 15, 16); /* { dg-warning "argument 2 declared attribute 'nonstring' is smaller than the specified bound 16" } */
81 T (NS
, /* [] */, NS
, 16, n
+ 1); /* { dg-warning "specified bound \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
85 void strncmp_range (void)
90 T (STR
, /* [] */, STR
, /* [] */, n
);
91 T (STR
, /* [] */, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
93 T (STR
, 1, STR
, /* [] */, 1);
94 T (STR
, 1, STR
, /* [] */, n
);
95 T (STR
, 2, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
97 T (STR
, /* [] */, STR
, 3, n
);
98 T (STR
, /* [] */, STR
, 4, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
100 T (STR
, /* [] */, NS
, /* [] */, n
);
101 T (STR
, /* [] */, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
103 T (STR
, 5, NS
, /* [] */, n
);
104 T (STR
, 6, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
106 T (STR
, /* [] */, NS
, 7, n
); /* { dg-warning "argument 2 declared attribute 'nonstring' is smaller than the specified bound \\\[\[0-9\]+, \[0-9\]+]" } */
108 T (STR
, /* [] */, NS
, 8, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
110 T (NS
, /* [] */, STR
, /* [] */, n
);
111 T (NS
, /* [] */, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
113 T (NS
, 9, STR
, /* [] */, n
); /* { dg-warning "argument 1 declared attribute .nonstring. is smaller than the specified bound" } */
114 T (NS
, 10, STR
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
116 T (NS
, /* [] */, STR
, 11, n
);
117 T (NS
, /* [] */, STR
, 12, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
119 T (NS
, /* [] */, NS
, /* [] */, n
);
120 T (NS
, /* [] */, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
122 T (NS
, 13, NS
, /* [] */, n
); /* { dg-warning "argument 1 declared attribute .nonstring. is smaller than the specified bound" } */
123 T (NS
, 14, NS
, /* [] */, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */
125 T (NS
, /* [] */, NS
, 15, n
); /* { dg-warning "argument 2 declared attribute .nonstring. is smaller than the specified bound" } */
126 T (NS
, /* [] */, NS
, 16, n
+ 1); /* { dg-warning "specified bound \\\[\[0-9\]+, \[0-9\]+] exceeds maximum object size \[0-9\]+" } */