1*1f5207b7SJohn Levon typedef unsigned int __attribute__((bitwise)) large_t; 2*1f5207b7SJohn Levon #define LBIT ((__attribute__((force)) large_t) 1) 3*1f5207b7SJohn Levon lfoo(large_t x)4*1f5207b7SJohn Levon_Bool lfoo(large_t x) { return x; } qfoo(large_t x)5*1f5207b7SJohn Levon_Bool qfoo(large_t x) { _Bool r = x; return r; } xfoo(large_t x)6*1f5207b7SJohn Levon_Bool xfoo(large_t x) { return (_Bool)x; } lbar(large_t x)7*1f5207b7SJohn Levon_Bool lbar(large_t x) { return ~x; } qbar(large_t x)8*1f5207b7SJohn Levon_Bool qbar(large_t x) { _Bool r = ~x; return r; } xbar(large_t x)9*1f5207b7SJohn Levon_Bool xbar(large_t x) { return (_Bool)~x; } lbaz(large_t x)10*1f5207b7SJohn Levon_Bool lbaz(large_t x) { return !x; } qbaz(large_t x)11*1f5207b7SJohn Levon_Bool qbaz(large_t x) { _Bool r = !x; return r; } xbaz(large_t x)12*1f5207b7SJohn Levon_Bool xbaz(large_t x) { return (_Bool)!x; } lqux(large_t x)13*1f5207b7SJohn Levon_Bool lqux(large_t x) { return x & LBIT; } qqux(large_t x)14*1f5207b7SJohn Levon_Bool qqux(large_t x) { _Bool r = x & LBIT; return r; } xqux(large_t x)15*1f5207b7SJohn Levon_Bool xqux(large_t x) { return (_Bool)(x & LBIT); } 16*1f5207b7SJohn Levon 17*1f5207b7SJohn Levon 18*1f5207b7SJohn Levon typedef unsigned short __attribute__((bitwise)) small_t; 19*1f5207b7SJohn Levon #define SBIT ((__attribute__((force)) small_t) 1) 20*1f5207b7SJohn Levon sfoo(small_t x)21*1f5207b7SJohn Levon_Bool sfoo(small_t x) { return x; } tfoo(small_t x)22*1f5207b7SJohn Levon_Bool tfoo(small_t x) { _Bool r = x; return r; } zfoo(small_t x)23*1f5207b7SJohn Levon_Bool zfoo(small_t x) { return (_Bool)x; } sbar(small_t x)24*1f5207b7SJohn Levon_Bool sbar(small_t x) { return ~x; } tbar(small_t x)25*1f5207b7SJohn Levon_Bool tbar(small_t x) { _Bool r = ~x; return r; } zbar(small_t x)26*1f5207b7SJohn Levon_Bool zbar(small_t x) { return (_Bool)~x; } sbaz(small_t x)27*1f5207b7SJohn Levon_Bool sbaz(small_t x) { return !x; } tbaz(small_t x)28*1f5207b7SJohn Levon_Bool tbaz(small_t x) { _Bool r = !x; return r; } zbaz(small_t x)29*1f5207b7SJohn Levon_Bool zbaz(small_t x) { return (_Bool)!x; } squx(small_t x)30*1f5207b7SJohn Levon_Bool squx(small_t x) { return x & SBIT; } tqux(small_t x)31*1f5207b7SJohn Levon_Bool tqux(small_t x) { _Bool r = x & SBIT; return r; } zqux(small_t x)32*1f5207b7SJohn Levon_Bool zqux(small_t x) { return (_Bool)(x & SBIT); } 33*1f5207b7SJohn Levon 34*1f5207b7SJohn Levon /* 35*1f5207b7SJohn Levon * check-name: bool-cast-restricted.c 36*1f5207b7SJohn Levon * check-command: sparse -Wno-decl $file 37*1f5207b7SJohn Levon * 38*1f5207b7SJohn Levon * check-error-start 39*1f5207b7SJohn Levon bool-cast-restricted.c:24:32: warning: restricted small_t degrades to integer 40*1f5207b7SJohn Levon bool-cast-restricted.c:25:35: warning: restricted small_t degrades to integer 41*1f5207b7SJohn Levon bool-cast-restricted.c:26:33: warning: restricted small_t degrades to integer 42*1f5207b7SJohn Levon * check-error-end 43*1f5207b7SJohn Levon */ 44