scc

Simple C99 Compiler
Log | Files | Refs | README | LICENSE

commit 6f9ef1f63042cefbb131583f8ade090962d48956
parent 916d231a2f99346dd4d1e0f0c768f6ffadccb8cd
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 20 Jan 2016 16:00:56 +0100

Add tests for initializers

Diffstat:
cc1/tests/test045.c | 33+++++++++++++++++++++++++++++++++
cc1/tests/test046.c | 44++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test047.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test048.c | 46++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test049.c | 36++++++++++++++++++++++++++++++++++++
cc1/tests/test050.c | 21+++++++++++++++++++++
cc1/tests/test051.c | 44++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test052.c | 54++++++++++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test053.c | 41+++++++++++++++++++++++++++++++++++++++++
cc1/tests/test054.c | 22++++++++++++++++++++++
cc1/tests/test055.c | 43+++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test056.c | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test057.c | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test058.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
cc1/tests/test059.c | 35+++++++++++++++++++++++++++++++++++
15 files changed, 646 insertions(+), 0 deletions(-)

diff --git a/cc1/tests/test045.c b/cc1/tests/test045.c @@ -0,0 +1,33 @@ +/* +name: TEST045 +description: Basic test of initializers +error: + +output: +G1 I x +( + #I5 +) +F2 I E +G3 F2 main +{ +\ + j L4 G1 #I5 =I + r #I1 +L4 + r #I0 +} + +*/ + + + +int x = 5; + +int +main() +{ + if(x != 5) + return 1; + return 0; +} diff --git a/cc1/tests/test046.c b/cc1/tests/test046.c @@ -0,0 +1,44 @@ +/* +name: TEST046 +description: Basic test for initializators +error: + +output: +V1 I #3 +G2 V1 x +( + #I1 + #I2 + #I3 +) +F3 I E +G4 F3 main +{ +\ + j L5 G2 #I1 =I + r #I1 +L5 + j L7 G2 'P #P2 +P @I #I2 =I + r #I2 +L7 + j L8 G2 'P #P4 +P @I #I3 =I + r #I3 +L8 + r #I0 +} + +*/ + +int x[3] = {1, 2, 3}; + +int +main() +{ + if(x[0] != 1) + return 1; + if(x[1] != 2) + return 2; + if(x[2] != 3) + return 3; + return 0; +} diff --git a/cc1/tests/test047.c b/cc1/tests/test047.c @@ -0,0 +1,55 @@ +/* +name: TEST047 +description: Basic test for initializer +error: + +output: +S2 S +M3 I a +M4 I b +M5 I c +G6 S2 x +( + #I1 + #I2 + #I3 +) +F7 I E +G8 F7 main +{ +\ + j L9 G6 M3 .I #I1 =I + r #I1 +L9 + j L10 G6 M4 .I #I2 =I + r #I2 +L10 + j L11 G6 M5 .I #I3 =I + r #I3 +L11 + r #I0 +} + +*/ + + + +struct S { + int a; + int b; + int c; +}; + +struct S x = {1, 2, 3}; + +int +main() +{ + if(x.a != 1) + return 1; + if(x.b != 2) + return 2; + if(x.c != 3) + return 3; + return 0; +} diff --git a/cc1/tests/test048.c b/cc1/tests/test048.c @@ -0,0 +1,46 @@ +/* +name: TEST048 +description: Basic test for initializer +error: + +output: +S2 S +M3 I a +M4 I b +V5 S2 #1 +G6 V5 x +( + #I1 + #I2 +) +F7 I E +G8 F7 main +{ +\ + j L9 G6 M3 .I #I1 =I + r #I1 +L9 + j L11 G6 M4 .I #I2 =I + r #I2 +L11 + r #I0 +} + +*/ + +struct S { + int a; + int b; +}; + +struct S x[1] = {{1, 2}}; + +int +main() +{ + if(x[0].a != 1) + return 1; + if(x[0].b != 2) + return 2; + return 0; +} diff --git a/cc1/tests/test049.c b/cc1/tests/test049.c @@ -0,0 +1,36 @@ +/* +name: TEST049 +description: Basic test for initializer +error: + +output: +G1 I x +( + #I5 +) +G3 P p +( + G1 'P +) +F4 I E +G5 F4 main +{ +\ + j L6 G3 @I #I5 =I + r #I1 +L6 + r #I0 +} + +*/ + +int x = 5; +int *p = &x; + +int +main() +{ + if(*p != 5) + return 1; + return 0; +} diff --git a/cc1/tests/test050.c b/cc1/tests/test050.c @@ -0,0 +1,21 @@ +/* +name: TEST050 +description: Basic test for initializer +error: +TODO +output: + +*/ + +struct S { int a; int b; }; +struct S s = (struct S){1, 2}; + +int +main() +{ + if(s.a != 1) + return 1; + if(s.b != 2) + return 2; + return 0; +} diff --git a/cc1/tests/test051.c b/cc1/tests/test051.c @@ -0,0 +1,44 @@ +/* +name: TEST051 +description: Basic test for initializer +error: + +output: +V1 I #3 +G2 V1 arr +( + #I0 + #I1 + #I2 +) +F3 I E +G4 F3 main +{ +\ + j L5 G2 #I0 =I + r #I1 +L5 + j L7 G2 'P #P2 +P @I #I1 =I + r #I2 +L7 + j L8 G2 'P #P4 +P @I #I2 =I + r #I3 +L8 + r #I0 +} + +*/ + +int arr[3] = {[2] = 2, [0] = 0, [1] = 1}; + +int +main() +{ + if(arr[0] != 0) + return 1; + if(arr[1] != 1) + return 2; + if(arr[2] != 2) + return 3; + return 0; +} diff --git a/cc1/tests/test052.c b/cc1/tests/test052.c @@ -0,0 +1,54 @@ +/* +name: TEST052 +description: Basic test for initializer +error: + +output: +S2 S +M3 I a +M4 I b +V5 S2 #2 +G6 V5 arr +( + #I1 + #I2 + #I3 + #I4 +) +F7 I E +G8 F7 main +{ +\ + j L9 G6 M3 .I #I1 =I + r #I1 +L9 + j L11 G6 M4 .I #I2 =I + r #I2 +L11 + j L12 G6 M3 .I #I3 =I + r #I3 +L12 + j L13 G6 M4 .I #I4 =I + r #I4 +L13 + r #I0 +} + +*/ + +struct S {int a; int b;}; +struct S arr[2] = {[1] = {3, 4}, [0] = {1, 2}}; + +int +main() +{ + if(arr[0].a != 1) + return 1; + if(arr[0].b != 2) + return 2; + if(arr[1].a != 3) + return 3; + if(arr[1].b != 4) + return 4; + return 0; +} diff --git a/cc1/tests/test053.c b/cc1/tests/test053.c @@ -0,0 +1,41 @@ +/* +name: TEST053 +description: Basic test for initializer +error: + +output: +S2 S +M3 I a +M4 I b +G5 S2 s +( + #I1 + #I2 +) +F6 I E +G7 F6 main +{ +\ + j L8 G5 M3 .I #I1 =I + r #I1 +L8 + j L9 G5 M4 .I #I2 =I + r #I2 +L9 + r #I0 +} + +*/ + +struct S {int a; int b;}; +struct S s = { .b = 2, .a = 1}; + +int +main() +{ + if(s.a != 1) + return 1; + if(s.b != 2) + return 2; + return 0; +} diff --git a/cc1/tests/test054.c b/cc1/tests/test054.c @@ -0,0 +1,22 @@ +/* +name: TEST054 +description: Basic test for initializer +error: +TODO +output: + +*/ + +struct S { int a; int b; }; +struct S *s = &(struct S) { 1, 2 }; + +int +main() +{ + if(s->a != 1) + return 1; + if(s->b != 2) + return 2; + return 0; +} + diff --git a/cc1/tests/test055.c b/cc1/tests/test055.c @@ -0,0 +1,43 @@ +/* +name: TEST055 +description: Basic test for initializer +error: +TODO +output: + +*/ + +struct S1 { + int a; + int b; +}; +struct S2 { + struct S1 s1; + struct S1 *ps1; + int arr[2]; +}; +struct S1 gs1 = (struct S1) {.a = 1, 2}; +struct S2 *s = &(struct S2) { + {.b = 2, .a = 1}, + &gs1, + {[0] = 1, 1+1} +}; + +int +main() +{ + if(s->s1.a != 1) + return 1; + if(s->s1.b != 2) + return 2; + if(s->ps1->a != 1) + return 3; + if(s->ps1->b != 2) + return 4; + if(s->arr[0] != 1) + return 5; + if(s->arr[1] != 2) + return 6; + return 0; +} + diff --git a/cc1/tests/test056.c b/cc1/tests/test056.c @@ -0,0 +1,53 @@ +/* +name: TEST056 +desciption: Test of overlaying designators +error: + +output: +V6 K #3 +S2 S +M3 I a +M4 I b +M5 I c +M7 V6 d +M8 I e +G9 S2 s +( + #I1 + #I2 + #I0 + #K4 + #K6 + #K0 + #I0 +) +F10 I +G11 F10 main +{ +\ +V12 K #0 +A13 V12 m + A13 :V12 + r G9 M7 .V6 'P #P2 +P @K gI gN #N0 !I +} + +*/ + +struct S { + int a, b, c; + char d[3]; + int e; +} s = { + .a = 1, + .b = 2, + .d = {[0] = 3, [2] = 5}, + .d = {[0] = 4, [1] = 6} +}; + +int +main(void) +{ + char m[] = {}; + + return sizeof(m) == s.d[2]; +} diff --git a/cc1/tests/test057.c b/cc1/tests/test057.c @@ -0,0 +1,51 @@ + +/* +name: TEST057 +description: test of initialization of incomplete arrays +error: + +output: +V1 I #3 +V2 V1 #2 +G3 V2 arr1 +( + #I2 + #I7 + #I5 + #I5 + #I1 + #I2 +) +G4 V2 arr2 +( + #I2 + #I7 + #I5 + #I5 + #I1 + #I2 +) +F5 I +G6 F5 main +{ +\ + r G3 'P #P6 +P #P4 +P @I G4 'P #P6 +P #P6 +P @I !I +} + +*/ + +int arr1[][3] = { + { 2, 7, 5, }, + { 5, 1, 2, }, +}; + +int arr2[2][3] = { + 2, 7, 5, + 5, 1, 2 +}; + +int +main(void) +{ + return !(arr1[1][2] == arr2[1][3]); +} diff --git a/cc1/tests/test058.c b/cc1/tests/test058.c @@ -0,0 +1,68 @@ +/* +name: TEST058 +description: Test of initialization mixing dsignators and sequence +error: + +output: +V1 I #5 +V2 V1 #3 +V3 V2 #2 +G4 V3 arr +( + #I0 + #I0 + #I3 + #I5 + #I0 + #I1 + #I0 + #I0 + #I6 + #I7 + #I0 + #I0 + #I0 + #I0 + #I0 + #I1 + #I2 + #I0 + #I0 + #I0 + #I0 + #I0 + #I0 + #I0 + #I7 + #I0 + #I0 + #I0 + #I0 + #I0 +) +F5 I +G6 F5 main +{ +\ + r G4 'P #PA +P #P8 +P @I G4 'P #P1E +P #PA +P #P8 +P @I !I +} + +*/ + +int arr[][3][5] = { + { + { 0, 0, 3, 5 }, + { 1, [3] = 6, 7 }, + }, + { + { 1, 2 }, + { [4] = 7, }, + }, +}; + + +int +main(void) +{ + return !(arr[0][1][4] == arr[1][1][4]); +} diff --git a/cc1/tests/test059.c b/cc1/tests/test059.c @@ -0,0 +1,35 @@ +/* +name: TEST059 +description: Test of initalizers for strings +error: +test059.c:33: warning: initializer-string for array of chars is too long +test059.c:35: error: array of inappropriate type initialized from string constant + +output: +V1 K #4 +G2 V1 s0 +( + "666F6F00 +) +V4 K #7 +G5 V4 s1 +( + "666F6F00000000 +) +V6 K #2 +G7 V6 s2 +( + "666F +) +G9 P p +( + "666F6F00 'P +) + +*/ + +char s0[] = "foo"; +char s1[7] = "foo"; +char s2[2] = "foo"; +char *p = "foo"; +int m[] = "foo";