aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xtest_all.sh11
-rw-r--r--testcases/fail1.c2
-rw-r--r--testcases/fail2.c4
-rw-r--r--testcases/fail3.c4
-rw-r--r--testcases/fail4.c3
-rw-r--r--testcases/fail5.c4
-rw-r--r--testcases/fail6.c5
-rw-r--r--testcases/fail7.c6
-rw-r--r--testcases/pass.c80
9 files changed, 119 insertions, 0 deletions
diff --git a/test_all.sh b/test_all.sh
new file mode 100755
index 0000000..28c26d4
--- /dev/null
+++ b/test_all.sh
@@ -0,0 +1,11 @@
+#! /bin/bash
+for file in test/*
+do
+ gcc $file -o /dev/null &> /dev/null
+ gcc_ret="$?"
+ ./cibic $file &> /dev/null
+ if [ $? -ne $gcc_ret ]; then
+ echo "Failed on $file"
+ break
+ fi
+done
diff --git a/testcases/fail1.c b/testcases/fail1.c
new file mode 100644
index 0000000..f80ecaa
--- /dev/null
+++ b/testcases/fail1.c
@@ -0,0 +1,2 @@
+int main(struct C c) { /* fail because of incomplete type of parameter */
+}
diff --git a/testcases/fail2.c b/testcases/fail2.c
new file mode 100644
index 0000000..a76d4e0
--- /dev/null
+++ b/testcases/fail2.c
@@ -0,0 +1,4 @@
+int main() {
+ /* fail because of incomplete type of local variable */
+ struct C c;
+}
diff --git a/testcases/fail3.c b/testcases/fail3.c
new file mode 100644
index 0000000..ad47f5f
--- /dev/null
+++ b/testcases/fail3.c
@@ -0,0 +1,4 @@
+int main(int main) {
+ /* fail because `f' is overrided by parameter */
+ main(3);
+}
diff --git a/testcases/fail4.c b/testcases/fail4.c
new file mode 100644
index 0000000..20033af
--- /dev/null
+++ b/testcases/fail4.c
@@ -0,0 +1,3 @@
+int main() {
+ (void)1 + 2; /* not ok */
+}
diff --git a/testcases/fail5.c b/testcases/fail5.c
new file mode 100644
index 0000000..0e8fba8
--- /dev/null
+++ b/testcases/fail5.c
@@ -0,0 +1,4 @@
+int main() {
+ /* fail because of incomplete field */
+ struct C {struct B b;} *c;
+}
diff --git a/testcases/fail6.c b/testcases/fail6.c
new file mode 100644
index 0000000..3419ce9
--- /dev/null
+++ b/testcases/fail6.c
@@ -0,0 +1,5 @@
+int main() {
+ struct C {int x;} *c;
+ /* fail because no member called `y' */
+ c->y;
+}
diff --git a/testcases/fail7.c b/testcases/fail7.c
new file mode 100644
index 0000000..5040408
--- /dev/null
+++ b/testcases/fail7.c
@@ -0,0 +1,6 @@
+int *main(int a,int b) {
+ struct {int x;} c;
+ /* fail because of wrong argument type */
+ main(2, c);
+ return &a;
+}
diff --git a/testcases/pass.c b/testcases/pass.c
new file mode 100644
index 0000000..b219178
--- /dev/null
+++ b/testcases/pass.c
@@ -0,0 +1,80 @@
+int;
+char;
+struct {int x;};
+/* useless declarations are ok */
+
+int a(int a);
+int a(int d);
+/* duplicate function declarations are ok */
+
+struct A {int x; int y;} b;
+
+/* struct definitions in parameters is in a local scope
+ * subsequent parameter can make use of previous defined struct */
+
+int foo(struct A {int x;} a, struct A b) {
+ /* function declaration in local scope is ok */
+ int f(char *x);
+ /* A is defined in parameters */
+ struct A c;
+ c.x = 43;
+}
+
+void bar() {
+ /* struct definition is ok inside a function */
+ struct A {int x;};
+ struct A a;
+ a.x = 1;
+ {
+ /* the following `A' is different from previous one */
+ struct A {int y;};
+ struct A b;
+ b.y = 2;
+ }
+}
+
+struct C c;
+struct C {
+ struct D {
+ int x, y;
+ } b;
+ int c;
+ struct D d;
+};
+struct D d; /* feasible here */
+
+void nonsense() {
+ char q;
+ (void)q;
+ return "yay";
+}
+
+int assign() {
+ int *a;
+ struct {int *x;} b;
+ a = b.x;
+}
+
+void incomplete() {
+ struct E {struct F *f;} e;
+}
+
+void delay() {
+ struct G *g;
+ struct G {int x; };
+ g->x = 1;
+}
+
+void comma() {
+ int a;
+ int *b;
+ (b++, a++) * 3;
+}
+
+struct Node n;
+struct Node {int x, y;} n;
+/* global forward declaration is ok */
+int main() {
+ n.x = 1;
+ n.y = 2;
+}