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