summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorThiebaud Weksteen <tweek@google.com>2018-04-25 14:02:17 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2018-12-17 23:19:34 +0100
commit45503a2bb1cbd400fe5aa01041cae3bf484b205b (patch)
tree19dd17daac551191ddbb7801ff39eb371332df4a
parent55324619d9fd35355629870b8d441eeb074e6739 (diff)
downloadsparse-45503a2bb1cbd400fe5aa01041cae3bf484b205b.tar.gz
Add testcases for bitwise cast on pointer
since it seems that the strict type checking is not done on pointers to restricted types. Signed-off-by: Thiebaud Weksteen <tweek@google.com> Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--validation/bitwise-cast-ptr.c34
-rw-r--r--validation/bitwise-cast.c6
2 files changed, 40 insertions, 0 deletions
diff --git a/validation/bitwise-cast-ptr.c b/validation/bitwise-cast-ptr.c
new file mode 100644
index 00000000..acf0ac35
--- /dev/null
+++ b/validation/bitwise-cast-ptr.c
@@ -0,0 +1,34 @@
+#define __bitwise __attribute__((bitwise))
+#define __force __attribute__((force))
+
+typedef unsigned int u32;
+typedef unsigned int __bitwise __be32;
+
+static __be32* tobi(u32 *x)
+{
+ return x; // should warn, implicit cast
+}
+
+static __be32* tobe(u32 *x)
+{
+ return (__be32 *) x; // should warn, explicit cast
+}
+
+static __be32* tobf(u32 *x)
+{
+ return (__force __be32 *) x; // should not warn, forced cast
+ return (__be32 __force *) x; // should not warn, forced cast
+}
+
+/*
+ * check-name: cast of bitwise pointers
+ * check-command: sparse -Wbitwise $file
+ * check-known-to-fail
+ *
+ * check-error-start
+bitwise-cast-ptr.c:9:16: warning: incorrect type in return expression (different base types)
+bitwise-cast-ptr.c:9:16: expected restricted __be32 [usertype] *
+bitwise-cast-ptr.c:9:16: got unsigned int [usertype] *x
+bitwise-cast-ptr.c:14:17: warning: cast to restricted __be32 [usertype] *<noident>
+ * check-error-end
+ */
diff --git a/validation/bitwise-cast.c b/validation/bitwise-cast.c
index baeca29e..0583461c 100644
--- a/validation/bitwise-cast.c
+++ b/validation/bitwise-cast.c
@@ -29,6 +29,12 @@ static __be32 quux(void)
return (__be32)1729;
}
+/* Explicit case of nonzero forced, legal */
+static __be32 quuy(void)
+{
+ return (__attribute__((force)) __be32) 1730;
+}
+
/*
* check-name: conversions to bitwise types
* check-command: sparse -Wbitwise $file