aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2016-01-07 02:47:09 +0100
committerChristopher Li <sparse@chrisli.org>2016-02-04 23:47:49 +0800
commit8efbac18a251580615e3a5c587155fd7233b1b13 (patch)
tree039677d4beaa69b85e009795a7cfaefbf724ae82 /validation
parent38c9e9f3b3faba3dea7f42c37d565a425867060e (diff)
downloadsparse-dev-8efbac18a251580615e3a5c587155fd7233b1b13.tar.gz
Fix size calculation of unsized bool array
This stops sparse from issuing the error message "error: cannot size expression" for code like: static _Bool boolarray[] = { 0, 1, }; static int n = sizeof(boolarray); The fix consists of using array_element_offset() for calculating the size of unsized arrays, like it is done elsewhere for sized ones. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation')
-rw-r--r--validation/bool-array.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/validation/bool-array.c b/validation/bool-array.c
new file mode 100644
index 00000000..6c4c8723
--- /dev/null
+++ b/validation/bool-array.c
@@ -0,0 +1,47 @@
+static _Bool boolarray_d1[1];
+static _Bool boolarray_d8[8];
+static _Bool boolarray_i2[2] = {
+ 0,
+ 1,
+};
+static int nd1 = sizeof(boolarray_d1);
+static int nd8 = sizeof(boolarray_d8);
+static int ni2 = sizeof(boolarray_i2);
+
+
+static long longarray_u2[] = {
+ 0,
+ 1,
+};
+static int nl2 = sizeof(longarray_u2);
+
+/*
+ * Used to get "warning: excessive elements in array initializer"
+ * for all elements but the first one.
+ * Note: only occurs if nbr of elements is a multiple of 8
+ * (if not, theer was another problem)
+ */
+static _Bool boolarray_u8[] = {
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+ 0,
+ 1,
+};
+
+/*
+ * Used to get "error: cannot size expression" for the sizeof.
+ */
+static _Bool boolarray_u2[] = {
+ 0,
+ 1,
+};
+static int nu2 = sizeof(boolarray_u2);
+
+/*
+ * check-name: sizeof(bool array)
+ * check-command: sparse -Wno-sizeof-bool $file
+ */