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
*);
8 static void good_use_address(void)
15 static ulong_nc_t
*good_ret_address(void)
22 static ulong_nc_t
good_deref(ulong_nc_t
*t
)
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
)
43 /* implicit cast to other types */
44 static unsigned long good_ret_samecast(ulong_nc_t t
)
48 static unsigned long long bad_ret_biggercast(ulong_nc_t t
)
52 static long bad_ret_signcast(ulong_nc_t t
)
56 static short bad_ret_smallercast(ulong_nc_t 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
;
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
;
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)
93 unsigned short us
= 1;
94 unsigned long long ull
= 1;
97 t
= ul
; /* implicit to nocast from same type: OK? */
103 static void bad_implicit_arg_to(void)
105 unsigned long ul
= 1;
106 unsigned short us
= 1;
107 unsigned long long ull
= 1;
110 use_val(ul
); /* implicit to nocast from same type: OK? */
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
)
127 static unsigned long long bad_implicit_ret_ull(ulong_nc_t t
)
132 static long bad_implicit_ret_l(ulong_nc_t 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
;
153 static void assign_value(void)
155 ulong_nc_t good_assign_self
= t
;
156 unsigned long good_assign_sametype
= t
;
160 * check-name: nocast.c
163 nocast.c:34:33: warning: incorrect type in initializer (different base types)
164 nocast.c:34:33: expected unsigned long [nocast] [usertype] *static [toplevel] bad_ptr_to
165 nocast.c:34:33: got unsigned long
166 nocast.c:34:33: warning: implicit cast to nocast type
167 nocast.c:35:39: warning: incorrect type in initializer (different modifiers)
168 nocast.c:35:39: expected unsigned long *static [toplevel] bad_ptr_from
169 nocast.c:35:39: got unsigned long [nocast] *
170 nocast.c:35:39: warning: implicit cast from nocast type
171 nocast.c:50:16: warning: implicit cast from nocast type
172 nocast.c:54:16: warning: implicit cast from nocast type
173 nocast.c:58:16: warning: implicit cast from nocast type
174 nocast.c:65:38: warning: implicit cast from nocast type
175 nocast.c:66:22: warning: implicit cast from nocast type
176 nocast.c:67:23: warning: implicit cast from nocast type
177 nocast.c:74:38: warning: implicit cast from nocast type
178 nocast.c:75:22: warning: implicit cast from nocast type
179 nocast.c:76:23: warning: implicit cast from nocast type
180 nocast.c:82:34: warning: incorrect type in initializer (different modifiers)
181 nocast.c:82:34: expected unsigned long *bad_mod
182 nocast.c:82:34: got unsigned long [nocast] [usertype] *t
183 nocast.c:82:34: warning: implicit cast from nocast type
184 nocast.c:83:49: warning: incorrect type in initializer (different type sizes)
185 nocast.c:83:49: expected unsigned long long [nocast] *bad_size
186 nocast.c:83:49: got unsigned long [nocast] [usertype] *t
187 nocast.c:83:49: warning: implicit cast to/from nocast type
188 nocast.c:84:33: warning: incorrect type in initializer (different type sizes)
189 nocast.c:84:33: expected short [nocast] *bad_i
190 nocast.c:84:33: got unsigned long [nocast] [usertype] *t
191 nocast.c:84:33: warning: implicit cast to/from nocast type
192 nocast.c:85:32: warning: implicit cast to/from nocast type
193 nocast.c:98:13: warning: implicit cast to nocast type
194 nocast.c:99:13: warning: implicit cast to nocast type
195 nocast.c:100:13: warning: implicit cast to nocast type
196 nocast.c:111:17: warning: implicit cast to nocast type
197 nocast.c:112:17: warning: implicit cast to nocast type
198 nocast.c:113:17: warning: implicit cast to nocast type
199 nocast.c:124:16: warning: implicit cast from nocast type
200 nocast.c:129:16: warning: implicit cast from nocast type
201 nocast.c:134:16: warning: implicit cast from nocast type