From cd832a311e56bda981c9c957ba45f1bc1f6cc737 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 4 Sep 2020 19:03:01 +0900 Subject: [PATCH] Rewrite tests in shell script in C --- .gitignore | 1 + Makefile | 17 ++- test.sh | 224 ------------------------------- test/arith.c | 36 +++++ test/common | 11 ++ test/control.c | 25 ++++ test-driver.sh => test/driver.sh | 2 +- test/function.c | 50 +++++++ test/pointer.c | 44 ++++++ test/string.c | 40 ++++++ test/test.h | 1 + test/variable.c | 52 +++++++ 12 files changed, 274 insertions(+), 229 deletions(-) delete mode 100755 test.sh create mode 100644 test/arith.c create mode 100644 test/common create mode 100644 test/control.c rename test-driver.sh => test/driver.sh (97%) create mode 100644 test/function.c create mode 100644 test/pointer.c create mode 100644 test/string.c create mode 100644 test/test.h create mode 100644 test/variable.c diff --git a/.gitignore b/.gitignore index efe9ce5..80996e9 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ **/a.out /tmp* /chibicc +/test/*.exe diff --git a/Makefile b/Makefile index 2b60351..000d77e 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,26 @@ CFLAGS=-std=c11 -g -fno-common + SRCS=$(wildcard *.c) OBJS=$(SRCS:.c=.o) +TEST_SRCS=$(wildcard test/*.c) +TESTS=$(TEST_SRCS:.c=.exe) + chibicc: $(OBJS) $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(OBJS): chibicc.h -test: chibicc - ./test.sh - ./test-driver.sh +test/%.exe: chibicc test/%.c + $(CC) -o- -E -P -C test/$*.c | ./chibicc -o test/$*.s - + $(CC) -o $@ test/$*.s -xc test/common + +test: $(TESTS) + for i in $^; do echo $$i; ./$$i || exit 1; echo; done + test/driver.sh clean: - rm -f chibicc *.o *~ tmp* + rm -rf chibicc tmp* $(TESTS) test/*.s test/*.exe + find * -type f '(' -name '*~' -o -name '*.o' ')' -exec rm {} ';' .PHONY: test clean diff --git a/test.sh b/test.sh deleted file mode 100755 index bb09ebb..0000000 --- a/test.sh +++ /dev/null @@ -1,224 +0,0 @@ -#!/bin/bash -cat < $actual" - else - echo "$input => $expected expected, but got $actual" - exit 1 - fi -} - -assert 0 'int main() { return 0; }' -assert 42 'int main() { return 42; }' -assert 21 'int main() { return 5+20-4; }' -assert 41 'int main() { return 12 + 34 - 5 ; }' -assert 47 'int main() { return 5+6*7; }' -assert 15 'int main() { return 5*(9-6); }' -assert 4 'int main() { return (3+5)/2; }' -assert 10 'int main() { return -10+20; }' -assert 10 'int main() { return - -10; }' -assert 10 'int main() { return - - +10; }' - -assert 0 'int main() { return 0==1; }' -assert 1 'int main() { return 42==42; }' -assert 1 'int main() { return 0!=1; }' -assert 0 'int main() { return 42!=42; }' - -assert 1 'int main() { return 0<1; }' -assert 0 'int main() { return 1<1; }' -assert 0 'int main() { return 2<1; }' -assert 1 'int main() { return 0<=1; }' -assert 1 'int main() { return 1<=1; }' -assert 0 'int main() { return 2<=1; }' - -assert 1 'int main() { return 1>0; }' -assert 0 'int main() { return 1>1; }' -assert 0 'int main() { return 1>2; }' -assert 1 'int main() { return 1>=0; }' -assert 1 'int main() { return 1>=1; }' -assert 0 'int main() { return 1>=2; }' - -assert 3 'int main() { int a; a=3; return a; }' -assert 3 'int main() { int a=3; return a; }' -assert 8 'int main() { int a=3; int z=5; return a+z; }' - -assert 1 'int main() { return 1; 2; 3; }' -assert 2 'int main() { 1; return 2; 3; }' -assert 3 'int main() { 1; 2; return 3; }' - -assert 3 'int main() { int a=3; return a; }' -assert 8 'int main() { int a=3; int z=5; return a+z; }' -assert 6 'int main() { int a; int b; a=b=3; return a+b; }' -assert 3 'int main() { int foo=3; return foo; }' -assert 8 'int main() { int foo123=3; int bar=5; return foo123+bar; }' - -assert 3 'int main() { if (0) return 2; return 3; }' -assert 3 'int main() { if (1-1) return 2; return 3; }' -assert 2 'int main() { if (1) return 2; return 3; }' -assert 2 'int main() { if (2-1) return 2; return 3; }' - -assert 55 'int main() { int i=0; int j=0; for (i=0; i<=10; i=i+1) j=i+j; return j; }' -assert 3 'int main() { for (;;) return 3; return 5; }' - -assert 10 'int main() { int i=0; while(i<10) i=i+1; return i; }' - -assert 3 'int main() { {1; {2;} return 3;} }' -assert 5 'int main() { ;;; return 5; }' - -assert 10 'int main() { int i=0; while(i<10) i=i+1; return i; }' -assert 55 'int main() { int i=0; int j=0; while(i<=10) {j=i+j; i=i+1;} return j; }' - -assert 3 'int main() { int x=3; return *&x; }' -assert 3 'int main() { int x=3; int *y=&x; int **z=&y; return **z; }' -assert 5 'int main() { int x=3; int y=5; return *(&x+1); }' -assert 3 'int main() { int x=3; int y=5; return *(&y-1); }' -assert 5 'int main() { int x=3; int y=5; return *(&x-(-1)); }' -assert 5 'int main() { int x=3; int *y=&x; *y=5; return x; }' -assert 7 'int main() { int x=3; int y=5; *(&x+1)=7; return y; }' -assert 7 'int main() { int x=3; int y=5; *(&y-2+1)=7; return x; }' -assert 5 'int main() { int x=3; return (&x+2)-&x+3; }' -assert 8 'int main() { int x, y; x=3; y=5; return x+y; }' -assert 8 'int main() { int x=3, y=5; return x+y; }' - -assert 3 'int main() { return ret3(); }' -assert 5 'int main() { return ret5(); }' -assert 8 'int main() { return add(3, 5); }' -assert 2 'int main() { return sub(5, 3); }' -assert 21 'int main() { return add6(1,2,3,4,5,6); }' -assert 66 'int main() { return add6(1,2,add6(3,4,5,6,7,8),9,10,11); }' -assert 136 'int main() { return add6(1,2,add6(3,add6(4,5,6,7,8,9),10,11,12,13),14,15,16); }' - -assert 32 'int main() { return ret32(); } int ret32() { return 32; }' -assert 7 'int main() { return add2(3,4); } int add2(int x, int y) { return x+y; }' -assert 1 'int main() { return sub2(4,3); } int sub2(int x, int y) { return x-y; }' -assert 55 'int main() { return fib(9); } int fib(int x) { if (x<=1) return 1; return fib(x-1) + fib(x-2); }' - -assert 3 'int main() { int x[2]; int *y=&x; *y=3; return *x; }' - -assert 3 'int main() { int x[3]; *x=3; *(x+1)=4; *(x+2)=5; return *x; }' -assert 4 'int main() { int x[3]; *x=3; *(x+1)=4; *(x+2)=5; return *(x+1); }' -assert 5 'int main() { int x[3]; *x=3; *(x+1)=4; *(x+2)=5; return *(x+2); }' - -assert 0 'int main() { int x[2][3]; int *y=x; *y=0; return **x; }' -assert 1 'int main() { int x[2][3]; int *y=x; *(y+1)=1; return *(*x+1); }' -assert 2 'int main() { int x[2][3]; int *y=x; *(y+2)=2; return *(*x+2); }' -assert 3 'int main() { int x[2][3]; int *y=x; *(y+3)=3; return **(x+1); }' -assert 4 'int main() { int x[2][3]; int *y=x; *(y+4)=4; return *(*(x+1)+1); }' -assert 5 'int main() { int x[2][3]; int *y=x; *(y+5)=5; return *(*(x+1)+2); }' - -assert 3 'int main() { int x[3]; *x=3; x[1]=4; x[2]=5; return *x; }' -assert 4 'int main() { int x[3]; *x=3; x[1]=4; x[2]=5; return *(x+1); }' -assert 5 'int main() { int x[3]; *x=3; x[1]=4; x[2]=5; return *(x+2); }' -assert 5 'int main() { int x[3]; *x=3; x[1]=4; x[2]=5; return *(x+2); }' -assert 5 'int main() { int x[3]; *x=3; x[1]=4; 2[x]=5; return *(x+2); }' - -assert 0 'int main() { int x[2][3]; int *y=x; y[0]=0; return x[0][0]; }' -assert 1 'int main() { int x[2][3]; int *y=x; y[1]=1; return x[0][1]; }' -assert 2 'int main() { int x[2][3]; int *y=x; y[2]=2; return x[0][2]; }' -assert 3 'int main() { int x[2][3]; int *y=x; y[3]=3; return x[1][0]; }' -assert 4 'int main() { int x[2][3]; int *y=x; y[4]=4; return x[1][1]; }' -assert 5 'int main() { int x[2][3]; int *y=x; y[5]=5; return x[1][2]; }' - -assert 8 'int main() { int x; return sizeof(x); }' -assert 8 'int main() { int x; return sizeof x; }' -assert 8 'int main() { int *x; return sizeof(x); }' -assert 32 'int main() { int x[4]; return sizeof(x); }' -assert 96 'int main() { int x[3][4]; return sizeof(x); }' -assert 32 'int main() { int x[3][4]; return sizeof(*x); }' -assert 8 'int main() { int x[3][4]; return sizeof(**x); }' -assert 9 'int main() { int x[3][4]; return sizeof(**x) + 1; }' -assert 9 'int main() { int x[3][4]; return sizeof **x + 1; }' -assert 8 'int main() { int x[3][4]; return sizeof(**x + 1); }' -assert 8 'int main() { int x=1; return sizeof(x=2); }' -assert 1 'int main() { int x=1; sizeof(x=2); return x; }' - -assert 0 'int x; int main() { return x; }' -assert 3 'int x; int main() { x=3; return x; }' -assert 7 'int x; int y; int main() { x=3; y=4; return x+y; }' -assert 7 'int x, y; int main() { x=3; y=4; return x+y; }' -assert 0 'int x[4]; int main() { x[0]=0; x[1]=1; x[2]=2; x[3]=3; return x[0]; }' -assert 1 'int x[4]; int main() { x[0]=0; x[1]=1; x[2]=2; x[3]=3; return x[1]; }' -assert 2 'int x[4]; int main() { x[0]=0; x[1]=1; x[2]=2; x[3]=3; return x[2]; }' -assert 3 'int x[4]; int main() { x[0]=0; x[1]=1; x[2]=2; x[3]=3; return x[3]; }' - -assert 8 'int x; int main() { return sizeof(x); }' -assert 32 'int x[4]; int main() { return sizeof(x); }' - -assert 1 'int main() { char x=1; return x; }' -assert 1 'int main() { char x=1; char y=2; return x; }' -assert 2 'int main() { char x=1; char y=2; return y; }' - -assert 1 'int main() { char x; return sizeof(x); }' -assert 10 'int main() { char x[10]; return sizeof(x); }' -assert 1 'int main() { return sub_char(7, 3, 3); } int sub_char(char a, char b, char c) { return a-b-c; }' - -assert 0 'int main() { return ""[0]; }' -assert 1 'int main() { return sizeof(""); }' - -assert 97 'int main() { return "abc"[0]; }' -assert 98 'int main() { return "abc"[1]; }' -assert 99 'int main() { return "abc"[2]; }' -assert 0 'int main() { return "abc"[3]; }' -assert 4 'int main() { return sizeof("abc"); }' - -assert 7 'int main() { return "\a"[0]; }' -assert 8 'int main() { return "\b"[0]; }' -assert 9 'int main() { return "\t"[0]; }' -assert 10 'int main() { return "\n"[0]; }' -assert 11 'int main() { return "\v"[0]; }' -assert 12 'int main() { return "\f"[0]; }' -assert 13 'int main() { return "\r"[0]; }' -assert 27 'int main() { return "\e"[0]; }' - -assert 106 'int main() { return "\j"[0]; }' -assert 107 'int main() { return "\k"[0]; }' -assert 108 'int main() { return "\l"[0]; }' - -assert 7 'int main() { return "\ax\ny"[0]; }' -assert 120 'int main() { return "\ax\ny"[1]; }' -assert 10 'int main() { return "\ax\ny"[2]; }' -assert 121 'int main() { return "\ax\ny"[3]; }' - -assert 0 'int main() { return "\0"[0]; }' -assert 16 'int main() { return "\20"[0]; }' -assert 65 'int main() { return "\101"[0]; }' -assert 104 'int main() { return "\1500"[0]; }' -assert 0 'int main() { return "\x00"[0]; }' -assert 119 'int main() { return "\x77"[0]; }' -assert 165 'int main() { return "\xA5"[0]; }' -assert 255 'int main() { return "\x00ff"[0]; }' - -assert 0 'int main() { return ({ 0; }); }' -assert 2 'int main() { return ({ 0; 1; 2; }); }' -assert 1 'int main() { ({ 0; return 1; 2; }); return 3; }' -assert 6 'int main() { return ({ 1; }) + ({ 2; }) + ({ 3; }); }' -assert 3 'int main() { return ({ int x=3; x; }); }' - -assert 2 'int main() { /* return 1; */ return 2; }' -assert 2 'int main() { // return 1; -return 2; }' - -assert 2 'int main() { int x=2; { int x=3; } return x; }' -assert 2 'int main() { int x=2; { int x=3; } { int y=4; return x; }}' -assert 3 'int main() { int x=2; { x=3; } return x; }' - -echo OK diff --git a/test/arith.c b/test/arith.c new file mode 100644 index 0000000..44b699c --- /dev/null +++ b/test/arith.c @@ -0,0 +1,36 @@ +#include "test.h" + +int main() { + ASSERT(0, 0); + ASSERT(42, 42); + ASSERT(21, 5+20-4); + ASSERT(41, 12 + 34 - 5 ); + ASSERT(47, 5+6*7); + ASSERT(15, 5*(9-6)); + ASSERT(4, (3+5)/2); + ASSERT(10, -10+20); + ASSERT(10, - -10); + ASSERT(10, - - +10); + + ASSERT(0, 0==1); + ASSERT(1, 42==42); + ASSERT(1, 0!=1); + ASSERT(0, 42!=42); + + ASSERT(1, 0<1); + ASSERT(0, 1<1); + ASSERT(0, 2<1); + ASSERT(1, 0<=1); + ASSERT(1, 1<=1); + ASSERT(0, 2<=1); + + ASSERT(1, 1>0); + ASSERT(0, 1>1); + ASSERT(0, 1>2); + ASSERT(1, 1>=0); + ASSERT(1, 1>=1); + ASSERT(0, 1>=2); + + printf("OK\n"); + return 0; +} diff --git a/test/common b/test/common new file mode 100644 index 0000000..9d16496 --- /dev/null +++ b/test/common @@ -0,0 +1,11 @@ +#include +#include + +void assert(int expected, int actual, char *code) { + if (expected == actual) { + printf("%s => %d\n", code, actual); + } else { + printf("%s => %d expected but got %d\n", code, expected, actual); + exit(1); + } +} diff --git a/test/control.c b/test/control.c new file mode 100644 index 0000000..7e8a5d0 --- /dev/null +++ b/test/control.c @@ -0,0 +1,25 @@ +#include "test.h" + +/* + * This is a block comment. + */ + +int main() { + ASSERT(3, ({ int x; if (0) x=2; else x=3; x; })); + ASSERT(3, ({ int x; if (1-1) x=2; else x=3; x; })); + ASSERT(2, ({ int x; if (1) x=2; else x=3; x; })); + ASSERT(2, ({ int x; if (2-1) x=2; else x=3; x; })); + + ASSERT(55, ({ int i=0; int j=0; for (i=0; i<=10; i=i+1) j=i+j; j; })); + + ASSERT(10, ({ int i=0; while(i<10) i=i+1; i; })); + + ASSERT(3, ({ 1; {2;} 3; })); + ASSERT(5, ({ ;;; 5; })); + + ASSERT(10, ({ int i=0; while(i<10) i=i+1; i; })); + ASSERT(55, ({ int i=0; int j=0; while(i<=10) {j=i+j; i=i+1;} j; })); + + printf("OK\n"); + return 0; +} diff --git a/test-driver.sh b/test/driver.sh similarity index 97% rename from test-driver.sh rename to test/driver.sh index 113336a..5f919fa 100755 --- a/test-driver.sh +++ b/test/driver.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash tmp=`mktemp -d /tmp/chibicc-test-XXXXXX` trap 'rm -rf $tmp' INT TERM HUP EXIT echo > $tmp/empty.c diff --git a/test/function.c b/test/function.c new file mode 100644 index 0000000..39fff11 --- /dev/null +++ b/test/function.c @@ -0,0 +1,50 @@ +#include "test.h" + +int ret3() { + return 3; + return 5; +} + +int add2(int x, int y) { + return x + y; +} + +int sub2(int x, int y) { + return x - y; +} + +int add6(int a, int b, int c, int d, int e, int f) { + return a + b + c + d + e + f; +} + +int addx(int *x, int y) { + return *x + y; +} + +int sub_char(char a, char b, char c) { + return a - b - c; +} + +int fib(int x) { + if (x<=1) + return 1; + return fib(x-1) + fib(x-2); +} + +int main() { + ASSERT(3, ret3()); + ASSERT(8, add2(3, 5)); + ASSERT(2, sub2(5, 3)); + ASSERT(21, add6(1,2,3,4,5,6)); + ASSERT(66, add6(1,2,add6(3,4,5,6,7,8),9,10,11)); + ASSERT(136, add6(1,2,add6(3,add6(4,5,6,7,8,9),10,11,12,13),14,15,16)); + + ASSERT(7, add2(3,4)); + ASSERT(1, sub2(4,3)); + ASSERT(55, fib(9)); + + ASSERT(1, ({ sub_char(7, 3, 3); })); + + printf("OK\n"); + return 0; +} diff --git a/test/pointer.c b/test/pointer.c new file mode 100644 index 0000000..f7b4e59 --- /dev/null +++ b/test/pointer.c @@ -0,0 +1,44 @@ +#include "test.h" + +int main() { + ASSERT(3, ({ int x=3; *&x; })); + ASSERT(3, ({ int x=3; int *y=&x; int **z=&y; **z; })); + ASSERT(5, ({ int x=3; int y=5; *(&x+1); })); + ASSERT(3, ({ int x=3; int y=5; *(&y-1); })); + ASSERT(5, ({ int x=3; int y=5; *(&x-(-1)); })); + ASSERT(5, ({ int x=3; int *y=&x; *y=5; x; })); + ASSERT(7, ({ int x=3; int y=5; *(&x+1)=7; y; })); + ASSERT(7, ({ int x=3; int y=5; *(&y-2+1)=7; x; })); + ASSERT(5, ({ int x=3; (&x+2)-&x+3; })); + ASSERT(8, ({ int x, y; x=3; y=5; x+y; })); + ASSERT(8, ({ int x=3, y=5; x+y; })); + + ASSERT(3, ({ int x[2]; int *y=&x; *y=3; *x; })); + + ASSERT(3, ({ int x[3]; *x=3; *(x+1)=4; *(x+2)=5; *x; })); + ASSERT(4, ({ int x[3]; *x=3; *(x+1)=4; *(x+2)=5; *(x+1); })); + ASSERT(5, ({ int x[3]; *x=3; *(x+1)=4; *(x+2)=5; *(x+2); })); + + ASSERT(0, ({ int x[2][3]; int *y=x; *y=0; **x; })); + ASSERT(1, ({ int x[2][3]; int *y=x; *(y+1)=1; *(*x+1); })); + ASSERT(2, ({ int x[2][3]; int *y=x; *(y+2)=2; *(*x+2); })); + ASSERT(3, ({ int x[2][3]; int *y=x; *(y+3)=3; **(x+1); })); + ASSERT(4, ({ int x[2][3]; int *y=x; *(y+4)=4; *(*(x+1)+1); })); + ASSERT(5, ({ int x[2][3]; int *y=x; *(y+5)=5; *(*(x+1)+2); })); + + ASSERT(3, ({ int x[3]; *x=3; x[1]=4; x[2]=5; *x; })); + ASSERT(4, ({ int x[3]; *x=3; x[1]=4; x[2]=5; *(x+1); })); + ASSERT(5, ({ int x[3]; *x=3; x[1]=4; x[2]=5; *(x+2); })); + ASSERT(5, ({ int x[3]; *x=3; x[1]=4; x[2]=5; *(x+2); })); + ASSERT(5, ({ int x[3]; *x=3; x[1]=4; 2[x]=5; *(x+2); })); + + ASSERT(0, ({ int x[2][3]; int *y=x; y[0]=0; x[0][0]; })); + ASSERT(1, ({ int x[2][3]; int *y=x; y[1]=1; x[0][1]; })); + ASSERT(2, ({ int x[2][3]; int *y=x; y[2]=2; x[0][2]; })); + ASSERT(3, ({ int x[2][3]; int *y=x; y[3]=3; x[1][0]; })); + ASSERT(4, ({ int x[2][3]; int *y=x; y[4]=4; x[1][1]; })); + ASSERT(5, ({ int x[2][3]; int *y=x; y[5]=5; x[1][2]; })); + + printf("OK\n"); + return 0; +} diff --git a/test/string.c b/test/string.c new file mode 100644 index 0000000..303e72b --- /dev/null +++ b/test/string.c @@ -0,0 +1,40 @@ +#include "test.h" + +int main() { + ASSERT(0, ""[0]); + ASSERT(1, sizeof("")); + + ASSERT(97, "abc"[0]); + ASSERT(98, "abc"[1]); + ASSERT(99, "abc"[2]); + ASSERT(0, "abc"[3]); + ASSERT(4, sizeof("abc")); + + ASSERT(7, "\a"[0]); + ASSERT(8, "\b"[0]); + ASSERT(9, "\t"[0]); + ASSERT(10, "\n"[0]); + ASSERT(11, "\v"[0]); + ASSERT(12, "\f"[0]); + ASSERT(13, "\r"[0]); + ASSERT(27, "\e"[0]); + + ASSERT(106, "\j"[0]); + ASSERT(107, "\k"[0]); + ASSERT(108, "\l"[0]); + + ASSERT(7, "\ax\ny"[0]); + ASSERT(120, "\ax\ny"[1]); + ASSERT(10, "\ax\ny"[2]); + ASSERT(121, "\ax\ny"[3]); + + ASSERT(0, "\0"[0]); + ASSERT(16, "\20"[0]); + ASSERT(65, "\101"[0]); + ASSERT(104, "\1500"[0]); + ASSERT(0, "\x00"[0]); + ASSERT(119, "\x77"[0]); + + printf("OK\n"); + return 0; +} diff --git a/test/test.h b/test/test.h new file mode 100644 index 0000000..bdbd474 --- /dev/null +++ b/test/test.h @@ -0,0 +1 @@ +#define ASSERT(x, y) assert(x, y, #y) diff --git a/test/variable.c b/test/variable.c new file mode 100644 index 0000000..2c995fd --- /dev/null +++ b/test/variable.c @@ -0,0 +1,52 @@ +#include "test.h" + +int g1, g2[4]; + +int main() { + ASSERT(3, ({ int a; a=3; a; })); + ASSERT(3, ({ int a=3; a; })); + ASSERT(8, ({ int a=3; int z=5; a+z; })); + + ASSERT(3, ({ int a=3; a; })); + ASSERT(8, ({ int a=3; int z=5; a+z; })); + ASSERT(6, ({ int a; int b; a=b=3; a+b; })); + ASSERT(3, ({ int foo=3; foo; })); + ASSERT(8, ({ int foo123=3; int bar=5; foo123+bar; })); + + ASSERT(8, ({ int x; sizeof(x); })); + ASSERT(8, ({ int x; sizeof x; })); + ASSERT(8, ({ int *x; sizeof(x); })); + ASSERT(32, ({ int x[4]; sizeof(x); })); + ASSERT(96, ({ int x[3][4]; sizeof(x); })); + ASSERT(32, ({ int x[3][4]; sizeof(*x); })); + ASSERT(8, ({ int x[3][4]; sizeof(**x); })); + ASSERT(9, ({ int x[3][4]; sizeof(**x) + 1; })); + ASSERT(9, ({ int x[3][4]; sizeof **x + 1; })); + ASSERT(8, ({ int x[3][4]; sizeof(**x + 1); })); + ASSERT(8, ({ int x=1; sizeof(x=2); })); + ASSERT(1, ({ int x=1; sizeof(x=2); x; })); + + ASSERT(0, g1); + ASSERT(3, ({ g1=3; g1; })); + ASSERT(0, ({ g2[0]=0; g2[1]=1; g2[2]=2; g2[3]=3; g2[0]; })); + ASSERT(1, ({ g2[0]=0; g2[1]=1; g2[2]=2; g2[3]=3; g2[1]; })); + ASSERT(2, ({ g2[0]=0; g2[1]=1; g2[2]=2; g2[3]=3; g2[2]; })); + ASSERT(3, ({ g2[0]=0; g2[1]=1; g2[2]=2; g2[3]=3; g2[3]; })); + + ASSERT(8, sizeof(g1)); + ASSERT(32, sizeof(g2)); + + ASSERT(1, ({ char x=1; x; })); + ASSERT(1, ({ char x=1; char y=2; x; })); + ASSERT(2, ({ char x=1; char y=2; y; })); + + ASSERT(1, ({ char x; sizeof(x); })); + ASSERT(10, ({ char x[10]; sizeof(x); })); + + ASSERT(2, ({ int x=2; { int x=3; } x; })); + ASSERT(2, ({ int x=2; { int x=3; } int y=4; x; })); + ASSERT(3, ({ int x=2; { x=3; } x; })); + + printf("OK\n"); + return 0; +}