| 1 |
/* PR c/94040 - ICE on a call to an invalid redeclaration of strftime |
| 2 |
{ dg-do compile } |
| 3 |
{ dg-options "-Wall" } */ |
| 4 |
|
| 5 |
typedef __SIZE_TYPE__ size_t; |
| 6 |
|
| 7 |
struct tm; |
| 8 |
|
| 9 |
size_t strftime (char *, size_t, int *, struct tm *); // { dg-warning "-Wbuiltin-declaration-mismatch" } |
| 10 |
|
| 11 |
size_t call_strftime (char *d, size_t n, int *f, struct tm *t) |
| 12 |
{ |
| 13 |
size_t r = 0; |
| 14 |
r += strftime (0, 0, 0, 0); |
| 15 |
r += strftime (d, 0, 0, 0); |
| 16 |
r += strftime (d, n, 0, 0); |
| 17 |
r += strftime (d, n, f, 0); |
| 18 |
r += strftime (d, n, f, t); |
| 19 |
return r; |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
char* strchr (char*, char*); // { dg-warning "-Wbuiltin-declaration-mismatch" } |
| 24 |
|
| 25 |
// Verify that missing/extra qualifiers aren't diagnosed without -Wextra. |
| 26 |
|
| 27 |
int strcmp (char*, char*); |
| 28 |
int strncmp (volatile char*, volatile char*, size_t); |
| 29 |
|
| 30 |
// Verify that a difference in pointers is diagnosed. |
| 31 |
|
| 32 |
size_t strlen (const char**); |
| 33 |
// { dg-warning "-Wbuiltin-declaration-mismatch" "pointer" { target *-*-* } .-1 } |
| 34 |
|
| 35 |
size_t strnlen (const char* const*, size_t); |
| 36 |
// { dg-warning "-Wbuiltin-declaration-mismatch" "pointer" { target *-*-* } .-1 } |
| 37 |
|
| 38 |
|
| 39 |
// Verify that calls to the compatibly-redeclared built-ins are treated |
| 40 |
// as those to the built-ins and diagnosed. |
| 41 |
|
| 42 |
int test_builtin_calls (size_t n) |
| 43 |
{ |
| 44 |
int r = 0; |
| 45 |
r += strcmp ((char*)0, ""); // { dg-warning "\\\[-Wnonnull]" } |
| 46 |
r += strcmp ("", (char*)0); // { dg-warning "\\\[-Wnonnull]" } |
| 47 |
|
| 48 |
r += strncmp ((char*)0, "", 1); // { dg-warning "\\\[-Wnonnull]" } |
| 49 |
r += strncmp ("", (char*)0, 1); // { dg-warning "\\\[-Wnonnull]" } |
| 50 |
|
| 51 |
r += strncmp ((char*)0, "", n); |
| 52 |
r += strncmp ("", (char*)0, n); |
| 53 |
|
| 54 |
r += strncmp ((char*)0, "", 0); |
| 55 |
r += strncmp ("", (char*)0, 0); |
| 56 |
|
| 57 |
return r; |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
// Verify that calls to the incompatibly-redeclared built-ins are not |
| 62 |
// treated as those to the built-ins by the middle-end. It doesn't |
| 63 |
// matter if the front-end diagnoses them but the middle-end should |
| 64 |
// not because it shouldn't recognize them as built-ins. |
| 65 |
|
| 66 |
#pragma GCC optimize "2" |
| 67 |
|
| 68 |
size_t test_nonbuiltin_calls (char *s, int c) |
| 69 |
{ |
| 70 |
void *null = 0; |
| 71 |
|
| 72 |
char *r; |
| 73 |
r = strchr ((char*)null, s); |
| 74 |
r = strchr (r, (char*)null); |
| 75 |
*s = *r; // use the result |
| 76 |
|
| 77 |
size_t n = 0; |
| 78 |
n += strftime (0, 0, 0, 0); |
| 79 |
n += strlen ((const char**)null); |
| 80 |
n += strnlen ((const char**)null, n); |
| 81 |
|
| 82 |
return n; |
| 83 |
} |