Print this page
new smatch
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/tools/smatch/src/validation/nocast.c
+++ new/usr/src/tools/smatch/src/validation/nocast.c
1 1 #define __nocast __attribute__((nocast))
2 2 typedef unsigned long __nocast ulong_nc_t;
3 3
4 4 extern void use_val(ulong_nc_t);
5 5 extern void use_ptr(ulong_nc_t *);
6 6
7 7 /* use address */
8 8 static void good_use_address(void)
9 9 {
10 10 ulong_nc_t t;
11 11
12 12 use_ptr(&t);
13 13 }
14 14
15 15 static ulong_nc_t *good_ret_address(void)
16 16 {
17 17 static ulong_nc_t t;
18 18
19 19 return &t;
20 20 }
21 21
22 22 static ulong_nc_t good_deref(ulong_nc_t *t)
23 23 {
24 24 return *t;
25 25 }
26 26
27 27 /* assign value */
28 28 static ulong_nc_t t;
29 29 static ulong_nc_t good_assign_self = t;
30 30 static unsigned long good_assign_sametype = t;
31 31
32 32 /* assign pointer */
33 33 static ulong_nc_t *good_ptr = &t;
34 34 static ulong_nc_t *bad_ptr_to = 1UL;
35 35 static unsigned long *bad_ptr_from = &t;
36 36
37 37 /* arithmetic operation */
38 38 static ulong_nc_t good_arith(ulong_nc_t t, unsigned int n)
39 39 {
40 40 return t + n;
41 41 }
42 42
43 43 /* implicit cast to other types */
44 44 static unsigned long good_ret_samecast(ulong_nc_t t)
45 45 {
46 46 return t;
47 47 }
48 48 static unsigned long long bad_ret_biggercast(ulong_nc_t t)
49 49 {
50 50 return t;
51 51 }
52 52 static long bad_ret_signcast(ulong_nc_t t)
53 53 {
54 54 return t;
55 55 }
56 56 static short bad_ret_smallercast(ulong_nc_t t)
57 57 {
58 58 return t;
59 59 }
60 60
61 61 static void assign_val(ulong_nc_t t)
62 62 {
63 63 ulong_nc_t good_c = t;
64 64 unsigned long good_ul = t;
65 65 unsigned long long bad_ull = t;
66 66 long bad_l = t;
67 67 short bad_i = t;
68 68 }
69 69
70 70 static void assign_via_ptr(ulong_nc_t *t)
71 71 {
72 72 ulong_nc_t good_c = *t;
73 73 unsigned long good_ul = *t;
74 74 unsigned long long bad_ull = *t;
75 75 long bad_l = *t;
76 76 short bad_i = *t;
77 77 }
78 78
79 79 static void assign_ptr(ulong_nc_t *t)
80 80 {
81 81 ulong_nc_t *good_same_type = t;
82 82 unsigned long *bad_mod = t;
83 83 unsigned long long __nocast *bad_size = t;
84 84 short __nocast *bad_i = t;
85 85 long __nocast *bad_l = t;
86 86 }
87 87
88 88 /* implicit cast to nocast */
89 89 static void implicit_assign_to(void)
90 90 {
91 91 ulong_nc_t t;
92 92 unsigned long ul = 1;
93 93 unsigned short us = 1;
94 94 unsigned long long ull = 1;
95 95 long l = 1;
96 96
97 97 t = ul; /* implicit to nocast from same type: OK? */
98 98 t = us;
99 99 t = ull;
100 100 t = l;
101 101 }
102 102
103 103 static void bad_implicit_arg_to(void)
104 104 {
105 105 unsigned long ul = 1;
106 106 unsigned short us = 1;
107 107 unsigned long long ull = 1;
108 108 long l = 1;
109 109
110 110 use_val(ul); /* implicit to nocast from same type: OK? */
111 111 use_val(us);
112 112 use_val(ull);
113 113 use_val(l);
114 114 }
115 115
116 116 /* implicit cast from nocast */
117 117 static unsigned long good_implicit_ret_ul(ulong_nc_t t)
118 118 {
119 119 return t; /* implicit to nocast from same type: OK? */
120 120 }
121 121
122 122 static unsigned short bad_implicit_ret_us(ulong_nc_t t)
123 123 {
124 124 return t;
125 125 }
126 126
127 127 static unsigned long long bad_implicit_ret_ull(ulong_nc_t t)
128 128 {
129 129 return t;
130 130 }
131 131
132 132 static long bad_implicit_ret_l(ulong_nc_t t)
133 133 {
134 134 return t;
135 135 }
136 136
137 137 /* FIXME: explicit cast: should we complain? */
138 138 static ulong_nc_t good_samecast(ulong_nc_t v)
139 139 {
140 140 return (ulong_nc_t) v;
141 141 }
142 142
143 143 static ulong_nc_t bad_tocast(unsigned long v)
144 144 {
145 145 return (ulong_nc_t) v;
146 146 }
147 147
148 148 static unsigned long bad_fromcast(ulong_nc_t v)
149 149 {
150 150 return (unsigned long) v;
151 151 }
152 152
↓ open down ↓ |
152 lines elided |
↑ open up ↑ |
153 153 /*
154 154 * check-name: nocast.c
155 155 *
156 156 * check-error-start
157 157 nocast.c:34:33: warning: incorrect type in initializer (different base types)
158 158 nocast.c:34:33: expected unsigned long [nocast] [usertype] *static [toplevel] bad_ptr_to
159 159 nocast.c:34:33: got unsigned long
160 160 nocast.c:34:33: warning: implicit cast to nocast type
161 161 nocast.c:35:39: warning: incorrect type in initializer (different modifiers)
162 162 nocast.c:35:39: expected unsigned long *static [toplevel] bad_ptr_from
163 -nocast.c:35:39: got unsigned long [nocast] *<noident>
163 +nocast.c:35:39: got unsigned long [nocast] *
164 164 nocast.c:35:39: warning: implicit cast from nocast type
165 165 nocast.c:50:16: warning: implicit cast from nocast type
166 166 nocast.c:54:16: warning: implicit cast from nocast type
167 167 nocast.c:58:16: warning: implicit cast from nocast type
168 168 nocast.c:65:38: warning: implicit cast from nocast type
169 169 nocast.c:66:22: warning: implicit cast from nocast type
170 170 nocast.c:67:23: warning: implicit cast from nocast type
171 171 nocast.c:74:38: warning: implicit cast from nocast type
172 172 nocast.c:75:22: warning: implicit cast from nocast type
173 173 nocast.c:76:23: warning: implicit cast from nocast type
174 174 nocast.c:82:34: warning: incorrect type in initializer (different modifiers)
175 175 nocast.c:82:34: expected unsigned long *bad_mod
176 176 nocast.c:82:34: got unsigned long [nocast] [usertype] *t
177 177 nocast.c:82:34: warning: implicit cast from nocast type
178 178 nocast.c:83:49: warning: incorrect type in initializer (different type sizes)
179 179 nocast.c:83:49: expected unsigned long long [nocast] *bad_size
180 180 nocast.c:83:49: got unsigned long [nocast] [usertype] *t
181 181 nocast.c:83:49: warning: implicit cast to/from nocast type
182 182 nocast.c:84:33: warning: incorrect type in initializer (different type sizes)
183 183 nocast.c:84:33: expected short [nocast] *bad_i
184 184 nocast.c:84:33: got unsigned long [nocast] [usertype] *t
185 185 nocast.c:84:33: warning: implicit cast to/from nocast type
186 186 nocast.c:85:32: warning: implicit cast to/from nocast type
187 187 nocast.c:98:13: warning: implicit cast to nocast type
188 188 nocast.c:99:13: warning: implicit cast to nocast type
189 189 nocast.c:100:13: warning: implicit cast to nocast type
190 190 nocast.c:111:17: warning: implicit cast to nocast type
191 191 nocast.c:112:17: warning: implicit cast to nocast type
192 192 nocast.c:113:17: warning: implicit cast to nocast type
193 193 nocast.c:124:16: warning: implicit cast from nocast type
194 194 nocast.c:129:16: warning: implicit cast from nocast type
195 195 nocast.c:134:16: warning: implicit cast from nocast type
196 196 * check-error-end
197 197 */
↓ open down ↓ |
24 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX