@@ -18,8 +18,6 @@ static __be32 bar(void)
/* Implicit casts of nonzero, bad */
static __be32 baz(void)
{
- __be32 x = 0x2a;
-
return 99;
}
@@ -29,16 +27,46 @@ static __be32 quux(void)
return (__be32)1729;
}
+/* Explicit case of nonzero forced, legal */
+static __be32 quuy(void)
+{
+ return (__attribute__((force)) __be32) 1730;
+}
+
+static u32 global_i = 31337;
+
+/* Implicit cast of pointer, bad */
+static __be32* quuz(void)
+{
+ u32* x = &global_i;
+ return x;
+}
+
+/* Explicit cast of pointer, bad */
+static __be32* quva(void)
+{
+ u32* x = &global_i;
+ return (__be32 *) x;
+}
+
+/* Explicit cast of pointer forced, legal */
+static __be32* quvb(void)
+{
+ u32* x = &global_i;
+ return (__attribute__((force)) __be32 *) x;
+}
+
/*
* check-name: conversions to bitwise types
* check-command: sparse -Wbitwise $file
* check-error-start
-bitwise-cast.c:21:20: warning: incorrect type in initializer (different base types)
-bitwise-cast.c:21:20: expected restricted __be32 [usertype] x
-bitwise-cast.c:21:20: got int
-bitwise-cast.c:23:16: warning: incorrect type in return expression (different base types)
-bitwise-cast.c:23:16: expected restricted __be32
-bitwise-cast.c:23:16: got int
-bitwise-cast.c:29:17: warning: cast to restricted __be32
+bitwise-cast.c:22:16: warning: incorrect type in return expression (different base types)
+bitwise-cast.c:22:16: expected restricted __be32
+bitwise-cast.c:22:16: got int
+bitwise-cast.c:28:17: warning: cast to restricted __be32
+bitwise-cast.c:43:16: warning: incorrect type in return expression (different base types)
+bitwise-cast.c:43:16: expected restricted __be32 [usertype] *
+bitwise-cast.c:43:16: got unsigned int [usertype] *x
+bitwise-cast.c:50:17: warning: cast to restricted __be32 *
* check-error-end
*/
Signed-off-by: Thiebaud Weksteen <tweek@google.com> --- validation/bitwise-cast.c | 46 +++++++++++++++++++++++++++++++-------- 1 file changed, 37 insertions(+), 9 deletions(-)