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