tests2: rework 117..119 to follow our conventions
[tinycc.git] / tests / tests2 / 119_random_stuff.c
blob6c425de25fdd182a5ed5105a5ff430361cb0ea58
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 #if !defined(__riscv)
37 *(int *)0x20000000 += 42;
38 #endif
39 munmap (addr, 4096);
42 #endif
44 struct zero_struct {};
46 struct zero_struct tst_zero_struct(void)
48 struct zero_struct ret;
49 return ret;
52 struct big_struct tst_big(struct big_struct tst)
54 return tst;
57 void tst_adr (int (*fp)(char *, const char *, ...))
59 char buf[10];
60 (*fp)(buf, "%.0f", 5.0);
61 printf("tst_adr %s\n", buf);
64 int tst(void)
66 long long value = 3;
67 return -value;
70 void tst_compare(void)
72 /* This failed on risc64 */
73 printf ("tst_compare: %s\n", tst() > 0 ? "error" : "ok");
76 #pragma pack(1)
77 struct S { int d:24; int f:14; } i, j;
78 #pragma pack()
80 void tst_pack (void)
82 i.f = 5; j.f = 5;
83 printf("tst_pack: j.f = %d, i.f = %d\n", j.f, i.f);
86 void tst_cast(void)
88 signed char c = (signed char) 0xaaaaaaaa;
89 int r = (unsigned short) c ^ (signed char) 0x99999999;
90 printf ("schar to ushort cast: %x\n", r);
93 int
94 main (void)
96 struct big_struct big;
98 tst_branch();
99 tst_shift();
100 tst_void_ptr(&big.a[0], 0);
101 #if !defined(_WIN32)
102 tst_const_addr();
103 #endif
104 tst_zero_struct();
105 tst_big(big);
106 tst_adr(&sprintf);
107 tst_compare();
108 tst_pack();
109 tst_cast();