aboutsummaryrefslogtreecommitdiff
path: root/tests/pp
diff options
context:
space:
mode:
authorgrischka <grischka>2015-05-09 14:29:39 +0200
committergrischka <grischka>2015-05-09 14:29:39 +0200
commit30df3189b177c65d65094bed3a066a2722fe2dc0 (patch)
tree5cc01304899af2f09b051cdb5cf980ceb8f6b9c1 /tests/pp
parent70a6c4601e471054edbe2fd984e37e2ca320db14 (diff)
downloadtinycc-30df3189b177c65d65094bed3a066a2722fe2dc0.tar.gz
tinycc-30df3189b177c65d65094bed3a066a2722fe2dc0.tar.bz2
tccpp: fix issues, add tests
* fix some macro expansion issues * add some pp tests in tests/pp * improved tcc -E output for better diff'ability * remove -dD feature (quirky code, exotic feature, didn't work well) Based partially on ideas / researches from PipCet Some issues remain with VA_ARGS macros (if used in a rather tricky way). Also, to keep it simple, the pp doesn't automtically add any extra spaces to separate tokens which otherwise would form wrong tokens if re-read from tcc -E output (such as '+' '=') GCC does that, other compilers don't. * cleanups - #line 01 "file" / # 01 "file" processing - #pragma comment(lib,"foo") - tcc -E: forward some pragmas to output (pack, comment(lib)) - fix macro parameter list parsing mess from a3fc54345949535524d01319e1ca6378b7c2c201 a715d7143d9d17da17e67fec6af1c01409a71a31 (some coffee might help, next time ;) - introduce TOK_PPSTR - to have character constants as written in the file (similar to TOK_PPNUM) - allow '\' appear in macros - new functions begin/end_macro to: - fix switching macro levels during expansion - allow unget_tok to unget more than one tok - slight speedup by using bitflags in isidnum_table Also: - x86_64.c : fix decl after statements - i386-gen,c : fix a vstack leak with VLA on windows - configure/Makefile : build on windows (MSYS) was broken - tcc_warning: fflush stderr to keep output order (win32)
Diffstat (limited to 'tests/pp')
-rw-r--r--tests/pp/01.c6
-rw-r--r--tests/pp/01.expect1
-rw-r--r--tests/pp/02.c28
-rw-r--r--tests/pp/02.expect5
-rw-r--r--tests/pp/03.c15
-rw-r--r--tests/pp/03.expect5
-rw-r--r--tests/pp/04.c4
-rw-r--r--tests/pp/04.expect1
-rw-r--r--tests/pp/05.c7
-rw-r--r--tests/pp/05.expect3
-rw-r--r--tests/pp/06.c5
-rw-r--r--tests/pp/06.expect1
-rw-r--r--tests/pp/07.c4
-rw-r--r--tests/pp/07.expect2
-rw-r--r--tests/pp/08.c4
-rw-r--r--tests/pp/08.expect1
-rw-r--r--tests/pp/09.c4
-rw-r--r--tests/pp/09.expect1
-rw-r--r--tests/pp/10.c10
-rw-r--r--tests/pp/10.expect5
-rw-r--r--tests/pp/11.c31
-rw-r--r--tests/pp/11.expect15
-rw-r--r--tests/pp/Makefile35
23 files changed, 193 insertions, 0 deletions
diff --git a/tests/pp/01.c b/tests/pp/01.c
new file mode 100644
index 0000000..2fc3d79
--- /dev/null
+++ b/tests/pp/01.c
@@ -0,0 +1,6 @@
+#define hash_hash # ## #
+#define mkstr(a) # a
+#define in_between(a) mkstr(a)
+#define join(c, d) in_between(c hash_hash d)
+char p[] = join(x, y);
+// char p[] = "x ## y";
diff --git a/tests/pp/01.expect b/tests/pp/01.expect
new file mode 100644
index 0000000..cf5b153
--- /dev/null
+++ b/tests/pp/01.expect
@@ -0,0 +1 @@
+char p[] = "x ## y";
diff --git a/tests/pp/02.c b/tests/pp/02.c
new file mode 100644
index 0000000..feb1254
--- /dev/null
+++ b/tests/pp/02.c
@@ -0,0 +1,28 @@
+#define x 3
+#define f(a) f(x * (a))
+#undef x
+#define x 2
+#define g f
+#define z z[0]
+#define h g(~
+#define m(a) a(w)
+#define w 0,1
+#define t(a) a
+#define p() int
+#define q(x) x
+#define r(x,y) x ## y
+#define str(x) # x
+f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
+g(x+(3,4)-w) | h 5) & m
+(f)^m(m);
+char c[2][6] = { str(hello), str() };
+/*
+ * f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
+ * f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
+ * char c[2][6] = { "hello", "" };
+ */
+#define L21 f(y+1) + f(f(z)) % t(t(g)(0) + t)(1);
+#define L22 g(x+(3,4)-w) | h 5) & m\
+(f)^m(m);
+L21
+L22
diff --git a/tests/pp/02.expect b/tests/pp/02.expect
new file mode 100644
index 0000000..16f42ae
--- /dev/null
+++ b/tests/pp/02.expect
@@ -0,0 +1,5 @@
+f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
+f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
+char c[2][6] = { "hello", "" };
+f(2 * (y+1)) + f(2 * (f(2 * (z[0])))) % f(2 * (0)) + t(1);
+f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
diff --git a/tests/pp/03.c b/tests/pp/03.c
new file mode 100644
index 0000000..a659245
--- /dev/null
+++ b/tests/pp/03.c
@@ -0,0 +1,15 @@
+#define str(s) # s
+#define xstr(s) str(s)
+#define debug(s, t) printf("x" # s "= %d, x" # t "= %s", \
+ x ## s, x ## t)
+#define INCFILE(n) vers ## n
+#define glue(a, b) a ## b
+#define xglue(a, b) glue(a, b)
+#define HIGHLOW "hello"
+#define LOW LOW ", world"
+debug(1, 2);
+fputs(str(strncmp("abc\0d", "abc", '\4') // this goes away
+ == 0) str(: @\n), s);
+\#include xstr(INCFILE(2).h)
+glue(HIGH, LOW);
+xglue(HIGH, LOW)
diff --git a/tests/pp/03.expect b/tests/pp/03.expect
new file mode 100644
index 0000000..44aad0a
--- /dev/null
+++ b/tests/pp/03.expect
@@ -0,0 +1,5 @@
+printf("x" "1" "= %d, x" "2" "= %s", x1, x2);
+fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0" ": @\n", s);
+\#include "vers2.h"
+"hello";
+"hello" ", world"
diff --git a/tests/pp/04.c b/tests/pp/04.c
new file mode 100644
index 0000000..0068f37
--- /dev/null
+++ b/tests/pp/04.c
@@ -0,0 +1,4 @@
+#define foobar 1
+#define C(x,y) x##y
+#define D(x) (C(x,bar))
+D(foo)
diff --git a/tests/pp/04.expect b/tests/pp/04.expect
new file mode 100644
index 0000000..7c67b01
--- /dev/null
+++ b/tests/pp/04.expect
@@ -0,0 +1 @@
+(1)
diff --git a/tests/pp/05.c b/tests/pp/05.c
new file mode 100644
index 0000000..7274941
--- /dev/null
+++ b/tests/pp/05.c
@@ -0,0 +1,7 @@
+#define t(x,y,z) x ## y ## z
+#define xxx(s) int s[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,), \
+ t(10,,), t(,11,), t(,,12), t(,,) };
+
+int j[] = { t(1,2,3), t(,4,5), t(6,,7), t(8,9,),
+ t(10,,), t(,11,), t(,,12), t(,,) };
+xxx(j)
diff --git a/tests/pp/05.expect b/tests/pp/05.expect
new file mode 100644
index 0000000..9f9be37
--- /dev/null
+++ b/tests/pp/05.expect
@@ -0,0 +1,3 @@
+int j[] = { 123, 45, 67, 89,
+ 10, 11, 12, };
+int j[] = { 123, 45, 67, 89, 10, 11, 12, };
diff --git a/tests/pp/06.c b/tests/pp/06.c
new file mode 100644
index 0000000..28cfdde
--- /dev/null
+++ b/tests/pp/06.c
@@ -0,0 +1,5 @@
+#define X(a,b, \
+ c,d) \
+ foo
+
+X(1,2,3,4)
diff --git a/tests/pp/06.expect b/tests/pp/06.expect
new file mode 100644
index 0000000..257cc56
--- /dev/null
+++ b/tests/pp/06.expect
@@ -0,0 +1 @@
+foo
diff --git a/tests/pp/07.c b/tests/pp/07.c
new file mode 100644
index 0000000..b22b22b
--- /dev/null
+++ b/tests/pp/07.c
@@ -0,0 +1,4 @@
+#define a() YES
+#define b() a
+b()
+b()()
diff --git a/tests/pp/07.expect b/tests/pp/07.expect
new file mode 100644
index 0000000..ad0e20a
--- /dev/null
+++ b/tests/pp/07.expect
@@ -0,0 +1,2 @@
+a
+YES
diff --git a/tests/pp/08.c b/tests/pp/08.c
new file mode 100644
index 0000000..93018e1
--- /dev/null
+++ b/tests/pp/08.c
@@ -0,0 +1,4 @@
+// test macro expansion in arguments
+#define s_pos s_s.s_pos
+#define foo(x) (x)
+foo(hej.s_pos)
diff --git a/tests/pp/08.expect b/tests/pp/08.expect
new file mode 100644
index 0000000..2b2e3ee
--- /dev/null
+++ b/tests/pp/08.expect
@@ -0,0 +1 @@
+(hej.s_s.s_pos)
diff --git a/tests/pp/09.c b/tests/pp/09.c
new file mode 100644
index 0000000..315b297
--- /dev/null
+++ b/tests/pp/09.c
@@ -0,0 +1,4 @@
+#define C(a,b,c) a##b##c
+#define N(x,y) C(x,_,y)
+#define A_O aaaaoooo
+N(A,O)
diff --git a/tests/pp/09.expect b/tests/pp/09.expect
new file mode 100644
index 0000000..adce0f9
--- /dev/null
+++ b/tests/pp/09.expect
@@ -0,0 +1 @@
+aaaaoooo
diff --git a/tests/pp/10.c b/tests/pp/10.c
new file mode 100644
index 0000000..f180eff
--- /dev/null
+++ b/tests/pp/10.c
@@ -0,0 +1,10 @@
+#define f(x) x
+#define g(x) f(x) f(x
+#define i(x) g(x)) g(x
+#define h(x) i(x))) i(x
+#define k(x) i(x))) i(x))))
+f(x)
+g(x))
+i(x)))
+h(x))))
+k(x))))
diff --git a/tests/pp/10.expect b/tests/pp/10.expect
new file mode 100644
index 0000000..bd18e18
--- /dev/null
+++ b/tests/pp/10.expect
@@ -0,0 +1,5 @@
+x
+x x
+x x x x
+x x x x x x x x
+x x x x x x x x))))
diff --git a/tests/pp/11.c b/tests/pp/11.c
new file mode 100644
index 0000000..c0edf62
--- /dev/null
+++ b/tests/pp/11.c
@@ -0,0 +1,31 @@
+#define D1(s, ...) s
+#define D2(s, ...) s D1(__VA_ARGS__)
+#define D3(s, ...) s D2(__VA_ARGS__)
+#define D4(s, ...) s D3(__VA_ARGS__)
+
+D1(a)
+D2(a, b)
+D3(a, b, c)
+D4(a, b, c, d)
+
+x D4(a, b, c, d) y
+x D4(a, b, c) y
+x D4(a, b) y
+x D4(a) y
+x D4() y
+
+#define GNU_COMMA(X,Y...) X,## Y
+
+x GNU_COMMA(A,B,C) y
+x GNU_COMMA(A,B) y
+x GNU_COMMA(A) y
+x GNU_COMMA() y
+
+#define __sun_attr___noreturn__ __attribute__((__noreturn__))
+#define ___sun_attr_inner(__a) __sun_attr_##__a
+#define __sun_attr__(__a) ___sun_attr_inner __a
+#define __NORETURN __sun_attr__((__noreturn__))
+__NORETURN
+#define X(...)
+#define Y(...) 1 __VA_ARGS__ 2
+Y(X X() ())
diff --git a/tests/pp/11.expect b/tests/pp/11.expect
new file mode 100644
index 0000000..6b9806c
--- /dev/null
+++ b/tests/pp/11.expect
@@ -0,0 +1,15 @@
+a
+a b
+a b c
+a b c d
+x a b c d y
+x a b c y
+x a b y
+x a y
+x y
+x A,B,C y
+x A,B y
+x A y
+x y
+__attribute__((__noreturn__))
+1 2
diff --git a/tests/pp/Makefile b/tests/pp/Makefile
new file mode 100644
index 0000000..c656f9a
--- /dev/null
+++ b/tests/pp/Makefile
@@ -0,0 +1,35 @@
+#
+# credits: 01..13.c from the pcc cpp-tests suite
+#
+
+TCC = ../../tcc
+TESTS = $(patsubst %.c,%.test,$(wildcard *.c))
+
+all test : $(TESTS)
+
+%.test: %.c %.expect
+ @echo PPTest $* ...
+ @$(TCC) -E -P $< >$*.output 2>&1 ; \
+ diff -Nu -b -B -I "^#" $(EXTRA_DIFF_OPTS) $*.expect $*.output \
+ && rm -f $*.output
+
+# automatically generate .expect files with gcc:
+%.expect :
+ gcc -E -P $*.c >$*.expect 2>&1
+
+# tell make not to delete
+.PRECIOUS: %.expect
+
+clean:
+ rm -vf *.output
+
+# 02.test : EXTRA_DIFF_OPTS = -w
+# 03.test : EXTRA_DIFF_OPTS = -w
+# 04.test : EXTRA_DIFF_OPTS = -w
+# 10.test : EXTRA_DIFF_OPTS = -w
+
+# diff options:
+# -b ighore space changes
+# -w ighore all whitespace
+# -B ignore blank lines
+# -I <RE> ignore lines matching RE