aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-18 20:18:45 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2020-11-18 21:57:55 +0100
commitd1351f69d73dc44529c03edaa9557f3318b0212c (patch)
tree7b602a9e379b14712eab5811478a52bac79ed813
parent626c474204e8262467a316099b6074cab964237c (diff)
downloadsparse-d1351f69d73dc44529c03edaa9557f3318b0212c.tar.gz
unqual: add testcases
Add some testcases related to qualifier dropping / lvalue conversion. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
-rw-r--r--validation/eval/unqual-comma.c13
-rw-r--r--validation/eval/unqual-postop.c23
-rw-r--r--validation/eval/unqual-stmt-expr.c13
-rw-r--r--validation/eval/unqual02.c26
4 files changed, 75 insertions, 0 deletions
diff --git a/validation/eval/unqual-comma.c b/validation/eval/unqual-comma.c
new file mode 100644
index 00000000..e06586cd
--- /dev/null
+++ b/validation/eval/unqual-comma.c
@@ -0,0 +1,13 @@
+#define __unqual_typeof(x) typeof(((void)0, (x)))
+
+int *foo(volatile int x);
+int *foo(volatile int x)
+{
+ extern __unqual_typeof(x) y;
+ return &y;
+}
+
+/*
+ * check-name: unqual-comma
+ * check-known-to-fail
+ */
diff --git a/validation/eval/unqual-postop.c b/validation/eval/unqual-postop.c
new file mode 100644
index 00000000..fb3082dc
--- /dev/null
+++ b/validation/eval/unqual-postop.c
@@ -0,0 +1,23 @@
+static void test_volatile(void)
+{
+ volatile int x = 0;
+ int *pp;
+
+ typeof(++x) v1; pp = &v1; // KO
+ typeof(x++) v2; pp = &v2; // KO
+}
+
+/*
+ * check-name: unqual-postop
+ * check-command: sparse -Wno-declaration-after-statement $file
+ * check-known-to-fail
+ *
+ * check-error-start
+eval/unqual-postop.c:6:40: warning: incorrect type in assignment (different modifiers)
+eval/unqual-postop.c:6:40: expected int *pp
+eval/unqual-postop.c:6:40: got int volatile *
+eval/unqual-postop.c:7:40: warning: incorrect type in assignment (different modifiers)
+eval/unqual-postop.c:7:40: expected int *pp
+eval/unqual-postop.c:7:40: got int volatile *
+ * check-error-end
+ */
diff --git a/validation/eval/unqual-stmt-expr.c b/validation/eval/unqual-stmt-expr.c
new file mode 100644
index 00000000..bac6cb6b
--- /dev/null
+++ b/validation/eval/unqual-stmt-expr.c
@@ -0,0 +1,13 @@
+#define __unqual_typeof(x) typeof(({ x; }))
+
+int *foo(volatile int x);
+int *foo(volatile int x)
+{
+ extern __unqual_typeof(x) y;
+ return &y;
+}
+
+/*
+ * check-name: unqual-stmt-expr
+ * check-known-to-fail
+ */
diff --git a/validation/eval/unqual02.c b/validation/eval/unqual02.c
new file mode 100644
index 00000000..f136cbd5
--- /dev/null
+++ b/validation/eval/unqual02.c
@@ -0,0 +1,26 @@
+static void test_const(volatile int x)
+{
+ const int x = 0;
+ typeof(1?x:x) i3; i3 = 0; // should be OK
+ typeof(+x) i4; i4 = 0; // should be OK
+ typeof(-x) i5; i5 = 0; // should be OK
+ typeof(!x) i6; i6 = 0; // should be OK
+ typeof(x+x) i7; i7 = 0; // should be OK
+}
+
+static void test_volatile(void)
+{
+ volatile int x = 0;
+ int *pp;
+
+ typeof(1?x:x) i3; pp = &i3; // should be OK
+ typeof(+x) i4; pp = &i4; // should be OK
+ typeof(-x) i5; pp = &i5; // should be OK
+ typeof(!x) i6; pp = &i6; // should be OK
+ typeof(x+x) i7; pp = &i7; // should be OK
+}
+
+/*
+ * check-name: unqual02
+ * check-command: sparse -Wno-declaration-after-statement $file
+ */