| 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[] __attribute__ ((nonstring)); |
| 20 |
extern char ar5[5] __attribute__ ((nonstring)); |
| 21 |
extern char str[]; |
| 22 |
|
| 23 |
enum { N = sizeof ar5 }; |
| 24 |
enum { X = sizeof ar5 + 1 }; |
| 25 |
|
| 26 |
|
| 27 |
int warn_strcmp_cst_1 (void) |
| 28 |
{ |
| 29 |
return strcmp ("bar", arx); /* { dg-warning "argument 2 declared attribute .nonstring." } */ |
| 30 |
} |
| 31 |
|
| 32 |
int warn_strcmp_cst_2 (void) |
| 33 |
{ |
| 34 |
return strcmp (arx, "foo"); /* { dg-warning "argument 1 declared attribute .nonstring." } */ |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
int warn_strncmp_cst_1 (void) |
| 39 |
{ |
| 40 |
return strncmp ("12345", ar5, X); /* { dg-warning "argument 2 declared attribute .nonstring." } */ |
| 41 |
} |
| 42 |
|
| 43 |
int warn_strncmp_cst_2 (void) |
| 44 |
{ |
| 45 |
return strncmp (ar5, "12345", X); /* { dg-warning "argument 1 declared attribute .nonstring." } */ |
| 46 |
} |
| 47 |
|
| 48 |
|
| 49 |
int nowarn_strncmp_cst_1 (void) |
| 50 |
{ |
| 51 |
return strncmp ("12345", ar5, N); |
| 52 |
} |
| 53 |
|
| 54 |
int nowarn_strncmp_cst_2 (void) |
| 55 |
{ |
| 56 |
return strncmp (ar5, "12345", N); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
int warn_strncmp_var_1 (void) |
| 61 |
{ |
| 62 |
return strncmp (str, ar5, X); /* { dg-warning "argument 2 declared attribute .nonstring." } */ |
| 63 |
} |
| 64 |
|
| 65 |
int warn_strncmp_var_2 (void) |
| 66 |
{ |
| 67 |
return strncmp (ar5, str, X); /* { dg-warning "argument 1 declared attribute .nonstring." } */ |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
int nowarn_strncmp_var_1 (void) |
| 72 |
{ |
| 73 |
return strncmp (str, ar5, N); |
| 74 |
} |
| 75 |
|
| 76 |
int nowarn_strncmp_var_2 (void) |
| 77 |
{ |
| 78 |
return strncmp (ar5, str, N); |
| 79 |
} |