aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/Waddress.c
blob: 441cdb1cbcd6419646b21cdd4fe35c2e17de9ebd (plain)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
extern int fun(void);
extern int arr[];
extern int var;

int test_address(int arg, int ptr[])
{

	if (fun())	return -1;
	if (var)	return -1;
	if (arg)	return -1;
	if (ptr)	return -1;

lab:
	if (arr)	return 1;
	if (&arr)	return 1;
	if (fun)	return 1;
	if (&fun)	return 1;
	if (*fun)	return 1;
	if (&var)	return 1;
	if (&arg)	return 1;
	if (&&lab)	return 1;

	return -1;
}

int test_address_not(int arg, int ptr[])
{

	if (!fun())	return -1;
	if (!var)	return -1;
	if (!arg)	return -1;
	if (!ptr)	return -1;

lab:
	if (!arr)	return 0;
	if (!&arr)	return 0;
	if (!fun)	return 0;
	if (!&fun)	return 0;
	if (!*fun)	return 0;
	if (!&var)	return 0;
	if (!&arg)	return 0;
	if (!&&lab)	return 0;

	return -1;
}

int test_address_cmp(int arg, int ptr[])
{
	if (fun() == 0)	return -1;
	if (0 == fun())	return -1;
	if (var == 0)	return -1;
	if (0 == var)	return -1;
	if (arg == 0)	return -1;
	if (0 == arg)	return -1;
	if (ptr == 0)	return -1;
	if (0 == ptr)	return -1;

lab:
	if (arr == 0)	return 0;
	if (0 == arr)	return 0;
	if (&arr == 0)	return 0;
	if (0 == &arr)	return 0;
	if (fun == 0)	return 0;
	if (0 == fun)	return 0;
	if (&fun == 0)	return 0;
	if (0 == &fun)	return 0;
	if (*fun == 0)	return 0;
	if (0 == *fun)	return 0;
	if (&var == 0)	return 0;
	if (0 == &var)	return 0;
	if (&arg == 0)	return 0;
	if (0 == &arg)	return 0;
	if (&&lab == 0)	return 0;
	if (0 == &&lab)	return 0;

	return -1;
}

/*
 * check-name: Waddress
 * check-command: sparse -Wno-decl -Wno-non-pointer-null -Waddress $file
 * check-known-to-fail
 *
 * check-error-start
Waddress.c:14:13: warning: the address of an array will always evaluate as true
Waddress.c:15:14: warning: the address of an array will always evaluate as true
Waddress.c:16:13: warning: the address of a function will always evaluate as true
Waddress.c:17:14: warning: the address of a function will always evaluate as true
Waddress.c:18:13: warning: the address of a variable will always evaluate as true
Waddress.c:19:13: warning: the address of a variable will always evaluate as true
Waddress.c:20:13: warning: the address of a label will always evaluate as true
Waddress.c:34:13: warning: the address of an array will always evaluate as true
Waddress.c:35:13: warning: the address of an array will always evaluate as true
Waddress.c:36:13: warning: the address of a function will always evaluate as true
Waddress.c:37:13: warning: the address of a function will always evaluate as true
Waddress.c:38:13: warning: the address of a variable will always evaluate as true
Waddress.c:39:13: warning: the address of a variable will always evaluate as true
Waddress.c:40:13: warning: the address of a label will always evaluate as true
Waddress.c:57:13: warning: the address of an array will always evaluate as true
Waddress.c:58:13: warning: the address of an array will always evaluate as true
Waddress.c:59:13: warning: the address of an array will always evaluate as true
Waddress.c:60:13: warning: the address of an array will always evaluate as true
Waddress.c:61:13: warning: the address of a function will always evaluate as true
Waddress.c:62:13: warning: the address of a function will always evaluate as true
Waddress.c:63:13: warning: the address of a function will always evaluate as true
Waddress.c:64:13: warning: the address of a function will always evaluate as true
Waddress.c:65:13: warning: the address of a variable will always evaluate as true
Waddress.c:66:13: warning: the address of a variable will always evaluate as true
Waddress.c:67:13: warning: the address of a variable will always evaluate as true
Waddress.c:68:13: warning: the address of a variable will always evaluate as true
Waddress.c:69:13: warning: the address of a label will always evaluate as true
Waddress.c:70:13: warning: the address of a label will always evaluate as true
 * check-error-end
 */