Debian Codegraph @

gcc/testsuite/gcc.dg/Wbuiltin-declaration-mismatch-15.c

raw
1 /* PR c/94040 - ICE on a call to an invalid redeclaration of strftime
2 { dg-do compile }
3 { dg-options "-Wall -Wextra" } */
4
5 typedef __SIZE_TYPE__ size_t;
6
7 struct tm;
8
9 size_t strftime (const char *, size_t, char *, struct tm *);
10 // { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
11
12 // Verify that missing/extra qualifiers are diagnosed with -Wextra.
13
14 int strcmp (char*, const char*);
15 // { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
16
17 int strncmp (const char*, volatile char*, size_t);
18 // { dg-warning "-Wbuiltin-declaration-mismatch" "arg 2" { target *-*-* } .-1 }
19
20 size_t strlen (char*);
21 // { dg-warning "-Wbuiltin-declaration-mismatch" "arg 1" { target *-*-* } .-1 }
22
23
24 // Verify that calls to built-ins declared with missing/extra qualifiers
25 // are still treated as those to built-ins by the front-end.
26
27 int test_builtin_calls_fe (size_t n)
28 {
29 int r = 0;
30 r += strcmp ((char*)0, ""); // { dg-warning "\\\[-Wnonnull]" }
31 r += strcmp ("", (char*)0); // { dg-warning "\\\[-Wnonnull]" }
32
33 r += strncmp ((char*)0, "", 1); // { dg-warning "\\\[-Wnonnull]" }
34 r += strncmp ("", (char*)0, 1); // { dg-warning "\\\[-Wnonnull]" }
35
36 r += strncmp ((char*)0, "", n);
37 r += strncmp ("", (char*)0, n);
38
39 r += strncmp ((char*)0, "", 0);
40 r += strncmp ("", (char*)0, 0);
41
42 r += strlen ((char*)0); // { dg-warning "\\\[-Wnonnull]" }
43 return r;
44 }
45
46
47 // Ditto but by the middle-end.
48
49 #pragma GCC optimize "2"
50
51 int test_builtin_calls_me (void)
52 {
53 char *null1 = 0;
54 char *null2 = null1;
55 char *null3 = null2;
56
57 int r = 0;
58 r += strcmp (null1, "123"); // { dg-warning "\\\[-Wnonnull]" }
59 r += strncmp ("2345", null2, 4); // { dg-warning "\\\[-Wnonnull]" }
60 r += strlen (null3); // { dg-warning "\\\[-Wnonnull]" }
61 return r;
62 }