aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/preprocessor
diff options
authorLuc Van Oostenryck <luc.vanoostenryck@gmail.com>2015-01-24 00:59:35 +0100
committerChristopher Li <sparse@chrisli.org>2015-02-08 16:54:58 -0800
commit40791b94c56b1a6da2a0ddeb1f9d5c9d64de8f93 (patch)
tree1ee8e890740c4a8eec3c8a2ce49fe40e706458bf /validation/preprocessor
parentde1fa7e60d3d179a1b67c47a0429b2d0ac4e4842 (diff)
downloadsparse-dev-40791b94c56b1a6da2a0ddeb1f9d5c9d64de8f93.tar.gz
Teach sparse about the __COUNTER__ predefined macro
__COUNTER__ macro is expanded to a sequential number starting from 0. This is sometimes used to declare unique variable names. Implement support for __COUNTER__ in sparse including a set of small test programs for the test suite. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com> Acked-by: Sam Ravnborg <sam@ravnborg.org> Reviewed-by: Josh Triplett <josh@joshtriplett.org> Tested-by: Christian Borntraeger <borntraeger@de.ibm.com> Signed-off-by: Christopher Li <sparse@chrisli.org>
Diffstat (limited to 'validation/preprocessor')
-rw-r--r--validation/preprocessor/counter1.c12
-rw-r--r--validation/preprocessor/counter2.c14
-rw-r--r--validation/preprocessor/counter2.h1
-rw-r--r--validation/preprocessor/counter3.c14
4 files changed, 41 insertions, 0 deletions
diff --git a/validation/preprocessor/counter1.c b/validation/preprocessor/counter1.c
new file mode 100644
index 00000000..98187ee6
--- /dev/null
+++ b/validation/preprocessor/counter1.c
@@ -0,0 +1,12 @@
+__COUNTER__
+__COUNTER__
+/*
+ * check-name: __COUNTER__ #1
+ * check-command: sparse -E $file
+ *
+ * check-output-start
+
+0
+1
+ * check-output-end
+ */
diff --git a/validation/preprocessor/counter2.c b/validation/preprocessor/counter2.c
new file mode 100644
index 00000000..9883b682
--- /dev/null
+++ b/validation/preprocessor/counter2.c
@@ -0,0 +1,14 @@
+__FILE__ __COUNTER__
+#include <counter2.h>
+__FILE__ __COUNTER__
+/*
+ * check-name: __COUNTER__ #2
+ * check-command: sparse -Ipreprocessor -E $file
+ *
+ * check-output-start
+
+"preprocessor/counter2.c" 0
+"preprocessor/counter2.h" 1
+"preprocessor/counter2.c" 2
+ * check-output-end
+ */
diff --git a/validation/preprocessor/counter2.h b/validation/preprocessor/counter2.h
new file mode 100644
index 00000000..447b70ab
--- /dev/null
+++ b/validation/preprocessor/counter2.h
@@ -0,0 +1 @@
+__FILE__ __COUNTER__
diff --git a/validation/preprocessor/counter3.c b/validation/preprocessor/counter3.c
new file mode 100644
index 00000000..fa3f173b
--- /dev/null
+++ b/validation/preprocessor/counter3.c
@@ -0,0 +1,14 @@
+/*
+ * check-name: __COUNTER__ #3
+ * check-command: sparse -Ipreprocessor -E preprocessor/counter1.c $file
+ *
+ * check-output-start
+
+0
+1
+"preprocessor/counter2.c" 0
+"preprocessor/counter2.h" 1
+"preprocessor/counter2.c" 2
+ * check-output-end
+ */
+#include "counter2.c"