aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
Diffstat (limited to 'validation')
-rw-r--r--validation/bug-expand-union0.c21
-rw-r--r--validation/bug-expand-union1.c20
-rw-r--r--validation/linear/range-op.c31
-rw-r--r--validation/preprocessor/phase2-backslash.c (renamed from validation/phase2/backslash)29
-rw-r--r--validation/preprocessor/phase3-comments.c (renamed from validation/phase3/comments)12
-rw-r--r--validation/range-syntax.c23
-rw-r--r--validation/typedef-redef-c89.c13
-rw-r--r--validation/typedef-redef.c13
-rw-r--r--validation/typediff-arraysize.c12
-rw-r--r--validation/typediff-enum.c34
10 files changed, 194 insertions, 14 deletions
diff --git a/validation/bug-expand-union0.c b/validation/bug-expand-union0.c
new file mode 100644
index 00000000..dd6d60c3
--- /dev/null
+++ b/validation/bug-expand-union0.c
@@ -0,0 +1,21 @@
+union u {
+ char c;
+ float f;
+};
+
+static int foo(void)
+{
+ union u u = { .f = 0.123 };
+ return u.c;
+}
+
+/*
+ * check-name: bug-expand-union
+ * check description: must not infer the value from the float
+ * check-command: test-linearize $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: load\\.
+ * check-output-excludes: ret\\..*\\$
+ */
diff --git a/validation/bug-expand-union1.c b/validation/bug-expand-union1.c
new file mode 100644
index 00000000..582a1f4f
--- /dev/null
+++ b/validation/bug-expand-union1.c
@@ -0,0 +1,20 @@
+union u {
+ int i;
+ float f;
+};
+
+static int foo(void)
+{
+ union u u = { .f = 0.123 };
+ return u.i;
+}
+
+/*
+ * check-name: bug-expand-union
+ * check description: must not infer the value from the float
+ * check-command: test-linearize $file
+ * check-known-to-fail
+ *
+ * check-output-ignore
+ * check-output-contains: load\\.
+ */
diff --git a/validation/linear/range-op.c b/validation/linear/range-op.c
new file mode 100644
index 00000000..4472bb33
--- /dev/null
+++ b/validation/linear/range-op.c
@@ -0,0 +1,31 @@
+static void foo(int a)
+{
+ __range__(a, 0, 8);
+}
+
+static void bar(int a, int b, int c)
+{
+ __range__(a, b, c);
+}
+
+/*
+ * check-name: range-op
+ * check-command: test-linearize -Wno-decl $file
+ *
+ * check-output-start
+foo:
+.L0:
+ <entry-point>
+ range-check %arg1 between $0..$8
+ ret
+
+
+bar:
+.L2:
+ <entry-point>
+ range-check %arg1 between %arg2..%arg3
+ ret
+
+
+ * check-output-end
+ */
diff --git a/validation/phase2/backslash b/validation/preprocessor/phase2-backslash.c
index 29c85b4d..21d94d7d 100644
--- a/validation/phase2/backslash
+++ b/validation/preprocessor/phase2-backslash.c
@@ -17,11 +17,26 @@
* the rest of tokenizer.
*/
+/*
+ * check-name: phase2-backslash
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+"\a"
+1
+D
+'\a'
+ * check-output-end
+ *
+ * check-error-start
+preprocessor/phase2-backslash.c:68:0: warning: backslash-newline at end of file
+ * check-error-end
+ */
+
#define A(x) #x
#define B(x) A(x)
/* This should result in "\a" */
-/* XXX: currently sparse produces "a" */
-/* Partially fixed: now it gives "\\a", which is a separate problem */
B(\a)
#define C\
@@ -32,31 +47,21 @@ C
#define D\
1
/* And this should give D, since '\n' is removed and we get no whitespace */
-/* XXX: currently sparse produces 1 */
-/* Fixed */
D
#define E '\\
a'
/* This should give '\a' - with no warnings issued */
-/* XXX: currently sparse complains a lot and ends up producing a */
-/* Fixed */
E
/* This should give nothing */
-/* XXX: currently sparse produces more junk */
-/* Fixed */
// junk \
more junk
/* This should also give nothing */
-/* XXX: currently sparse produces / * comment * / */
-/* Fixed */
/\
* comment *\
/
/* And this should complain since final newline should not be eaten by '\\' */
-/* XXX: currently sparse does not notice */
-/* Fixed */
\
diff --git a/validation/phase3/comments b/validation/preprocessor/phase3-comments.c
index 8f51a307..7106b480 100644
--- a/validation/phase3/comments
+++ b/validation/preprocessor/phase3-comments.c
@@ -3,7 +3,15 @@
*/
/* This should give nothing */
-/* XXX: currently sparse produces Y */
-/* Fixed */
#define X /*
*/ Y
+
+/*
+ * check-name: phase3-comments
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+
+ * check-output-end
+ */
diff --git a/validation/range-syntax.c b/validation/range-syntax.c
new file mode 100644
index 00000000..c43fff0e
--- /dev/null
+++ b/validation/range-syntax.c
@@ -0,0 +1,23 @@
+
+static void ok(int a, int b, int c)
+{
+ __range__(a, 0, 8);
+ __range__(a, b, c);
+}
+
+static void ko(int a, int b, int c)
+{
+ __range__ a, 0, 8;
+ __range__ a, b, c;
+}
+
+/*
+ * check-name: range syntax
+ *
+ * check-error-start
+range-syntax.c:10:19: error: Expected ( after __range__ statement
+range-syntax.c:10:19: error: got a
+range-syntax.c:11:19: error: Expected ( after __range__ statement
+range-syntax.c:11:19: error: got a
+ * check-error-end
+ */
diff --git a/validation/typedef-redef-c89.c b/validation/typedef-redef-c89.c
new file mode 100644
index 00000000..6d4dc28c
--- /dev/null
+++ b/validation/typedef-redef-c89.c
@@ -0,0 +1,13 @@
+typedef int int_t;
+typedef int int_t;
+
+/*
+ * check-name: typedef-redef-c89
+ * check-command: sparse -std=c89 --pedantic $file
+ * check-known-to-fail
+ *
+ * check-error-start
+typedef-redef-c89.c:2:13: warning: redefinition of typedef 'int_t'
+typedef-redef-c89.c:1:13: info: originally defined here
+ * check-error-end
+ */
diff --git a/validation/typedef-redef.c b/validation/typedef-redef.c
new file mode 100644
index 00000000..3a60a773
--- /dev/null
+++ b/validation/typedef-redef.c
@@ -0,0 +1,13 @@
+typedef int ok_t;
+typedef int ok_t;
+
+typedef int ko_t;
+typedef long ko_t;
+
+/*
+ * check-name: typedef-redef
+ *
+ * check-error-start
+typedef-redef.c:5:14: error: symbol 'ko_t' redeclared with different type (originally declared at typedef-redef.c:4) - different type sizes
+ * check-error-end
+ */
diff --git a/validation/typediff-arraysize.c b/validation/typediff-arraysize.c
new file mode 100644
index 00000000..dd7a2ca5
--- /dev/null
+++ b/validation/typediff-arraysize.c
@@ -0,0 +1,12 @@
+extern int ok0[]; int ok0[1]; // OK
+extern int ok1[1]; int ok1[]; // OK but size should be 1
+extern int ko1[1]; int ko1[2]; // KO
+
+/*
+ * check-name: typediff-arraysize
+ * check-known-to-fail
+ *
+ * check-error-start
+typediff-arraysize.c:3:29: error: symbol 'ko1' redeclared with different type (originally declared at typediff-arraysize.c:3) - different array sizes
+ * check-error-end
+ */
diff --git a/validation/typediff-enum.c b/validation/typediff-enum.c
new file mode 100644
index 00000000..c5f2dc0a
--- /dev/null
+++ b/validation/typediff-enum.c
@@ -0,0 +1,34 @@
+enum num { ZERO, ONE, MANY, };
+typedef enum num num;
+
+extern int v;
+num v = 0;
+
+extern num w;
+int w = 0;
+
+int foo(void);
+num foo(void) { return ZERO; }
+
+num bar(void);
+int bar(void) { return ZERO; }
+
+void baz(int a);
+void baz(num a) { }
+
+void qux(num a);
+void qux(int a) { }
+
+/*
+ * check-name: typediff-enum
+ * check-known-to-fail
+ *
+ * check-error-start
+typediff-enum.c:5:5: error: symbol 'v' redeclared with different type (originally declared at typediff-enum.c:4) - different types
+typediff-enum.c:8:5: error: symbol 'w' redeclared with different type (originally declared at typediff-enum.c:7) - different types
+typediff-enum.c:11:5: error: symbol 'foo' redeclared with different type (originally declared at typediff-enum.c:10) - different types
+typediff-enum.c:14:5: error: symbol 'bar' redeclared with different type (originally declared at typediff-enum.c:13) - different types
+typediff-enum.c:17:6: error: symbol 'baz' redeclared with different type (originally declared at typediff-enum.c:16) - incompatible argument 1 (different types)
+typediff-enum.c:20:6: error: symbol 'qux' redeclared with different type (originally declared at typediff-enum.c:19) - incompatible argument 1 (different types)
+ * check-error-end
+ */