expressions: make assign_expression() take an op argument
[smatch.git] / validation / nocast.c
blobcc0ab6b7c0c77dec5ef03eaf4bd6597d242b2f8d
1 #define __nocast __attribute__((nocast))
2 typedef unsigned long __nocast ulong_nc_t;
4 extern void use_val(ulong_nc_t);
5 extern void use_ptr(ulong_nc_t *);
7 /* use address */
8 static void good_use_address(void)
10 ulong_nc_t t;
12 use_ptr(&t);
15 static ulong_nc_t *good_ret_address(void)
17 static ulong_nc_t t;
19 return &t;
22 static ulong_nc_t good_deref(ulong_nc_t *t)
24 return *t;
27 /* assign value */
28 static ulong_nc_t t;
29 static ulong_nc_t good_assign_self = t;
30 static unsigned long good_assign_sametype = t;
32 /* assign pointer */
33 static ulong_nc_t *good_ptr = &t;
34 static ulong_nc_t *bad_ptr_to = 1UL;
35 static unsigned long *bad_ptr_from = &t;
37 /* arithmetic operation */
38 static ulong_nc_t good_arith(ulong_nc_t t, unsigned int n)
40 return t + n;
43 /* implicit cast to other types */
44 static unsigned long good_ret_samecast(ulong_nc_t t)
46 return t;
48 static unsigned long long bad_ret_biggercast(ulong_nc_t t)
50 return t;
52 static long bad_ret_signcast(ulong_nc_t t)
54 return t;
56 static short bad_ret_smallercast(ulong_nc_t t)
58 return t;
61 static void assign_val(ulong_nc_t t)
63 ulong_nc_t good_c = t;
64 unsigned long good_ul = t;
65 unsigned long long bad_ull = t;
66 long bad_l = t;
67 short bad_i = t;
70 static void assign_via_ptr(ulong_nc_t *t)
72 ulong_nc_t good_c = *t;
73 unsigned long good_ul = *t;
74 unsigned long long bad_ull = *t;
75 long bad_l = *t;
76 short bad_i = *t;
79 static void assign_ptr(ulong_nc_t *t)
81 ulong_nc_t *good_same_type = t;
82 unsigned long *bad_mod = t;
83 unsigned long long __nocast *bad_size = t;
84 short __nocast *bad_i = t;
85 long __nocast *bad_l = t;
88 /* implicit cast to nocast */
89 static void implicit_assign_to(void)
91 ulong_nc_t t;
92 unsigned long ul = 1;
93 unsigned short us = 1;
94 unsigned long long ull = 1;
95 long l = 1;
97 t = ul; /* implicit to nocast from same type: OK? */
98 t = us;
99 t = ull;
100 t = l;
103 static void bad_implicit_arg_to(void)
105 unsigned long ul = 1;
106 unsigned short us = 1;
107 unsigned long long ull = 1;
108 long l = 1;
110 use_val(ul); /* implicit to nocast from same type: OK? */
111 use_val(us);
112 use_val(ull);
113 use_val(l);
116 /* implicit cast from nocast */
117 static unsigned long good_implicit_ret_ul(ulong_nc_t t)
119 return t; /* implicit to nocast from same type: OK? */
122 static unsigned short bad_implicit_ret_us(ulong_nc_t t)
124 return t;
127 static unsigned long long bad_implicit_ret_ull(ulong_nc_t t)
129 return t;
132 static long bad_implicit_ret_l(ulong_nc_t t)
134 return t;
137 /* FIXME: explicit cast: should we complain? */
138 static ulong_nc_t good_samecast(ulong_nc_t v)
140 return (ulong_nc_t) v;
143 static ulong_nc_t bad_tocast(unsigned long v)
145 return (ulong_nc_t) v;
148 static unsigned long bad_fromcast(ulong_nc_t v)
150 return (unsigned long) v;
154 * check-name: nocast.c
156 * check-error-start
157 nocast.c:34:33: warning: incorrect type in initializer (different base types)
158 nocast.c:34:33: expected unsigned long [nocast] [usertype] *static [toplevel] bad_ptr_to
159 nocast.c:34:33: got unsigned long
160 nocast.c:34:33: warning: implicit cast to nocast type
161 nocast.c:35:39: warning: incorrect type in initializer (different modifiers)
162 nocast.c:35:39: expected unsigned long *static [toplevel] bad_ptr_from
163 nocast.c:35:39: got unsigned long [nocast] *<noident>
164 nocast.c:35:39: warning: implicit cast from nocast type
165 nocast.c:50:16: warning: implicit cast from nocast type
166 nocast.c:54:16: warning: implicit cast from nocast type
167 nocast.c:58:16: warning: implicit cast from nocast type
168 nocast.c:65:38: warning: implicit cast from nocast type
169 nocast.c:66:22: warning: implicit cast from nocast type
170 nocast.c:67:23: warning: implicit cast from nocast type
171 nocast.c:74:38: warning: implicit cast from nocast type
172 nocast.c:75:22: warning: implicit cast from nocast type
173 nocast.c:76:23: warning: implicit cast from nocast type
174 nocast.c:82:34: warning: incorrect type in initializer (different modifiers)
175 nocast.c:82:34: expected unsigned long *bad_mod
176 nocast.c:82:34: got unsigned long [nocast] [usertype] *t
177 nocast.c:82:34: warning: implicit cast from nocast type
178 nocast.c:83:49: warning: incorrect type in initializer (different type sizes)
179 nocast.c:83:49: expected unsigned long long [nocast] *bad_size
180 nocast.c:83:49: got unsigned long [nocast] [usertype] *t
181 nocast.c:83:49: warning: implicit cast to/from nocast type
182 nocast.c:84:33: warning: incorrect type in initializer (different type sizes)
183 nocast.c:84:33: expected short [nocast] *bad_i
184 nocast.c:84:33: got unsigned long [nocast] [usertype] *t
185 nocast.c:84:33: warning: implicit cast to/from nocast type
186 nocast.c:85:32: warning: implicit cast to/from nocast type
187 nocast.c:98:13: warning: implicit cast to nocast type
188 nocast.c:99:13: warning: implicit cast to nocast type
189 nocast.c:100:13: warning: implicit cast to nocast type
190 nocast.c:111:17: warning: implicit cast to nocast type
191 nocast.c:112:17: warning: implicit cast to nocast type
192 nocast.c:113:17: warning: implicit cast to nocast type
193 nocast.c:124:16: warning: implicit cast from nocast type
194 nocast.c:129:16: warning: implicit cast from nocast type
195 nocast.c:134:16: warning: implicit cast from nocast type
196 * check-error-end