11f5207b7SJohn Levon typedef unsigned int u32; 21f5207b7SJohn Levon typedef u32 __attribute__((bitwise)) __be32; 31f5207b7SJohn Levon 41f5207b7SJohn Levon /* Implicit casts of 0, legal */ foo(void)51f5207b7SJohn Levonstatic __be32 foo(void) 61f5207b7SJohn Levon { 71f5207b7SJohn Levon __be32 x = 0; 81f5207b7SJohn Levon 91f5207b7SJohn Levon return 0; 101f5207b7SJohn Levon } 111f5207b7SJohn Levon 121f5207b7SJohn Levon /* Explicit cast of 0, legal */ bar(void)131f5207b7SJohn Levonstatic __be32 bar(void) 141f5207b7SJohn Levon { 151f5207b7SJohn Levon return (__be32)0; 161f5207b7SJohn Levon } 171f5207b7SJohn Levon 181f5207b7SJohn Levon /* Implicit casts of nonzero, bad */ baz(void)191f5207b7SJohn Levonstatic __be32 baz(void) 201f5207b7SJohn Levon { 211f5207b7SJohn Levon __be32 x = 0x2a; 221f5207b7SJohn Levon 231f5207b7SJohn Levon return 99; 241f5207b7SJohn Levon } 251f5207b7SJohn Levon 261f5207b7SJohn Levon /* Explicit cast of nonzero, bad */ quux(void)271f5207b7SJohn Levonstatic __be32 quux(void) 281f5207b7SJohn Levon { 291f5207b7SJohn Levon return (__be32)1729; 301f5207b7SJohn Levon } 311f5207b7SJohn Levon 32*c85f09ccSJohn Levon /* Explicit case of nonzero forced, legal */ quuy(void)33*c85f09ccSJohn Levonstatic __be32 quuy(void) 34*c85f09ccSJohn Levon { 35*c85f09ccSJohn Levon return (__attribute__((force)) __be32) 1730; 36*c85f09ccSJohn Levon } 37*c85f09ccSJohn Levon 381f5207b7SJohn Levon /* 391f5207b7SJohn Levon * check-name: conversions to bitwise types 401f5207b7SJohn Levon * check-command: sparse -Wbitwise $file 411f5207b7SJohn Levon * check-error-start 421f5207b7SJohn Levon bitwise-cast.c:21:20: warning: incorrect type in initializer (different base types) 431f5207b7SJohn Levon bitwise-cast.c:21:20: expected restricted __be32 [usertype] x 441f5207b7SJohn Levon bitwise-cast.c:21:20: got int 451f5207b7SJohn Levon bitwise-cast.c:23:16: warning: incorrect type in return expression (different base types) 461f5207b7SJohn Levon bitwise-cast.c:23:16: expected restricted __be32 471f5207b7SJohn Levon bitwise-cast.c:23:16: got int 481f5207b7SJohn Levon bitwise-cast.c:29:17: warning: cast to restricted __be32 491f5207b7SJohn Levon * check-error-end 501f5207b7SJohn Levon */ 51