aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/validation/preprocessor
diff options
authorJosh Triplett <josh@freedesktop.org>2007-06-28 00:04:05 -0700
committerJosh Triplett <josh@freedesktop.org>2007-06-28 00:04:05 -0700
commit20492904c5356c3b844a952bfbc8e6eb2c8e2727 (patch)
treeb8d776b29a0a0b7134d7ed76ac5f881706c9295d /validation/preprocessor
parentbb0cc4bf39162e972fc519dd3bb96a98372a3d38 (diff)
downloadsparse-dev-20492904c5356c3b844a952bfbc8e6eb2c8e2727.tar.gz
Move all the preprocessor tests into validation/preprocessor/
The preprocessor tests shouldn't run through the entire Sparse compiler, just the preprocessor (sparse -E). Signed-off-by: Josh Triplett <josh@freedesktop.org>
Diffstat (limited to 'validation/preprocessor')
-rw-r--r--validation/preprocessor/preprocessor-loop.c2
-rw-r--r--validation/preprocessor/preprocessor1.c14
-rw-r--r--validation/preprocessor/preprocessor10.c13
-rw-r--r--validation/preprocessor/preprocessor11.c10
-rw-r--r--validation/preprocessor/preprocessor12.c7
-rw-r--r--validation/preprocessor/preprocessor13.c7
-rw-r--r--validation/preprocessor/preprocessor14.c7
-rw-r--r--validation/preprocessor/preprocessor15.c7
-rw-r--r--validation/preprocessor/preprocessor16.c21
-rw-r--r--validation/preprocessor/preprocessor17.c7
-rw-r--r--validation/preprocessor/preprocessor18.c3
-rw-r--r--validation/preprocessor/preprocessor19.c5
-rw-r--r--validation/preprocessor/preprocessor2.c15
-rw-r--r--validation/preprocessor/preprocessor20.c4
-rw-r--r--validation/preprocessor/preprocessor20.h6
-rw-r--r--validation/preprocessor/preprocessor3.c37
-rw-r--r--validation/preprocessor/preprocessor4.c10
-rw-r--r--validation/preprocessor/preprocessor5.c9
-rw-r--r--validation/preprocessor/preprocessor6.c27
-rw-r--r--validation/preprocessor/preprocessor7.c5
-rw-r--r--validation/preprocessor/preprocessor8.c16
-rw-r--r--validation/preprocessor/preprocessor9.c10
22 files changed, 242 insertions, 0 deletions
diff --git a/validation/preprocessor/preprocessor-loop.c b/validation/preprocessor/preprocessor-loop.c
new file mode 100644
index 00000000..035777e6
--- /dev/null
+++ b/validation/preprocessor/preprocessor-loop.c
@@ -0,0 +1,2 @@
+#if 1
+#if
diff --git a/validation/preprocessor/preprocessor1.c b/validation/preprocessor/preprocessor1.c
new file mode 100644
index 00000000..5ae20aab
--- /dev/null
+++ b/validation/preprocessor/preprocessor1.c
@@ -0,0 +1,14 @@
+/*
+ * This makes us really hurl chunks, causing
+ * infinite recursion until we run out of stack.
+ *
+ * It _should_ result in just a single plain
+ *
+ * "foo"
+ *
+ * (without the quotes).
+ */
+#define func(x) x
+#define bar func(
+#define foo bar foo
+foo )
diff --git a/validation/preprocessor/preprocessor10.c b/validation/preprocessor/preprocessor10.c
new file mode 100644
index 00000000..7fcac360
--- /dev/null
+++ b/validation/preprocessor/preprocessor10.c
@@ -0,0 +1,13 @@
+/*
+ * result should be
+ * defined
+ * since concatenation of 'defi' and 'ned' should result in the same token
+ * we would get if we had 'defined' in the input stream.
+ */
+#define A
+#define B defi ## ned
+#if B(A)
+defined
+#else
+undefined
+#endif
diff --git a/validation/preprocessor/preprocessor11.c b/validation/preprocessor/preprocessor11.c
new file mode 100644
index 00000000..4c6c1c0a
--- /dev/null
+++ b/validation/preprocessor/preprocessor11.c
@@ -0,0 +1,10 @@
+#define A(1) x
+#define B(x
+#define C(x,
+#define D(,)
+#define E(__VA_ARGS__)
+#define F(x+
+#define G(x...,
+#define H(x...,y)
+#define I(...+
+#define J(x,y)
diff --git a/validation/preprocessor/preprocessor12.c b/validation/preprocessor/preprocessor12.c
new file mode 100644
index 00000000..385c1a7d
--- /dev/null
+++ b/validation/preprocessor/preprocessor12.c
@@ -0,0 +1,7 @@
+/*
+ * GNU kludge
+ */
+#define A(x,...) x,##__VA_ARGS__
+A(1)
+A(1,2)
+A(1,2,3)
diff --git a/validation/preprocessor/preprocessor13.c b/validation/preprocessor/preprocessor13.c
new file mode 100644
index 00000000..96c813ee
--- /dev/null
+++ b/validation/preprocessor/preprocessor13.c
@@ -0,0 +1,7 @@
+/*
+ * GNU kludge, corner case
+ */
+#define A(x,...) x##,##__VA_ARGS__
+A(1)
+A(1,2)
+A(1,2,3)
diff --git a/validation/preprocessor/preprocessor14.c b/validation/preprocessor/preprocessor14.c
new file mode 100644
index 00000000..001f1f2d
--- /dev/null
+++ b/validation/preprocessor/preprocessor14.c
@@ -0,0 +1,7 @@
+/*
+ * GNU kludge, another corner case
+ */
+#define A(x,y,...) ,##x##__VA_ARGS__
+A(,1)
+#define B(x,y,...) x##,##__VA_ARGS__
+B(,1)
diff --git a/validation/preprocessor/preprocessor15.c b/validation/preprocessor/preprocessor15.c
new file mode 100644
index 00000000..0a2dfd7f
--- /dev/null
+++ b/validation/preprocessor/preprocessor15.c
@@ -0,0 +1,7 @@
+#define A defi
+#define B ned
+#define C(x,y) x##y
+#define D(x,y) C(x,y)
+#if D(A,B) B
+D(1,2)
+#endif
diff --git a/validation/preprocessor/preprocessor16.c b/validation/preprocessor/preprocessor16.c
new file mode 100644
index 00000000..e3bd0d9c
--- /dev/null
+++ b/validation/preprocessor/preprocessor16.c
@@ -0,0 +1,21 @@
+#if 0
+/*
+From 6.10.1(5):
+ Each directive's condition is checked in order. If it evaluates
+ to false (zero), the group it controls is skipped: directives are
+ processed only through the name that determines the directive in
+ order to keep track of the level of nested conditionals; the rest
+ of the directives' preprocessing tokens are ignores, >>as are the
+ other preprocessing tokens in the group<<.
+
+In other words, bogus arguments of directives are silently ignored and
+so are text lines and non-directives (# <something unknown>). We *do*
+complain about the things like double #else or #elif after #else, since
+they hit before we get to the level of groups.
+*/
+
+#define 1
+#undef 1
+#bullshit
+
+#endif
diff --git a/validation/preprocessor/preprocessor17.c b/validation/preprocessor/preprocessor17.c
new file mode 100644
index 00000000..dfcbee8c
--- /dev/null
+++ b/validation/preprocessor/preprocessor17.c
@@ -0,0 +1,7 @@
+#if 0
+/* these should not warn */
+#ifdef (
+#endif
+#ifndef (
+#endif
+#endif
diff --git a/validation/preprocessor/preprocessor18.c b/validation/preprocessor/preprocessor18.c
new file mode 100644
index 00000000..b5988bf1
--- /dev/null
+++ b/validation/preprocessor/preprocessor18.c
@@ -0,0 +1,3 @@
+/* one warning for each, please... */
+#define 1
+#undef 1
diff --git a/validation/preprocessor/preprocessor19.c b/validation/preprocessor/preprocessor19.c
new file mode 100644
index 00000000..0f7da475
--- /dev/null
+++ b/validation/preprocessor/preprocessor19.c
@@ -0,0 +1,5 @@
+/* got burned by that - freed the new defintion in the case when we had
+ warned and replaced the old one */
+#define A x
+#define A y
+A
diff --git a/validation/preprocessor/preprocessor2.c b/validation/preprocessor/preprocessor2.c
new file mode 100644
index 00000000..340938ee
--- /dev/null
+++ b/validation/preprocessor/preprocessor2.c
@@ -0,0 +1,15 @@
+/*
+ * This one we happen to get right.
+ *
+ * It should result in a simple
+ *
+ * a + b
+ *
+ * for a proper preprocessor.
+ */
+#define TWO a, b
+
+#define UNARY(x) BINARY(x)
+#define BINARY(x, y) x + y
+
+UNARY(TWO)
diff --git a/validation/preprocessor/preprocessor20.c b/validation/preprocessor/preprocessor20.c
new file mode 100644
index 00000000..68c0ccc1
--- /dev/null
+++ b/validation/preprocessor/preprocessor20.c
@@ -0,0 +1,4 @@
+#include "preprocessor20.h"
+#define X
+#define Y
+#include "preprocessor20.h"
diff --git a/validation/preprocessor/preprocessor20.h b/validation/preprocessor/preprocessor20.h
new file mode 100644
index 00000000..322c543a
--- /dev/null
+++ b/validation/preprocessor/preprocessor20.h
@@ -0,0 +1,6 @@
+#ifdef X
+B
+#endif
+#ifndef Y
+A
+#endif
diff --git a/validation/preprocessor/preprocessor3.c b/validation/preprocessor/preprocessor3.c
new file mode 100644
index 00000000..71b9acde
--- /dev/null
+++ b/validation/preprocessor/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/preprocessor/preprocessor4.c b/validation/preprocessor/preprocessor4.c
new file mode 100644
index 00000000..8b8c4da2
--- /dev/null
+++ b/validation/preprocessor/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/preprocessor/preprocessor5.c b/validation/preprocessor/preprocessor5.c
new file mode 100644
index 00000000..fa389376
--- /dev/null
+++ b/validation/preprocessor/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)
diff --git a/validation/preprocessor/preprocessor6.c b/validation/preprocessor/preprocessor6.c
new file mode 100644
index 00000000..87b79431
--- /dev/null
+++ b/validation/preprocessor/preprocessor6.c
@@ -0,0 +1,27 @@
+/*
+ * We get '##' wrong for the kernel.
+ *
+ * It could possibly be argued that the kernel usage
+ * is undefined (since the different sides of the '##'
+ * are not proper tokens), but that's probably a load
+ * of bull. We should just try to do it right.
+ *
+ * This _should_ result in
+ *
+ * static char __vendorstr_003d[] __devinitdata = "Lockheed Martin-Marietta Corp";
+ *
+ * but we break up the "003d" into two tokens ('003' and 'd')
+ * and then we also put the 'o' marker to mark the token 003
+ * as an octal number, so we end up with
+ *
+ * static char __vendorstr_o03 d [ ] __devinitdata = "Lockheed Martin-Marietta Corp";
+ *
+ * which doesn't work, of course.
+ */
+
+#define __devinitdata __attribute__((section(".devinit")))
+
+#define VENDOR( vendor, name ) \
+ static char __vendorstr_##vendor[] __devinitdata = name;
+VENDOR(003d,"Lockheed Martin-Marietta Corp")
+
diff --git a/validation/preprocessor/preprocessor7.c b/validation/preprocessor/preprocessor7.c
new file mode 100644
index 00000000..e7e1d375
--- /dev/null
+++ b/validation/preprocessor/preprocessor7.c
@@ -0,0 +1,5 @@
+#define A(x) C(B, D
+#define D A(1))
+#define C(x,y) E(y)
+#define E(y) #y
+A(2))
diff --git a/validation/preprocessor/preprocessor8.c b/validation/preprocessor/preprocessor8.c
new file mode 100644
index 00000000..861dfe51
--- /dev/null
+++ b/validation/preprocessor/preprocessor8.c
@@ -0,0 +1,16 @@
+#define A(x) ## x
+#define B(x) x ##
+#define C(x) x ## ## ##
+#define D(x) x#y
+#define E x#y
+#define F(x,y) x x##y #x y
+#define G a##b
+#define H 1##2
+#define I(x,y,z) x y z
+"A(x)" : A(x)
+"B(x)" : B(x)
+"C(x)" : C(x)
+"D(x)" : D(x)
+"x#y" : E
+"ab GH \"G\" 12" : F(G,H)
+"a ## b" : I(a,##,b)
diff --git a/validation/preprocessor/preprocessor9.c b/validation/preprocessor/preprocessor9.c
new file mode 100644
index 00000000..76d6e414
--- /dev/null
+++ b/validation/preprocessor/preprocessor9.c
@@ -0,0 +1,10 @@
+/*
+ * Should result in
+ * #define X 1
+ * X
+ * since only # in the input stream marks beginning of preprocessor command
+ * and here we get it from macro expansion.
+ */
+#define A # define X 1
+A
+X