Debian Codegraph @

gcc/testsuite/c-c++-common/attr-nonstring-12.c

raw
1 /* PR middle-end/83131 - c-c++/common/attr-nonstring-3 failure for strcmp
2 tests on PowerPC
3 { dg-do compile }
4 { dg-options "-O2 -Wstringop-overflow -ftrack-macro-expansion=0" } */
5
6 #if __cplusplus
7 extern "C" {
8 #endif
9
10 typedef __SIZE_TYPE__ size_t;
11
12 extern int strcmp (const char*, const char*);
13 extern int strncmp (const char*, const char*, size_t);
14
15 #if __cplusplus
16 } /* extern "C" */
17 #endif
18
19 extern char arx[][18] __attribute__ ((nonstring));
20 extern char ar5[5][5] __attribute__ ((nonstring));
21 extern char str[][18];
22
23 enum { N = sizeof ar5[2] };
24 enum { X = sizeof ar5[2] + 1 };
25
26
27 int warn_strcmp_cst_1 (void)
28 {
29 return strcmp ("bar", arx[3]);
30 }
31
32 int warn_strcmp_cst_2 (void)
33 {
34 return strcmp (arx[3], "foo");
35 }
36
37 int warn_strcmp_cst_3 (void)
38 {
39 return strcmp ("barfoobazquxcorge1", arx[3]); /* { dg-warning "argument 2 declared attribute .nonstring." } */
40 }
41
42 int warn_strcmp_cst_4 (void)
43 {
44 return strcmp (arx[3], "foobarbazquxcorge1"); /* { dg-warning "argument 1 declared attribute .nonstring." } */
45 }
46
47
48 int warn_strncmp_cst_1 (void)
49 {
50 return strncmp ("12345", ar5[2], X); /* { dg-warning "argument 2 declared attribute .nonstring." } */
51 }
52
53 int warn_strncmp_cst_2 (void)
54 {
55 return strncmp (ar5[2], "12345", X); /* { dg-warning "argument 1 declared attribute .nonstring." } */
56 }
57
58
59 int nowarn_strncmp_cst_1 (void)
60 {
61 return strncmp ("12345", ar5[2], N);
62 }
63
64 int nowarn_strncmp_cst_2 (void)
65 {
66 return strncmp (ar5[2], "12345", N);
67 }
68
69
70 int warn_strncmp_var_1 (void)
71 {
72 return strncmp (str[5], ar5[2], X); /* { dg-warning "argument 2 declared attribute .nonstring." } */
73 }
74
75 int warn_strncmp_var_2 (void)
76 {
77 return strncmp (ar5[2], str[5], X); /* { dg-warning "argument 1 declared attribute .nonstring." } */
78 }
79
80
81 int nowarn_strncmp_var_1 (void)
82 {
83 return strncmp (str[5], ar5[2], N);
84 }
85
86 int nowarn_strncmp_var_2 (void)
87 {
88 return strncmp (ar5[2], str[5], N);
89 }