[PATCH 1/3] union-cast: add some testcases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Casts to union type are a GCC extension and are similar to
compound literals.

However, sparse doesn't know about them and treats them like
other casts to non-scalars.

Add some testcases for this and its upcoming warning flag.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx>
---
 validation/eval/union-cast-no.c | 24 ++++++++++++++++++++++++
 validation/eval/union-cast.c    | 25 +++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/validation/eval/union-cast-no.c b/validation/eval/union-cast-no.c
new file mode 100644
index 000000000000..d06b348d209e
--- /dev/null
+++ b/validation/eval/union-cast-no.c
@@ -0,0 +1,24 @@
+union u {
+	int	i;
+	char	x[8];
+};
+
+static union u foo(int i)
+{
+	return (union u)i;
+}
+
+static union u bar(long l)
+{
+	return (union u)l;
+}
+
+/*
+ * check-name: union-cast-no
+ * check-command: sparse -Wno-union-cast $file
+ * check-known-to-fail
+ *
+ * check-error-start
+eval/union-cast-no.c:13:17: warning: cast to non-scalar
+ * check-error-end
+ */
diff --git a/validation/eval/union-cast.c b/validation/eval/union-cast.c
new file mode 100644
index 000000000000..1d8167531081
--- /dev/null
+++ b/validation/eval/union-cast.c
@@ -0,0 +1,25 @@
+union u {
+	int	i;
+	char	x[8];
+};
+
+static union u foo(int a)
+{
+	return (union u)a;
+}
+
+static union u bar(long a)
+{
+	return (union u)a;
+}
+
+/*
+ * check-name: union-cast
+ * check-command: sparse -Wunion-cast $file
+ * check-known-to-fail
+ *
+ * check-error-start
+eval/union-cast.c:8:17: warning: cast to union type
+eval/union-cast.c:13:17: warning: cast to non-scalar
+ * check-error-end
+ */
-- 
2.28.0




[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux