forked from rui314/chibicc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
tests
989 lines (820 loc) · 44.7 KB
/
tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
// -*- c -*-
// This is a line comment.
/*
* This is a block comment.
*/
#include <varvara.h>
void print(char *s) {
for (; *s; *s++) putchar(*s);
}
void put_hex(int word) {
char hex[16] = "0123456789abcdef";
putchar(hex[word >> 12 & 0xf]);
putchar(hex[word >> 8 & 0xf]);
putchar(hex[word >> 4 & 0xf]);
putchar(hex[word & 0xf]);
}
int strcmp(char *a, char *b) {
for (;;) {
char ac = *a++;
char bc = *b++;
if (ac - bc || (!ac && !bc)) {
return ac - bc;
}
}
}
int memcmp(void *a, void *b, int count) {
for (int i = 0; i < count; i++) {
char ac = *(*(char**)&a)++;
char bc = *(*(char**)&b)++;
if (ac - bc) {
return ac - bc;
}
}
}
int g1, g2[4];
typedef int MyInt;
char g3 = 3, *g8 = "abc";
short g4 = 4;
int g5 = 5;
// long isn't supported
//long g6 = 6;
int *g7 = &g5;
int g9[3] = {0, 1, 2};
char *g10[] = {"foo", "bar"};
struct {char a; int b;} g11[2] = {{1, 2}, {3, 4}};
struct {int a[2];} g12[2] = {{{1, 2}}};
struct {int a[2];} g13[2] = {{1, 2}, 3, 4};
struct {int a[2];} g14[2] = {1, 2, 3, 4};
char *g15 = {"foo"};
char g16[][4] = {'f', 'o', 'o', 0, 'b', 'a', 'r', 0};
char g17[] = "foobar";
char g18[10] = "foobar";
char g19[3] = "foobar";
char *g20 = g17+0;
// label + non-zero addend isn't supported
//char *g21 = g17+3;
//char *g22 = &g17-3;
//char *g23[] = {g17+0, g17+3, g17-3};
int g24=3;
int *g25=&g24;
int g26[3] = {1, 2, 3};
//int *g27 = g26 + 1;
typedef struct Tree {
int val;
struct Tree *lhs;
struct Tree *rhs;
} Tree;
Tree *tree = &(Tree){
1,
&(Tree){
2,
&(Tree){ 3, 0, 0 },
&(Tree){ 4, 0, 0 },
},
0,
};
// TODO: restore extern tests (separate uxntal file?)
//extern int ext1;
//extern int *ext2;
//static int ext3 = 3;
int;
struct {char a; int b;};
typedef struct {char a; int b;} Ty1;
int assert(int /*long*/ expected, int /*long*/ actual, char *code) {
if (expected == actual) {
print(code);
print("\e[32m PASS \e[0m");
put_hex(actual);
putchar('\n');
} else {
print(code);
print("\e[31m FAIL \e[0mexpected ");
put_hex(expected);
print(" but got ");
put_hex(actual);
putchar('\n');
exit(1);
}
}
int ret3() {
return 3;
return 5;
}
char ret_char_minus1(void)
{
return -1;
}
char ret_char_0xff(void)
{
return 0xff;
}
_Bool ret_bool_256(void)
{
return 256;
}
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 sub_short(short a, short b, short c) {
return a - b - c;
}
//int sub_long(long a, long b, long c) {
// return a - b - c;
//}
int *g1_ptr() {
return &g1;
}
int fib(int x) {
if (x<=1)
return 1;
return fib(x-1) + fib(x-2);
}
void ret_none() {
return;
}
// also extern (this definition is in this file but the test is to check the
// definition in another file isn't used)
//static int static_fn() { return 3; }
int param_decay(int x[]) { return x[0]; }
void voidfn(void) {}
int counter() {
static int i;
static int j = 1+1;
return i++ + j++;
}
// also extern
//_Bool true_fn();
//_Bool false_fn();
// also extern
//int add_all1(int x, ...);
//int add_all3(int z, int b, int c, ...);
int add_all1(int x, ...) {
va_list ap;
va_start(ap, x);
for (;;) {
int y = va_arg(ap, int);
if (y == 0)
return x;
x += y;
}
}
int add_all3(int x, int y, int z, ...) {
va_list ap;
va_start(ap, z);
x = x + y + z;
for (;;) {
int y = va_arg(ap, int);
if (y == 0)
return x;
x += y;
}
}
void main() {
// ********************************
// * Tests inherited from chibicc *
// ********************************
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");
assert(0, 0, "0");
assert(42, 42, "42");
assert(5, 5, "0");
assert(41, 12 + 34 - 5 , " 12 + 34 - 5 ");
assert(5, 5, "0");
assert(15, 5*(9-6), "5*(9-6)");
assert(4, (3+5)/2, "(3+5)/2");
assert(-10, -10, "0");
assert(10, - -10, "- -10");
assert(10, - - +10, "- - +10");
assert(0, 0==1, "0==1");
assert(1, 42==42, "42==42");
assert(1, 0!=1, "0!=1");
assert(0, 42!=42, "42!=42");
assert(1, 0<1, "0<1");
assert(0, 1<1, "1<1");
assert(0, 2<1, "2<1");
assert(1, 0<=1, "0<=1");
assert(1, 1<=1, "1<=1");
assert(0, 2<=1, "2<=1");
assert(1, 1>0, "1>0");
assert(0, 1>1, "1>1");
assert(0, 1>2, "1>2");
assert(1, 1>=0, "1>=0");
assert(1, 1>=1, "1>=1");
assert(0, 1>=2, "1>=2");
assert(3, ({ int a; a=3; a; }), "int a; a=3; a;");
assert(8, ({ int a; int z; a=3; z=5; a+z; }), "int a; int z; a=3; z=5; a+z;");
assert(3, ({ int a=3; a; }), "int a=3; a;");
assert(8, ({ int a=3; int z=5; a+z; }), "int a=3; int z=5; a+z;");
assert(3, ({ int foo=3; foo; }), "int foo=3; foo;");
assert(8, ({ int foo123=3; int bar=5; foo123+bar; }), "int foo123=3; int bar=5; foo123+bar;");
assert(3, ret3(), "ret3();");
assert(3, ({ int x=0; if (0) x=2; else x=3; x; }), "int x=0; if (0) x=2; else x=3; x;");
assert(3, ({ int x=0; if (1-1) x=2; else x=3; x; }), "int x=0; if (1-1) x=2; else x=3; x;");
assert(2, ({ int x=0; if (1) x=2; else x=3; x; }), "int x=0; if (1) x=2; else x=3; x;");
assert(2, ({ int x=0; if (2-1) x=2; else x=3; x; }), "int x=0; if (2-1) x=2; else x=3; x;");
assert(3, ({ 1; {2;} 3; }), "1; {2;} 3;");
assert(10, ({ int i=0; i=0; while(i<10) i=i+1; i; }), "int i=0; 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; }), "int i=0; int j=0; while(i<=10) {j=i+j; i=i+1;} j;");
assert(55, ({ int i=0; int j=0; for (i=0; i<=10; i=i+1) j=i+j; j; }), "int i=0; int j=0; for (i=0; i<=10; i=i+1) j=i+j; j;");
assert(8, add2(3, 5), "add(3, 5)");
assert(2, sub2(5, 3), "sub(5, 3)");
assert(21, add6(1,2,3,4,5,6), "add6(1,2,3,4,5,6)");
assert(55, fib(9), "fib(9)");
assert(3, ({ int x=3; *&x; }), "int x=3; *&x;");
assert(3, ({ int x=3; int *y=&x; int **z=&y; **z; }), "int x=3; int *y=&x; int **z=&y; **z;");
// Taking a pointer to one variable and doing arithmetic so it points to
// another variable is not defined behaviour in standard C and, if it does
// work, it depends on the stack layout. The layout seems to be reversed from
// the upstream (non-uxn) chibicc so these tests' signs have been reversed.
assert(5, ({ int x=3; int y=5; *(&x-1); }), "int x=3; int y=5; *(&x-1);");
assert(5, ({ int x=3; int y=5; *(-1+&x); }), "int x=3; int y=5; *(-1+&x);");
assert(3, ({ int x=3; int y=5; *(&y+1); }), "int x=3; int y=5; *(&y+1);");
assert(2, ({ int x=3; (&x+2)-&x; }), "int x=3; (&x+2)-&x;");
assert(5, ({ int x=3; int y=5; int *z=&x; *(z-1); }), "int x=3; int y=5; int *z=&x; *(z-1);");
assert(3, ({ int x=3; int y=5; int *z=&y; *(z+1); }), "int x=3; int y=5; int *z=&y; *(z+1);");
assert(5, ({ int x=3; int *y=&x; *y=5; x; }), "int x=3; int *y=&x; *y=5; x;");
assert(7, ({ int x=3; int y=5; *(&x-1)=7; y; }), "int x=3; int y=5; *(&x-1)=7; y;");
assert(7, ({ int x=3; int y=5; *(&y+1)=7; x; }), "int x=3; int y=5; *(&y+1)=7; x;");
assert(8, ({ int x=3; int y=5; addx(&x, y); }), "int x=3; int y=5; addx(&x, y);");
assert(3, ({ int x[2]; int *y=&x; *y=3; *x; }), "int x[2]; int *y=&x; *y=3; *x;");
assert(3, ({ int x[3]; *x=3; *(x+1)=4; *(x+2)=5; *x; }), "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); }), "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); }), "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; }), "int x[2][3]; int *y=x; *y=0; **x;");
assert(1, ({ int x[2][3]; int *y=x; *(y+1)=1; *(*x+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); }), "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); }), "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); }), "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); }), "int x[2][3]; int *y=x; *(y+5)=5; *(*(x+1)+2);");
assert(6, ({ int x[2][3]; int *y=x; *(y+6)=6; **(x+2); }), "int x[2][3]; int *y=x; *(y+6)=6; **(x+2);");
assert(3, ({ int x[3]; *x=3; x[1]=4; x[2]=5; *x; }), "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); }), "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); }), "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); }), "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); }), "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]; }), "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]; }), "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]; }), "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]; }), "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]; }), "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]; }), "int x[2][3]; int *y=x; y[5]=5; x[1][2];");
assert(6, ({ int x[2][3]; int *y=x; y[6]=6; x[2][0]; }), "int x[2][3]; int *y=x; y[6]=6; x[2][0];");
assert(2, ({ int x; sizeof(x); }), "int x; sizeof(x);");
assert(2, ({ int x; sizeof x; }), "int x; sizeof x;");
assert(2, ({ int *x; sizeof(x); }), "int *x; sizeof(x);");
assert(8, ({ int x[4]; sizeof(x); }), "int x[4]; sizeof(x);");
assert(24, ({ int x[3][4]; sizeof(x); }), "int x[3][4]; sizeof(x);");
assert(8, ({ int x[3][4]; sizeof(*x); }), "int x[3][4]; sizeof(*x);");
assert(2, ({ int x[3][4]; sizeof(**x); }), "int x[3][4]; sizeof(**x);");
assert(3, ({ int x[3][4]; sizeof(**x) + 1; }), "int x[3][4]; sizeof(**x) + 1;");
assert(3, ({ int x[3][4]; sizeof **x + 1; }), "int x[3][4]; sizeof **x + 1;");
assert(2, ({ int x[3][4]; sizeof(**x + 1); }), "int x[3][4]; sizeof(**x + 1);");
assert(0, g1, "g1");
g1=3;
assert(3, g1, "g1");
g2[0]=0; g2[1]=1; g2[2]=2; g2[3]=3;
assert(0, g2[0], "g2[0]");
assert(1, g2[1], "g2[1]");
assert(2, g2[2], "g2[2]");
assert(3, g2[3], "g2[3]");
assert(2, sizeof(g1), "sizeof(g1)");
assert(8, sizeof(g2), "sizeof(g2)");
assert(1, ({ char x=1; x; }), "char x=1; x;");
assert(1, ({ char x=1; char y=2; x; }), "char x=1; char y=2; x;");
assert(2, ({ char x=1; char y=2; y; }), "char x=1; char y=2; y;");
assert(1, ({ char x; sizeof(x); }), "char x; sizeof(x);");
assert(10, ({ char x[10]; sizeof(x); }), "char x[10]; sizeof(x);");
assert(1, sub_char(7, 3, 3), "sub_char(7, 3, 3)");
assert(97, "abc"[0], "\"abc\"[0]");
assert(98, "abc"[1], "\"abc\"[1]");
assert(99, "abc"[2], "\"abc\"[2]");
assert(0, "abc"[3], "\"abc\"[3]");
assert(4, sizeof("abc"), "sizeof(\"abc\")");
assert(7, "\a"[0], "\"\\a\"[0]");
assert(8, "\b"[0], "\"\\b\"[0]");
assert(9, "\t"[0], "\"\\t\"[0]");
assert(10, "\n"[0], "\"\\n\"[0]");
assert(11, "\v"[0], "\"\\v\"[0]");
assert(12, "\f"[0], "\"\\f\"[0]");
assert(13, "\r"[0], "\"\\r\"[0]");
assert(27, "\e"[0], "\"\\e\"[0]");
assert(0, "\0"[0], "\"\\0\"[0]");
assert(106, "\j"[0], "\"\\j\"[0]");
assert(107, "\k"[0], "\"\\k\"[0]");
assert(108, "\l"[0], "\"\\l\"[0]");
assert(2, ({ int x=2; { int x=3; } x; }), "int x=2; { int x=3; } x;");
assert(2, ({ int x=2; { int x=3; } int y=4; x; }), "int x=2; { int x=3; } int y=4; x;");
assert(3, ({ int x=2; { x=3; } x; }), "int x=2; { x=3; } x;");
assert(2, ({ int x[5]; int *y=x+2; y-x; }), "int x[5]; int *y=x+2; y-x;");
assert(1, ({ struct {int a, b;} x; x.a=1; x.b=2; x.a; }), "struct {int a, b;} x; x.a=1; x.b=2; x.a;");
assert(2, ({ struct {int a, b;} x; x.a=1; x.b=2; x.b; }), "struct {int a, b;} x; x.a=1; x.b=2; x.b;");
assert(1, ({ struct {char a; int b; char c;} x; x.a=1; x.b=2; x.c=3; x.a; }), "struct {char a; int b; char c;} x; x.a=1; x.b=2; x.c=3; x.a;");
assert(2, ({ struct {char a; int b; char c;} x; x.b=1; x.b=2; x.c=3; x.b; }), "struct {char a; int b; char c;} a; x.b=x; x.a=2; x.b=3; x.b;");
assert(3, ({ struct {char a; int b; char c;} x; x.a=1; x.b=2; x.c=3; x.c; }), "struct {char a; int b; char c;} x; x.a=1; x.b=2; x.c=3; x.c;");
assert(0, ({ struct {int a; int b;} x[3]; int *p=x; p[0]=0; x[0].a; }), "struct {int a; int b;} x[3]; int *p=x; p[0]=0; x[0].a;");
assert(1, ({ struct {int a; int b;} x[3]; int *p=x; p[1]=1; x[0].b; }), "struct {int a; int b;} x[3]; int *p=x; p[1]=1; x[0].b;");
assert(2, ({ struct {int a; int b;} x[3]; int *p=x; p[2]=2; x[1].a; }), "struct {int a; int b;} x[3]; int *p=x; p[2]=2; x[1].a;");
assert(3, ({ struct {int a; int b;} x[3]; int *p=x; p[3]=3; x[1].b; }), "struct {int a; int b;} x[3]; int *p=x; p[3]=3; x[1].b;");
assert(6, ({ struct {int a[3], b[5];} x; int *p=&x; x.a[0]=6; p[0]; }), "struct {int a[3], b[5];} x; int *p=&x; x.a[0]=6; p[0];");
assert(7, ({ struct {int a[3], b[5];} x; int *p=&x; x.b[0]=7; p[3]; }), "struct {int a[3], b[5];} x; int *p=&x; x.b[0]=7; p[3];");
assert(6, ({ struct { struct { int b; } a; } x; x.a.b=6; x.a.b; }), "struct { struct { int b; } a; } x; x.a.b=6; x.a.b;");
assert(2, ({ struct {int a;} x; sizeof(x); }), "struct {int a;} x; sizeof(x);");
assert(4, ({ struct {int a; int b;} x; sizeof(x); }), "struct {int a; int b;} x; sizeof(x);");
assert(6, ({ struct {int a[3];} x; sizeof(x); }), "struct {int a[3];} x; sizeof(x);");
assert(8, ({ struct {int a;} x[4]; sizeof(x); }), "struct {int a;} x[4]; sizeof(x);");
assert(12, ({ struct {int a[3];} x[2]; sizeof(x); }), "struct {int a[3];} x[2]; sizeof(x)};");
assert(2, ({ struct {char a; char b;} x; sizeof(x); }), "struct {char a; char b;} x; sizeof(x);");
assert(4, ({ struct {char a; int b;} x; sizeof(x); }), "struct {char a; int b;} x; sizeof(x);");
assert(4, ({ struct {int a; char b;} x; sizeof(x); }), "struct {int a; char b;} x; sizeof(x);");
// Flipped signs again here
assert(2, ({ int x; char y; int a=&x; int b=&y; a-b; }), "int x; char y; int a=&x; int b=&y; a-b;");
assert(2, ({ char x; int y; int a=&x; int b=&y; a-b; }), "char x; int y; int a=&x; int b=&y; a-b;");
assert(2, ({ struct t {char a[2];}; { struct t {char a[4];}; } struct t y; sizeof(y); }), "struct t {char a[2];}; { struct t {char a[4];}; } struct t y; sizeof(y);");
assert(3, ({ struct t {int x;}; int t=1; struct t y; y.x=2; t+y.x; }), "struct t {int x;}; int t=1; struct t y; y.x=2; t+y.x;");
assert(3, ({ struct t {char a;} x; struct t *y = &x; x.a=3; y->a; }), "struct t {char a;} x; struct t *y = &x; x.a=3; y->a;");
assert(3, ({ struct t {char a;} x; struct t *y = &x; y->a=3; x.a; }), "struct t {char a;} x; struct t *y = &x; y->a=3; x.a;");
assert(1, ({ typedef int t; t x=1; x; }), "typedef int t; t x=1; x;");
assert(1, ({ typedef struct {int a;} t; t x; x.a=1; x.a; }), "typedef struct {int a;} t; t x; x.a=1; x.a;");
assert(1, ({ typedef int t; t t=1; t; }), "typedef int t; t t=1; t;");
assert(2, ({ typedef struct {int a;} t; { typedef int t; } t x; x.a=2; x.a; }), "typedef struct {int a;} t; { typedef int t; } t x; x.a=2; x.a;");
assert(4, ({ struct t {int a; int b;} x; struct t y; sizeof(y); }), "struct t {int a; int b;} x; struct t y; sizeof(y);");
assert(4, ({ struct t {int a; int b;}; struct t y; sizeof(y); }), "struct t {int a; int b;}; struct t y; sizeof(y);");
assert(2, ({ short x; sizeof(x); }), "short x; sizeof(x);");
assert(4, ({ struct {char a; short b;} x; sizeof(x); }), "struct {char a; short b;} x; sizeof(x);");
//assert(8, ({ long x; sizeof(x); }), "long x; sizeof(x);");
//assert(16, ({ struct {char a; long b;} x; sizeof(x); }), "struct {char a; long b} x; sizeof(x);");
assert(1, sub_short(7, 3, 3), "sub_short(7, 3, 3)");
//assert(1, sub_long(7, 3, 3), "sub_long(7, 3, 3)");
assert(6, ({ int *x[3]; sizeof(x); }), "int *x[3]; sizeof(x);");
assert(2, ({ int (*x)[3]; sizeof(x); }), "int (*x)[3]; sizeof(x);");
assert(3, ({ int *x[3]; int y; x[0]=&y; y=3; x[0][0]; }), "int *x[3]; int y; x[0]=&y; y=3; x[0][0];");
assert(4, ({ int x[3]; int (*y)[3]=x; y[0][0]=4; y[0][0]; }), "int x[3]; int (*y)[3]=x; y[0][0]=4; y[0][0];");
assert(3, *g1_ptr(), "*g1_ptr()");
{ void *x; }
assert(0, ({ _Bool x=0; x; }), "_Bool x=0; x;");
assert(1, ({ _Bool x=1; x; }), "_Bool x=1; x;");
assert(1, ({ _Bool x=2; x; }), "_Bool x=2; x;");
assert(1, ({ char x; sizeof(x); }), "char x; sizeof(x);");
assert(2, ({ short int x; sizeof(x); }), "short int x; sizeof(x);");
assert(2, ({ int short x; sizeof(x); }), "int short x; sizeof(x);");
assert(2, ({ int x; sizeof(x); }), "int x; sizeof(x);");
assert(2, ({ typedef t; t x; sizeof(x); }), "typedef t; t x; sizeof(x);");
assert(2, ({ typedef typedef t; t x; sizeof(x); }), "typedef typedef t; t x; sizeof(x);");
//assert(8, ({ long int x; sizeof(x); }), "long int x; sizeof(x);");
//assert(8, ({ int long x; sizeof(x); }), "int long x; sizeof(x);");
//assert(8, ({ long long x; sizeof(x); }), "long long x; sizeof(x);");
//assert(8, ({ long int long x; sizeof(x); }), "long int long x; sizeof(x);");
assert(3, ({ MyInt x=3; x; }), "MyInt x=3; x;");
assert(1, sizeof(char), "sizeof(char)");
assert(2, sizeof(short), "sizeof(short)");
assert(2, sizeof(short int), "sizeof(short int)");
assert(2, sizeof(int short), "sizeof(int short)");
assert(2, sizeof(int), "sizeof(int)");
//assert(8, sizeof(long), "sizeof(long)");
//assert(8, sizeof(long int), "sizeof(long int)");
//assert(8, sizeof(long int), "sizeof(long int)");
assert(2, sizeof(char *), "sizeof(char *)");
assert(2, sizeof(int *), "sizeof(int *)");
//assert(8, sizeof(long *), "sizeof(long *)");
assert(2, sizeof(int **), "sizeof(int **)");
assert(2, sizeof(int(*)[4]), "sizeof(int(*)[4])");
assert(8, sizeof(int*[4]), "sizeof(int(*)[4])");
assert(8, sizeof(int[4]), "sizeof(int[4])");
assert(24, sizeof(int[3][4]), "sizeof(int[3][4])");
assert(4, sizeof(struct {int a; int b;}), "sizeof(struct {int a; int b;})");
// TODO: new truncation tests, these ones' literals are too big
//assert(131585, (int)8590066177, "(int)8590066177");
//assert(513, (short)8590066177, "(short)8590066177");
//assert(1, (char)8590066177, "(char)8590066177");
assert(1, (_Bool)1, "(_Bool)1");
assert(1, (_Bool)2, "(_Bool)2");
assert(0, (_Bool)(char)256, "(_Bool)(char)256");
//assert(1, (long)1, "(long)1");
//assert(0, (long)&*(int *)0, "(long)&*(int *)0");
//assert(5, ({ int x=5; long y=(long)&x; *(int*)y; }), "int x=5; long y=(long)&x; *(int*)y");
assert(97, 'a', "'a'");
assert(10, '\n', "\'\\n\'");
assert(0, ({ enum { zero, one, two }; zero; }), "enum { zero, one, two }; zero;");
assert(1, ({ enum { zero, one, two }; one; }), "enum { zero, one, two }; one;");
assert(2, ({ enum { zero, one, two }; two; }), "enum { zero, one, two }; two;");
assert(5, ({ enum { five=5, six, seven }; five; }), "enum { five=5, six, seven }; five;");
assert(6, ({ enum { five=5, six, seven }; six; }), "enum { five=5, six, seven }; six;");
assert(0, ({ enum { zero, five=5, three=3, four }; zero; }), "enum { zero, five=5, three=3, four }; zero;");
assert(5, ({ enum { zero, five=5, three=3, four }; five; }), "enum { zero, five=5, three=3, four }; five;");
assert(3, ({ enum { zero, five=5, three=3, four }; three; }), "enum { zero, five=5, three=3, four }; three;");
assert(4, ({ enum { zero, five=5, three=3, four }; four; }), "enum { zero, five=5, three=3, four }; four;");
assert(2, ({ enum { zero, one, two } x; sizeof(x); }), "enum { zero, one, two } x; sizeof(x);");
assert(2, ({ enum t { zero, one, two }; enum t y; sizeof(y); }), "enum t { zero, one, two }; enum t y; sizeof(y);");
//assert(3, static_fn(), "static_fn()");
assert(55, ({ int j=0; for (int i=0; i<=10; i=i+1) j=j+i; j; }), "int j=0; for (int i=0; i<=10; i=i+1) j=j+i; j;");
assert(3, ({ int i=3; int j=0; for (int i=0; i<=10; i=i+1) j=j+i; i; }), "int i=3; int j=0; for (int i=0; i<=10; i=i+1) j=j+i; i;");
assert(3, (1,2,3), "(1,2,3)");
assert(3, ({ int i=2; ++i; }), "int i=2; ++i;");
assert(1, ({ int i=2; --i; }), "int i=2; --i;");
assert(2, ({ int i=2; i++; }), "int i=2; i++;");
assert(2, ({ int i=2; i--; }), "int i=2; i--;");
assert(3, ({ int i=2; i++; i; }), "int i=2; i++; i;");
assert(1, ({ int i=2; i--; i; }), "int i=2; i--; i;");
assert(1, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; *p++; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; *p++;");
assert(2, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; ++*p; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; ++*p;");
assert(1, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; *p--; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; *p--;");
assert(0, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; --*p; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; --*p;");
assert(0, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++)--; a[0]; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++); a[0];");
assert(0, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++)--; a[1]; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++); a[1];");
assert(2, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++)--; a[2]; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++); a[2];");
assert(2, ({ int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++)--; *p; }), "int a[3]; a[0]=0; a[1]=1; a[2]=2; int *p=a+1; (*p++); *p;");
assert(7, ({ int i=2; i+=5; i; }), "int i=2; i+=5; i;");
assert(7, ({ int i=2; i+=5; }), "int i=2; i+=5;");
assert(3, ({ int i=5; i-=2; i; }), "int i=5; i-=2; i;");
assert(3, ({ int i=5; i-=2; }), "int i=5; i-=2;");
assert(6, ({ int i=3; i*=2; i; }), "int i=3; i*=2; i;");
assert(6, ({ int i=3; i*=2; }), "int i=3; i*=2;");
assert(3, ({ int i=6; i/=2; i; }), "int i=6; i/=2; i;");
assert(3, ({ int i=6; i/=2; }), "int i=6; i/=2;");
assert(511, 0777, "0777");
assert(0, 0x0, "0x0");
assert(10, 0xa, "0xa");
assert(10, 0XA, "0XA");
//assert(48879, 0xbeef, "0xbeef");
//assert(48879, 0xBEEF, "0xBEEF");
//assert(48879, 0XBEEF, "0XBEEF");
assert(0, 0b0, "0b0");
assert(1, 0b1, "0b1");
assert(47, 0b101111, "0b101111");
assert(47, 0B101111, "0B101111");
assert(0, !1, "!1");
assert(0, !2, "!2");
assert(1, !0, "!0");
assert(-1, ~0, "~0");
assert(0, ~-1, "~-1");
assert(0, 0&1, "0&1");
assert(1, 3&1, "3&1");
assert(3, 7&3, "7&3");
assert(10, -1&10, " -1&10");
assert(1, 0|1, "0|1");
assert(0b10011, 0b10000|0b00011, "01000|0b0011");
assert(0, 0^0, "0^0");
assert(0, 0b1111^0b1111, "0b1111^0b1111");
assert(0b110100, 0b111000^0b001100, "0b111000^0b001100");
assert(1, 0||1, "0||1");
assert(1, 0||(2-2)||5, "0||(2-2)||5");
assert(0, 0||0, "0||0");
assert(0, 0||(2-2), "0||(2-2)");
assert(0, 0&&1, "0&&1");
assert(0, (2-2)&&5, "(2-2)&&5");
assert(1, 1&&5, "1&&5");
assert(3, ({ int x[2]; x[0]=3; param_decay(x); }), "int x[2]; x[0]=3; param_decay(x);");
assert(2, ({ struct *foo; sizeof(foo); }), "struct *foo; sizeof(foo);");
assert(2, ({ struct T *foo; struct T {int x;}; sizeof(struct T); }), "struct T *foo; struct T {int x;}; sizeof(struct T);");
assert(1, ({ struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x; }), "struct T { struct T *next; int x; } a; struct T b; b.x=1; a.next=&b; a.next->x;");
assert(3, ({ int i=0; for(;i<10;i++) { if (i == 3) break; } i; }), "int i=0; for(;i<10;i++) { if (i == 3) break; } i;");
assert(4, ({ int i=0; while (1) { if (i++ == 3) break; } i; }), "int i=0; while { if (i == 3) break; } i;");
assert(3, ({ int i=0; for(;i<10;i++) { for (;;) break; if (i == 3) break; } i; }), "int i=0; for(;i<10;i++) { if (i == 3) break; } i;");
assert(4, ({ int i=0; while (1) { while(1) break; if (i++ == 3) break; } i; }), "int i=0; while { if (i == 3) break; } i;");
assert(10, ({ int i=0; int j=0; for (;i<10;i++) { if (i>5) continue; j++; } i; }), "int i=0; int j=0; for (;i<10;i++) { if (i>5) continue; j++; } i;");
assert(6, ({ int i=0; int j=0; for (;i<10;i++) { if (i>5) continue; j++; } j; }), "int i=0; int j=0; for (;i<10;i++) { if (i>5) continue; j++; } j;");
assert(10, ({ int i=0; int j=0; for(;!i;) { for (;j!=10;j++) continue; break; } j; }), "int i=0; int j=0; for(;!i;) { for (;j!=10;j++) continue; break; } j;");
assert(11, ({ int i=0; int j=0; while (i++<10) { if (i>5) continue; j++; } i; }), "int i=0; int j=0; while (i++<10) { if (i>5) continue; j++; } i;");
assert(5, ({ int i=0; int j=0; while (i++<10) { if (i>5) continue; j++; } j; }), "int i=0; int j=0; while (i++<10) { if (i>5) continue; j++; } j;");
assert(11, ({ int i=0; int j=0; while(!i) { while (j++!=10) continue; break; } j; }), "int i=0; int j=0; while(!i) { while (j++!=10) continue; break; } j;");
assert(3, ({ int i=0; goto a; a: i++; b: i++; c: i++; i; }), "int i=0; goto a; a: i++; b: i++; c: i++; i;");
assert(2, ({ int i=0; goto e; d: i++; e: i++; f: i++; i; }), "int i=0; goto d; d: i++; e: i++; f: i++; i;");
assert(1, ({ int i=0; goto i; g: i++; h: i++; i: i++; i; }), "int i=0; goto g; h: i++; i: i++; j: i++; i;");
assert(5, ({ int i=0; switch(0) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i; }), "int i=0; switch(0) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i;");
assert(6, ({ int i=0; switch(1) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i; }), "int i=0; switch(1) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i;");
assert(7, ({ int i=0; switch(2) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i; }), "int i=0; switch(2) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i;");
assert(0, ({ int i=0; switch(3) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i; }), "int i=0; switch(3) { case 0:i=5;break; case 1:i=6;break; case 2:i=7;break; } i;");
assert(5, ({ int i=0; switch(0) { case 0:i=5;break; default:i=7; } i; }), "int i=0; switch(0) { case 0:i=5;break; default:i=7; } i;");
assert(7, ({ int i=0; switch(1) { case 0:i=5;break; default:i=7; } i; }), "int i=0; switch(1) { case 0:i=5;break; default:i=7; } i;");
assert(2, ({ int i=0; switch(1) { case 0: 0; case 1: 0; case 2: 0; i=2; } i; }), "int i=0; switch(1) { case 0: 0; case 1: 0; case 2: 0; i=2; } i;");
assert(0, ({ int i=0; switch(3) { case 0: 0; case 1: 0; case 2: 0; i=2; } i; }), "int i=0; switch(3) { case 0: 0; case 1: 0; case 2: 0; i=2; } i;");
voidfn();
assert(1, 1<<0, "1<<0");
assert(8, 1<<3, "1<<3");
assert(10, 5<<1, "5<<1");
assert(2, 5>>1, "5>>1");
assert(-1, -1>>1, "-1>>1");
assert(1, ({ int i=1; i<<=0; i; }), "int i=1; i<<0;");
assert(8, ({ int i=1; i<<=3; i; }), "int i=1; i<<3;");
assert(10, ({ int i=5; i<<=1; i; }), "int i=5; i<<1;");
assert(2, ({ int i=5; i>>=1; i; }), "int i=5; i>>1;");
assert(-1, -1, "-1");
assert(-1, ({ int i=-1; i; }), "int i=-1; i;");
assert(-1, ({ int i=-1; i>>=1; i; }), "int i=1; i>>1;");
assert(2, 0?1:2, "0?1:2");
assert(1, 1?1:2, "0?1:2");
assert(10, ({ enum { ten=1+2+3+4, }; ten; }), "enum { ten=1+2+3+4, }; ten;");
assert(1, ({ int i=0; switch(3) { case 5-2+0*3: i++; } i; }), "int i=0; switch(3) { case 5-2+0*3: i++; ); i;");
assert(4, ({ int x[1+1]; sizeof(x); }), "int x[1+1]; sizeof(x);");
assert(2, ({ char x[1?2:3]; sizeof(x); }), "char x[0?2:3]; sizeof(x);");
assert(3, ({ char x[0?2:3]; sizeof(x); }), "char x[1?2:3]; sizeof(x);");
assert(1, ({ int x[3]={1,2,3}; x[0]; }), "int x[3]={1,2,3}; x[0];");
assert(2, ({ int x[3]={1,2,3}; x[1]; }), "int x[3]={1,2,3}; x[0];");
assert(3, ({ int x[3]={1,2,3}; x[2]; }), "int x[3]={1,2,3}; x[0];");
assert(3, ({ int x[3]={1,2,3,}; x[2]; }), "int x[3]={1,2,3}; x[0];");
assert(0, ({ int x[3]={}; x[0]; }), "int x[3]={}; x[0];");
assert(0, ({ int x[3]={}; x[1]; }), "int x[3]={}; x[1];");
assert(0, ({ int x[3]={}; x[2]; }), "int x[3]={}; x[2];");
assert(2, ({ int x[2][3]={{1,2,3},{4,5,6}}; x[0][1]; }), "int x[2][3]={{1,2,3},{4,5,6}}; x[0][1];");
assert(4, ({ int x[2][3]={{1,2,3},{4,5,6}}; x[1][0]; }), "int x[2][3]={{1,2,3},{4,5,6}}; x[1][0];");
assert(6, ({ int x[2][3]={{1,2,3},{4,5,6}}; x[1][2]; }), "int x[2][3]={{1,2,3},{4,5,6}}; x[1][2];");
assert(2, ({ int x[2][3]={{1,2}}; x[0][1]; }), "int x[2][3]={{1,2}}; x[0][1];");
assert(0, ({ int x[2][3]={{1,2}}; x[1][0]; }), "int x[2][3]={{1,2}}; x[1][0];");
assert(0, ({ int x[2][3]={{1,2}}; x[1][2]; }), "int x[2][3]={{1,2}}; x[1][2];");
assert('a', ({ char x[4]="abc"; x[0]; }), "char x[4]=\"abc\"; x[0]; }");
assert('c', ({ char x[4]="abc"; x[2]; }), "char x[4]=\"abc\"; x[2]; }");
assert(0, ({ char x[4]="abc"; x[3]; }), "char x[4]=\"abc\"; x[3]; }");
assert('a', ({ char x[2][4]={"abc","def"}; x[0][0]; }), "char x[2][4]=\"abc\",\"def\"}; x[0][0]; }");
assert(0, ({ char x[2][4]={"abc","def"}; x[0][3]; }), "char x[2][4]=\"abc\",\"def\"}; x[0][3]; }");
assert('d', ({ char x[2][4]={"abc","def"}; x[1][0]; }), "char x[2][4]=\"abc\",\"def\"}; x[1][0]; }");
assert('f', ({ char x[2][4]={"abc","def"}; x[1][2]; }), "char x[2][4]=\"abc\",\"def\"}; x[1][2]; }");
assert(4, ({ int x[]={1,2,3,4}; x[3]; }), "int x[]={1,2,3,4}; x[3];");
assert(8, ({ int x[]={1,2,3,4}; sizeof(x); }), "int x[]={1,2,3,4}; sizeof(x);");
assert(4, ({ char x[]="foo"; sizeof(x); }), "char x[]=\"foo\"; sizeof(x); }");
assert(1, ({ struct {int a; int b; int c;} x={1,2,3}; x.a; }), "struct {int a; int b; int c;} x={1,2,3}; x.a;");
assert(2, ({ struct {int a; int b; int c;} x={1,2,3}; x.b; }), "struct {int a; int b; int c;} x={1,2,3}; x.b;");
assert(3, ({ struct {int a; int b; int c;} x={1,2,3}; x.c; }), "struct {int a; int b; int c;} x={1,2,3}; x.c;");
assert(1, ({ struct {int a; int b; int c;} x={1}; x.a; }), "struct {int a; int b; int c;} x={1}; x.a;");
assert(0, ({ struct {int a; int b; int c;} x={1}; x.b; }), "struct {int a; int b; int c;} x={1}; x.b;");
assert(0, ({ struct {int a; int b; int c;} x={1}; x.c; }), "struct {int a; int b; int c;} x={1}; x.c;");
assert(1, ({ struct {int a; int b;} x[2]={{1,2},{3,4}}; x[0].a; }), "struct {int a; int b;} x[2]={{1,2},{3,4}}; x[0].a;");
assert(2, ({ struct {int a; int b;} x[2]={{1,2},{3,4}}; x[0].b; }), "struct {int a; int b;} x[2]={{1,2},{3,4}}; x[0].b;");
assert(3, ({ struct {int a; int b;} x[2]={{1,2},{3,4}}; x[1].a; }), "struct {int a; int b;} x[2]={{1,2},{3,4}}; x[1].a;");
assert(4, ({ struct {int a; int b;} x[2]={{1,2},{3,4}}; x[1].b; }), "struct {int a; int b;} x[2]={{1,2},{3,4}}; x[1].b;");
assert(0, ({ struct {int a; int b;} x[2]={{1,2}}; x[1].b; }), "struct {int a; int b;} x[2]={{1,2}}; x[1].b;");
assert(0, ({ struct {int a; int b;} x={}; x.a; }), "struct {int a; int b;} x={}; x.a;");
assert(0, ({ struct {int a; int b;} x={}; x.b; }), "struct {int a; int b;} x={}; x.b;");
assert(3, g3, "g3");
assert(4, g4, "g4");
assert(5, g5, "g5");
//assert(6, g6, "g6");
assert(5, *g7, "*g7");
assert(0, strcmp(g8, "abc"), "strcmp(g8, \"abc\")");
assert(0, g9[0], "g9[0]");
assert(1, g9[1], "g9[1]");
assert(2, g9[2], "g9[2]");
assert(0, strcmp(g10[0], "foo"), "strcmp(g10[0], \"foo\")");
assert(0, strcmp(g10[1], "bar"), "strcmp(g10[1], \"bar\")");
assert(0, g10[1][3], "g10[1][3]");
assert(2, sizeof(g10) / sizeof(*g10), "sizeof(g10) / sizeof(*g10)");
assert(1, g11[0].a, "g11[0].a");
assert(2, g11[0].b, "g11[0].b");
assert(3, g11[1].a, "g11[1].a");
assert(4, g11[1].b, "g11[1].b");
assert(1, g12[0].a[0], "g12[0].a[0]");
assert(2, g12[0].a[1], "g12[0].a[1]");
assert(0, g12[1].a[0], "g12[1].a[0]");
assert(0, g12[1].a[1], "g12[1].a[1]");
assert(1, g13[0].a[0], "g13[0].a[0]");
assert(2, g13[0].a[1], "g13[0].a[1]");
assert(3, g13[1].a[0], "g13[1].a[0]");
assert(4, g13[1].a[1], "g13[1].a[1]");
assert(1, g14[0].a[0], "g14[0].a[0]");
assert(2, g14[0].a[1], "g14[0].a[1]");
assert(3, g14[1].a[0], "g14[1].a[0]");
assert(4, g14[1].a[1], "g14[1].a[1]");
assert(0, ({ int x[2][3]={0,1,2,3,4,5,}; x[0][0]; }), "int x[2][3]={0,1,2,3,4,5,}; x[0][0];");
assert(3, ({ int x[2][3]={0,1,2,3,4,5,}; x[1][0]; }), "int x[2][3]={0,1,2,3,4,5,}; x[1][0];");
assert(0, ({ struct {int a; int b;} x[2]={0,1,2,3}; x[0].a; }), "struct {int a; int b;} x[2]={0,1,2,3}; x[0].a;");
assert(2, ({ struct {int a; int b;} x[2]={0,1,2,3}; x[1].a; }), "struct {int a; int b;} x[2]={0,1,2,3}; x[1].a;");
assert(9, ({ struct {int a; int b; int c;} x = {2,3,4}, y = {0,0,0}; y = x; y.a + y.b + y.c; }),
"struct {int a; int b; int c;} x = {2,3,4}, y = {0,0,0}; y = x; y.a + y.b + y.c;");
assert(2, ({ struct {char a; int b;} x={1,2}, y={0,0}; (y = x).b; }),
"struct {char a; int b;} x={1,2}, y={0,0}; (y = x).b;");
assert(6, ({ struct {char a; int b;} x={1,2}, y={0,0}, z={0,0}; z = y = x; z.a + z.b + y.a + y.b; }),
"struct {char a; int b;} x={1,2}, y={0,0}, z={0,0}; z = y = x; z.a + z.b + y.a + y.b;");
assert(0, strcmp(g15, "foo"), "strcmp(g15, \"foo\")");
assert(0, strcmp(g16[0], "foo"), "strcmp(g16[0], \"foo\")");
assert(0, strcmp(g16[1], "bar"), "strcmp(g16[1], \"bar\")");
assert(7, sizeof(g17), "sizeof(g17)");
assert(10, sizeof(g18), "sizeof(g18)");
assert(3, sizeof(g19), "sizeof(g19)");
assert(0, memcmp(g17, "foobar", 7), "memcmp(g17, \"foobar\", 7)");
assert(0, memcmp(g18, "foobar\0\0\0", 10), "memcmp(g18, \"foobar\\0\\0\\0\", 10)");
assert(0, memcmp(g19, "foo", 3), "memcmp(g19, \"foo\", 3)");
assert(0, strcmp(g20, "foobar"), "strcmp(g20, \"foobar\")");
//assert(0, strcmp(g21, "bar"), "strcmp(g21, \"bar\")");
//assert(0, strcmp(g22+3, "foobar"), "strcmp(g22+3, \"foobar\")");
//assert(0, strcmp(g23[0], "foobar"), "strcmp(g23[0], \"foobar\")");
//assert(0, strcmp(g23[1], "bar"), "strcmp(g23[1], \"bar\")");
//assert(0, strcmp(g23[2]+3, "foobar"), "strcmp(g23[2]+3, \"foobar\")");
assert(3, g24, "g24");
assert(3, *g25, "*g25");
//assert(2, *g27, "*g27");
//ext1 = 5;
//assert(5, ext1, "ext1");
//ext2 = &ext1;
//assert(5, *ext2, "*ext2");
;
assert(1, _Alignof(char), "_Alignof(char)");
assert(2, _Alignof(short), "_Alignof(short)");
assert(2, _Alignof(int), "_Alignof(int)");
//assert(8, _Alignof(long), "_Alignof(long)");
//assert(8, _Alignof(long long), "_Alignof(long long)");
assert(1, _Alignof(char[3]), "_Alignof(char[3])");
assert(2, _Alignof(int[3]), "_Alignof(int[3])");
assert(1, _Alignof(struct {char a; char b;}[2]), "_Alignof(struct {char a; char b;}[2])");
//assert(8, _Alignof(struct {char a; long b;}[2]), "_Alignof(struct {char a; long b;}[2])");
assert(2, counter(), "counter()");
assert(4, counter(), "counter()");
assert(6, counter(), "counter()");
assert(1, (int){1}, "(int){1}");
assert(2, ((int[]){0,1,2})[2], "(int[]){0,1,2}[2]");
assert('a', ((struct {char a; int b;}){'a', 3}).a, "((struct {char a; int b;}){'a', 3}).a");
assert(3, ({ int x=3; (int){x}; }), "int x=3; (int){x};");
assert(1, tree->val, "tree->val");
assert(2, tree->lhs->val, "tree->lhs->val");
assert(3, tree->lhs->lhs->val, "tree->lhs->lhs->val");
assert(4, tree->lhs->rhs->val, "tree->lhs->rhs->val");
ret_none();
//assert(3, ext3, "ext3");
assert(2, ({ int i=6; i&=3; i; }), "int i=6; i&=3; i;");
assert(7, ({ int i=6; i|=3; i; }), "int i=6; i|=3; i;");
assert(10, ({ int i=15; i^=5; i; }), "int 15; i^=5; i;");
assert(7, ({ int i=0; int j=0; do { j++; } while (i++ < 6); j; }), "int i=0; int j=0; do { j++; } while (i++ < 6); j;");
assert(4, ({ int i=0; int j=0; int k=0; do { if (++j > 3) break; continue; k++; } while (1); j; }), "int i=0; int j=0; int k=0; do { if (j++ > 3) break; continue; k++; } while (1); j;");
//assert(1, true_fn(), "true_fn()");
//assert(0, false_fn(), "false_fn()");
assert(6, add_all1(1,2,3,0), "add_all1(1,2,3,0)");
assert(5, add_all1(1,2,3,-1,0), "add_all1(1,2,3,-1,0)");
assert(6, add_all3(1,2,3,0), "add_all3(1,2,3,0)");
assert(5, add_all3(1,2,3,-1,0), "add_all3(1,2,3,-1,0)");
assert(1, sizeof(char), "sizeof(char)");
assert(1, sizeof(signed char), "sizeof(signed char)");
assert(1, sizeof(signed char signed), "sizeof(signed char signed)");
assert(2, sizeof(short), "sizeof(short)");
assert(2, sizeof(int short), "sizeof(int short)");
assert(2, sizeof(short int), "sizeof(short int)");
assert(2, sizeof(signed short), "sizeof(signed short)");
assert(2, sizeof(int short signed), "sizeof(int short signed)");
assert(2, sizeof(int), "sizeof(int)");
assert(2, sizeof(signed int), "sizeof(signed int)");
assert(2, sizeof(signed), "sizeof(signed)");
assert(2, sizeof(signed signed), "sizeof(signed signed)");
//assert(8, sizeof(long), "sizeof(long)");
//assert(8, sizeof(signed long), "sizeof(signed long)");
//assert(8, sizeof(signed long int), "sizeof(signed long int)");
//assert(8, sizeof(long long), "sizeof(long long)");
//assert(8, sizeof(signed long long), "sizeof(signed long long)");
//assert(8, sizeof(signed long long int), "sizeof(signed long long int)");
assert(2, sizeof(0), "sizeof(0)");
//assert(8, sizeof(0L), "sizeof(0L)");
//assert(8, sizeof(0LL), "sizeof(0LL)");
//assert(8, sizeof(0l), "sizeof(0l)");
//assert(8, sizeof(0ll), "sizeof(0ll)");
//assert(8, sizeof(0x0L), "sizeof(0x0L)");
//assert(8, sizeof(0b0L), "sizeof(0b0L)");
//assert(4, sizeof(2147483647), "sizeof(2147483647)");
//assert(8, sizeof(2147483648), "sizeof(2147483648)");
// *********************
// * New tests for uxn *
// *********************
// Storing to base types
assert(256, ({ int n = 256; n; }), "int n = 256; n;");
assert(0, ({ char n = 256; n; }), "char n = 256; n;");
assert(1, ({ _Bool n = 256; n; }), "_Bool n = 256; n;");
// Returning base types
assert(-1, ({ int n = ret_char_minus1(); n; }), "int n = ret_char_minus1(); n;");
assert(-1, ({ int n = ret_char_0xff(); n; }), "int n = ret_char_0xff(); n;");
assert(1, ({ int n = ret_bool_256(); n; }), "int n = ret_bool_256(); n;");
// Sign extension tests
assert(-1, (char)0xff, "(char)0xff");
assert(0x10, (char)0x10, "(char)0x10");
assert(-1, ({ int x = 0xff; char y = x; y; }), "int x = 0xff; char y = x; y;");
assert(0xff, ({ int x = 0xff; char y = x; x; }), "int x = 0xff; char y = x; x;");
assert(0x10, ({ int x = 0x10; char y = x; y; }), "int x = 0x10; char y = x; y;");
assert(0x10, ({ int x = 0x10; char y = x; x; }), "int x = 0x10; char y = x; x;");
// Signed comparison
assert(1, 1 < 2, "1 < 2");
assert(1, 1 <= 2, "1 <= 2");
assert(0, 1 < -2, "1 < -2");
assert(0, 1 <= -2, "1 <= -2");
assert(1, -1 < 2, "-1 < 2");
assert(1, -1 <= 2, "-1 <= 2");
assert(0, -1 < -2, "-1 < -2");
assert(0, -1 <= -2, "-1 <= -2");
assert(0, 2 < 2, "2 < 2");
assert(1, 2 <= 2, "2 <= 2");
assert(0, -2 < -2, "-2 < -2");
assert(1, -2 <= -2, "-2 <= -2");
// ~0x7fff is INT_MIN, 0x7fff is INT_MAX
assert(1, ~0x7fff < 0x7fff, "~0x7fff < 0x7fff");
assert(1, ~0x7fff <= 0x7fff, "~0x7fff <= 0x7fff");
assert(0, 0x7fff < ~0x7fff, "0x7fff < ~0x7fff");
assert(0, 0x7fff <= ~0x7fff, "0x7fff <= ~0x7fff");
assert(0, 0x7fff < 0x7fff, "0x7fff < 0x7fff");
assert(1, 0x7fff <= 0x7fff, "0x7fff <= 0x7fff");
assert(0, ~0x7fff < ~0x7fff, "~0x7fff < ~0x7fff");
assert(1, ~0x7fff <= ~0x7fff, "~0x7fff <= ~0x7fff");
// Signed division
assert(1, 3 / 2, "3 / 2");
assert(-1, -3 / 2, "-3 / 2");
assert(-1, 3 / -2, "3 / -2");
assert(1, -3 / -2, "-3 / -2");
assert(1, 3 % 2, "3 % 2");
assert(-1, -3 % 2, "-3 % 2");
assert(1, 3 % -2, "3 % -2");
assert(-1, -3 % -2, "-3 % -2");
assert(0, 3 / 5, "3 / 5");
assert(0, -3 / 5, "-3 / 5");
assert(0, 3 / -5, "3 / -5");
assert(0, -3 / -5, "-3 / -5");
assert(3, 3 % 5, "3 % 5");
assert(-3, -3 % 5, "-3 % 5");
assert(3, 3 % -5, "3 % -5");
assert(-3, -3 % -5, "-3 % -5");
// Signed division again but with bigger numbers to ensure the correct bytes
// in the words are tested during division.
assert(1, 0x300 / 0x200, "0x300 / 0x200");
assert(-1, -0x300 / 0x200, "-0x300 / 0x200");
assert(-1, 0x300 / -0x200, "0x300 / -0x200");
assert(1, -0x300 / -0x200, "-0x300 / -0x200");
assert(0x100, 0x300 % 0x200, "0x300 % 0x200");
assert(-0x100, -0x300 % 0x200, "-0x300 % 0x200");
assert(0x100, 0x300 % -0x200, "0x300 % -0x200");
assert(-0x100, -0x300 % -0x200, "-0x300 % -0x200");
assert(0, 0x300 / 0x500, "0x300 / 0x500");
assert(0, -0x300 / 0x500, "-0x300 / 0x500");
assert(0, 0x300 / -0x500, "0x300 / -0x500");
assert(0, -0x300 / -0x500, "-0x300 / -0x500");
assert(0x300, 0x300 % 0x500, "0x300 % 0x500");
assert(-0x300, -0x300 % 0x500, "-0x300 % 0x500");
assert(0x300, 0x300 % -0x500, "0x300 % -0x500");
assert(-0x300, -0x300 % -0x500, "-0x300 % -0x500");
// Basic unsigned integer tests
assert(1, sizeof(unsigned char), "sizeof(unsigned char)");
assert(1, sizeof(unsigned char) == sizeof(signed char), "sizeof(unsigned char) == sizeof(signed char)");
assert(2, sizeof(unsigned short), "sizeof(unsigned short)");
assert(1, sizeof(unsigned short) == sizeof(signed short), "sizeof(unsigned short) == sizeof(signed short)");
assert(2, sizeof(unsigned int), "sizeof(unsigned int)");
assert(1, sizeof(unsigned int) == sizeof(signed int), "sizeof(unsigned int) == sizeof(signed int)");
assert(1, sizeof(1u) == sizeof(unsigned int), "sizeof(1u) == sizeof(unsigned int)");
assert(1, sizeof(1U) == sizeof(unsigned int), "sizeof(1U) == sizeof(unsigned int)");
// Zero extension tests
assert(0xff, (unsigned char)-1, "(unsigned char)-1");
assert(0xff, (int)(unsigned char)-1, "(int)(unsigned char)-1");
assert(0xff, ({ unsigned char c = -1; c; }), "unsigned char c = -1; c;");
assert(0xff, ({ unsigned char c = -1; (int)c; }), "unsigned char c = -1; (int)c;");
// C standard "usual arithmetic conversions" and "integer promotions"
// (and unsigned right shift and division)
assert(-1, ((unsigned char)0 - (unsigned char)1) >> 1, "((unsigned char)0 - (unsigned char)1) >> 1");
assert(0, ((unsigned char)0 - (unsigned char)1) / 2, "((unsigned char)0 - (unsigned char)1) / 2");
assert(-1, ((unsigned char)0 - 1) >> 1, "((unsigned char)0 - 1) >> 1");
assert(0, ((unsigned char)0 - 1) / 2, "((unsigned char)0 - 1) / 2");
assert(-1, (0 - (unsigned char)1) >> 1, "(0 - (unsigned char)1) >> 1");
assert(0, (0 - (unsigned char)1) / 2, "(0 - (unsigned char)1) / 2");
assert(0x7fff, ((unsigned)0 - (unsigned)1) >> 1, "((unsigned)0 - (unsigned)1) >> 1");
assert(0x7fff, ((unsigned)0 - (unsigned)1) / 2, "((unsigned)0 - (unsigned)1) / 2");
assert(0x7fff, ((unsigned)0 - (unsigned char)1) >> 1, "((unsigned)0 - (unsigned char)1) >> 1");
assert(0x7fff, ((unsigned)0 - (unsigned char)1) / 2, "((unsigned)0 - (unsigned char)1) / 2");
assert(0x7fff, ((unsigned char)0 - (unsigned)1) >> 1, "((unsigned char)0 - (unsigned)1) >> 1");
assert(0x7fff, ((unsigned char)0 - (unsigned)1) / 2, "((unsigned char)0 - (unsigned)1) / 2");
assert(0x7fff, ((unsigned short)0 - (unsigned short)1) >> 1, "((unsigned short)0 - (unsigned short)1) >> 1");
assert(0x7fff, ((unsigned short)0 - (unsigned short)1) / 2, "((unsigned short)0 - (unsigned short)1) / 2");
assert(0x7fff, ((unsigned short)0 - (unsigned char)1) >> 1, "((unsigned short)0 - (unsigned char)1) >> 1");
assert(0x7fff, ((unsigned short)0 - (unsigned char)1) / 2, "((unsigned short)0 - (unsigned char)1) / 2");
assert(0x7fff, ((unsigned char)0 - (unsigned short)1) >> 1, "((unsigned char)0 - (unsigned short)1) >> 1");
assert(0x7fff, ((unsigned char)0 - (unsigned short)1) / 2, "((unsigned char)0 - (unsigned short)1) / 2");
assert(0x7fff, (0u - 1u) >> 1, "(0u - 1u) >> 1");
assert(0x7fff, (0u - 1u) / 2, "(0u - 1u) / 2");
assert(0x7fff, (0u - 1) >> 1, "(0u - 1) >> 1");
assert(0x7fff, (0u - 1) / 2, "(0u - 1) / 2");
assert(0x7fff, (0 - 1u) >> 1, "(0 - 1u) >> 1");
assert(0x7fff, (0 - 1u) / 2, "(0 - 1u) / 2");
// Unsigned comparison (and "usual arithmetic conversions")
assert(1, 0 < (unsigned)-1, "0 < (unsigned)-1");
assert(0, (unsigned)-1 < (unsigned)-1, "(unsigned)-1 < (unsigned)-1");
assert(1, 0 <= (unsigned)-1, "0 <= (unsigned)-1");
assert(1, (unsigned)-1 <= (unsigned)-1, "(unsigned)-1 <= (unsigned)-1");
assert(0, 0 > (unsigned)-1, "0 > (unsigned)-1");
assert(0, (unsigned)-1 > (unsigned)-1, "(unsigned)-1 > (unsigned)-1");
assert(0, 0 >= (unsigned)-1, "0 >= (unsigned)-1");
assert(1, (unsigned)-1 >= (unsigned)-1, "(unsigned)-1 >= (unsigned)-1");
// Pointer diffs must use signed division
// (they are evaluated like ((char*)a - (char*)b) / sizeof(*a))
assert(-3, ({ int a[4]; int *b = &a[3]; int *c = &a[0]; c - b; }), "int a[4]; int *b = &a[3]; int *c = &a[0]; c - b;");
// Multiple declarations
assert(3, ({ int x=1, y=2; x+y; }), "int x=1, y=2; x+y;");
assert(1, ({ int x=1, *y; y = &x; *y; }), "int x=1, *y; y = &x; *y");
assert(1, ({ int *y, x=1; y = &x; *y; }), "int *y, x=1; y = &x; *y");
// asm expressions
assert(25, asm(5, "DUP2 MUL2"), "asm(5, \"DUP2 MUL2\")");
assert(18, asm(3, 5, "OVR2 MUL2 ADD2"), "asm(3, 5, \"OVR2 MUL2 ADD2\")");
assert(18, asm(3, 5, "OVR2 MUL2 ADD2"), "asm(3, 5, \"OVR2 MUL2 ADD2\")");
assert(5, asm(3, 5, "GTH2k JMP SWP2 POP2"), "asm(3, 5, \"GTH2k JMP SWP2 POP2\")");
assert(5, asm(5, 3, "GTH2k JMP SWP2 POP2"), "asm(5, 3, \"GTH2k JMP SWP2 POP2\")");
print("All tests passed!\n");
exit(0);
}