tccelf.c: write section headers before sections
[tinycc.git] / tests / tests2 / 119_random_stuff.c
blob5530c096ce82bbe6a02ae1d8ae75a4a404ec2ae7
1 #include <stdio.h>
3 struct big_struct { char a[262144]; };
5 static const char str[] = "abcdefghijklmnopqrstuvwxyz";
7 void tst_branch(void)
9 printf("tst_branch --");
10 goto *&&a;
11 printf (" dummy");
12 a: ;
13 printf(" --\n");
16 void tst_void_ptr(void *pv, int i)
18 i ? *pv : *pv; // dr106
21 void tst_shift(void)
23 int i = 1;
24 long long l = 1;
25 i = i << 32; // illegal. just test
26 l = l << 64; // illegal. just test
29 #if !defined(_WIN32)
30 #include <sys/mman.h>
32 void tst_const_addr(void)
34 void *addr = mmap ((void *)0x20000000, 4096, PROT_READ | PROT_WRITE, MAP_FIXED | MAP_ANONYMOUS, -1, 0);
35 if (addr != (void *) -1) {
36 *(int *)0x20000000 += 42;
37 munmap (addr, 4096);
40 #endif
42 struct zero_struct {};
44 struct zero_struct tst_zero_struct(void)
46 struct zero_struct ret;
47 return ret;
50 struct big_struct tst_big(struct big_struct tst)
52 return tst;
55 void tst_adr (int (*fp)(char *, const char *, ...))
57 char buf[10];
58 (*fp)(buf, "%.0f", 5.0);
59 printf("tst_adr %s\n", buf);
62 int tst(void)
64 long long value = 3;
65 return -value;
68 void tst_compare(void)
70 /* This failed on risc64 */
71 printf ("tst_compare: %s\n", tst() > 0 ? "error" : "ok");
74 #pragma pack(1)
75 struct S { int d:24; int f:14; } i, j;
76 #pragma pack()
78 void tst_pack (void)
80 i.f = 5; j.f = 5;
81 printf("tst_pack: j.f = %d, i.f = %d\n", j.f, i.f);
84 void tst_cast(void)
86 signed char c = (signed char) 0xaaaaaaaa;
87 int r = (unsigned short) c ^ (signed char) 0x99999999;
88 printf ("schar to ushort cast: %x\n", r);
91 struct {
92 int (*print)(const char *format, ...);
93 } tst_indir = {
94 printf
97 void tst_indir_func(void)
99 tst_indir.print("tst_indir_func %d\n", 10);
102 struct V {
103 int x, y, z;
106 struct V vec(void)
108 return (struct V) { 1, 2, 3 };
111 void func(float f, struct V v)
113 printf("%g\n", f);
116 void tst_struct_return_align(void)
118 float d = 5.0f;
119 func(d, vec());
123 main (void)
125 struct big_struct big;
127 tst_branch();
128 tst_shift();
129 tst_void_ptr(&big.a[0], 0);
130 #if !defined(_WIN32)
131 tst_const_addr();
132 #endif
133 tst_zero_struct();
134 tst_big(big);
135 tst_adr(&sprintf);
136 tst_compare();
137 tst_pack();
138 tst_cast();
139 tst_indir_func();
140 tst_struct_return_align();