aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation
diff options
authorLinus Torvalds <torvalds@home.osdl.org>2003-07-18 19:07:03 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-07 21:00:56 -0700
commit95e1e20937a430ab9f5fac6daf7a41a7ec55b524 (patch)
treeedc96408d20ee71d1ae6ce1cd46af4491f0052da /validation
parent10e9653b49d81800837f1e7c8ea39039cb32a27f (diff)
downloadsparse-dev-95e1e20937a430ab9f5fac6daf7a41a7ec55b524.tar.gz
More preprocessor validation tests from comp.std.c.
One is interesting (preprocessor3.c), and we get it wrong. Surprise surprise.
Diffstat (limited to 'validation')
-rw-r--r--validation/preprocessor3.c37
-rw-r--r--validation/preprocessor4.c10
-rw-r--r--validation/preprocessor5.c9
3 files changed, 56 insertions, 0 deletions
diff --git a/validation/preprocessor3.c b/validation/preprocessor3.c
new file mode 100644
index 00000000..71b9acde
--- /dev/null
+++ b/validation/preprocessor3.c
@@ -0,0 +1,37 @@
+/*
+ * We get this one wrong too.
+ *
+ * It should result in a sequence
+ *
+ * B ( )
+ * A ( )
+ * B ( )
+ * A ( )
+ *
+ * because each iteration of the scanning of "SCAN()"
+ * should re-evaluate the recursive B->A->B expansion.
+ * But we never re-evaluate something that we noticed
+ * was recursive. So we will cause it to evaluate to
+ *
+ * B ( )
+ * A ( )
+ * A ( )
+ * A ( )
+ *
+ * Which is really quite wrong.
+ *
+ * Did I already mention that the C preprocessor language
+ * is a perverse thing?
+ */
+
+#define LP (
+
+#define A() B LP )
+#define B() A LP )
+
+#define SCAN(x) x
+
+A() // B ( )
+SCAN( A() ) // A ( )
+SCAN(SCAN( A() )) // B ( )
+SCAN(SCAN(SCAN( A() ))) // A ( )
diff --git a/validation/preprocessor4.c b/validation/preprocessor4.c
new file mode 100644
index 00000000..8b8c4da2
--- /dev/null
+++ b/validation/preprocessor4.c
@@ -0,0 +1,10 @@
+/*
+ * More examples from the comp.std.c discussion.
+ *
+ * This should result in bar(bar). We get it right.
+ */
+#define foo bar
+#define mac(x) x(foo)
+
+mac(foo)
+
diff --git a/validation/preprocessor5.c b/validation/preprocessor5.c
new file mode 100644
index 00000000..fa389376
--- /dev/null
+++ b/validation/preprocessor5.c
@@ -0,0 +1,9 @@
+/*
+ * Yet more examples from comp.std.c.
+ *
+ * This should result in "a|". We get it right.
+ */
+#define a a|
+#define b(x) x
+
+b(a)