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, "", n); // { dg-warning "\\\[-Wnonnull]" }
49 r += strncmp ("", (char*)0, n); // { dg-warning "\\\[-Wnonnull]" }
50
51 return r;
52 }
53
54
55 // Verify that calls to the incompatibly-redeclared built-ins are not
56 // treated as those to the built-ins by the middle-end. It doesn't
57 // matter if the front-end diagnoses them but the middle-end should
58 // not because it shouldn't recognize them as built-ins.
59
60 #pragma GCC optimize "2"
61
62 size_t test_nonbuiltin_calls (char *s, int c)
63 {
64 void *null = 0;
65
66 char *r;
67 r = strchr ((char*)null, s);
68 r = strchr (r, (char*)null);
69 *s = *r; // use the result
70
71 size_t n = 0;
72 n += strftime (0, 0, 0, 0);
73 n += strlen ((const char**)null);
74 n += strnlen ((const char**)null, n);
75
76 return n;
77 }