aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-04 14:33:38 +0100
committerLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2017-12-07 17:44:50 +0100
commit913471cdaccb49e735011818e1faea2141f0175b (patch)
treeef2ad661f4c2645bd1b60d613d4462aa439392fa /validation
parent8d781d16644e826476b6f410acd5a48e1d7b98d6 (diff)
downloadsparse-dev-913471cdaccb49e735011818e1faea2141f0175b.tar.gz
add more testcases for using addresses in conditionals
and unify the existing ones. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Diffstat (limited to 'validation')
-rw-r--r--validation/Waddress-array.c25
-rw-r--r--validation/Waddress-function.c17
-rw-r--r--validation/Waddress-weak.c25
-rw-r--r--validation/Waddress.c110
-rw-r--r--validation/cond-address-array.c26
-rw-r--r--validation/cond-address-function.c18
6 files changed, 177 insertions, 44 deletions
diff --git a/validation/Waddress-array.c b/validation/Waddress-array.c
new file mode 100644
index 00000000..83178454
--- /dev/null
+++ b/validation/Waddress-array.c
@@ -0,0 +1,25 @@
+int foo(void) {
+ extern int a[];
+
+ if (a)
+ return 1;
+ return 0;
+}
+
+int bar(void) {
+ int a[2];
+
+ if (a)
+ return 1;
+ return 0;
+}
+
+/*
+ * check-name: Waddress-array
+ * check-command: sparse -Wno-decl -Waddress $file
+ *
+ * check-error-start
+Waddress-array.c:4:13: warning: the address of an array will always evaluate as true
+Waddress-array.c:12:13: warning: the address of an array will always evaluate as true
+ * check-error-end
+ */
diff --git a/validation/Waddress-function.c b/validation/Waddress-function.c
new file mode 100644
index 00000000..fccbe2d8
--- /dev/null
+++ b/validation/Waddress-function.c
@@ -0,0 +1,17 @@
+extern void func(void);
+
+int global_function(void)
+{
+ if (func)
+ return 1;
+ return 0;
+}
+
+/*
+ * check-name: Waddress-function
+ * check-command: sparse -Wno-decl -Waddress $file
+ *
+ * check-error-start
+Waddress-function.c:5:13: warning: the address of a function will always evaluate as true
+ * check-error-end
+ */
diff --git a/validation/Waddress-weak.c b/validation/Waddress-weak.c
new file mode 100644
index 00000000..1fe8d33c
--- /dev/null
+++ b/validation/Waddress-weak.c
@@ -0,0 +1,25 @@
+extern int var __attribute__((weak));
+extern int arr[] __attribute__((weak));
+extern int fun(void) __attribute__((weak));
+
+int test_addr_weak_fun(void)
+{
+ if ( &var) return 1;
+ if ( arr) return 1;
+ if ( &arr) return 1;
+ if ( fun) return 1;
+ if ( &fun) return 1;
+ if (!&var) return 0;
+ if (! arr) return 0;
+ if (!&arr) return 0;
+ if (! fun) return 0;
+ if (!&fun) return 0;
+ return -1;
+}
+
+/*
+ * check-name: Waddress-weak
+ * check-note: Undefined weak symbols (can) have a null address.
+ * check-command: sparse -Wno-decl -Waddress $file
+ * check-known-to-fail
+ */
diff --git a/validation/Waddress.c b/validation/Waddress.c
new file mode 100644
index 00000000..10556c3a
--- /dev/null
+++ b/validation/Waddress.c
@@ -0,0 +1,110 @@
+extern int fun(void);
+extern int arr[];
+extern int var;
+
+int test_address(int arg, int ptr[])
+{
+
+ if (fun()) return -1;
+ if (var) return -1;
+ if (arg) return -1;
+ if (ptr) return -1;
+
+lab:
+ if (arr) return 1;
+ if (&arr) return 1;
+ if (fun) return 1;
+ if (&fun) return 1;
+ if (&var) return 1;
+ if (&arg) return 1;
+ if (&&lab) return 1;
+
+ return -1;
+}
+
+int test_address_not(int arg, int ptr[])
+{
+
+ if (!fun()) return -1;
+ if (!var) return -1;
+ if (!arg) return -1;
+ if (!ptr) return -1;
+
+lab:
+ if (!arr) return 0;
+ if (!&arr) return 0;
+ if (!fun) return 0;
+ if (!&fun) return 0;
+ if (!&var) return 0;
+ if (!&arg) return 0;
+ if (!&&lab) return 0;
+
+ return -1;
+}
+
+int test_address_cmp(int arg, int ptr[])
+{
+ if (fun() == 0) return -1;
+ if (0 == fun()) return -1;
+ if (var == 0) return -1;
+ if (0 == var) return -1;
+ if (arg == 0) return -1;
+ if (0 == arg) return -1;
+ if (ptr == 0) return -1;
+ if (0 == ptr) return -1;
+
+lab:
+ if (arr == 0) return 0;
+ if (0 == arr) return 0;
+ if (&arr == 0) return 0;
+ if (0 == &arr) return 0;
+ if (fun == 0) return 0;
+ if (0 == fun) return 0;
+ if (&fun == 0) return 0;
+ if (0 == &fun) return 0;
+ if (&var == 0) return 0;
+ if (0 == &var) return 0;
+ if (&arg == 0) return 0;
+ if (0 == &arg) return 0;
+ if (&&lab == 0) return 0;
+ if (0 == &&lab) return 0;
+
+ return -1;
+}
+
+/*
+ * check-name: Waddress
+ * check-command: sparse -Wno-decl -Wno-non-pointer-null -Waddress $file
+ * check-known-to-fail
+ *
+ * check-error-start
+Waddress.c:14:13: warning: the address of an array will always evaluate as true
+Waddress.c:15:14: warning: the address of an array will always evaluate as true
+Waddress.c:16:13: warning: the address of a function will always evaluate as true
+Waddress.c:17:14: warning: the address of a function will always evaluate as true
+Waddress.c:18:13: warning: the address of a variable will always evaluate as true
+Waddress.c:19:13: warning: the address of a variable will always evaluate as true
+Waddress.c:20:13: warning: the address of a label will always evaluate as true
+Waddress.c:34:13: warning: the address of an array will always evaluate as true
+Waddress.c:35:13: warning: the address of an array will always evaluate as true
+Waddress.c:36:13: warning: the address of a function will always evaluate as true
+Waddress.c:37:13: warning: the address of a function will always evaluate as true
+Waddress.c:38:13: warning: the address of a variable will always evaluate as true
+Waddress.c:39:13: warning: the address of a variable will always evaluate as true
+Waddress.c:40:13: warning: the address of a label will always evaluate as true
+Waddress.c:57:13: warning: the address of an array will always evaluate as true
+Waddress.c:58:13: warning: the address of an array will always evaluate as true
+Waddress.c:59:13: warning: the address of an array will always evaluate as true
+Waddress.c:60:13: warning: the address of an array will always evaluate as true
+Waddress.c:61:13: warning: the address of a function will always evaluate as true
+Waddress.c:62:13: warning: the address of a function will always evaluate as true
+Waddress.c:63:13: warning: the address of a function will always evaluate as true
+Waddress.c:64:13: warning: the address of a function will always evaluate as true
+Waddress.c:65:13: warning: the address of a variable will always evaluate as true
+Waddress.c:66:13: warning: the address of a variable will always evaluate as true
+Waddress.c:67:13: warning: the address of a variable will always evaluate as true
+Waddress.c:68:13: warning: the address of a variable will always evaluate as true
+Waddress.c:69:13: warning: the address of a label will always evaluate as true
+Waddress.c:70:13: warning: the address of a label will always evaluate as true
+ * check-error-end
+ */
diff --git a/validation/cond-address-array.c b/validation/cond-address-array.c
deleted file mode 100644
index e1d2f87f..00000000
--- a/validation/cond-address-array.c
+++ /dev/null
@@ -1,26 +0,0 @@
-int foo(void) {
- extern int a[];
-
- if (a)
- return 1;
- return 0;
-}
-
-int bar(void) {
- int a[2];
-
- if (a)
- return 1;
- return 0;
-}
-
-/*
- * check-name: cond-address-array.c
- * check-command: test-linearize -Wno-decl -Waddress $file
- * check-output-ignore
- *
- * check-error-start
-cond-address-array.c:4:13: warning: the address of an array will always evaluate as true
-cond-address-array.c:12:13: warning: the address of an array will always evaluate as true
- * check-error-end
- */
diff --git a/validation/cond-address-function.c b/validation/cond-address-function.c
deleted file mode 100644
index 9a143a00..00000000
--- a/validation/cond-address-function.c
+++ /dev/null
@@ -1,18 +0,0 @@
-extern void func(void);
-
-int global_function(void)
-{
- if (func)
- return 1;
- return 0;
-}
-
-/*
- * check-name: cond-address-function
- * check-command: test-linearize -Wno-decl -Waddress $file
- * check-output-ignore
- *
- * check-error-start
-cond-address-function.c:5:13: warning: the address of a function will always evaluate as true
- * check-error-end
- */