aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-18 22:00:41 +0200
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-08-18 22:00:41 +0200
commit101649206777f00be5c23f60f87f01066ad64ece (patch)
treec1f17a02ef5823f9af19f4f7a9735930716a4dbe /validation
parentad7af4347d271874378a7d826a91fd05e41d4051 (diff)
parent8b3cbf54ad42c68f5ea2fa5bc2cef5ce9e608571 (diff)
downloadsparse-dev-101649206777f00be5c23f60f87f01066ad64ece.tar.gz
Merge branch 'union-cast' into master
* teach sparse about union casts
Diffstat (limited to 'validation')
-rw-r--r--validation/eval/union-cast-no.c23
-rw-r--r--validation/eval/union-cast.c24
2 files changed, 47 insertions, 0 deletions
diff --git a/validation/eval/union-cast-no.c b/validation/eval/union-cast-no.c
new file mode 100644
index 00000000..6ba38db8
--- /dev/null
+++ b/validation/eval/union-cast-no.c
@@ -0,0 +1,23 @@
+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-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 00000000..5bee9e0d
--- /dev/null
+++ b/validation/eval/union-cast.c
@@ -0,0 +1,24 @@
+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-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
+ */