11f5207b7SJohn Levon #define __nocast __attribute__((nocast)) 21f5207b7SJohn Levon typedef unsigned long __nocast ulong_nc_t; 31f5207b7SJohn Levon 41f5207b7SJohn Levon extern void use_val(ulong_nc_t); 51f5207b7SJohn Levon extern void use_ptr(ulong_nc_t *); 61f5207b7SJohn Levon 71f5207b7SJohn Levon /* use address */ good_use_address(void)81f5207b7SJohn Levonstatic void good_use_address(void) 91f5207b7SJohn Levon { 101f5207b7SJohn Levon ulong_nc_t t; 111f5207b7SJohn Levon 121f5207b7SJohn Levon use_ptr(&t); 131f5207b7SJohn Levon } 141f5207b7SJohn Levon good_ret_address(void)151f5207b7SJohn Levonstatic ulong_nc_t *good_ret_address(void) 161f5207b7SJohn Levon { 171f5207b7SJohn Levon static ulong_nc_t t; 181f5207b7SJohn Levon 191f5207b7SJohn Levon return &t; 201f5207b7SJohn Levon } 211f5207b7SJohn Levon good_deref(ulong_nc_t * t)221f5207b7SJohn Levonstatic ulong_nc_t good_deref(ulong_nc_t *t) 231f5207b7SJohn Levon { 241f5207b7SJohn Levon return *t; 251f5207b7SJohn Levon } 261f5207b7SJohn Levon 271f5207b7SJohn Levon /* assign value */ 281f5207b7SJohn Levon static ulong_nc_t t; 291f5207b7SJohn Levon static ulong_nc_t good_assign_self = t; 301f5207b7SJohn Levon static unsigned long good_assign_sametype = t; 311f5207b7SJohn Levon 321f5207b7SJohn Levon /* assign pointer */ 331f5207b7SJohn Levon static ulong_nc_t *good_ptr = &t; 341f5207b7SJohn Levon static ulong_nc_t *bad_ptr_to = 1UL; 351f5207b7SJohn Levon static unsigned long *bad_ptr_from = &t; 361f5207b7SJohn Levon 371f5207b7SJohn Levon /* arithmetic operation */ good_arith(ulong_nc_t t,unsigned int n)381f5207b7SJohn Levonstatic ulong_nc_t good_arith(ulong_nc_t t, unsigned int n) 391f5207b7SJohn Levon { 401f5207b7SJohn Levon return t + n; 411f5207b7SJohn Levon } 421f5207b7SJohn Levon 431f5207b7SJohn Levon /* implicit cast to other types */ good_ret_samecast(ulong_nc_t t)441f5207b7SJohn Levonstatic unsigned long good_ret_samecast(ulong_nc_t t) 451f5207b7SJohn Levon { 461f5207b7SJohn Levon return t; 471f5207b7SJohn Levon } bad_ret_biggercast(ulong_nc_t t)481f5207b7SJohn Levonstatic unsigned long long bad_ret_biggercast(ulong_nc_t t) 491f5207b7SJohn Levon { 501f5207b7SJohn Levon return t; 511f5207b7SJohn Levon } bad_ret_signcast(ulong_nc_t t)521f5207b7SJohn Levonstatic long bad_ret_signcast(ulong_nc_t t) 531f5207b7SJohn Levon { 541f5207b7SJohn Levon return t; 551f5207b7SJohn Levon } bad_ret_smallercast(ulong_nc_t t)561f5207b7SJohn Levonstatic short bad_ret_smallercast(ulong_nc_t t) 571f5207b7SJohn Levon { 581f5207b7SJohn Levon return t; 591f5207b7SJohn Levon } 601f5207b7SJohn Levon assign_val(ulong_nc_t t)611f5207b7SJohn Levonstatic void assign_val(ulong_nc_t t) 621f5207b7SJohn Levon { 631f5207b7SJohn Levon ulong_nc_t good_c = t; 641f5207b7SJohn Levon unsigned long good_ul = t; 651f5207b7SJohn Levon unsigned long long bad_ull = t; 661f5207b7SJohn Levon long bad_l = t; 671f5207b7SJohn Levon short bad_i = t; 681f5207b7SJohn Levon } 691f5207b7SJohn Levon assign_via_ptr(ulong_nc_t * t)701f5207b7SJohn Levonstatic void assign_via_ptr(ulong_nc_t *t) 711f5207b7SJohn Levon { 721f5207b7SJohn Levon ulong_nc_t good_c = *t; 731f5207b7SJohn Levon unsigned long good_ul = *t; 741f5207b7SJohn Levon unsigned long long bad_ull = *t; 751f5207b7SJohn Levon long bad_l = *t; 761f5207b7SJohn Levon short bad_i = *t; 771f5207b7SJohn Levon } 781f5207b7SJohn Levon assign_ptr(ulong_nc_t * t)791f5207b7SJohn Levonstatic void assign_ptr(ulong_nc_t *t) 801f5207b7SJohn Levon { 811f5207b7SJohn Levon ulong_nc_t *good_same_type = t; 821f5207b7SJohn Levon unsigned long *bad_mod = t; 831f5207b7SJohn Levon unsigned long long __nocast *bad_size = t; 841f5207b7SJohn Levon short __nocast *bad_i = t; 851f5207b7SJohn Levon long __nocast *bad_l = t; 861f5207b7SJohn Levon } 871f5207b7SJohn Levon 881f5207b7SJohn Levon /* implicit cast to nocast */ implicit_assign_to(void)891f5207b7SJohn Levonstatic void implicit_assign_to(void) 901f5207b7SJohn Levon { 911f5207b7SJohn Levon ulong_nc_t t; 921f5207b7SJohn Levon unsigned long ul = 1; 931f5207b7SJohn Levon unsigned short us = 1; 941f5207b7SJohn Levon unsigned long long ull = 1; 951f5207b7SJohn Levon long l = 1; 961f5207b7SJohn Levon 971f5207b7SJohn Levon t = ul; /* implicit to nocast from same type: OK? */ 981f5207b7SJohn Levon t = us; 991f5207b7SJohn Levon t = ull; 1001f5207b7SJohn Levon t = l; 1011f5207b7SJohn Levon } 1021f5207b7SJohn Levon bad_implicit_arg_to(void)1031f5207b7SJohn Levonstatic void bad_implicit_arg_to(void) 1041f5207b7SJohn Levon { 1051f5207b7SJohn Levon unsigned long ul = 1; 1061f5207b7SJohn Levon unsigned short us = 1; 1071f5207b7SJohn Levon unsigned long long ull = 1; 1081f5207b7SJohn Levon long l = 1; 1091f5207b7SJohn Levon 1101f5207b7SJohn Levon use_val(ul); /* implicit to nocast from same type: OK? */ 1111f5207b7SJohn Levon use_val(us); 1121f5207b7SJohn Levon use_val(ull); 1131f5207b7SJohn Levon use_val(l); 1141f5207b7SJohn Levon } 1151f5207b7SJohn Levon 1161f5207b7SJohn Levon /* implicit cast from nocast */ good_implicit_ret_ul(ulong_nc_t t)1171f5207b7SJohn Levonstatic unsigned long good_implicit_ret_ul(ulong_nc_t t) 1181f5207b7SJohn Levon { 1191f5207b7SJohn Levon return t; /* implicit to nocast from same type: OK? */ 1201f5207b7SJohn Levon } 1211f5207b7SJohn Levon bad_implicit_ret_us(ulong_nc_t t)1221f5207b7SJohn Levonstatic unsigned short bad_implicit_ret_us(ulong_nc_t t) 1231f5207b7SJohn Levon { 1241f5207b7SJohn Levon return t; 1251f5207b7SJohn Levon } 1261f5207b7SJohn Levon bad_implicit_ret_ull(ulong_nc_t t)1271f5207b7SJohn Levonstatic unsigned long long bad_implicit_ret_ull(ulong_nc_t t) 1281f5207b7SJohn Levon { 1291f5207b7SJohn Levon return t; 1301f5207b7SJohn Levon } 1311f5207b7SJohn Levon bad_implicit_ret_l(ulong_nc_t t)1321f5207b7SJohn Levonstatic long bad_implicit_ret_l(ulong_nc_t t) 1331f5207b7SJohn Levon { 1341f5207b7SJohn Levon return t; 1351f5207b7SJohn Levon } 1361f5207b7SJohn Levon 1371f5207b7SJohn Levon /* FIXME: explicit cast: should we complain? */ good_samecast(ulong_nc_t v)1381f5207b7SJohn Levonstatic ulong_nc_t good_samecast(ulong_nc_t v) 1391f5207b7SJohn Levon { 1401f5207b7SJohn Levon return (ulong_nc_t) v; 1411f5207b7SJohn Levon } 1421f5207b7SJohn Levon bad_tocast(unsigned long v)1431f5207b7SJohn Levonstatic ulong_nc_t bad_tocast(unsigned long v) 1441f5207b7SJohn Levon { 1451f5207b7SJohn Levon return (ulong_nc_t) v; 1461f5207b7SJohn Levon } 1471f5207b7SJohn Levon bad_fromcast(ulong_nc_t v)1481f5207b7SJohn Levonstatic unsigned long bad_fromcast(ulong_nc_t v) 1491f5207b7SJohn Levon { 1501f5207b7SJohn Levon return (unsigned long) v; 1511f5207b7SJohn Levon } 1521f5207b7SJohn Levon 1531f5207b7SJohn Levon /* 1541f5207b7SJohn Levon * check-name: nocast.c 1551f5207b7SJohn Levon * 1561f5207b7SJohn Levon * check-error-start 1571f5207b7SJohn Levon nocast.c:34:33: warning: incorrect type in initializer (different base types) 1581f5207b7SJohn Levon nocast.c:34:33: expected unsigned long [nocast] [usertype] *static [toplevel] bad_ptr_to 1591f5207b7SJohn Levon nocast.c:34:33: got unsigned long 1601f5207b7SJohn Levon nocast.c:34:33: warning: implicit cast to nocast type 1611f5207b7SJohn Levon nocast.c:35:39: warning: incorrect type in initializer (different modifiers) 1621f5207b7SJohn Levon nocast.c:35:39: expected unsigned long *static [toplevel] bad_ptr_from 163*c85f09ccSJohn Levon nocast.c:35:39: got unsigned long [nocast] * 1641f5207b7SJohn Levon nocast.c:35:39: warning: implicit cast from nocast type 1651f5207b7SJohn Levon nocast.c:50:16: warning: implicit cast from nocast type 1661f5207b7SJohn Levon nocast.c:54:16: warning: implicit cast from nocast type 1671f5207b7SJohn Levon nocast.c:58:16: warning: implicit cast from nocast type 1681f5207b7SJohn Levon nocast.c:65:38: warning: implicit cast from nocast type 1691f5207b7SJohn Levon nocast.c:66:22: warning: implicit cast from nocast type 1701f5207b7SJohn Levon nocast.c:67:23: warning: implicit cast from nocast type 1711f5207b7SJohn Levon nocast.c:74:38: warning: implicit cast from nocast type 1721f5207b7SJohn Levon nocast.c:75:22: warning: implicit cast from nocast type 1731f5207b7SJohn Levon nocast.c:76:23: warning: implicit cast from nocast type 1741f5207b7SJohn Levon nocast.c:82:34: warning: incorrect type in initializer (different modifiers) 1751f5207b7SJohn Levon nocast.c:82:34: expected unsigned long *bad_mod 1761f5207b7SJohn Levon nocast.c:82:34: got unsigned long [nocast] [usertype] *t 1771f5207b7SJohn Levon nocast.c:82:34: warning: implicit cast from nocast type 1781f5207b7SJohn Levon nocast.c:83:49: warning: incorrect type in initializer (different type sizes) 1791f5207b7SJohn Levon nocast.c:83:49: expected unsigned long long [nocast] *bad_size 1801f5207b7SJohn Levon nocast.c:83:49: got unsigned long [nocast] [usertype] *t 1811f5207b7SJohn Levon nocast.c:83:49: warning: implicit cast to/from nocast type 1821f5207b7SJohn Levon nocast.c:84:33: warning: incorrect type in initializer (different type sizes) 1831f5207b7SJohn Levon nocast.c:84:33: expected short [nocast] *bad_i 1841f5207b7SJohn Levon nocast.c:84:33: got unsigned long [nocast] [usertype] *t 1851f5207b7SJohn Levon nocast.c:84:33: warning: implicit cast to/from nocast type 1861f5207b7SJohn Levon nocast.c:85:32: warning: implicit cast to/from nocast type 1871f5207b7SJohn Levon nocast.c:98:13: warning: implicit cast to nocast type 1881f5207b7SJohn Levon nocast.c:99:13: warning: implicit cast to nocast type 1891f5207b7SJohn Levon nocast.c:100:13: warning: implicit cast to nocast type 1901f5207b7SJohn Levon nocast.c:111:17: warning: implicit cast to nocast type 1911f5207b7SJohn Levon nocast.c:112:17: warning: implicit cast to nocast type 1921f5207b7SJohn Levon nocast.c:113:17: warning: implicit cast to nocast type 1931f5207b7SJohn Levon nocast.c:124:16: warning: implicit cast from nocast type 1941f5207b7SJohn Levon nocast.c:129:16: warning: implicit cast from nocast type 1951f5207b7SJohn Levon nocast.c:134:16: warning: implicit cast from nocast type 1961f5207b7SJohn Levon * check-error-end 1971f5207b7SJohn Levon */ 198