mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-25 20:10:29 +00:00
Add chibicc
This program popped up on Hacker News recently. It's the only modern compiler I've ever seen that doesn't have dependencies and is easily modified. So I added all of the missing GNU extensions I like to use which means it might be possible soon to build on non-Linux and have third party not vendor gcc binaries.
This commit is contained in:
parent
e44a0cf6f8
commit
8da931a7f6
298 changed files with 19493 additions and 11950 deletions
103
third_party/chibicc/test/alignof_test.c
vendored
Normal file
103
third_party/chibicc/test/alignof_test.c
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int _Alignas(512) g1;
|
||||
int _Alignas(512) g2;
|
||||
char g3;
|
||||
int g4;
|
||||
long g5;
|
||||
char g6;
|
||||
|
||||
int main() {
|
||||
ASSERT(1, _Alignof(char));
|
||||
ASSERT(2, _Alignof(short));
|
||||
ASSERT(4, _Alignof(int));
|
||||
ASSERT(8, _Alignof(long));
|
||||
ASSERT(8, _Alignof(long long));
|
||||
ASSERT(1, _Alignof(char[3]));
|
||||
ASSERT(4, _Alignof(int[3]));
|
||||
ASSERT(1, _Alignof(struct {
|
||||
char a;
|
||||
char b;
|
||||
}[2]));
|
||||
ASSERT(8, _Alignof(struct {
|
||||
char a;
|
||||
long b;
|
||||
}[2]));
|
||||
|
||||
ASSERT(1, ({
|
||||
_Alignas(char) char x, y;
|
||||
&y - &x;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
_Alignas(long) char x, y;
|
||||
&y - &x;
|
||||
}));
|
||||
ASSERT(32, ({
|
||||
_Alignas(32) char x, y;
|
||||
&y - &x;
|
||||
}));
|
||||
ASSERT(32, ({
|
||||
_Alignas(32) int *x, *y;
|
||||
((char *)&y) - ((char *)&x);
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
struct {
|
||||
_Alignas(16) char x, y;
|
||||
} a;
|
||||
&a.y - &a.x;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct T {
|
||||
_Alignas(8) char a;
|
||||
};
|
||||
_Alignof(struct T);
|
||||
}));
|
||||
|
||||
ASSERT(0, (long)(char *)&g1 % 512);
|
||||
ASSERT(0, (long)(char *)&g2 % 512);
|
||||
ASSERT(0, (long)(char *)&g4 % 4);
|
||||
ASSERT(0, (long)(char *)&g5 % 8);
|
||||
|
||||
ASSERT(1, ({
|
||||
char x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x;
|
||||
_Alignof x;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
_Alignof x;
|
||||
}));
|
||||
|
||||
ASSERT(1, _Alignof(char) << 31 >> 31);
|
||||
ASSERT(1, _Alignof(char) << 63 >> 63);
|
||||
ASSERT(1, ({
|
||||
char x;
|
||||
_Alignof(x) << 63 >> 63;
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
char x[16];
|
||||
(unsigned long)&x % 16;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[17];
|
||||
(unsigned long)&x % 16;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[100];
|
||||
(unsigned long)&x % 16;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[101];
|
||||
(unsigned long)&x % 16;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
29
third_party/chibicc/test/alloca_test.c
vendored
Normal file
29
third_party/chibicc/test/alloca_test.c
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
void *fn(int x, void *p, int y) {
|
||||
return p;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = 0;
|
||||
|
||||
char *p1 = alloca(16);
|
||||
char *p2 = alloca(16);
|
||||
char *p3 = 1 + (char *)alloca(3) + 1;
|
||||
p3 -= 2;
|
||||
char *p4 = fn(1, alloca(16), 3);
|
||||
|
||||
ASSERT(16, p1 - p2);
|
||||
ASSERT(16, p2 - p3);
|
||||
ASSERT(16, p3 - p4);
|
||||
|
||||
memcpy(p1, "0123456789abcdef", 16);
|
||||
memcpy(p2, "ghijklmnopqrstuv", 16);
|
||||
memcpy(p3, "wxy", 3);
|
||||
|
||||
ASSERT(0, memcmp(p1, "0123456789abcdef", 16));
|
||||
ASSERT(0, memcmp(p2, "ghijklmnopqrstuv", 16));
|
||||
ASSERT(0, memcmp(p3, "wxy", 3));
|
||||
|
||||
return 0;
|
||||
}
|
341
third_party/chibicc/test/arith_test.c
vendored
Normal file
341
third_party/chibicc/test/arith_test.c
vendored
Normal file
|
@ -0,0 +1,341 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(0, 0);
|
||||
ASSERT(42, 42);
|
||||
ASSERT(21, 5 + 20 - 4);
|
||||
ASSERT(41, 12 + 34 - 5);
|
||||
ASSERT(47, 5 + 6 * 7);
|
||||
ASSERT(15, 5 * (9 - 6));
|
||||
ASSERT(4, (3 + 5) / 2);
|
||||
ASSERT(10, -10 + 20);
|
||||
|
||||
ASSERT(0, 0 == 1);
|
||||
ASSERT(1, 42 == 42);
|
||||
ASSERT(1, 0 != 1);
|
||||
ASSERT(0, 42 != 42);
|
||||
|
||||
ASSERT(1, 0 < 1);
|
||||
ASSERT(0, 1 < 1);
|
||||
ASSERT(0, 2 < 1);
|
||||
ASSERT(1, 0 <= 1);
|
||||
ASSERT(1, 1 <= 1);
|
||||
ASSERT(0, 2 <= 1);
|
||||
|
||||
ASSERT(1, 1 > 0);
|
||||
ASSERT(0, 1 > 1);
|
||||
ASSERT(0, 1 > 2);
|
||||
ASSERT(1, 1 >= 0);
|
||||
ASSERT(1, 1 >= 1);
|
||||
ASSERT(0, 1 >= 2);
|
||||
|
||||
ASSERT(0, 1073741824 * 100 / 100);
|
||||
|
||||
ASSERT(7, ({
|
||||
int i = 2;
|
||||
i += 5;
|
||||
i;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
int i = 2;
|
||||
i += 5;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 5;
|
||||
i -= 2;
|
||||
i;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 5;
|
||||
i -= 2;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int i = 3;
|
||||
i *= 2;
|
||||
i;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int i = 3;
|
||||
i *= 2;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 6;
|
||||
i /= 2;
|
||||
i;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 6;
|
||||
i /= 2;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
int i = 2;
|
||||
++i;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
int i = 2;
|
||||
i++;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int i = 2;
|
||||
i--;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 2;
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int i = 2;
|
||||
i--;
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
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--;
|
||||
}));
|
||||
|
||||
ASSERT(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];
|
||||
}));
|
||||
ASSERT(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++;
|
||||
*p;
|
||||
}));
|
||||
|
||||
ASSERT(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];
|
||||
}));
|
||||
ASSERT(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;
|
||||
}));
|
||||
|
||||
ASSERT(0, !1);
|
||||
ASSERT(0, !2);
|
||||
ASSERT(1, !0);
|
||||
ASSERT(1, !(char)0);
|
||||
ASSERT(0, !(long)3);
|
||||
ASSERT(4, sizeof(!(char)0));
|
||||
ASSERT(4, sizeof(!(long)0));
|
||||
|
||||
ASSERT(-1, ~0);
|
||||
ASSERT(0, ~-1);
|
||||
|
||||
ASSERT(5, 17 % 6);
|
||||
ASSERT(5, ((long)17) % 6);
|
||||
ASSERT(2, ({
|
||||
int i = 10;
|
||||
i %= 4;
|
||||
i;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
long i = 10;
|
||||
i %= 4;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(0, 0 & 1);
|
||||
ASSERT(1, 3 & 1);
|
||||
ASSERT(3, 7 & 3);
|
||||
ASSERT(10, -1 & 10);
|
||||
|
||||
ASSERT(1, 0 | 1);
|
||||
ASSERT(0b10011, 0b10000 | 0b00011);
|
||||
|
||||
ASSERT(0, 0 ^ 0);
|
||||
ASSERT(0, 0b1111 ^ 0b1111);
|
||||
ASSERT(0b110100, 0b111000 ^ 0b001100);
|
||||
|
||||
ASSERT(2, ({
|
||||
int i = 6;
|
||||
i &= 3;
|
||||
i;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
int i = 6;
|
||||
i |= 3;
|
||||
i;
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
int i = 15;
|
||||
i ^= 5;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(1, 1 << 0);
|
||||
ASSERT(8, 1 << 3);
|
||||
ASSERT(10, 5 << 1);
|
||||
ASSERT(2, 5 >> 1);
|
||||
ASSERT(-1, -1 >> 1);
|
||||
ASSERT(1, ({
|
||||
int i = 1;
|
||||
i <<= 0;
|
||||
i;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int i = 1;
|
||||
i <<= 3;
|
||||
i;
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
int i = 5;
|
||||
i <<= 1;
|
||||
i;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int i = 5;
|
||||
i >>= 1;
|
||||
i;
|
||||
}));
|
||||
ASSERT(-1, -1);
|
||||
ASSERT(-1, ({
|
||||
int i = -1;
|
||||
i;
|
||||
}));
|
||||
ASSERT(-1, ({
|
||||
int i = -1;
|
||||
i >>= 1;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(2, 0 ? 1 : 2);
|
||||
ASSERT(1, 1 ? 1 : 2);
|
||||
ASSERT(-1, 0 ? -2 : -1);
|
||||
ASSERT(-2, 1 ? -2 : -1);
|
||||
ASSERT(4, sizeof(0 ? 1 : 2));
|
||||
ASSERT(8, sizeof(0 ? (long)1 : (long)2));
|
||||
ASSERT(-1, 0 ? (long)-2 : -1);
|
||||
ASSERT(-1, 0 ? -2 : (long)-1);
|
||||
ASSERT(-2, 1 ? (long)-2 : -1);
|
||||
ASSERT(-2, 1 ? -2 : (long)-1);
|
||||
|
||||
1 ? -2 : (void)-1;
|
||||
|
||||
ASSERT(20, ({
|
||||
int x;
|
||||
int *p = &x;
|
||||
p + 20 - p;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int x;
|
||||
int *p = &x;
|
||||
p + 20 - p > 0;
|
||||
}));
|
||||
ASSERT(-20, ({
|
||||
int x;
|
||||
int *p = &x;
|
||||
p - 20 - p;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int x;
|
||||
int *p = &x;
|
||||
p - 20 - p < 0;
|
||||
}));
|
||||
|
||||
ASSERT(15, (char *)0xffffffffffffffff - (char *)0xfffffffffffffff0);
|
||||
ASSERT(-15, (char *)0xfffffffffffffff0 - (char *)0xffffffffffffffff);
|
||||
ASSERT(1, (void *)0xffffffffffffffff > (void *)0);
|
||||
|
||||
ASSERT(3, 3 ?: 5);
|
||||
ASSERT(5, 0 ?: 5);
|
||||
ASSERT(4, ({
|
||||
int i = 3;
|
||||
++i ?: 10;
|
||||
}));
|
||||
|
||||
ASSERT(3, (long double)3);
|
||||
ASSERT(5, (long double)3 + 2);
|
||||
ASSERT(6, (long double)3 * 2);
|
||||
ASSERT(5, (long double)3 + 2.0);
|
||||
|
||||
return 0;
|
||||
}
|
132
third_party/chibicc/test/asm_test.c
vendored
Normal file
132
third_party/chibicc/test/asm_test.c
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
char *asm_fn1(void) {
|
||||
asm("mov\t$50,%rax\n\t"
|
||||
"mov\t%rbp,%rsp\n\t"
|
||||
"leave\n\t"
|
||||
"ret");
|
||||
}
|
||||
|
||||
char *asm_fn2(void) {
|
||||
asm inline volatile("mov\t$55,%rax\n\t"
|
||||
"mov\t%rbp,%rsp\n\t"
|
||||
"leave\n\t"
|
||||
"ret");
|
||||
}
|
||||
|
||||
void *repmovsb(void *dst, void *src, unsigned long n) {
|
||||
asm("rep movsb"
|
||||
: "=D"(dst), "=S"(src), "=c"(n), "=m"(*(char(*)[n])dst)
|
||||
: "0"(dst), "1"(src), "2"(n), "m"(*(const char(*)[n])src));
|
||||
return dst;
|
||||
}
|
||||
|
||||
void *repmovsbeax(void *dst, void *src, unsigned long n) {
|
||||
void *res;
|
||||
asm("rep movsb\n\t"
|
||||
"xchg\t%0,%1"
|
||||
: "=a"(res), "=D"(dst), "=S"(src), "=c"(n), "=m"(*(char(*)[n])dst)
|
||||
: "1"(dst), "2"(src), "3"(n), "m"(*(const char(*)[n])src)
|
||||
: "rbx", "rbp", "r12", "r13", "r14", "r15", "cc");
|
||||
return res;
|
||||
}
|
||||
|
||||
void testSmashStackFrame_clobberIsRestored(void) {
|
||||
asm volatile("xor\t%%ebp,%%ebp"
|
||||
: /* no outputs */
|
||||
: /* no inputs */
|
||||
: "rbp", "cc");
|
||||
}
|
||||
|
||||
void testFlagOutputs(void) {
|
||||
bool zf, cf, sf;
|
||||
asm("xor\t%%eax,%%eax\n\t"
|
||||
"inc\t%%eax"
|
||||
: "=@ccz"(zf), "=@ccs"(cf)
|
||||
: /* no inputs */
|
||||
: "rax");
|
||||
ASSERT(false, zf);
|
||||
ASSERT(false, sf);
|
||||
asm("xor\t%%eax,%%eax\n\t"
|
||||
"dec\t%%eax"
|
||||
: "=@ccz"(zf), "=@ccs"(cf)
|
||||
: /* no inputs */
|
||||
: "rax");
|
||||
ASSERT(false, zf);
|
||||
ASSERT(true, sf);
|
||||
asm("xor\t%%eax,%%eax\n\t"
|
||||
"cmc"
|
||||
: "=@ccz"(zf), "=@ccc"(cf), "=@ccs"(sf)
|
||||
: /* no inputs */
|
||||
: "rax");
|
||||
ASSERT(true, zf);
|
||||
ASSERT(true, cf);
|
||||
ASSERT(false, sf);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ASSERT(50, asm_fn1());
|
||||
ASSERT(55, asm_fn2());
|
||||
|
||||
{
|
||||
char buf[] = "HELLO";
|
||||
char *s = "hello";
|
||||
char *p = repmovsb(buf, s, 4);
|
||||
ASSERT(4, p - buf);
|
||||
ASSERT('h', buf[0]);
|
||||
ASSERT('e', buf[1]);
|
||||
ASSERT('l', buf[2]);
|
||||
ASSERT('l', buf[3]);
|
||||
ASSERT('O', buf[4]);
|
||||
}
|
||||
|
||||
{
|
||||
char buf[] = "HELLO";
|
||||
char *s = "hello";
|
||||
char *p = repmovsbeax(buf, s, 4);
|
||||
ASSERT(4, p - buf);
|
||||
ASSERT('h', buf[0]);
|
||||
ASSERT('e', buf[1]);
|
||||
ASSERT('l', buf[2]);
|
||||
ASSERT('l', buf[3]);
|
||||
ASSERT('O', buf[4]);
|
||||
}
|
||||
|
||||
testSmashStackFrame_clobberIsRestored();
|
||||
|
||||
short v1[8] = {0, 1, 2, 3, 4, 5, 6, 7};
|
||||
short v2[8] = {1, 1, 1, 1, 1, 1, 1, 1};
|
||||
short v3[8] = {2, 2, 2, 2, 2, 2, 2, 2};
|
||||
asm("paddsw\t%1,%0\n\t"
|
||||
"paddsw\t%2,%0"
|
||||
: "+x"(v1)
|
||||
: "xm"(v2), "xm"(v3));
|
||||
ASSERT(3, v1[0]);
|
||||
ASSERT(4, v1[1]);
|
||||
ASSERT(5, v1[2]);
|
||||
ASSERT(6, v1[3]);
|
||||
ASSERT(7, v1[4]);
|
||||
ASSERT(8, v1[5]);
|
||||
ASSERT(9, v1[6]);
|
||||
ASSERT(10, v1[7]);
|
||||
|
||||
return 0;
|
||||
}
|
160
third_party/chibicc/test/attribute_test.c
vendored
Normal file
160
third_party/chibicc/test/attribute_test.c
vendored
Normal file
|
@ -0,0 +1,160 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(5, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((packed)) x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0, offsetof(
|
||||
struct __attribute__((packed)) {
|
||||
char a;
|
||||
int b;
|
||||
},
|
||||
a));
|
||||
ASSERT(1, offsetof(
|
||||
struct __attribute__((packed)) {
|
||||
char a;
|
||||
int b;
|
||||
},
|
||||
b));
|
||||
|
||||
ASSERT(5, ({
|
||||
struct __attribute__((packed)) {
|
||||
char a;
|
||||
int b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0, offsetof(
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((packed)),
|
||||
a));
|
||||
ASSERT(1, offsetof(
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((packed)),
|
||||
b));
|
||||
|
||||
ASSERT(9, ({
|
||||
typedef struct {
|
||||
char a;
|
||||
int b[2];
|
||||
} __attribute__((packed)) T;
|
||||
sizeof(T);
|
||||
}));
|
||||
ASSERT(9, ({
|
||||
typedef struct __attribute__((packed)) {
|
||||
char a;
|
||||
int b[2];
|
||||
} T;
|
||||
sizeof(T);
|
||||
}));
|
||||
|
||||
ASSERT(1, offsetof(
|
||||
struct __attribute__((packed)) T {
|
||||
char a;
|
||||
int b[2];
|
||||
},
|
||||
b));
|
||||
ASSERT(1, _Alignof(struct __attribute__((packed)) {
|
||||
char a;
|
||||
int b[2];
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct __attribute__((aligned(8))) {
|
||||
int a;
|
||||
} x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
int a;
|
||||
} __attribute__((aligned(8))) x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct __attribute__((aligned(8), packed)) {
|
||||
char a;
|
||||
int b;
|
||||
} x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((aligned(8), packed)) x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(1, offsetof(
|
||||
struct __attribute__((aligned(8), packed)) {
|
||||
char a;
|
||||
int b;
|
||||
},
|
||||
b));
|
||||
ASSERT(1, offsetof(
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((aligned(8), packed)),
|
||||
b));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct __attribute__((aligned(8))) __attribute__((packed)) {
|
||||
char a;
|
||||
int b;
|
||||
} x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((aligned(8))) __attribute__((packed)) x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(1, offsetof(
|
||||
struct __attribute__((aligned(8))) __attribute__((packed)) {
|
||||
char a;
|
||||
int b;
|
||||
},
|
||||
b));
|
||||
ASSERT(1, offsetof(
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((aligned(8))) __attribute__((packed)),
|
||||
b));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct __attribute__((aligned(8))) {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((packed)) x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
ASSERT(1, offsetof(
|
||||
struct __attribute__((aligned(8))) {
|
||||
char a;
|
||||
int b;
|
||||
} __attribute__((packed)),
|
||||
b));
|
||||
|
||||
ASSERT(16, ({
|
||||
struct __attribute__((aligned(8 + 8))) {
|
||||
char a;
|
||||
int b;
|
||||
} x;
|
||||
_Alignof(x);
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
128
third_party/chibicc/test/bitfield_test.c
vendored
Normal file
128
third_party/chibicc/test/bitfield_test.c
vendored
Normal file
|
@ -0,0 +1,128 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
struct {
|
||||
char a;
|
||||
int b : 5;
|
||||
int c : 10;
|
||||
} g45 = {1, 2, 3}, g46 = {};
|
||||
|
||||
int main() {
|
||||
ASSERT(4, sizeof(struct { int x : 1; }));
|
||||
ASSERT(8, sizeof(struct { long x : 1; }));
|
||||
|
||||
struct bit1 {
|
||||
short a;
|
||||
char b;
|
||||
int c : 2;
|
||||
int d : 3;
|
||||
int e : 3;
|
||||
};
|
||||
|
||||
ASSERT(4, sizeof(struct bit1));
|
||||
ASSERT(1, ({
|
||||
struct bit1 x;
|
||||
x.a = 1;
|
||||
x.b = 2;
|
||||
x.c = 3;
|
||||
x.d = 4;
|
||||
x.e = 5;
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct bit1 x = {1, 2, 3, 4, 5};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct bit1 x = {1, 2, 3, 4, 5};
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(-1, ({
|
||||
struct bit1 x = {1, 2, 3, 4, 5};
|
||||
x.c;
|
||||
}));
|
||||
ASSERT(-4, ({
|
||||
struct bit1 x = {1, 2, 3, 4, 5};
|
||||
x.d;
|
||||
}));
|
||||
ASSERT(-3, ({
|
||||
struct bit1 x = {1, 2, 3, 4, 5};
|
||||
x.e;
|
||||
}));
|
||||
|
||||
ASSERT(1, g45.a);
|
||||
ASSERT(2, g45.b);
|
||||
ASSERT(3, g45.c);
|
||||
|
||||
ASSERT(0, g46.a);
|
||||
ASSERT(0, g46.b);
|
||||
ASSERT(0, g46.c);
|
||||
|
||||
typedef struct {
|
||||
int a : 10;
|
||||
int b : 10;
|
||||
int c : 10;
|
||||
} T3;
|
||||
|
||||
ASSERT(1, ({
|
||||
T3 x = {1, 2, 3};
|
||||
x.a++;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
T3 x = {1, 2, 3};
|
||||
x.b++;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
T3 x = {1, 2, 3};
|
||||
x.c++;
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
T3 x = {1, 2, 3};
|
||||
++x.a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
T3 x = {1, 2, 3};
|
||||
++x.b;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
T3 x = {1, 2, 3};
|
||||
++x.c;
|
||||
}));
|
||||
|
||||
ASSERT(4, sizeof(struct {
|
||||
int a : 3;
|
||||
int c : 1;
|
||||
int c : 5;
|
||||
}));
|
||||
ASSERT(8, sizeof(struct {
|
||||
int a : 3;
|
||||
int : 0;
|
||||
int c : 5;
|
||||
}));
|
||||
ASSERT(4, sizeof(struct {
|
||||
int a : 3;
|
||||
int : 0;
|
||||
}));
|
||||
|
||||
typedef struct {
|
||||
long p : 1;
|
||||
long a : 40;
|
||||
long b : 20;
|
||||
} T4;
|
||||
|
||||
ASSERT(0xfffffffffffaaaaa, ({
|
||||
T4 x = {1, 0x31337313371337, 0xaaaaaaaaaaaaaaaa};
|
||||
x.b++;
|
||||
}));
|
||||
ASSERT(0x7313371337, ({
|
||||
T4 x = {1, 0x31337313371337, 0xaaaaaaaaaaaaaaaa};
|
||||
x.a++;
|
||||
}));
|
||||
ASSERT(0xffffffffffffffd4, ({
|
||||
T4 x;
|
||||
x.b = -44;
|
||||
x.b++;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
242
third_party/chibicc/test/builtin_test.c
vendored
Normal file
242
third_party/chibicc/test/builtin_test.c
vendored
Normal file
|
@ -0,0 +1,242 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
#define FPNAN 0
|
||||
#define FPINFINITE 1
|
||||
#define FPZERO 2
|
||||
#define FPSUBNORMAL 3
|
||||
#define FPNORMAL 4
|
||||
#define FPCLASSIFY(x) \
|
||||
__builtin_fpclassify(FPNAN, FPINFINITE, FPNORMAL, FPSUBNORMAL, FPZERO, x)
|
||||
|
||||
void test_constant(void) {
|
||||
ASSERT(1, __builtin_constant_p(1));
|
||||
ASSERT(0, __builtin_constant_p(stdin));
|
||||
ASSERT(1, __builtin_constant_p(__builtin_popcount(0b10111011)));
|
||||
}
|
||||
|
||||
void test_fpclassify(void) {
|
||||
float minf = __FLT_MIN__;
|
||||
double min = __DBL_MIN__;
|
||||
long double minl = __LDBL_MIN__;
|
||||
ASSERT(FPZERO, FPCLASSIFY(.0f));
|
||||
ASSERT(FPZERO, FPCLASSIFY(.0));
|
||||
ASSERT(FPZERO, FPCLASSIFY(.0L));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.f));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.L));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.f));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(1.L));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(minf));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(min));
|
||||
ASSERT(FPNORMAL, FPCLASSIFY(minl));
|
||||
ASSERT(FPSUBNORMAL, FPCLASSIFY(minf / 2));
|
||||
ASSERT(FPSUBNORMAL, FPCLASSIFY(min / 2));
|
||||
ASSERT(FPSUBNORMAL, FPCLASSIFY(minl / 2));
|
||||
ASSERT(FPNAN, FPCLASSIFY(__builtin_nanf("")));
|
||||
ASSERT(FPNAN, FPCLASSIFY(__builtin_nan("")));
|
||||
ASSERT(FPNAN, FPCLASSIFY(__builtin_nanl("")));
|
||||
}
|
||||
|
||||
void __attribute__((__aligned__(16))) test_clz(void) {
|
||||
ASSERT(31, __builtin_clz(1));
|
||||
ASSERT(63, __builtin_clzl(1));
|
||||
ASSERT(63, __builtin_clzll(1));
|
||||
ASSERT(25, __builtin_clz(77));
|
||||
ASSERT(4, __builtin_clz(0x08000000));
|
||||
ASSERT(4, __builtin_clz(0xfff08000000));
|
||||
}
|
||||
|
||||
__attribute__((__weak__)) void test_ctz(void) {
|
||||
ASSERT(0, __builtin_ctz(1));
|
||||
ASSERT(0, __builtin_ctz(77));
|
||||
ASSERT(27, __builtin_ctz(0x08000000));
|
||||
ASSERT(27, __builtin_ctz(0xffff08000000));
|
||||
ASSERT(63, __builtin_ctzl(0x8000000000000000));
|
||||
ASSERT(63, __builtin_ctzll(0x8000000000000000));
|
||||
}
|
||||
|
||||
void test_ffs(void) {
|
||||
ASSERT(0, __builtin_ffs(0));
|
||||
ASSERT(1, __builtin_ffs(1));
|
||||
ASSERT(1, __builtin_ffs(77));
|
||||
ASSERT(28, __builtin_ffs(0x08000000));
|
||||
ASSERT(28, __builtin_ffs(0xffff08000000));
|
||||
}
|
||||
|
||||
void test_popcnt(void) {
|
||||
ASSERT(0, __builtin_popcount(0));
|
||||
ASSERT(1, __builtin_popcount(1));
|
||||
ASSERT(6, __builtin_popcount(0b10111011));
|
||||
ASSERT(6, __builtin_popcountl(0b10111011));
|
||||
ASSERT(6, __builtin_popcountll(0xbb00000000000000));
|
||||
}
|
||||
|
||||
void test_bswap(void) {
|
||||
ASSERT(0x3412, __builtin_bswap16(0x1234));
|
||||
ASSERT(0x78563412, __builtin_bswap32(0x12345678));
|
||||
ASSERT(0xefcdab8967452301, __builtin_bswap64(0x0123456789abcdef));
|
||||
ASSERT(0xefcdab89, __builtin_bswap32(0x0123456789abcdef));
|
||||
}
|
||||
|
||||
void test_memcpy(void) {
|
||||
{
|
||||
char x[5] = {4, 3, 2, 1, 0};
|
||||
char y[5] = {0, 1, 2, 3, 4};
|
||||
char z[5] = {2, 3, 4, 1, 0};
|
||||
ASSERT(1, x == __builtin_memcpy(x, y + 2, 3));
|
||||
ASSERT(0, memcmp(x, z, 5));
|
||||
}
|
||||
{
|
||||
int n = 3;
|
||||
char x[5] = {4, 3, 2, 1, 0};
|
||||
char y[5] = {0, 1, 2, 3, 4};
|
||||
char z[5] = {2, 3, 4, 1, 0};
|
||||
ASSERT(1, x == __builtin_memcpy(x, y + 2, n));
|
||||
ASSERT(0, memcmp(x, z, 5));
|
||||
}
|
||||
}
|
||||
|
||||
void test_inf(void) {
|
||||
ASSERT(0, __builtin_isinf(0));
|
||||
ASSERT(0, __builtin_isinf(1));
|
||||
ASSERT(1, __builtin_isinf(__builtin_inff()));
|
||||
ASSERT(1, __builtin_isinf(-__builtin_inff()));
|
||||
ASSERT(1, __builtin_isinf(__builtin_inf()));
|
||||
ASSERT(1, __builtin_isinf(-__builtin_inf()));
|
||||
ASSERT(1, __builtin_isinf(__builtin_infl()));
|
||||
ASSERT(1, __builtin_isinf(-__builtin_infl()));
|
||||
ASSERT(1, __builtin_isfinite(0));
|
||||
ASSERT(1, __builtin_isfinite(1));
|
||||
ASSERT(0, __builtin_isfinite(__builtin_inff()));
|
||||
ASSERT(0, __builtin_isfinite(-__builtin_inff()));
|
||||
ASSERT(0, __builtin_isfinite(__builtin_inf()));
|
||||
ASSERT(0, __builtin_isfinite(-__builtin_inf()));
|
||||
ASSERT(0, __builtin_isfinite(__builtin_infl()));
|
||||
ASSERT(0, __builtin_isfinite(-__builtin_infl()));
|
||||
}
|
||||
|
||||
void test_signbit(void) {
|
||||
ASSERT(0, !!__builtin_signbitf(0));
|
||||
ASSERT(0, !!__builtin_signbitf(0.f));
|
||||
ASSERT(0, !!__builtin_signbit(0.));
|
||||
ASSERT(0, !!__builtin_signbitl(0.L));
|
||||
ASSERT(1, !!__builtin_signbitf(-0.f));
|
||||
ASSERT(1, !!__builtin_signbit(-0.));
|
||||
ASSERT(1, !!__builtin_signbitl(-0.L));
|
||||
ASSERT(0, !!__builtin_signbitf(__builtin_nanf("")));
|
||||
ASSERT(1, !!__builtin_signbitf(-__builtin_nanf("")));
|
||||
ASSERT(0, !!__builtin_signbit(__builtin_nan("")));
|
||||
ASSERT(1, !!__builtin_signbit(-__builtin_nan("")));
|
||||
ASSERT(0, !!__builtin_signbitl(__builtin_nanl("")));
|
||||
ASSERT(1, !!__builtin_signbitl(-__builtin_nanl("")));
|
||||
ASSERT(0, !!__builtin_signbitf(__builtin_inff()));
|
||||
ASSERT(1, !!__builtin_signbitf(-__builtin_inff()));
|
||||
ASSERT(0, !!__builtin_signbit(__builtin_inf()));
|
||||
ASSERT(1, !!__builtin_signbit(-__builtin_inf()));
|
||||
ASSERT(0, !!__builtin_signbitl(__builtin_infl()));
|
||||
ASSERT(1, !!__builtin_signbitl(-__builtin_infl()));
|
||||
}
|
||||
|
||||
void test_nan(void) {
|
||||
ASSERT(0, __builtin_isnan(0));
|
||||
ASSERT(0, __builtin_isnan(1));
|
||||
ASSERT(1, __builtin_isnan(__builtin_nanf("")));
|
||||
ASSERT(1, __builtin_isnan(-__builtin_nanf("")));
|
||||
ASSERT(1, __builtin_isnan(__builtin_nan("")));
|
||||
ASSERT(1, __builtin_isnan(-__builtin_nan("")));
|
||||
ASSERT(1, __builtin_isnan(__builtin_nanl("")));
|
||||
ASSERT(1, __builtin_isnan(-__builtin_nanl("")));
|
||||
ASSERT(0, __builtin_isunordered(0, 0));
|
||||
ASSERT(0, __builtin_isunordered(-1, 1));
|
||||
ASSERT(1, __builtin_isunordered(0, __builtin_nanf("")));
|
||||
ASSERT(1, __builtin_isunordered(__builtin_nanf(""), 0));
|
||||
ASSERT(1, __builtin_isunordered(__builtin_nanf(""), __builtin_nanf("")));
|
||||
}
|
||||
|
||||
void test_double(void) { /* TODO */
|
||||
/* ASSERT(1, __DBL_MIN__ < 0.0L); */
|
||||
/* ASSERT(1, __DBL_MAX__ > 0.0L); */
|
||||
}
|
||||
|
||||
void test_types_compatible_p(void) {
|
||||
ASSERT(1, __builtin_types_compatible_p(int, int));
|
||||
ASSERT(1, __builtin_types_compatible_p(double, double));
|
||||
ASSERT(0, __builtin_types_compatible_p(int, long));
|
||||
ASSERT(0, __builtin_types_compatible_p(long, float));
|
||||
ASSERT(1, __builtin_types_compatible_p(int *, int *));
|
||||
ASSERT(0, __builtin_types_compatible_p(short *, int *));
|
||||
ASSERT(0, __builtin_types_compatible_p(int **, int *));
|
||||
ASSERT(1, __builtin_types_compatible_p(const int, int));
|
||||
ASSERT(0, __builtin_types_compatible_p(unsigned, int));
|
||||
ASSERT(1, __builtin_types_compatible_p(signed, int));
|
||||
ASSERT(0, __builtin_types_compatible_p(
|
||||
struct { int a; }, struct { int a; }));
|
||||
ASSERT(1, __builtin_types_compatible_p(int (*)(void), int (*)(void)));
|
||||
ASSERT(1, __builtin_types_compatible_p(void (*)(int), void (*)(int)));
|
||||
ASSERT(1, __builtin_types_compatible_p(void (*)(int, double),
|
||||
void (*)(int, double)));
|
||||
ASSERT(1, __builtin_types_compatible_p(int (*)(float, double),
|
||||
int (*)(float, double)));
|
||||
ASSERT(0, __builtin_types_compatible_p(int (*)(float, double), int));
|
||||
ASSERT(0,
|
||||
__builtin_types_compatible_p(int (*)(float, double), int (*)(float)));
|
||||
ASSERT(0, __builtin_types_compatible_p(int (*)(float, double),
|
||||
int (*)(float, double, int)));
|
||||
ASSERT(1, __builtin_types_compatible_p(double (*)(...), double (*)(...)));
|
||||
ASSERT(0, __builtin_types_compatible_p(double (*)(...), double (*)(void)));
|
||||
ASSERT(1, ({
|
||||
typedef struct {
|
||||
int a;
|
||||
} T;
|
||||
__builtin_types_compatible_p(T, T);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
typedef struct {
|
||||
int a;
|
||||
} T;
|
||||
__builtin_types_compatible_p(T, const T);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
} x;
|
||||
__builtin_types_compatible_p(typeof(x.a), typeof(x.b));
|
||||
}));
|
||||
}
|
||||
|
||||
void test_offsetof(void) {
|
||||
ASSERT(0, ({
|
||||
struct T {
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
__builtin_offsetof(struct T, a);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
struct T {
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
__builtin_offsetof(struct T, b);
|
||||
}));
|
||||
}
|
||||
|
||||
int main() {
|
||||
test_constant();
|
||||
test_types_compatible_p();
|
||||
test_clz();
|
||||
test_ctz();
|
||||
test_ffs();
|
||||
test_bswap();
|
||||
test_popcnt();
|
||||
test_inf();
|
||||
test_nan();
|
||||
test_double();
|
||||
test_fpclassify();
|
||||
test_signbit();
|
||||
test_memcpy();
|
||||
test_offsetof();
|
||||
return 0;
|
||||
}
|
80
third_party/chibicc/test/cast_test.c
vendored
Normal file
80
third_party/chibicc/test/cast_test.c
vendored
Normal file
|
@ -0,0 +1,80 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(131585, (int)8590066177);
|
||||
ASSERT(513, (short)8590066177);
|
||||
ASSERT(1, (char)8590066177);
|
||||
ASSERT(1, (long)1);
|
||||
ASSERT(0, (long)&*(int *)0);
|
||||
ASSERT(513, ({
|
||||
int x = 512;
|
||||
*(char *)&x = 1;
|
||||
x;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 5;
|
||||
long y = (long)&x;
|
||||
*(int *)y;
|
||||
}));
|
||||
|
||||
(void)1;
|
||||
|
||||
ASSERT(-1, (char)255);
|
||||
ASSERT(-1, (signed char)255);
|
||||
ASSERT(255, (unsigned char)255);
|
||||
ASSERT(-1, (short)65535);
|
||||
ASSERT(65535, (unsigned short)65535);
|
||||
ASSERT(-1, (int)0xffffffff);
|
||||
ASSERT(0xffffffff, (unsigned)0xffffffff);
|
||||
|
||||
ASSERT(1, -1 < 1);
|
||||
ASSERT(0, -1 < (unsigned)1);
|
||||
ASSERT(254, (char)127 + (char)127);
|
||||
ASSERT(65534, (short)32767 + (short)32767);
|
||||
ASSERT(-1, -1 >> 1);
|
||||
ASSERT(-1, (unsigned long)-1);
|
||||
ASSERT(2147483647, ((unsigned)-1) >> 1);
|
||||
ASSERT(-50, (-100) / 2);
|
||||
ASSERT(2147483598, ((unsigned)-100) / 2);
|
||||
ASSERT(9223372036854775758, ((unsigned long)-100) / 2);
|
||||
ASSERT(0, ((long)-1) / (unsigned)100);
|
||||
ASSERT(-2, (-100) % 7);
|
||||
ASSERT(2, ((unsigned)-100) % 7);
|
||||
ASSERT(6, ((unsigned long)-100) % 9);
|
||||
|
||||
ASSERT(65535, (int)(unsigned short)65535);
|
||||
ASSERT(65535, ({
|
||||
unsigned short x = 65535;
|
||||
x;
|
||||
}));
|
||||
ASSERT(65535, ({
|
||||
unsigned short x = 65535;
|
||||
(int)x;
|
||||
}));
|
||||
|
||||
ASSERT(-1, ({
|
||||
typedef short T;
|
||||
T x = 65535;
|
||||
(int)x;
|
||||
}));
|
||||
ASSERT(65535, ({
|
||||
typedef unsigned short T;
|
||||
T x = 65535;
|
||||
(int)x;
|
||||
}));
|
||||
|
||||
ASSERT(0, (_Bool)0.0);
|
||||
ASSERT(1, (_Bool)0.1);
|
||||
ASSERT(3, (char)3.0);
|
||||
ASSERT(1000, (short)1000.3);
|
||||
ASSERT(3, (int)3.99);
|
||||
ASSERT(2000000000000000, (long)2e15);
|
||||
ASSERT(3, (float)3.5);
|
||||
ASSERT(5, (double)(float)5.5);
|
||||
ASSERT(3, (float)3);
|
||||
ASSERT(3, (double)3);
|
||||
ASSERT(3, (float)3L);
|
||||
ASSERT(3, (double)3L);
|
||||
|
||||
return 0;
|
||||
}
|
195
third_party/chibicc/test/common.c
vendored
Normal file
195
third_party/chibicc/test/common.c
vendored
Normal file
|
@ -0,0 +1,195 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
void Assert(long expected, long actual, char *code) {
|
||||
if (expected != actual) {
|
||||
fprintf(stderr, "%s => %ld expected but got %ld\n", code, expected, actual);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Assert2(long expected, long actual, char *code, char *func, int line) {
|
||||
if (expected != actual) {
|
||||
fprintf(stderr, "%s:%d: %s => expected %ld but got %ld\n", func, line, code,
|
||||
expected, actual);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void Assert128(__int128 k, __int128 x, char *code, char *func, int line) {
|
||||
if (k != x) {
|
||||
fprintf(stderr, "%s:%d: %s => want %jd but got %jd\n", func, line, code, k,
|
||||
x);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
static int static_fn() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
int ext1 = 5;
|
||||
int *ext2 = &ext1;
|
||||
int ext3 = 7;
|
||||
|
||||
int ext_fn1(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int ext_fn2(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int common_ext2 = 3;
|
||||
static int common_local;
|
||||
|
||||
int false_fn() {
|
||||
return 512;
|
||||
}
|
||||
|
||||
int true_fn() {
|
||||
return 513;
|
||||
}
|
||||
|
||||
int char_fn() {
|
||||
return (2 << 8) + 3;
|
||||
}
|
||||
|
||||
int short_fn() {
|
||||
return (2 << 16) + 5;
|
||||
}
|
||||
|
||||
int uchar_fn() {
|
||||
return (2 << 10) - 1 - 4;
|
||||
}
|
||||
|
||||
int ushort_fn() {
|
||||
return (2 << 20) - 1 - 7;
|
||||
}
|
||||
|
||||
int schar_fn() {
|
||||
return (2 << 10) - 1 - 4;
|
||||
}
|
||||
|
||||
int sshort_fn() {
|
||||
return (2 << 20) - 1 - 7;
|
||||
}
|
||||
|
||||
int add_all(int n, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, n);
|
||||
int sum = 0;
|
||||
for (int i = 0; i < n; i++) sum += va_arg(ap, int);
|
||||
va_end(ap);
|
||||
return sum;
|
||||
}
|
||||
|
||||
float add_float(float x, float y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
double add_double(double x, double y) {
|
||||
return x + y;
|
||||
}
|
||||
|
||||
int add10_int(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8,
|
||||
int x9, int x10) {
|
||||
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10;
|
||||
}
|
||||
|
||||
float add10_float(float x1, float x2, float x3, float x4, float x5, float x6,
|
||||
float x7, float x8, float x9, float x10) {
|
||||
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10;
|
||||
}
|
||||
|
||||
double add10_double(double x1, double x2, double x3, double x4, double x5,
|
||||
double x6, double x7, double x8, double x9, double x10) {
|
||||
return x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9 + x10;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int a, b;
|
||||
short c;
|
||||
char d;
|
||||
} Ty4;
|
||||
|
||||
typedef struct {
|
||||
int a;
|
||||
float b;
|
||||
double c;
|
||||
} Ty5;
|
||||
|
||||
typedef struct {
|
||||
unsigned char a[3];
|
||||
} Ty6;
|
||||
|
||||
typedef struct {
|
||||
long a, b, c;
|
||||
} Ty7;
|
||||
|
||||
int struct_test4(Ty4 x, int n) {
|
||||
switch (n) {
|
||||
case 0:
|
||||
return x.a;
|
||||
case 1:
|
||||
return x.b;
|
||||
case 2:
|
||||
return x.c;
|
||||
default:
|
||||
return x.d;
|
||||
}
|
||||
}
|
||||
|
||||
int struct_test5(Ty5 x, int n) {
|
||||
switch (n) {
|
||||
case 0:
|
||||
return x.a;
|
||||
case 1:
|
||||
return x.b;
|
||||
default:
|
||||
return x.c;
|
||||
}
|
||||
}
|
||||
|
||||
int struct_test6(Ty6 x, int n) {
|
||||
return x.a[n];
|
||||
}
|
||||
|
||||
int struct_test7(Ty7 x, int n) {
|
||||
switch (n) {
|
||||
case 0:
|
||||
return x.a;
|
||||
case 1:
|
||||
return x.b;
|
||||
default:
|
||||
return x.c;
|
||||
}
|
||||
}
|
||||
|
||||
Ty4 struct_test24(void) {
|
||||
return (Ty4){10, 20, 30, 40};
|
||||
}
|
||||
|
||||
Ty5 struct_test25(void) {
|
||||
return (Ty5){10, 20, 30};
|
||||
}
|
||||
|
||||
Ty6 struct_test26(void) {
|
||||
return (Ty6){{10, 20, 30}};
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned char a[10];
|
||||
} Ty20;
|
||||
|
||||
typedef struct {
|
||||
unsigned char a[20];
|
||||
} Ty21;
|
||||
|
||||
Ty20 struct_test27(void) {
|
||||
return (Ty20){{10, 20, 30, 40, 50, 60, 70, 80, 90, 100}};
|
||||
}
|
||||
|
||||
Ty21 struct_test28(void) {
|
||||
return (Ty21){
|
||||
{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}};
|
||||
}
|
18
third_party/chibicc/test/compat_test.c
vendored
Normal file
18
third_party/chibicc/test/compat_test.c
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
_Noreturn noreturn_fn(int restrict x) {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
void funcy_type(int arg[restrict static 3]) {
|
||||
}
|
||||
|
||||
int main() {
|
||||
{ volatile x; }
|
||||
{ int volatile x; }
|
||||
{ volatile int x; }
|
||||
{ volatile int volatile volatile x; }
|
||||
{ int volatile *volatile volatile x; }
|
||||
{ auto **restrict __restrict __restrict__ const volatile *x; }
|
||||
return 0;
|
||||
}
|
31
third_party/chibicc/test/complit_test.c
vendored
Normal file
31
third_party/chibicc/test/complit_test.c
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
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};
|
||||
|
||||
int main() {
|
||||
ASSERT(1, (int){1});
|
||||
ASSERT(2, ((int[]){0, 1, 2})[2]);
|
||||
ASSERT('a', ((struct {
|
||||
char a;
|
||||
int b;
|
||||
}){'a', 3})
|
||||
.a);
|
||||
ASSERT(3, ({
|
||||
int x = 3;
|
||||
(int){x};
|
||||
}));
|
||||
(int){3} = 5;
|
||||
|
||||
ASSERT(1, tree->val);
|
||||
ASSERT(2, tree->lhs->val);
|
||||
ASSERT(3, tree->lhs->lhs->val);
|
||||
ASSERT(4, tree->lhs->rhs->val);
|
||||
|
||||
return 0;
|
||||
}
|
23
third_party/chibicc/test/const_test.c
vendored
Normal file
23
third_party/chibicc/test/const_test.c
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
{ const x; }
|
||||
{ int const x; }
|
||||
{ const int x; }
|
||||
{ const int const const x; }
|
||||
ASSERT(5, ({
|
||||
const x = 5;
|
||||
x;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
const x = 8;
|
||||
int *const y = &x;
|
||||
*y;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
const x = 6;
|
||||
*(const *const) & x;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
181
third_party/chibicc/test/constexpr_test.c
vendored
Normal file
181
third_party/chibicc/test/constexpr_test.c
vendored
Normal file
|
@ -0,0 +1,181 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
float g40 = 1.5;
|
||||
double g41 = 0.0 ? 55 : (0, 1 + 1 * 5.0 / 2 * (double)2 * (int)2.0);
|
||||
|
||||
int main() {
|
||||
ASSERT(10, ({
|
||||
enum { ten = 1 + 2 + 3 + 4 };
|
||||
ten;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int i = 0;
|
||||
switch (3) {
|
||||
case 5 - 2 + 0 * 3:
|
||||
i++;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x[1 + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
char x[8 - 2];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
char x[2 * 3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char x[12 / 4];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[12 % 10];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0b100, ({
|
||||
char x[0b110 & 0b101];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0b111, ({
|
||||
char x[0b110 | 0b101];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0b110, ({
|
||||
char x[0b111 ^ 0b001];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char x[1 << 2];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[4 >> 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[(1 == 1) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(1 != 1) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(1 < 1) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[(1 <= 1) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[1 ? 2 : 3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char x[0 ? 2 : 3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char x[(1, 3)];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[!0 + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[!1 + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[~-3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[(5 || 6) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(0 || 0) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x[(1 && 1) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(1 && 0) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char x[(int)3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(15, ({
|
||||
char x[(char)0xffffff0f];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0x10f, ({
|
||||
char x[(short)0xffff010f];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char x[(int)0xfffffffffff + 5];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
char x[(int*)0 + 2];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
char x[(int*)16 - 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char x[(int*)16 - (int*)4];
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
char x[(-1 >> 31) + 5];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(255, ({
|
||||
char x[(unsigned char)0xffffffff];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0x800f, ({
|
||||
char x[(unsigned short)0xffff800f];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(unsigned int)0xfffffffffff >> 31];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(long)-1 / ((long)1 << 62) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char x[(unsigned long)-1 / ((long)1 << 62) + 1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(unsigned)1 < -1];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x[(unsigned)1 <= -1];
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(1, g40 == 1.5);
|
||||
ASSERT(1, g41 == 11);
|
||||
|
||||
return 0;
|
||||
}
|
542
third_party/chibicc/test/control_test.c
vendored
Normal file
542
third_party/chibicc/test/control_test.c
vendored
Normal file
|
@ -0,0 +1,542 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
/*
|
||||
* This is a block comment.
|
||||
*/
|
||||
|
||||
int main() {
|
||||
ASSERT(3, ({
|
||||
int x;
|
||||
if (0)
|
||||
x = 2;
|
||||
else
|
||||
x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x;
|
||||
if (1 - 1)
|
||||
x = 2;
|
||||
else
|
||||
x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int x;
|
||||
if (1)
|
||||
x = 2;
|
||||
else
|
||||
x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int x;
|
||||
if (2 - 1)
|
||||
x = 2;
|
||||
else
|
||||
x = 3;
|
||||
x;
|
||||
}));
|
||||
|
||||
ASSERT(55, ({
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
for (i = 0; i <= 10; i = i + 1) j = i + j;
|
||||
j;
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
int i = 0;
|
||||
while (i < 10) i = i + 1;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
1;
|
||||
{ 2; }
|
||||
3;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
;
|
||||
;
|
||||
;
|
||||
5;
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
int 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;
|
||||
}));
|
||||
|
||||
ASSERT(3, (1, 2, 3));
|
||||
ASSERT(5, ({
|
||||
int i = 2, j = 3;
|
||||
(i = 5, j) = 6;
|
||||
i;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int i = 2, j = 3;
|
||||
(i = 5, j) = 6;
|
||||
j;
|
||||
}));
|
||||
|
||||
ASSERT(55, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(1, 0 || 1);
|
||||
ASSERT(1, 0 || (2 - 2) || 5);
|
||||
ASSERT(0, 0 || 0);
|
||||
ASSERT(0, 0 || (2 - 2));
|
||||
|
||||
ASSERT(0, 0 && 1);
|
||||
ASSERT(0, (2 - 2) && 5);
|
||||
ASSERT(1, 1 && 5);
|
||||
|
||||
ASSERT(3, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int i = 0;
|
||||
goto i;
|
||||
g:
|
||||
i++;
|
||||
h:
|
||||
i++;
|
||||
i:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
typedef int foo;
|
||||
goto foo;
|
||||
foo:;
|
||||
1;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
int i = 0;
|
||||
for (; i < 10; i++) {
|
||||
if (i == 3) break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int i = 0;
|
||||
while (1) {
|
||||
if (i++ == 3) break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int i = 0;
|
||||
for (; i < 10; i++) {
|
||||
for (;;) break;
|
||||
if (i == 3) break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int i = 0;
|
||||
while (1) {
|
||||
while (1) break;
|
||||
if (i++ == 3) break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(5, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
int i = 0;
|
||||
switch (-1) {
|
||||
case 0xffffffff:
|
||||
i = 3;
|
||||
break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(7, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(0, 0.0 && 0.0);
|
||||
ASSERT(0, 0.0 && 0.1);
|
||||
ASSERT(0, 0.3 && 0.0);
|
||||
ASSERT(1, 0.3 && 0.5);
|
||||
ASSERT(0, 0.0 || 0.0);
|
||||
ASSERT(1, 0.0 || 0.1);
|
||||
ASSERT(1, 0.3 || 0.0);
|
||||
ASSERT(1, 0.3 || 0.5);
|
||||
ASSERT(5, ({
|
||||
int x;
|
||||
if (0.0)
|
||||
x = 3;
|
||||
else
|
||||
x = 5;
|
||||
x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x;
|
||||
if (0.1)
|
||||
x = 3;
|
||||
else
|
||||
x = 5;
|
||||
x;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 5;
|
||||
if (0.0) x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x = 5;
|
||||
if (0.1) x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
double i = 10.0;
|
||||
int j = 0;
|
||||
for (; i; i--, j++)
|
||||
;
|
||||
j;
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
double i = 10.0;
|
||||
int j = 0;
|
||||
do
|
||||
j++;
|
||||
while (--i);
|
||||
j;
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
int i = 0;
|
||||
switch (7) {
|
||||
case 0 ... 5:
|
||||
i = 1;
|
||||
break;
|
||||
case 6 ... 20:
|
||||
i = 2;
|
||||
break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int i = 0;
|
||||
switch (7) {
|
||||
case 0 ... 7:
|
||||
i = 1;
|
||||
break;
|
||||
case 8 ... 10:
|
||||
i = 2;
|
||||
break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int i = 0;
|
||||
switch (7) {
|
||||
case 0:
|
||||
i = 1;
|
||||
break;
|
||||
case 7 ... 7:
|
||||
i = 1;
|
||||
break;
|
||||
}
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
void *p = &&v11;
|
||||
int i = 0;
|
||||
goto *p;
|
||||
v11:
|
||||
i++;
|
||||
v12:
|
||||
i++;
|
||||
v13:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
void *p = &&v22;
|
||||
int i = 0;
|
||||
goto *p;
|
||||
v21:
|
||||
i++;
|
||||
v22:
|
||||
i++;
|
||||
v23:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
void *p = &&v33;
|
||||
int i = 0;
|
||||
goto *p;
|
||||
v31:
|
||||
i++;
|
||||
v32:
|
||||
i++;
|
||||
v33:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
static void *p[] = {&&v41, &&v42, &&v43};
|
||||
int i = 0;
|
||||
goto *p[0];
|
||||
v41:
|
||||
i++;
|
||||
v42:
|
||||
i++;
|
||||
v43:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
static void *p[] = {&&v52, &&v52, &&v53};
|
||||
int i = 0;
|
||||
goto *p[1];
|
||||
v51:
|
||||
i++;
|
||||
v52:
|
||||
i++;
|
||||
v53:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
static void *p[] = {&&v62, &&v62, &&v63};
|
||||
int i = 0;
|
||||
goto *p[2];
|
||||
v61:
|
||||
i++;
|
||||
v62:
|
||||
i++;
|
||||
v63:
|
||||
i++;
|
||||
i;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
51
third_party/chibicc/test/decl_test.c
vendored
Normal file
51
third_party/chibicc/test/decl_test.c
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(1, ({
|
||||
char x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
short int x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int short x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
long int x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int long x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
long long x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
_Bool x = 0;
|
||||
x;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
_Bool x = 1;
|
||||
x;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
_Bool x = 2;
|
||||
x;
|
||||
}));
|
||||
ASSERT(1, (_Bool)1);
|
||||
ASSERT(1, (_Bool)2);
|
||||
ASSERT(0, (_Bool)(char)256);
|
||||
|
||||
return 0;
|
||||
}
|
50
third_party/chibicc/test/enum_test.c
vendored
Normal file
50
third_party/chibicc/test/enum_test.c
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(0, ({
|
||||
enum { zero, one, two };
|
||||
zero;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
enum { zero, one, two };
|
||||
one;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
enum { zero, one, two };
|
||||
two;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
enum { five = 5, six, seven };
|
||||
five;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
enum { five = 5, six, seven };
|
||||
six;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
enum { zero, five = 5, three = 3, four };
|
||||
zero;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
enum { zero, five = 5, three = 3, four };
|
||||
five;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
enum { zero, five = 5, three = 3, four };
|
||||
three;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
enum { zero, five = 5, three = 3, four };
|
||||
four;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
enum { zero, one, two } x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
enum t { zero, one, two };
|
||||
enum t y;
|
||||
sizeof(y);
|
||||
}));
|
||||
return 0;
|
||||
}
|
24
third_party/chibicc/test/extern_test.c
vendored
Normal file
24
third_party/chibicc/test/extern_test.c
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
extern int ext1;
|
||||
extern int *ext2;
|
||||
|
||||
inline int inline_fn(void) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ASSERT(5, ext1);
|
||||
ASSERT(5, *ext2);
|
||||
|
||||
extern int ext3;
|
||||
ASSERT(7, ext3);
|
||||
|
||||
int ext_fn1(int x);
|
||||
ASSERT(5, ext_fn1(5));
|
||||
|
||||
extern int ext_fn2(int x);
|
||||
ASSERT(8, ext_fn2(8));
|
||||
|
||||
return 0;
|
||||
}
|
92
third_party/chibicc/test/float_test.c
vendored
Normal file
92
third_party/chibicc/test/float_test.c
vendored
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(35, (float)(char)35);
|
||||
ASSERT(35, (float)(short)35);
|
||||
ASSERT(35, (float)(int)35);
|
||||
ASSERT(35, (float)(long)35);
|
||||
ASSERT(35, (float)(unsigned char)35);
|
||||
ASSERT(35, (float)(unsigned short)35);
|
||||
ASSERT(35, (float)(unsigned int)35);
|
||||
ASSERT(35, (float)(unsigned long)35);
|
||||
|
||||
ASSERT(35, (double)(char)35);
|
||||
ASSERT(35, (double)(short)35);
|
||||
ASSERT(35, (double)(int)35);
|
||||
ASSERT(35, (double)(long)35);
|
||||
ASSERT(35, (double)(unsigned char)35);
|
||||
ASSERT(35, (double)(unsigned short)35);
|
||||
ASSERT(35, (double)(unsigned int)35);
|
||||
ASSERT(35, (double)(unsigned long)35);
|
||||
|
||||
ASSERT(35, (char)(float)35);
|
||||
ASSERT(35, (short)(float)35);
|
||||
ASSERT(35, (int)(float)35);
|
||||
ASSERT(35, (long)(float)35);
|
||||
ASSERT(35, (unsigned char)(float)35);
|
||||
ASSERT(35, (unsigned short)(float)35);
|
||||
ASSERT(35, (unsigned int)(float)35);
|
||||
ASSERT(35, (unsigned long)(float)35);
|
||||
|
||||
ASSERT(35, (char)(double)35);
|
||||
ASSERT(35, (short)(double)35);
|
||||
ASSERT(35, (int)(double)35);
|
||||
ASSERT(35, (long)(double)35);
|
||||
ASSERT(35, (unsigned char)(double)35);
|
||||
ASSERT(35, (unsigned short)(double)35);
|
||||
ASSERT(35, (unsigned int)(double)35);
|
||||
ASSERT(35, (unsigned long)(double)35);
|
||||
|
||||
ASSERT(0x8000000000000000, (double)(unsigned long)(long)-1);
|
||||
|
||||
ASSERT(1, 2e3 == 2e3);
|
||||
ASSERT(0, 2e3 == 2e5);
|
||||
ASSERT(1, 2.0 == 2);
|
||||
ASSERT(0, 5.1 < 5);
|
||||
ASSERT(0, 5.0 < 5);
|
||||
ASSERT(1, 4.9 < 5);
|
||||
ASSERT(0, 5.1 <= 5);
|
||||
ASSERT(1, 5.0 <= 5);
|
||||
ASSERT(1, 4.9 <= 5);
|
||||
|
||||
ASSERT(1, 2e3f == 2e3);
|
||||
ASSERT(0, 2e3f == 2e5);
|
||||
ASSERT(1, 2.0f == 2);
|
||||
ASSERT(0, 5.1f < 5);
|
||||
ASSERT(0, 5.0f < 5);
|
||||
ASSERT(1, 4.9f < 5);
|
||||
ASSERT(0, 5.1f <= 5);
|
||||
ASSERT(1, 5.0f <= 5);
|
||||
ASSERT(1, 4.9f <= 5);
|
||||
|
||||
ASSERT(6, 2.3 + 3.8);
|
||||
ASSERT(-1, 2.3 - 3.8);
|
||||
ASSERT(-3, -3.8);
|
||||
ASSERT(13, 3.3 * 4);
|
||||
ASSERT(2, 5.0 / 2);
|
||||
|
||||
ASSERT(6, 2.3f + 3.8f);
|
||||
ASSERT(6, 2.3f + 3.8);
|
||||
ASSERT(-1, 2.3f - 3.8);
|
||||
ASSERT(-3, -3.8f);
|
||||
ASSERT(13, 3.3f * 4);
|
||||
ASSERT(2, 5.0f / 2);
|
||||
|
||||
ASSERT(0, 0.0 / 0.0 == 0.0 / 0.0);
|
||||
ASSERT(1, 0.0 / 0.0 != 0.0 / 0.0);
|
||||
|
||||
ASSERT(0, 0.0 / 0.0 < 0);
|
||||
ASSERT(0, 0.0 / 0.0 <= 0);
|
||||
ASSERT(0, 0.0 / 0.0 > 0);
|
||||
ASSERT(0, 0.0 / 0.0 >= 0);
|
||||
|
||||
ASSERT(0, !3.);
|
||||
ASSERT(1, !0.);
|
||||
ASSERT(0, !3.f);
|
||||
ASSERT(1, !0.f);
|
||||
|
||||
ASSERT(5, 0.0 ? 3 : 5);
|
||||
ASSERT(3, 1.2 ? 3 : 5);
|
||||
|
||||
return 0;
|
||||
}
|
534
third_party/chibicc/test/function_test.c
vendored
Normal file
534
third_party/chibicc/test/function_test.c
vendored
Normal file
|
@ -0,0 +1,534 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int ret3(void) {
|
||||
return 3;
|
||||
return 5;
|
||||
}
|
||||
|
||||
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 fib(int x) {
|
||||
if (x <= 1) return 1;
|
||||
return fib(x - 1) + fib(x - 2);
|
||||
}
|
||||
|
||||
int sub_long(long a, long b, long c) {
|
||||
return a - b - c;
|
||||
}
|
||||
|
||||
int sub_short(short a, short b, short c) {
|
||||
return a - b - c;
|
||||
}
|
||||
|
||||
int g1;
|
||||
|
||||
int *g1_ptr(void) {
|
||||
return &g1;
|
||||
}
|
||||
char int_to_char(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int div_long(long a, long b) {
|
||||
return a / b;
|
||||
}
|
||||
|
||||
_Bool bool_fn_add(_Bool x) {
|
||||
return x + 1;
|
||||
}
|
||||
_Bool bool_fn_sub(_Bool x) {
|
||||
return x - 1;
|
||||
}
|
||||
|
||||
static int static_fn(void) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
int param_decay(int x[]) {
|
||||
return x[0];
|
||||
}
|
||||
|
||||
int counter() {
|
||||
static int i;
|
||||
static int j = 1 + 1;
|
||||
return i++ + j++;
|
||||
}
|
||||
|
||||
void ret_none() {
|
||||
return;
|
||||
}
|
||||
|
||||
_Bool true_fn();
|
||||
_Bool false_fn();
|
||||
char char_fn();
|
||||
short short_fn();
|
||||
|
||||
unsigned char uchar_fn();
|
||||
unsigned short ushort_fn();
|
||||
|
||||
char schar_fn();
|
||||
short sshort_fn();
|
||||
|
||||
int add_all(int n, ...);
|
||||
|
||||
typedef struct {
|
||||
int gp_offset;
|
||||
int fp_offset;
|
||||
void *overflow_arg_area;
|
||||
void *reg_save_area;
|
||||
} __va_elem;
|
||||
|
||||
typedef __va_elem va_list[1];
|
||||
|
||||
int add_all(int n, ...);
|
||||
int sprintf(char *buf, char *fmt, ...);
|
||||
int vsprintf(char *buf, char *fmt, va_list ap);
|
||||
|
||||
char *fmt(char *buf, char *fmt, ...) {
|
||||
va_list ap;
|
||||
*ap = *(__va_elem *)__va_area__;
|
||||
vsprintf(buf, fmt, ap);
|
||||
}
|
||||
|
||||
double add_double(double x, double y);
|
||||
float add_float(float x, float y);
|
||||
|
||||
float add_float3(float x, float y, float z) {
|
||||
return x + y + z;
|
||||
}
|
||||
|
||||
double add_double3(double x, double y, double z) {
|
||||
return x + y + z;
|
||||
}
|
||||
|
||||
int (*fnptr(int (*fn)(int n, ...)))(int, ...) {
|
||||
return fn;
|
||||
}
|
||||
|
||||
int param_decay2(int x()) {
|
||||
return x();
|
||||
}
|
||||
|
||||
char *func_fn(void) {
|
||||
return __func__;
|
||||
}
|
||||
|
||||
char *function_fn(void) {
|
||||
return __FUNCTION__;
|
||||
}
|
||||
|
||||
int add10_int(int x1, int x2, int x3, int x4, int x5, int x6, int x7, int x8,
|
||||
int x9, int x10);
|
||||
float add10_float(float x1, float x2, float x3, float x4, float x5, float x6,
|
||||
float x7, float x8, float x9, float x10);
|
||||
double add10_double(double x1, double x2, double x3, double x4, double x5,
|
||||
double x6, double x7, double x8, double x9, double x10);
|
||||
|
||||
int many_args1(int a, int b, int c, int d, int e, int f, int g, int h) {
|
||||
return g / h;
|
||||
}
|
||||
|
||||
double many_args2(double a, double b, double c, double d, double e, double f,
|
||||
double g, double h, double i, double j) {
|
||||
return i / j;
|
||||
}
|
||||
|
||||
int many_args3(int a, double b, int c, int d, double e, int f, double g, int h,
|
||||
double i, double j, double k, double l, double m, int n, int o,
|
||||
double p) {
|
||||
return o / p;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
int a, b;
|
||||
short c;
|
||||
char d;
|
||||
} Ty4;
|
||||
typedef struct {
|
||||
int a;
|
||||
float b;
|
||||
double c;
|
||||
} Ty5;
|
||||
typedef struct {
|
||||
unsigned char a[3];
|
||||
} Ty6;
|
||||
typedef struct {
|
||||
long a, b, c;
|
||||
} Ty7;
|
||||
|
||||
int struct_test5(Ty5 x, int n);
|
||||
int struct_test4(Ty4 x, int n);
|
||||
int struct_test6(Ty6 x, int n);
|
||||
int struct_test7(Ty7 x, int n);
|
||||
|
||||
int struct_test14(Ty4 x, int n) {
|
||||
switch (n) {
|
||||
case 0:
|
||||
return x.a;
|
||||
case 1:
|
||||
return x.b;
|
||||
case 2:
|
||||
return x.c;
|
||||
default:
|
||||
return x.d;
|
||||
}
|
||||
}
|
||||
|
||||
int struct_test15(Ty5 x, int n) {
|
||||
switch (n) {
|
||||
case 0:
|
||||
return x.a;
|
||||
case 1:
|
||||
return x.b;
|
||||
default:
|
||||
return x.c;
|
||||
}
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
unsigned char a[10];
|
||||
} Ty20;
|
||||
typedef struct {
|
||||
unsigned char a[20];
|
||||
} Ty21;
|
||||
|
||||
Ty4 struct_test24(void);
|
||||
Ty5 struct_test25(void);
|
||||
Ty6 struct_test26(void);
|
||||
Ty20 struct_test27(void);
|
||||
Ty21 struct_test28(void);
|
||||
|
||||
Ty4 struct_test34(void) {
|
||||
return (Ty4){10, 20, 30, 40};
|
||||
}
|
||||
|
||||
Ty5 struct_test35(void) {
|
||||
return (Ty5){10, 20, 30};
|
||||
}
|
||||
|
||||
Ty6 struct_test36(void) {
|
||||
return (Ty6){10, 20, 30};
|
||||
}
|
||||
|
||||
Ty20 struct_test37(void) {
|
||||
return (Ty20){10, 20, 30, 40, 50, 60, 70, 80, 90, 100};
|
||||
}
|
||||
|
||||
Ty21 struct_test38(void) {
|
||||
return (Ty21){1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
|
||||
11, 12, 13, 14, 15, 16, 17, 18, 19, 20};
|
||||
}
|
||||
|
||||
inline int inline_fn(void) {
|
||||
return 3;
|
||||
}
|
||||
|
||||
double to_double(long double x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
long double to_ldouble(int x) {
|
||||
return x;
|
||||
}
|
||||
|
||||
int main() {
|
||||
FILE *f = fopen("/dev/null", "w");
|
||||
|
||||
ASSERT(3, ret3());
|
||||
ASSERT(8, add2(3, 5));
|
||||
ASSERT(2, sub2(5, 3));
|
||||
ASSERT(21, add6(1, 2, 3, 4, 5, 6));
|
||||
ASSERT(66, add6(1, 2, add6(3, 4, 5, 6, 7, 8), 9, 10, 11));
|
||||
ASSERT(136, add6(1, 2, add6(3, add6(4, 5, 6, 7, 8, 9), 10, 11, 12, 13), 14,
|
||||
15, 16));
|
||||
|
||||
ASSERT(7, add2(3, 4));
|
||||
ASSERT(1, sub2(4, 3));
|
||||
ASSERT(55, fib(9));
|
||||
|
||||
ASSERT(1, ({ sub_char(7, 3, 3); }));
|
||||
|
||||
ASSERT(1, sub_long(7, 3, 3));
|
||||
ASSERT(1, sub_short(7, 3, 3));
|
||||
|
||||
g1 = 3;
|
||||
|
||||
ASSERT(3, *g1_ptr());
|
||||
ASSERT(5, int_to_char(261));
|
||||
ASSERT(5, int_to_char(261));
|
||||
ASSERT(-5, div_long(-10, 2));
|
||||
|
||||
ASSERT(1, bool_fn_add(3));
|
||||
ASSERT(0, bool_fn_sub(3));
|
||||
ASSERT(1, bool_fn_add(-3));
|
||||
ASSERT(0, bool_fn_sub(-3));
|
||||
ASSERT(1, bool_fn_add(0));
|
||||
ASSERT(1, bool_fn_sub(0));
|
||||
|
||||
ASSERT(3, static_fn());
|
||||
|
||||
ASSERT(3, ({
|
||||
int x[2];
|
||||
x[0] = 3;
|
||||
param_decay(x);
|
||||
}));
|
||||
|
||||
ASSERT(2, counter());
|
||||
ASSERT(4, counter());
|
||||
ASSERT(6, counter());
|
||||
|
||||
ret_none();
|
||||
|
||||
ASSERT(1, true_fn());
|
||||
ASSERT(0, false_fn());
|
||||
ASSERT(3, char_fn());
|
||||
ASSERT(5, short_fn());
|
||||
|
||||
ASSERT(6, add_all(3, 1, 2, 3));
|
||||
ASSERT(5, add_all(4, 1, 2, 3, -1));
|
||||
|
||||
{
|
||||
char buf[100];
|
||||
fmt(buf, "%d %d %s", 1, 2, "foo");
|
||||
fprintf(f, "%s\n", buf);
|
||||
}
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
sprintf(buf, "%d %d %s", 1, 2, "foo");
|
||||
strcmp("1 2 foo", buf);
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
fmt(buf, "%d %d %s", 1, 2, "foo");
|
||||
strcmp("1 2 foo", buf);
|
||||
}));
|
||||
|
||||
ASSERT(251, uchar_fn());
|
||||
ASSERT(65528, ushort_fn());
|
||||
ASSERT(-5, schar_fn());
|
||||
ASSERT(-8, sshort_fn());
|
||||
|
||||
ASSERT(6, add_float(2.3, 3.8));
|
||||
ASSERT(6, add_double(2.3, 3.8));
|
||||
|
||||
ASSERT(7, add_float3(2.5, 2.5, 2.5));
|
||||
ASSERT(7, add_double3(2.5, 2.5, 2.5));
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
sprintf(buf, "%.1f", (float)3.5);
|
||||
strcmp(buf, "3.5");
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
fmt(buf, "%.1f", (float)3.5);
|
||||
strcmp(buf, "3.5");
|
||||
}));
|
||||
|
||||
ASSERT(5, (add2)(2, 3));
|
||||
ASSERT(5, (&add2)(2, 3));
|
||||
ASSERT(7, ({
|
||||
int (*fn)(int, int) = add2;
|
||||
fn(2, 5);
|
||||
}));
|
||||
ASSERT(6, fnptr(add_all)(3, 1, 2, 3));
|
||||
|
||||
ASSERT(3, param_decay2(ret3));
|
||||
|
||||
ASSERT(5, sizeof(__func__));
|
||||
ASSERT(0, strcmp("main", __func__));
|
||||
ASSERT(0, strcmp("func_fn", func_fn()));
|
||||
ASSERT(0, strcmp("main", __FUNCTION__));
|
||||
ASSERT(0, strcmp("function_fn", function_fn()));
|
||||
|
||||
ASSERT(55, add10_int(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
ASSERT(55, add10_float(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
ASSERT(55, add10_double(1, 2, 3, 4, 5, 6, 7, 8, 9, 10));
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[200];
|
||||
sprintf(buf,
|
||||
"%d %.1f %.1f %.1f %d %d %.1f %d %d %d %d %.1f %d %d %.1f "
|
||||
"%.1f %.1f %.1f %d",
|
||||
1, 1.0, 1.0, 1.0, 1, 1, 1.0, 1, 1, 1, 1, 1.0, 1, 1, 1.0, 1.0,
|
||||
1.0, 1.0, 1);
|
||||
strcmp("1 1.0 1.0 1.0 1 1 1.0 1 1 1 1 1.0 1 1 1.0 1.0 1.0 1.0 1",
|
||||
buf);
|
||||
}));
|
||||
|
||||
ASSERT(4, many_args1(1, 2, 3, 4, 5, 6, 40, 10));
|
||||
ASSERT(4, many_args2(1, 2, 3, 4, 5, 6, 7, 8, 40, 10));
|
||||
ASSERT(8, many_args3(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 80, 10));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test4(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test4(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test4(x, 2);
|
||||
}));
|
||||
ASSERT(40, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test4(x, 3);
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test5(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test5(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test5(x, 2);
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty6 x = {10, 20, 30};
|
||||
struct_test6(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty6 x = {10, 20, 30};
|
||||
struct_test6(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty6 x = {10, 20, 30};
|
||||
struct_test6(x, 2);
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty7 x = {10, 20, 30};
|
||||
struct_test7(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty7 x = {10, 20, 30};
|
||||
struct_test7(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty7 x = {10, 20, 30};
|
||||
struct_test7(x, 2);
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test14(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test14(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test14(x, 2);
|
||||
}));
|
||||
ASSERT(40, ({
|
||||
Ty4 x = {10, 20, 30, 40};
|
||||
struct_test14(x, 3);
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test15(x, 0);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test15(x, 1);
|
||||
}));
|
||||
ASSERT(30, ({
|
||||
Ty5 x = {10, 20, 30};
|
||||
struct_test15(x, 2);
|
||||
}));
|
||||
|
||||
ASSERT(10, struct_test24().a);
|
||||
ASSERT(20, struct_test24().b);
|
||||
ASSERT(30, struct_test24().c);
|
||||
ASSERT(40, struct_test24().d);
|
||||
|
||||
ASSERT(10, struct_test25().a);
|
||||
ASSERT(20, struct_test25().b);
|
||||
ASSERT(30, struct_test25().c);
|
||||
|
||||
ASSERT(10, struct_test26().a[0]);
|
||||
ASSERT(20, struct_test26().a[1]);
|
||||
ASSERT(30, struct_test26().a[2]);
|
||||
|
||||
ASSERT(10, struct_test27().a[0]);
|
||||
ASSERT(60, struct_test27().a[5]);
|
||||
ASSERT(100, struct_test27().a[9]);
|
||||
|
||||
ASSERT(1, struct_test28().a[0]);
|
||||
ASSERT(5, struct_test28().a[4]);
|
||||
ASSERT(10, struct_test28().a[9]);
|
||||
ASSERT(15, struct_test28().a[14]);
|
||||
ASSERT(20, struct_test28().a[19]);
|
||||
|
||||
ASSERT(10, struct_test34().a);
|
||||
ASSERT(20, struct_test34().b);
|
||||
ASSERT(30, struct_test34().c);
|
||||
ASSERT(40, struct_test34().d);
|
||||
|
||||
ASSERT(10, struct_test35().a);
|
||||
ASSERT(20, struct_test35().b);
|
||||
ASSERT(30, struct_test35().c);
|
||||
|
||||
ASSERT(10, struct_test36().a[0]);
|
||||
ASSERT(20, struct_test36().a[1]);
|
||||
ASSERT(30, struct_test36().a[2]);
|
||||
|
||||
ASSERT(10, struct_test37().a[0]);
|
||||
ASSERT(60, struct_test37().a[5]);
|
||||
ASSERT(100, struct_test37().a[9]);
|
||||
|
||||
ASSERT(1, struct_test38().a[0]);
|
||||
ASSERT(5, struct_test38().a[4]);
|
||||
ASSERT(10, struct_test38().a[9]);
|
||||
ASSERT(15, struct_test38().a[14]);
|
||||
ASSERT(20, struct_test38().a[19]);
|
||||
|
||||
ASSERT(5, (***add2)(2, 3));
|
||||
|
||||
ASSERT(3, inline_fn());
|
||||
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
sprintf(buf, "%Lf", (long double)12.3);
|
||||
strncmp(buf, "12.3", 4);
|
||||
}));
|
||||
|
||||
ASSERT(1, to_double(3.5) == 3.5);
|
||||
ASSERT(0, to_double(3.5) == 3);
|
||||
|
||||
ASSERT(1, (long double)5.0 == (long double)5.0);
|
||||
ASSERT(0, (long double)5.0 == (long double)5.2);
|
||||
|
||||
ASSERT(1, to_ldouble(5.0) == 5.0);
|
||||
ASSERT(0, to_ldouble(5.0) == 5.2);
|
||||
}
|
10
third_party/chibicc/test/generic_test.c
vendored
Normal file
10
third_party/chibicc/test/generic_test.c
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(1, _Generic(100.0, double : 1, int * : 2, int : 3, float : 4));
|
||||
ASSERT(2, _Generic((int *)0, double : 1, int * : 2, int : 3, float : 4));
|
||||
ASSERT(2, _Generic((int[3]){}, double : 1, int * : 2, int : 3, float : 4));
|
||||
ASSERT(3, _Generic(100, double : 1, int * : 2, int : 3, float : 4));
|
||||
ASSERT(4, _Generic(100f, double : 1, int * : 2, int : 3, float : 4));
|
||||
return 0;
|
||||
}
|
5
third_party/chibicc/test/include1.h
vendored
Normal file
5
third_party/chibicc/test/include1.h
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
#include "third_party/chibicc/test/include2.h"
|
||||
|
||||
char *include1_filename = __FILE__;
|
||||
int include1_line = __LINE__;
|
||||
int include1 = 5;
|
1
third_party/chibicc/test/include2.h
vendored
Normal file
1
third_party/chibicc/test/include2.h
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
int include2 = 7;
|
1
third_party/chibicc/test/include3.h
vendored
Normal file
1
third_party/chibicc/test/include3.h
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
#define foo 3
|
1
third_party/chibicc/test/include4.h
vendored
Normal file
1
third_party/chibicc/test/include4.h
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
#define foo 4
|
793
third_party/chibicc/test/initializer_test.c
vendored
Normal file
793
third_party/chibicc/test/initializer_test.c
vendored
Normal file
|
@ -0,0 +1,793 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
char g3 = 3;
|
||||
short g4 = 4;
|
||||
int g5 = 5;
|
||||
long g6 = 6;
|
||||
int g9[3] = {0, 1, 2};
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} g11[2] = {{1, 2}, {3, 4}};
|
||||
struct {
|
||||
int a[2];
|
||||
} g12[2] = {{{1, 2}}};
|
||||
union {
|
||||
int a;
|
||||
char b[8];
|
||||
} g13[2] = {0x01020304, 0x05060708};
|
||||
char g17[] = "foobar";
|
||||
char g18[10] = "foobar";
|
||||
char g19[3] = "foobar";
|
||||
char *g20 = g17 + 0;
|
||||
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;
|
||||
int *g28 = &g11[1].a;
|
||||
long g29 = (long)(long)g26;
|
||||
struct {
|
||||
struct {
|
||||
int a[3];
|
||||
} a;
|
||||
} g30 = {{{1, 2, 3}}};
|
||||
int *g31 = g30.a.a;
|
||||
struct {
|
||||
int a[2];
|
||||
} g40[2] = {{1, 2}, 3, 4};
|
||||
struct {
|
||||
int a[2];
|
||||
} g41[2] = {1, 2, 3, 4};
|
||||
char g43[][4] = {'f', 'o', 'o', 0, 'b', 'a', 'r', 0};
|
||||
char *g44 = {"foo"};
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} g50 = {.b[2] = 0x12};
|
||||
union {
|
||||
int a;
|
||||
} g51[2] = {};
|
||||
|
||||
typedef char T60[];
|
||||
T60 g60 = {1, 2, 3};
|
||||
T60 g61 = {1, 2, 3, 4, 5, 6};
|
||||
|
||||
typedef struct {
|
||||
char a, b[];
|
||||
} T65;
|
||||
T65 g65 = {'f', 'o', 'o', 0};
|
||||
T65 g66 = {'f', 'o', 'o', 'b', 'a', 'r', 0};
|
||||
|
||||
int main() {
|
||||
ASSERT(1, ({
|
||||
int x[3] = {1, 2, 3};
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int x[3] = {1, 2, 3};
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x[3] = {1, 2, 3};
|
||||
x[2];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x[3] = {1, 2, 3};
|
||||
x[2];
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
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];
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int x[2][3] = {{1, 2, 3}, {4, 5, 6}};
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
int x[3] = {};
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
int x[3] = {};
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
int x[3] = {};
|
||||
x[2];
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
int x[2][3] = {{1, 2}};
|
||||
x[0][1];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
int x[2][3] = {{1, 2}};
|
||||
x[1][0];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
int x[2][3] = {{1, 2}};
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
ASSERT('a', ({
|
||||
char x[4] = "abc";
|
||||
x[0];
|
||||
}));
|
||||
ASSERT('c', ({
|
||||
char x[4] = "abc";
|
||||
x[2];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[4] = "abc";
|
||||
x[3];
|
||||
}));
|
||||
ASSERT('a', ({
|
||||
char x[2][4] = {"abc", "def"};
|
||||
x[0][0];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[2][4] = {"abc", "def"};
|
||||
x[0][3];
|
||||
}));
|
||||
ASSERT('d', ({
|
||||
char x[2][4] = {"abc", "def"};
|
||||
x[1][0];
|
||||
}));
|
||||
ASSERT('f', ({
|
||||
char x[2][4] = {"abc", "def"};
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
int x[] = {1, 2, 3, 4};
|
||||
x[3];
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
int x[] = {1, 2, 3, 4};
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char x[] = "foo";
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
typedef char T[];
|
||||
T x = "foo";
|
||||
T y = "x";
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
typedef char T[];
|
||||
T x = "foo";
|
||||
T y = "x";
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
typedef char T[];
|
||||
T x = "x";
|
||||
T y = "foo";
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
typedef char T[];
|
||||
T x = "x";
|
||||
T y = "foo";
|
||||
sizeof(y);
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
} x = {1};
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
} x = {};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
} x = {};
|
||||
x.b;
|
||||
}));
|
||||
|
||||
ASSERT(5, ({
|
||||
typedef struct {
|
||||
int a, b, c, d, e, f;
|
||||
} T;
|
||||
T x = {1, 2, 3, 4, 5, 6};
|
||||
T y;
|
||||
y = x;
|
||||
y.e;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y, z;
|
||||
z = y = x;
|
||||
z.b;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y = x;
|
||||
y.a;
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x = {0x01020304};
|
||||
x.b[0];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x = {0x01020304};
|
||||
x.b[1];
|
||||
}));
|
||||
|
||||
ASSERT(0x01020304, ({
|
||||
union {
|
||||
struct {
|
||||
char a, b, c, d;
|
||||
} e;
|
||||
int f;
|
||||
} x = {{4, 3, 2, 1}};
|
||||
x.f;
|
||||
}));
|
||||
|
||||
ASSERT(3, g3);
|
||||
ASSERT(4, g4);
|
||||
ASSERT(5, g5);
|
||||
ASSERT(6, g6);
|
||||
|
||||
ASSERT(0, g9[0]);
|
||||
ASSERT(1, g9[1]);
|
||||
ASSERT(2, g9[2]);
|
||||
|
||||
ASSERT(1, g11[0].a);
|
||||
ASSERT(2, g11[0].b);
|
||||
ASSERT(3, g11[1].a);
|
||||
ASSERT(4, g11[1].b);
|
||||
|
||||
ASSERT(1, g12[0].a[0]);
|
||||
ASSERT(2, g12[0].a[1]);
|
||||
ASSERT(0, g12[1].a[0]);
|
||||
ASSERT(0, g12[1].a[1]);
|
||||
|
||||
ASSERT(4, g13[0].b[0]);
|
||||
ASSERT(3, g13[0].b[1]);
|
||||
ASSERT(8, g13[1].b[0]);
|
||||
ASSERT(7, g13[1].b[1]);
|
||||
|
||||
ASSERT(7, sizeof(g17));
|
||||
ASSERT(10, sizeof(g18));
|
||||
ASSERT(3, sizeof(g19));
|
||||
|
||||
ASSERT(0, memcmp(g17, "foobar", 7));
|
||||
ASSERT(0, memcmp(g18, "foobar\0\0\0", 10));
|
||||
ASSERT(0, memcmp(g19, "foo", 3));
|
||||
|
||||
ASSERT(0, strcmp(g20, "foobar"));
|
||||
ASSERT(0, strcmp(g21, "bar"));
|
||||
ASSERT(0, strcmp(g22 + 3, "foobar"));
|
||||
|
||||
ASSERT(0, strcmp(g23[0], "foobar"));
|
||||
ASSERT(0, strcmp(g23[1], "bar"));
|
||||
ASSERT(0, strcmp(g23[2] + 3, "foobar"));
|
||||
|
||||
ASSERT(3, g24);
|
||||
ASSERT(3, *g25);
|
||||
ASSERT(2, *g27);
|
||||
ASSERT(3, *g28);
|
||||
ASSERT(1, *(int *)g29);
|
||||
|
||||
ASSERT(1, g31[0]);
|
||||
ASSERT(2, g31[1]);
|
||||
ASSERT(3, g31[2]);
|
||||
|
||||
ASSERT(1, g40[0].a[0]);
|
||||
ASSERT(2, g40[0].a[1]);
|
||||
ASSERT(3, g40[1].a[0]);
|
||||
ASSERT(4, g40[1].a[1]);
|
||||
|
||||
ASSERT(1, g41[0].a[0]);
|
||||
ASSERT(2, g41[0].a[1]);
|
||||
ASSERT(3, g41[1].a[0]);
|
||||
ASSERT(4, g41[1].a[1]);
|
||||
|
||||
ASSERT(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];
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(0, strcmp(g43[0], "foo"));
|
||||
ASSERT(0, strcmp(g43[1], "bar"));
|
||||
ASSERT(0, strcmp(g44, "foo"));
|
||||
|
||||
ASSERT(3, ({
|
||||
int a[] = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
};
|
||||
a[2];
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a, b, c;
|
||||
} x = {
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
enum {
|
||||
x,
|
||||
y,
|
||||
z,
|
||||
};
|
||||
z;
|
||||
}));
|
||||
|
||||
ASSERT(3, sizeof(g60));
|
||||
ASSERT(6, sizeof(g61));
|
||||
|
||||
ASSERT(4, sizeof(g65));
|
||||
ASSERT(7, sizeof(g66));
|
||||
ASSERT(0, strcmp(g65.b, "oo"));
|
||||
ASSERT(0, strcmp(g66.b, "oobar"));
|
||||
|
||||
ASSERT(4, ({
|
||||
int x[3] = {1, 2, 3, [0] = 4, 5};
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[3] = {1, 2, 3, [0] = 4, 5};
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x[3] = {1, 2, 3, [0] = 4, 5};
|
||||
x[2];
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[0][0];
|
||||
}));
|
||||
ASSERT(11, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[0][1];
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[0][2];
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[1][0];
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[1][1];
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0][1] = 7, 8, [0] = 9, [0] = 10, 11, [1][0] = 12};
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
ASSERT(7, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[0][0];
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[0][1];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[0][2];
|
||||
}));
|
||||
ASSERT(9, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[1][0];
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[1][1];
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int x[2][3] = {1, 2, 3, 4, 5, 6, [0] = {7, 8}, 9, 10};
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
ASSERT(7, ((int[10]){[3] = 7})[3]);
|
||||
ASSERT(0, ((int[10]){[3] = 7})[4]);
|
||||
|
||||
ASSERT(10, ({
|
||||
char x[] = {[10 - 3] = 1, 2, 3};
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
char x[][2] = {[8][1] = 1, 2};
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(3, sizeof(g60));
|
||||
ASSERT(6, sizeof(g61));
|
||||
|
||||
ASSERT(4, sizeof(g65));
|
||||
ASSERT(7, sizeof(g66));
|
||||
ASSERT(0, strcmp(g65.b, "oo"));
|
||||
ASSERT(0, strcmp(g66.b, "oobar"));
|
||||
|
||||
ASSERT(7, ((int[10]){[3] 7})[3]);
|
||||
ASSERT(0, ((int[10]){[3] 7})[4]);
|
||||
|
||||
ASSERT(4, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x = {1, 2, .b = 3, .a = 4};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x = {1, 2, .b = 3, .a = 4};
|
||||
x.b;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
struct {
|
||||
int a, b;
|
||||
} c;
|
||||
} x = {.c = 1, 2};
|
||||
x.c.a;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
struct {
|
||||
int a, b;
|
||||
} c;
|
||||
} x = {.c = 1, 2};
|
||||
x.c.b;
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
struct {
|
||||
int a, b;
|
||||
} c;
|
||||
} x = {.c.b = 1};
|
||||
x.c.a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
struct {
|
||||
int a, b;
|
||||
} c;
|
||||
} x = {.c.b = 1};
|
||||
x.c.b;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a[2];
|
||||
} x = {.a = 1, 2};
|
||||
x.a[0];
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
int a[2];
|
||||
} x = {.a = 1, 2};
|
||||
x.a[1];
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a[2];
|
||||
} x = {.a[1] = 1};
|
||||
x.a[0];
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a[2];
|
||||
} x = {.a[1] = 1};
|
||||
x.a[1];
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[0].a;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[0].b;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[1].a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[1].b;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[2].a;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x[] = {
|
||||
[1].b = 1,
|
||||
2,
|
||||
[0] = 3,
|
||||
4,
|
||||
};
|
||||
x[2].b;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y[] = {x};
|
||||
y[0].a;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y[] = {x};
|
||||
y[0].b;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y[] = {x, [0].b = 3};
|
||||
y[0].a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
typedef struct {
|
||||
int a, b;
|
||||
} T;
|
||||
T x = {1, 2};
|
||||
T y[] = {x, [0].b = 3};
|
||||
y[0].b;
|
||||
}));
|
||||
|
||||
ASSERT(5, ((struct { int a, b, c; }){.c = 5}).c);
|
||||
ASSERT(0, ((struct { int a, b, c; }){.c = 5}).a);
|
||||
|
||||
ASSERT(0x00ff, ({
|
||||
union {
|
||||
unsigned short a;
|
||||
char b[2];
|
||||
} x = {.b[0] = 0xff};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(0xff00, ({
|
||||
union {
|
||||
unsigned short a;
|
||||
char b[2];
|
||||
} x = {.b[1] = 0xff};
|
||||
x.a;
|
||||
}));
|
||||
|
||||
ASSERT(0x00120000, g50.a);
|
||||
ASSERT(0, g51[0].a);
|
||||
ASSERT(0, g51[1].a);
|
||||
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
struct {
|
||||
int a;
|
||||
struct {
|
||||
int b;
|
||||
};
|
||||
};
|
||||
int c;
|
||||
} x = {1, 2, 3, .b = 4, 5};
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
struct {
|
||||
struct {
|
||||
int a;
|
||||
struct {
|
||||
int b;
|
||||
};
|
||||
};
|
||||
int c;
|
||||
} x = {1, 2, 3, .b = 4, 5};
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
struct {
|
||||
struct {
|
||||
int a;
|
||||
struct {
|
||||
int b;
|
||||
};
|
||||
};
|
||||
int c;
|
||||
} x = {1, 2, 3, .b = 4, 5};
|
||||
x.c;
|
||||
}));
|
||||
|
||||
ASSERT(16, ({
|
||||
char x[] = {[2 ... 10] = 'a', [7] = 'b', [15 ... 15] = 'c', [3 ... 5] = 'd'};
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[] = {[2 ... 10] = 'a', [7] = 'b', [15 ... 15] = 'c', [3 ... 5] = 'd'};
|
||||
memcmp(x, "\0\0adddabaaa\0\0\0\0c", 16);
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
8183
third_party/chibicc/test/int128_test.c
vendored
Normal file
8183
third_party/chibicc/test/int128_test.c
vendored
Normal file
File diff suppressed because it is too large
Load diff
20
third_party/chibicc/test/line_test.c
vendored
Normal file
20
third_party/chibicc/test/line_test.c
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
#line 500 "foo"
|
||||
ASSERT(501, __LINE__);
|
||||
ASSERT(0, strcmp(__FILE__, "foo"));
|
||||
|
||||
#line 800 "bar"
|
||||
ASSERT(801, __LINE__);
|
||||
ASSERT(0, strcmp(__FILE__, "bar"));
|
||||
|
||||
#line 1
|
||||
ASSERT(2, __LINE__);
|
||||
|
||||
# 200 "xyz" 2 3
|
||||
ASSERT(201, __LINE__);
|
||||
ASSERT(0, strcmp(__FILE__, "xyz"));
|
||||
|
||||
return 0;
|
||||
}
|
108
third_party/chibicc/test/literal_test.c
vendored
Normal file
108
third_party/chibicc/test/literal_test.c
vendored
Normal file
|
@ -0,0 +1,108 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(97, 'a');
|
||||
ASSERT(10, '\n');
|
||||
ASSERT(-128, '\x80');
|
||||
|
||||
ASSERT(511, 0777);
|
||||
ASSERT(0, 0x0);
|
||||
ASSERT(10, 0xa);
|
||||
ASSERT(10, 0XA);
|
||||
ASSERT(48879, 0xbeef);
|
||||
ASSERT(48879, 0xBEEF);
|
||||
ASSERT(48879, 0XBEEF);
|
||||
ASSERT(0, 0b0);
|
||||
ASSERT(1, 0b1);
|
||||
ASSERT(47, 0b101111);
|
||||
ASSERT(47, 0B101111);
|
||||
|
||||
ASSERT(4, sizeof(0));
|
||||
ASSERT(8, sizeof(0L));
|
||||
ASSERT(8, sizeof(0LU));
|
||||
ASSERT(8, sizeof(0UL));
|
||||
ASSERT(8, sizeof(0LL));
|
||||
ASSERT(8, sizeof(0LLU));
|
||||
ASSERT(8, sizeof(0Ull));
|
||||
ASSERT(8, sizeof(0l));
|
||||
ASSERT(8, sizeof(0ll));
|
||||
ASSERT(8, sizeof(0x0L));
|
||||
ASSERT(8, sizeof(0b0L));
|
||||
ASSERT(4, sizeof(2147483647));
|
||||
ASSERT(8, sizeof(2147483648));
|
||||
ASSERT(-1, 0xffffffffffffffff);
|
||||
ASSERT(8, sizeof(0xffffffffffffffff));
|
||||
ASSERT(4, sizeof(4294967295U));
|
||||
ASSERT(8, sizeof(4294967296U));
|
||||
|
||||
ASSERT(3, -1U >> 30);
|
||||
ASSERT(3, -1Ul >> 62);
|
||||
ASSERT(3, -1ull >> 62);
|
||||
|
||||
ASSERT(1, 0xffffffffffffffffl >> 63);
|
||||
ASSERT(1, 0xffffffffffffffffll >> 63);
|
||||
|
||||
ASSERT(-1, 18446744073709551615);
|
||||
ASSERT(8, sizeof(18446744073709551615));
|
||||
ASSERT(-1, 18446744073709551615 >> 63);
|
||||
|
||||
ASSERT(-1, 0xffffffffffffffff);
|
||||
ASSERT(8, sizeof(0xffffffffffffffff));
|
||||
ASSERT(1, 0xffffffffffffffff >> 63);
|
||||
|
||||
ASSERT(-1, 01777777777777777777777);
|
||||
ASSERT(8, sizeof(01777777777777777777777));
|
||||
ASSERT(1, 01777777777777777777777 >> 63);
|
||||
|
||||
ASSERT(-1,
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111);
|
||||
ASSERT(
|
||||
8,
|
||||
sizeof(
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111));
|
||||
ASSERT(
|
||||
1,
|
||||
0b1111111111111111111111111111111111111111111111111111111111111111 >> 63);
|
||||
|
||||
ASSERT(8, sizeof(2147483648));
|
||||
ASSERT(4, sizeof(2147483647));
|
||||
|
||||
ASSERT(8, sizeof(0x1ffffffff));
|
||||
ASSERT(4, sizeof(0xffffffff));
|
||||
ASSERT(1, 0xffffffff >> 31);
|
||||
|
||||
ASSERT(8, sizeof(040000000000));
|
||||
ASSERT(4, sizeof(037777777777));
|
||||
ASSERT(1, 037777777777 >> 31);
|
||||
|
||||
ASSERT(8, sizeof(0b111111111111111111111111111111111));
|
||||
ASSERT(4, sizeof(0b11111111111111111111111111111111));
|
||||
ASSERT(1, 0b11111111111111111111111111111111 >> 31);
|
||||
|
||||
ASSERT(-1, 1 << 31 >> 31);
|
||||
ASSERT(-1, 01 << 31 >> 31);
|
||||
ASSERT(-1, 0x1 << 31 >> 31);
|
||||
ASSERT(-1, 0b1 << 31 >> 31);
|
||||
|
||||
0.0;
|
||||
1.0;
|
||||
3e+8;
|
||||
0x10.1p0;
|
||||
.1E4f;
|
||||
|
||||
ASSERT(4, sizeof(8f));
|
||||
ASSERT(4, sizeof(0.3F));
|
||||
ASSERT(8, sizeof(0.));
|
||||
ASSERT(8, sizeof(.0));
|
||||
ASSERT(16, sizeof(5.l));
|
||||
ASSERT(16, sizeof(2.0L));
|
||||
|
||||
Assert(1, size\
|
||||
of(char),
|
||||
"sizeof(char)");
|
||||
|
||||
ASSERT(4, sizeof(L'\0'));
|
||||
ASSERT(97, L'a');
|
||||
|
||||
return 0;
|
||||
}
|
413
third_party/chibicc/test/macro_test.c
vendored
Normal file
413
third_party/chibicc/test/macro_test.c
vendored
Normal file
|
@ -0,0 +1,413 @@
|
|||
#include "third_party/chibicc/test/include1.h"
|
||||
#include "third_party/chibicc/test/test.h"
|
||||
/* clang-format off */
|
||||
char *main_filename1 = __FILE__;
|
||||
int main_line1 = __LINE__;
|
||||
#define LINE() __LINE__
|
||||
int main_line2 = LINE();
|
||||
|
||||
#
|
||||
|
||||
/* */ #
|
||||
|
||||
int ret3(void) { return 3; }
|
||||
int dbl(int x) { return x*x; }
|
||||
|
||||
int add2(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 main() {
|
||||
ASSERT(5, include1);
|
||||
ASSERT(7, include2);
|
||||
|
||||
#if 0
|
||||
#include "/no/such/file"
|
||||
ASSERT(0, 1);
|
||||
#if nested
|
||||
#endif
|
||||
#endif
|
||||
|
||||
int m = 0;
|
||||
|
||||
#if 1
|
||||
m = 5;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
#if 1
|
||||
# if 0
|
||||
# if 1
|
||||
foo bar
|
||||
# endif
|
||||
# endif
|
||||
m = 3;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#if 1-1
|
||||
# if 1
|
||||
# endif
|
||||
# if 1
|
||||
# else
|
||||
# endif
|
||||
# if 0
|
||||
# else
|
||||
# endif
|
||||
m = 2;
|
||||
#else
|
||||
# if 1
|
||||
m = 3;
|
||||
# endif
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#if 1
|
||||
m = 2;
|
||||
#else
|
||||
m = 3;
|
||||
#endif
|
||||
ASSERT(2, m);
|
||||
|
||||
#if 1
|
||||
m = 2;
|
||||
#else
|
||||
m = 3;
|
||||
#endif
|
||||
ASSERT(2, m);
|
||||
|
||||
#if 0
|
||||
m = 1;
|
||||
#elif 0
|
||||
m = 2;
|
||||
#elif 3+5
|
||||
m = 3;
|
||||
#elif 1*5
|
||||
m = 4;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#if 1+5
|
||||
m = 1;
|
||||
#elif 1
|
||||
m = 2;
|
||||
#elif 3
|
||||
m = 2;
|
||||
#endif
|
||||
ASSERT(1, m);
|
||||
|
||||
#if 0
|
||||
m = 1;
|
||||
#elif 1
|
||||
# if 1
|
||||
m = 2;
|
||||
# else
|
||||
m = 3;
|
||||
# endif
|
||||
#else
|
||||
m = 5;
|
||||
#endif
|
||||
ASSERT(2, m);
|
||||
|
||||
int M1 = 5;
|
||||
|
||||
#define M1 3
|
||||
ASSERT(3, M1);
|
||||
#define M1 4
|
||||
ASSERT(4, M1);
|
||||
|
||||
#define M1 3+4+
|
||||
ASSERT(12, M1 5);
|
||||
|
||||
#define M1 3+4
|
||||
ASSERT(23, M1*5);
|
||||
|
||||
#define ASSERT_ Assert(
|
||||
#define if 5
|
||||
#define five "5"
|
||||
#define END )
|
||||
ASSERT_ 5, if, five END;
|
||||
|
||||
#undef ASSERT_
|
||||
#undef if
|
||||
#undef five
|
||||
#undef END
|
||||
|
||||
if (0);
|
||||
|
||||
#define M 5
|
||||
#if M
|
||||
m = 5;
|
||||
#else
|
||||
m = 6;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
#define M 5
|
||||
#if M-5
|
||||
m = 6;
|
||||
#elif M
|
||||
m = 5;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
int M2 = 6;
|
||||
#define M2 M2 + 3
|
||||
ASSERT(9, M2);
|
||||
|
||||
#define M3 M2 + 3
|
||||
ASSERT(12, M3);
|
||||
|
||||
int M4 = 3;
|
||||
#define M4 M5 * 5
|
||||
#define M5 M4 + 2
|
||||
ASSERT(13, M4);
|
||||
|
||||
#ifdef M6
|
||||
m = 5;
|
||||
#else
|
||||
m = 3;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#define M6
|
||||
#ifdef M6
|
||||
m = 5;
|
||||
#else
|
||||
m = 3;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
#ifndef M7
|
||||
m = 3;
|
||||
#else
|
||||
m = 5;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#define M7
|
||||
#ifndef M7
|
||||
m = 3;
|
||||
#else
|
||||
m = 5;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
#if 0
|
||||
#ifdef NO_SUCH_MACRO
|
||||
#endif
|
||||
#ifndef NO_SUCH_MACRO
|
||||
#endif
|
||||
#else
|
||||
#endif
|
||||
|
||||
#define M7() 1
|
||||
int M7 = 5;
|
||||
ASSERT(1, M7());
|
||||
ASSERT(5, M7);
|
||||
|
||||
#define M7 ()
|
||||
ASSERT(3, ret3 M7);
|
||||
|
||||
#define M8(x,y) x+y
|
||||
ASSERT(7, M8(3, 4));
|
||||
|
||||
#define M8(x,y) x*y
|
||||
ASSERT(24, M8(3+4, 4+5));
|
||||
|
||||
#define M8(x,y) (x)*(y)
|
||||
ASSERT(63, M8(3+4, 4+5));
|
||||
|
||||
#define M8(x,y) x y
|
||||
ASSERT(9, M8(, 4+5));
|
||||
|
||||
#define M8(x,y) x*y
|
||||
ASSERT(20, M8((2+3), 4));
|
||||
|
||||
#define M8(x,y) x*y
|
||||
ASSERT(12, M8((2,3), 4));
|
||||
|
||||
#define dbl(x) M10(x) * x
|
||||
#define M10(x) dbl(x) + 3
|
||||
ASSERT(10, dbl(2));
|
||||
|
||||
#define M11(x) #x
|
||||
ASSERT('a', M11( a!b `""c)[0]);
|
||||
ASSERT('!', M11( a!b `""c)[1]);
|
||||
ASSERT('b', M11( a!b `""c)[2]);
|
||||
ASSERT(' ', M11( a!b `""c)[3]);
|
||||
ASSERT('`', M11( a!b `""c)[4]);
|
||||
ASSERT('"', M11( a!b `""c)[5]);
|
||||
ASSERT('"', M11( a!b `""c)[6]);
|
||||
ASSERT('c', M11( a!b `""c)[7]);
|
||||
ASSERT(0, M11( a!b `""c)[8]);
|
||||
|
||||
#define paste(x,y) x##y
|
||||
ASSERT(15, paste(1,5));
|
||||
ASSERT(255, paste(0,xff));
|
||||
ASSERT(3, ({ int foobar=3; paste(foo,bar); }));
|
||||
ASSERT(5, paste(5,));
|
||||
ASSERT(5, paste(,5));
|
||||
|
||||
#define i 5
|
||||
ASSERT(101, ({ int i3=100; paste(1+i,3); }));
|
||||
#undef i
|
||||
|
||||
#define paste2(x) x##5
|
||||
ASSERT(26, paste2(1+2));
|
||||
|
||||
#define paste3(x) 2##x
|
||||
ASSERT(23, paste3(1+2));
|
||||
|
||||
#define paste4(x, y, z) x##y##z
|
||||
ASSERT(123, paste4(1,2,3));
|
||||
|
||||
#define M12
|
||||
#if defined(M12)
|
||||
m = 3;
|
||||
#else
|
||||
m = 4;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#define M12
|
||||
#if defined M12
|
||||
m = 3;
|
||||
#else
|
||||
m = 4;
|
||||
#endif
|
||||
ASSERT(3, m);
|
||||
|
||||
#if defined(M12) - 1
|
||||
m = 3;
|
||||
#else
|
||||
m = 4;
|
||||
#endif
|
||||
ASSERT(4, m);
|
||||
|
||||
#if defined(NO_SUCH_MACRO)
|
||||
m = 3;
|
||||
#else
|
||||
m = 4;
|
||||
#endif
|
||||
ASSERT(4, m);
|
||||
|
||||
#if no_such_symbol == 0
|
||||
m = 5;
|
||||
#else
|
||||
m = 6;
|
||||
#endif
|
||||
ASSERT(5, m);
|
||||
|
||||
#define STR(x) #x
|
||||
#define M12(x) STR(x)
|
||||
#define M13(x) M12(foo.x)
|
||||
ASSERT(0, strcmp(M13(bar), "foo.bar"));
|
||||
|
||||
#define M13(x) M12(foo. x)
|
||||
ASSERT(0, strcmp(M13(bar), "foo. bar"));
|
||||
|
||||
#define M12 foo
|
||||
#define M13(x) STR(x)
|
||||
#define M14(x) M13(x.M12)
|
||||
ASSERT(0, strcmp(M14(bar), "bar.foo"));
|
||||
|
||||
#define M14(x) M13(x. M12)
|
||||
ASSERT(0, strcmp(M14(bar), "bar. foo"));
|
||||
|
||||
#include "third_party/chibicc/test/include3.h"
|
||||
ASSERT(3, foo);
|
||||
|
||||
#include "third_party/chibicc/test/include4.h"
|
||||
ASSERT(4, foo);
|
||||
|
||||
#define M13 "third_party/chibicc/test/include3.h"
|
||||
#include M13
|
||||
ASSERT(3, foo);
|
||||
|
||||
#define M13 < third_party/chibicc/test/include4.h
|
||||
#include M13 >
|
||||
ASSERT(4, foo);
|
||||
|
||||
#undef foo
|
||||
|
||||
ASSERT(1, __STDC__);
|
||||
|
||||
ASSERT(0, strcmp(main_filename1, "third_party/chibicc/test/macro_test.c"));
|
||||
ASSERT(5, main_line1);
|
||||
ASSERT(7, main_line2);
|
||||
ASSERT(0, strcmp(include1_filename, "third_party/chibicc/test/include1.h"));
|
||||
ASSERT(4, include1_line);
|
||||
|
||||
#define M14(...) 3
|
||||
ASSERT(3, M14());
|
||||
|
||||
#define M14(...) __VA_ARGS__
|
||||
ASSERT(2, M14() 2);
|
||||
ASSERT(5, M14(5));
|
||||
|
||||
#define M14(...) add2(__VA_ARGS__)
|
||||
ASSERT(8, M14(2, 6));
|
||||
|
||||
#define M14(...) add6(1,2,__VA_ARGS__,6)
|
||||
ASSERT(21, M14(3,4,5));
|
||||
|
||||
#define M14(x, ...) add6(1,2,x,__VA_ARGS__,6)
|
||||
ASSERT(21, M14(3,4,5));
|
||||
|
||||
#define M14(args...) 3
|
||||
ASSERT(3, M14());
|
||||
|
||||
#define M14(x, ...) x
|
||||
ASSERT(5, M14(5));
|
||||
|
||||
#define M14(args...) args
|
||||
ASSERT(2, M14() 2);
|
||||
ASSERT(5, M14(5));
|
||||
|
||||
#define M14(args...) add2(args)
|
||||
ASSERT(8, M14(2, 6));
|
||||
|
||||
#define M14(args...) add6(1,2,args,6)
|
||||
ASSERT(21, M14(3,4,5));
|
||||
|
||||
#define M14(x, args...) add6(1,2,x,args,6)
|
||||
ASSERT(21, M14(3,4,5));
|
||||
|
||||
#define M14(x, args...) x
|
||||
ASSERT(5, M14(5));
|
||||
|
||||
#define CONCAT(x,y) x##y
|
||||
ASSERT(5, ({ int f0zz=5; CONCAT(f,0zz); }));
|
||||
ASSERT(5, ({ CONCAT(4,.57) + 0.5; }));
|
||||
|
||||
ASSERT(11, strlen(__DATE__));
|
||||
ASSERT(8, strlen(__TIME__));
|
||||
|
||||
ASSERT(0, __COUNTER__);
|
||||
ASSERT(1, __COUNTER__);
|
||||
ASSERT(2, __COUNTER__);
|
||||
|
||||
ASSERT(24, strlen(__TIMESTAMP__));
|
||||
|
||||
ASSERT(0, strcmp(__BASE_FILE__, "third_party/chibicc/test/macro_test.c"));
|
||||
|
||||
#define M30(buf, fmt, ...) sprintf(buf, fmt __VA_OPT__(,) __VA_ARGS__)
|
||||
ASSERT(0, ({ char buf[100]; M30(buf, "foo"); strcmp(buf, "foo"); }));
|
||||
ASSERT(0, ({ char buf[100]; M30(buf, "foo%d", 3); strcmp(buf, "foo3"); }));
|
||||
ASSERT(0, ({ char buf[100]; M30(buf, "foo%d%d", 3, 5); strcmp(buf, "foo35"); }));
|
||||
|
||||
#define M31(buf, fmt, ...) sprintf(buf, fmt, ## __VA_ARGS__)
|
||||
ASSERT(0, ({ char buf[100]; M31(buf, "foo"); strcmp(buf, "foo"); }));
|
||||
ASSERT(0, ({ char buf[100]; M31(buf, "foo%d", 3); strcmp(buf, "foo3"); }));
|
||||
ASSERT(0, ({ char buf[100]; M31(buf, "foo%d%d", 3, 5); strcmp(buf, "foo35"); }));
|
||||
|
||||
#define M31(x, y) (1, ##x y)
|
||||
ASSERT(3, M31(, 3));
|
||||
|
||||
return 0;
|
||||
}
|
17
third_party/chibicc/test/offsetof_test.c
vendored
Normal file
17
third_party/chibicc/test/offsetof_test.c
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
typedef struct {
|
||||
int a;
|
||||
char b;
|
||||
int c;
|
||||
double d;
|
||||
} T;
|
||||
|
||||
int main() {
|
||||
ASSERT(0, offsetof(T, a));
|
||||
ASSERT(4, offsetof(T, b));
|
||||
ASSERT(8, offsetof(T, c));
|
||||
ASSERT(16, offsetof(T, d));
|
||||
|
||||
return 0;
|
||||
}
|
202
third_party/chibicc/test/pointer_test.c
vendored
Normal file
202
third_party/chibicc/test/pointer_test.c
vendored
Normal file
|
@ -0,0 +1,202 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(3, ({
|
||||
int x = 3;
|
||||
*&x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x = 3;
|
||||
int *y = &x;
|
||||
int **z = &y;
|
||||
**z;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
*(&x + 1);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
*(&y - 1);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
*(&x - (-1));
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 3;
|
||||
int *y = &x;
|
||||
*y = 5;
|
||||
x;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
*(&x + 1) = 7;
|
||||
y;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
int x = 3;
|
||||
int y = 5;
|
||||
*(&y - 2 + 1) = 7;
|
||||
x;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x = 3;
|
||||
(&x + 2) - &x + 3;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x, y;
|
||||
x = 3;
|
||||
y = 5;
|
||||
x + y;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x = 3, y = 5;
|
||||
x + y;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
int x[2];
|
||||
int *y = &x;
|
||||
*y = 3;
|
||||
*x;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
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);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(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);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
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);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[2][3];
|
||||
int *y = x;
|
||||
*(y + 5) = 5;
|
||||
*(*(x + 1) + 2);
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
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);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
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);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
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];
|
||||
}));
|
||||
ASSERT(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];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
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];
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[2][3];
|
||||
int *y = x;
|
||||
y[5] = 5;
|
||||
x[1][2];
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
9
third_party/chibicc/test/pragma-once_test.c
vendored
Normal file
9
third_party/chibicc/test/pragma-once_test.c
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "third_party/chibicc/test/pragma-once_test.c"
|
||||
|
||||
int main() {
|
||||
return 0;
|
||||
}
|
113
third_party/chibicc/test/sizeof_test.c
vendored
Normal file
113
third_party/chibicc/test/sizeof_test.c
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(1, sizeof(char));
|
||||
ASSERT(2, sizeof(short));
|
||||
ASSERT(2, sizeof(short int));
|
||||
ASSERT(2, sizeof(int short));
|
||||
ASSERT(4, sizeof(int));
|
||||
ASSERT(8, sizeof(long));
|
||||
ASSERT(8, sizeof(long int));
|
||||
ASSERT(8, sizeof(long int));
|
||||
ASSERT(8, sizeof(char *));
|
||||
ASSERT(8, sizeof(int *));
|
||||
ASSERT(8, sizeof(long *));
|
||||
ASSERT(8, sizeof(int **));
|
||||
ASSERT(8, sizeof(int(*)[4]));
|
||||
ASSERT(32, sizeof(int *[4]));
|
||||
ASSERT(16, sizeof(int[4]));
|
||||
ASSERT(48, sizeof(int[3][4]));
|
||||
ASSERT(8, sizeof(struct {
|
||||
int a;
|
||||
int b;
|
||||
}));
|
||||
|
||||
ASSERT(8, sizeof(-10 + (long)5));
|
||||
ASSERT(8, sizeof(-10 - (long)5));
|
||||
ASSERT(8, sizeof(-10 * (long)5));
|
||||
ASSERT(8, sizeof(-10 / (long)5));
|
||||
ASSERT(8, sizeof((long)-10 + 5));
|
||||
ASSERT(8, sizeof((long)-10 - 5));
|
||||
ASSERT(8, sizeof((long)-10 * 5));
|
||||
ASSERT(8, sizeof((long)-10 / 5));
|
||||
|
||||
ASSERT(1, ({
|
||||
char i;
|
||||
sizeof(++i);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char i;
|
||||
sizeof(i++);
|
||||
}));
|
||||
|
||||
ASSERT(8, sizeof(int(*)[10]));
|
||||
ASSERT(8, sizeof(int(*)[][10]));
|
||||
|
||||
ASSERT(4, sizeof(struct { int x, y[]; }));
|
||||
|
||||
ASSERT(1, sizeof(char));
|
||||
ASSERT(1, sizeof(signed char));
|
||||
ASSERT(1, sizeof(signed char signed));
|
||||
ASSERT(1, sizeof(unsigned char));
|
||||
ASSERT(1, sizeof(unsigned char unsigned));
|
||||
|
||||
ASSERT(2, sizeof(short));
|
||||
ASSERT(2, sizeof(int short));
|
||||
ASSERT(2, sizeof(short int));
|
||||
ASSERT(2, sizeof(signed short));
|
||||
ASSERT(2, sizeof(int short signed));
|
||||
ASSERT(2, sizeof(unsigned short));
|
||||
ASSERT(2, sizeof(int short unsigned));
|
||||
|
||||
ASSERT(4, sizeof(int));
|
||||
ASSERT(4, sizeof(signed int));
|
||||
ASSERT(4, sizeof(signed));
|
||||
ASSERT(4, sizeof(signed signed));
|
||||
ASSERT(4, sizeof(unsigned int));
|
||||
ASSERT(4, sizeof(unsigned));
|
||||
ASSERT(4, sizeof(unsigned unsigned));
|
||||
|
||||
ASSERT(8, sizeof(long));
|
||||
ASSERT(8, sizeof(signed long));
|
||||
ASSERT(8, sizeof(signed long int));
|
||||
ASSERT(8, sizeof(unsigned long));
|
||||
ASSERT(8, sizeof(unsigned long int));
|
||||
|
||||
ASSERT(8, sizeof(long long));
|
||||
ASSERT(8, sizeof(signed long long));
|
||||
ASSERT(8, sizeof(signed long long int));
|
||||
ASSERT(8, sizeof(unsigned long long));
|
||||
ASSERT(8, sizeof(unsigned long long int));
|
||||
|
||||
ASSERT(1, sizeof((char)1));
|
||||
ASSERT(2, sizeof((short)1));
|
||||
ASSERT(4, sizeof((int)1));
|
||||
ASSERT(8, sizeof((long)1));
|
||||
|
||||
ASSERT(4, sizeof((char)1 + (char)1));
|
||||
ASSERT(4, sizeof((short)1 + (short)1));
|
||||
ASSERT(4, sizeof(1 ? 2 : 3));
|
||||
ASSERT(4, sizeof(1 ? (short)2 : (char)3));
|
||||
ASSERT(8, sizeof(1 ? (long)2 : (char)3));
|
||||
|
||||
ASSERT(1, sizeof(char) << 31 >> 31);
|
||||
ASSERT(1, sizeof(char) << 63 >> 63);
|
||||
|
||||
ASSERT(4, sizeof(float));
|
||||
ASSERT(8, sizeof(double));
|
||||
|
||||
ASSERT(4, sizeof(1f + 2));
|
||||
ASSERT(8, sizeof(1.0 + 2));
|
||||
ASSERT(4, sizeof(1f - 2));
|
||||
ASSERT(8, sizeof(1.0 - 2));
|
||||
ASSERT(4, sizeof(1f * 2));
|
||||
ASSERT(8, sizeof(1.0 * 2));
|
||||
ASSERT(4, sizeof(1f / 2));
|
||||
ASSERT(8, sizeof(1.0 / 2));
|
||||
|
||||
ASSERT(16, sizeof(long double));
|
||||
|
||||
ASSERT(1, sizeof(main));
|
||||
|
||||
return 0;
|
||||
}
|
105
third_party/chibicc/test/string_test.c
vendored
Normal file
105
third_party/chibicc/test/string_test.c
vendored
Normal file
|
@ -0,0 +1,105 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(0, ""[0]);
|
||||
ASSERT(1, sizeof(""));
|
||||
|
||||
ASSERT(97, "abc"[0]);
|
||||
ASSERT(98, "abc"[1]);
|
||||
ASSERT(99, "abc"[2]);
|
||||
ASSERT(0, "abc"[3]);
|
||||
ASSERT(4, sizeof("abc"));
|
||||
|
||||
ASSERT(7, "\a"[0]);
|
||||
ASSERT(8, "\b"[0]);
|
||||
ASSERT(9, "\t"[0]);
|
||||
ASSERT(10, "\n"[0]);
|
||||
ASSERT(11, "\v"[0]);
|
||||
ASSERT(12, "\f"[0]);
|
||||
ASSERT(13, "\r"[0]);
|
||||
ASSERT(27, "\e"[0]);
|
||||
|
||||
ASSERT(106, "\j"[0]);
|
||||
ASSERT(107, "\k"[0]);
|
||||
ASSERT(108, "\l"[0]);
|
||||
|
||||
ASSERT(7, "\ax\ny"[0]);
|
||||
ASSERT(120, "\ax\ny"[1]);
|
||||
ASSERT(10, "\ax\ny"[2]);
|
||||
ASSERT(121, "\ax\ny"[3]);
|
||||
|
||||
ASSERT(0, "\0"[0]);
|
||||
ASSERT(16, "\20"[0]);
|
||||
ASSERT(65, "\101"[0]);
|
||||
ASSERT(104, "\1500"[0]);
|
||||
ASSERT(0, "\x00"[0]);
|
||||
ASSERT(119, "\x77"[0]);
|
||||
|
||||
ASSERT(7, sizeof("abc"
|
||||
"def"));
|
||||
ASSERT(9, sizeof("abc"
|
||||
"d"
|
||||
"efgh"));
|
||||
ASSERT(0, strcmp("abc"
|
||||
"d"
|
||||
"\nefgh",
|
||||
"abcd\nefgh"));
|
||||
ASSERT(0, !strcmp("abc"
|
||||
"d",
|
||||
"abcd\nefgh"));
|
||||
ASSERT(0, strcmp("\x9"
|
||||
"0",
|
||||
"\t0"));
|
||||
|
||||
ASSERT(16, sizeof(L"abc"
|
||||
""));
|
||||
|
||||
ASSERT(28, sizeof(L"abc"
|
||||
"def"));
|
||||
ASSERT(28, sizeof(L"abc"
|
||||
L"def"));
|
||||
ASSERT(14, sizeof(u"abc"
|
||||
"def"));
|
||||
ASSERT(14, sizeof(u"abc"
|
||||
u"def"));
|
||||
|
||||
ASSERT(L'a', (L"abc"
|
||||
"def")[0]);
|
||||
ASSERT(L'd', (L"abc"
|
||||
"def")[3]);
|
||||
ASSERT(L'\0', (L"abc"
|
||||
"def")[6]);
|
||||
|
||||
ASSERT(u'a', (u"abc"
|
||||
"def")[0]);
|
||||
ASSERT(u'd', (u"abc"
|
||||
"def")[3]);
|
||||
ASSERT(u'\0', (u"abc"
|
||||
"def")[6]);
|
||||
|
||||
ASSERT(L'あ', ("あ"
|
||||
L"")[0]);
|
||||
ASSERT(0343, ("\343\201\202"
|
||||
L"")[0]);
|
||||
ASSERT(0201, ("\343\201\202"
|
||||
L"")[1]);
|
||||
ASSERT(0202, ("\343\201\202"
|
||||
L"")[2]);
|
||||
ASSERT(0, ("\343\201\202"
|
||||
L"")[3]);
|
||||
|
||||
ASSERT(L'a', ("a"
|
||||
"b"
|
||||
L"c")[0]);
|
||||
ASSERT(L'b', ("a"
|
||||
"b"
|
||||
L"c")[1]);
|
||||
ASSERT(L'c', ("a"
|
||||
"b"
|
||||
L"c")[2]);
|
||||
ASSERT(0, ("a"
|
||||
"b"
|
||||
L"c")[3]);
|
||||
|
||||
return 0;
|
||||
}
|
379
third_party/chibicc/test/struct_test.c
vendored
Normal file
379
third_party/chibicc/test/struct_test.c
vendored
Normal file
|
@ -0,0 +1,379 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
} x;
|
||||
x.a = 1;
|
||||
x.b = 2;
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
int a;
|
||||
int 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;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
char c;
|
||||
} x;
|
||||
x.b = 1;
|
||||
x.b = 2;
|
||||
x.c = 3;
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
char c;
|
||||
} x;
|
||||
x.a = 1;
|
||||
x.b = 2;
|
||||
x.c = 3;
|
||||
x.c;
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
char a;
|
||||
char b;
|
||||
} x[3];
|
||||
char *p = x;
|
||||
p[0] = 0;
|
||||
x[0].a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
struct {
|
||||
char a;
|
||||
char b;
|
||||
} x[3];
|
||||
char *p = x;
|
||||
p[1] = 1;
|
||||
x[0].b;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
char a;
|
||||
char b;
|
||||
} x[3];
|
||||
char *p = x;
|
||||
p[2] = 2;
|
||||
x[1].a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
char a;
|
||||
char b;
|
||||
} x[3];
|
||||
char *p = x;
|
||||
p[3] = 3;
|
||||
x[1].b;
|
||||
}));
|
||||
|
||||
ASSERT(6, ({
|
||||
struct {
|
||||
char a[3];
|
||||
char b[5];
|
||||
} x;
|
||||
char *p = &x;
|
||||
x.a[0] = 6;
|
||||
p[0];
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
struct {
|
||||
char a[3];
|
||||
char b[5];
|
||||
} x;
|
||||
char *p = &x;
|
||||
x.b[0] = 7;
|
||||
p[3];
|
||||
}));
|
||||
|
||||
ASSERT(6, ({
|
||||
struct {
|
||||
struct {
|
||||
char b;
|
||||
} a;
|
||||
} x;
|
||||
x.a.b = 6;
|
||||
x.a.b;
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
struct {
|
||||
int a;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
int a;
|
||||
int b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
struct {
|
||||
int a[3];
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
struct {
|
||||
int a;
|
||||
} x[4];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(24, ({
|
||||
struct {
|
||||
int a[3];
|
||||
} x[2];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
struct {
|
||||
char a;
|
||||
char b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
struct {
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
char a;
|
||||
int b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct {
|
||||
int a;
|
||||
char b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct t {
|
||||
int a;
|
||||
int b;
|
||||
} x;
|
||||
struct t y;
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct t {
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
struct t y;
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
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;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x, y;
|
||||
x.a = 3;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
struct t {
|
||||
int a, b;
|
||||
};
|
||||
struct t x;
|
||||
x.a = 7;
|
||||
struct t y;
|
||||
struct t *z = &y;
|
||||
*z = x;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
struct t {
|
||||
int a, b;
|
||||
};
|
||||
struct t x;
|
||||
x.a = 7;
|
||||
struct t y, *p = &x, *q = &y;
|
||||
*q = *p;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
struct t {
|
||||
char a, b;
|
||||
} x, y;
|
||||
x.a = 5;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
int a, b;
|
||||
} x, y;
|
||||
x.a = 3;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
struct t {
|
||||
int a, b;
|
||||
};
|
||||
struct t x;
|
||||
x.a = 7;
|
||||
struct t y;
|
||||
struct t *z = &y;
|
||||
*z = x;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(7, ({
|
||||
struct t {
|
||||
int a, b;
|
||||
};
|
||||
struct t x;
|
||||
x.a = 7;
|
||||
struct t y, *p = &x, *q = &y;
|
||||
*q = *p;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
struct t {
|
||||
char a, b;
|
||||
} x, y;
|
||||
x.a = 5;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct t {
|
||||
int a;
|
||||
int b;
|
||||
} x;
|
||||
struct t y;
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
struct t {
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
struct t y;
|
||||
sizeof(y);
|
||||
}));
|
||||
|
||||
ASSERT(16, ({
|
||||
struct {
|
||||
char a;
|
||||
long b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
struct {
|
||||
char a;
|
||||
short b;
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
struct foo *bar;
|
||||
sizeof(bar);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
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;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
typedef struct T T;
|
||||
struct T {
|
||||
int x;
|
||||
};
|
||||
sizeof(T);
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
11
third_party/chibicc/test/test.h
vendored
Normal file
11
third_party/chibicc/test/test.h
vendored
Normal file
|
@ -0,0 +1,11 @@
|
|||
#include "libc/fmt/fmt.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define ASSERT(x, y) Assert2(x, y, #y, __FILE__, __LINE__)
|
||||
#define ASSERT128(x, y) Assert128(x, y, #y, __FILE__, __LINE__)
|
||||
|
||||
void Assert(long, long, char *);
|
||||
void Assert2(long, long, char *, char *, int);
|
||||
void Assert128(__int128, __int128, char *, char *, int);
|
100
third_party/chibicc/test/test.mk
vendored
Normal file
100
third_party/chibicc/test/test.mk
vendored
Normal file
|
@ -0,0 +1,100 @@
|
|||
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
|
||||
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
|
||||
#
|
||||
# SYNOPSIS
|
||||
#
|
||||
# C Compiler Unit Tests
|
||||
#
|
||||
# OVERVIEW
|
||||
#
|
||||
# This makefile compiles and runs each test twice. The first with
|
||||
# GCC-built chibicc, and a second time with chibicc-built chibicc
|
||||
|
||||
PKGS += THIRD_PARTY_CHIBICC_TEST
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_A = o/$(MODE)/third_party/chibicc/test/test.a
|
||||
THIRD_PARTY_CHIBICC_TEST2_A = o/$(MODE)/third_party/chibicc/test/test2.a
|
||||
THIRD_PARTY_CHIBICC_TEST_FILES := $(wildcard third_party/chibicc/test/*)
|
||||
THIRD_PARTY_CHIBICC_TEST_SRCS = $(filter %.c,$(THIRD_PARTY_CHIBICC_TEST_FILES))
|
||||
THIRD_PARTY_CHIBICC_TEST_SRCS_TEST = $(filter %_test.c,$(THIRD_PARTY_CHIBICC_TEST_SRCS))
|
||||
THIRD_PARTY_CHIBICC_TEST_HDRS = $(filter %.h,$(THIRD_PARTY_CHIBICC_TEST_FILES))
|
||||
THIRD_PARTY_CHIBICC_TEST_TESTS = $(THIRD_PARTY_CHIBICC_TEST_COMS:%=%.ok)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_COMS = \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%.c=o/$(MODE)/%.com) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS_TEST:%.c=o/$(MODE)/%2.com)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_OBJS = \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%=o/$(MODE)/%.zip.o) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%.c=o/$(MODE)/%.chibicc.o)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST2_OBJS = \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%=o/$(MODE)/%.zip.o) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%.c=o/$(MODE)/%.chibicc2.o)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_BINS = \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_COMS) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_COMS:%=%.dbg)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_CHECKS = \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_COMS:%=%.runs) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_HDRS:%=o/$(MODE)/%.ok)
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS = \
|
||||
LIBC_RUNTIME \
|
||||
LIBC_FMT \
|
||||
LIBC_STR \
|
||||
LIBC_STDIO \
|
||||
LIBC_STUBS \
|
||||
LIBC_NEXGEN32E \
|
||||
LIBC_UNICODE \
|
||||
LIBC_MEM \
|
||||
THIRD_PARTY_COMPILER_RT
|
||||
|
||||
THIRD_PARTY_CHIBICC_TEST_DEPS := \
|
||||
$(call uniq,$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x))))
|
||||
|
||||
$(THIRD_PARTY_CHIBICC_TEST_A): \
|
||||
third_party/chibicc/test/ \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_A).pkg \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_OBJS)
|
||||
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_A): \
|
||||
third_party/chibicc/test/ \
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_A).pkg \
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_OBJS)
|
||||
|
||||
$(THIRD_PARTY_CHIBICC_TEST_A).pkg: \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_A).pkg: \
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_OBJS) \
|
||||
$(foreach x,$(THIRD_PARTY_CHIBICC_TEST_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/third_party/chibicc/test/%.com.dbg: \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_DEPS) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_A) \
|
||||
o/$(MODE)/third_party/chibicc/test/%.chibicc.o \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_A).pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
o/$(MODE)/third_party/chibicc/test/%2.com.dbg: \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_DEPS) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_A) \
|
||||
o/$(MODE)/third_party/chibicc/test/%.chibicc2.o \
|
||||
$(THIRD_PARTY_CHIBICC_TEST2_A).pkg \
|
||||
$(LIBC_TESTMAIN) \
|
||||
$(CRT) \
|
||||
$(APE)
|
||||
@$(APELINK)
|
||||
|
||||
.PHONY: o/$(MODE)/third_party/chibicc/test
|
||||
o/$(MODE)/third_party/chibicc/test: \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_BINS) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_CHECKS) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%.c=o/$(MODE)/%.chibicc.s) \
|
||||
$(THIRD_PARTY_CHIBICC_TEST_SRCS:%.c=o/$(MODE)/%.chibicc2.s)
|
18
third_party/chibicc/test/tls_test.c.todo
vendored
Normal file
18
third_party/chibicc/test/tls_test.c.todo
vendored
Normal file
|
@ -0,0 +1,18 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
_Thread_local int x;
|
||||
|
||||
void add(void) {
|
||||
x += 3;
|
||||
}
|
||||
|
||||
_Noreturn int test(void) {
|
||||
x = 7;
|
||||
add();
|
||||
ASSERT(10, x);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
test();
|
||||
}
|
49
third_party/chibicc/test/typedef_test.c
vendored
Normal file
49
third_party/chibicc/test/typedef_test.c
vendored
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
typedef int MyInt, MyInt2[4];
|
||||
typedef int;
|
||||
|
||||
int main() {
|
||||
ASSERT(1, ({
|
||||
typedef int t;
|
||||
t x = 1;
|
||||
x;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
typedef struct {
|
||||
int a;
|
||||
} t;
|
||||
t x;
|
||||
x.a = 1;
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
typedef int t;
|
||||
t t = 1;
|
||||
t;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
typedef struct {
|
||||
int a;
|
||||
} t;
|
||||
{ typedef int t; }
|
||||
t x;
|
||||
x.a = 2;
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
typedef t;
|
||||
t x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
MyInt x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
MyInt2 x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
29
third_party/chibicc/test/typeof_test.c
vendored
Normal file
29
third_party/chibicc/test/typeof_test.c
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(3, ({
|
||||
typeof(int) x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
typeof(1) x = 3;
|
||||
x;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
typeof(x) y;
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int x;
|
||||
typeof(&x) y;
|
||||
sizeof(y);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
typeof("foo") x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(12, sizeof(typeof(struct { int a, b, c; })));
|
||||
|
||||
return 0;
|
||||
}
|
138
third_party/chibicc/test/unicode_test.c
vendored
Normal file
138
third_party/chibicc/test/unicode_test.c
vendored
Normal file
|
@ -0,0 +1,138 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
/* TODO(jart): shl overflow in read_escaped_char */
|
||||
|
||||
#define STR(x) #x
|
||||
|
||||
typedef unsigned short char16_t;
|
||||
typedef unsigned int char32_t;
|
||||
typedef int wchar_t;
|
||||
|
||||
int π = 3;
|
||||
|
||||
int main() {
|
||||
ASSERT(4, sizeof(L'\0'));
|
||||
ASSERT(97, L'a');
|
||||
|
||||
ASSERT(0, strcmp("αβγ", "\u03B1\u03B2\u03B3"));
|
||||
ASSERT(0, strcmp("日本語", "\u65E5\u672C\u8A9E"));
|
||||
ASSERT(0, strcmp("日本語", "\U000065E5\U0000672C\U00008A9E"));
|
||||
ASSERT(0, strcmp("🌮", "\U0001F32E"));
|
||||
|
||||
ASSERT(-1, L'\xffffffff' >> 31);
|
||||
ASSERT(946, L'β');
|
||||
ASSERT(12354, L'あ');
|
||||
ASSERT(127843, L'🍣');
|
||||
|
||||
ASSERT(2, sizeof(u'\0'));
|
||||
ASSERT(1, u'\xffff' >> 15);
|
||||
ASSERT(97, u'a');
|
||||
ASSERT(946, u'β');
|
||||
ASSERT(12354, u'あ');
|
||||
ASSERT(62307, u'🍣');
|
||||
|
||||
ASSERT(0, strcmp(STR(u'a'), "u'a'"));
|
||||
|
||||
ASSERT(4, sizeof(U'\0'));
|
||||
ASSERT(1, U'\xffffffff' >> 31);
|
||||
ASSERT(97, U'a');
|
||||
ASSERT(946, U'β');
|
||||
ASSERT(12354, U'あ');
|
||||
ASSERT(127843, U'🍣');
|
||||
|
||||
ASSERT(0, strcmp(STR(U'a'), "U'a'"));
|
||||
|
||||
ASSERT(4, sizeof(u8"abc"));
|
||||
ASSERT(0, strcmp(u8"abc", "abc"));
|
||||
|
||||
ASSERT(0, strcmp(STR(u8"a"), "u8\"a\""));
|
||||
|
||||
ASSERT(2, sizeof(u""));
|
||||
ASSERT(10, sizeof(u"\xffzzz"));
|
||||
ASSERT(0, memcmp(u"", "\0\0", 2));
|
||||
ASSERT(0, memcmp(u"abc", "a\0b\0c\0\0\0", 8));
|
||||
ASSERT(0, memcmp(u"日本語", "\345e,g\236\212\0\0", 8));
|
||||
ASSERT(0, memcmp(u"🍣", "<\330c\337\0\0", 6));
|
||||
ASSERT(u'β', u"βb"[0]);
|
||||
ASSERT(u'b', u"βb"[1]);
|
||||
ASSERT(0, u"βb"[2]);
|
||||
|
||||
ASSERT(0, strcmp(STR(u"a"), "u\"a\""));
|
||||
|
||||
ASSERT(4, sizeof(U""));
|
||||
ASSERT(20, sizeof(U"\xffzzz"));
|
||||
ASSERT(0, memcmp(U"", "\0\0\0\0", 4));
|
||||
ASSERT(0, memcmp(U"abc", "a\0\0\0b\0\0\0c\0\0\0\0\0\0\0", 16));
|
||||
ASSERT(0, memcmp(U"日本語", "\345e\0\0,g\0\0\236\212\0\0\0\0\0\0", 16));
|
||||
ASSERT(0, memcmp(U"🍣", "c\363\001\0\0\0\0\0", 8));
|
||||
ASSERT(u'β', U"βb"[0]);
|
||||
ASSERT(u'b', U"βb"[1]);
|
||||
ASSERT(0, U"βb"[2]);
|
||||
ASSERT(1, U"\xffffffff"[0] >> 31);
|
||||
|
||||
ASSERT(0, strcmp(STR(U"a"), "U\"a\""));
|
||||
|
||||
ASSERT(4, sizeof(L""));
|
||||
ASSERT(20, sizeof(L"\xffzzz"));
|
||||
ASSERT(0, memcmp(L"", "\0\0\0\0", 4));
|
||||
ASSERT(0, memcmp(L"abc", "a\0\0\0b\0\0\0c\0\0\0\0\0\0\0", 16));
|
||||
ASSERT(0, memcmp(L"日本語", "\345e\0\0,g\0\0\236\212\0\0\0\0\0\0", 16));
|
||||
ASSERT(0, memcmp(L"🍣", "c\363\001\0\0\0\0\0", 8));
|
||||
ASSERT(u'β', L"βb"[0]);
|
||||
ASSERT(u'b', L"βb"[1]);
|
||||
ASSERT(0, L"βb"[2]);
|
||||
ASSERT(-1, L"\xffffffff"[0] >> 31);
|
||||
|
||||
ASSERT(0, strcmp(STR(L"a"), "L\"a\""));
|
||||
|
||||
ASSERT(u'α', ({
|
||||
char16_t x[] = u"αβ";
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(u'β', ({
|
||||
char16_t x[] = u"αβ";
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
char16_t x[] = u"αβ";
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(U'🤔', ({
|
||||
char32_t x[] = U"🤔x";
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(U'x', ({
|
||||
char32_t x[] = U"🤔x";
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
char32_t x[] = U"🤔x";
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(L'🤔', ({
|
||||
wchar_t x[] = L"🤔x";
|
||||
x[0];
|
||||
}));
|
||||
ASSERT(L'x', ({
|
||||
wchar_t x[] = L"🤔x";
|
||||
x[1];
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
wchar_t x[] = L"🤔x";
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(3, π);
|
||||
ASSERT(3, ({
|
||||
int あβ0¾ = 3;
|
||||
あβ0¾;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int $$$ = 5;
|
||||
$$$;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
132
third_party/chibicc/test/union_test.c
vendored
Normal file
132
third_party/chibicc/test/union_test.c
vendored
Normal file
|
@ -0,0 +1,132 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(8, ({
|
||||
union {
|
||||
int a;
|
||||
char b[6];
|
||||
} x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x;
|
||||
x.a = 515;
|
||||
x.b[0];
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x;
|
||||
x.a = 515;
|
||||
x.b[1];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x;
|
||||
x.a = 515;
|
||||
x.b[2];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
union {
|
||||
int a;
|
||||
char b[4];
|
||||
} x;
|
||||
x.a = 515;
|
||||
x.b[3];
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
union {
|
||||
int a, b;
|
||||
} x, y;
|
||||
x.a = 3;
|
||||
y.a = 5;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
union {
|
||||
struct {
|
||||
int a, b;
|
||||
} c;
|
||||
} x, y;
|
||||
x.c.b = 3;
|
||||
y.c.b = 5;
|
||||
y = x;
|
||||
y.c.b;
|
||||
}));
|
||||
|
||||
ASSERT(0xef, ({
|
||||
union {
|
||||
struct {
|
||||
unsigned char a, b, c, d;
|
||||
};
|
||||
long e;
|
||||
} x;
|
||||
x.e = 0xdeadbeef;
|
||||
x.a;
|
||||
}));
|
||||
ASSERT(0xbe, ({
|
||||
union {
|
||||
struct {
|
||||
unsigned char a, b, c, d;
|
||||
};
|
||||
long e;
|
||||
} x;
|
||||
x.e = 0xdeadbeef;
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(0xad, ({
|
||||
union {
|
||||
struct {
|
||||
unsigned char a, b, c, d;
|
||||
};
|
||||
long e;
|
||||
} x;
|
||||
x.e = 0xdeadbeef;
|
||||
x.c;
|
||||
}));
|
||||
ASSERT(0xde, ({
|
||||
union {
|
||||
struct {
|
||||
unsigned char a, b, c, d;
|
||||
};
|
||||
long e;
|
||||
} x;
|
||||
x.e = 0xdeadbeef;
|
||||
x.d;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
struct {
|
||||
union {
|
||||
int a, b;
|
||||
};
|
||||
union {
|
||||
int c, d;
|
||||
};
|
||||
} x;
|
||||
x.a = 3;
|
||||
x.b;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
struct {
|
||||
union {
|
||||
int a, b;
|
||||
};
|
||||
union {
|
||||
int c, d;
|
||||
};
|
||||
} x;
|
||||
x.d = 5;
|
||||
x.c;
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
58
third_party/chibicc/test/usualconv_test.c
vendored
Normal file
58
third_party/chibicc/test/usualconv_test.c
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
static int ret10(void) {
|
||||
return 10;
|
||||
}
|
||||
|
||||
int main() {
|
||||
ASSERT((long)-5, -10 + (long)5);
|
||||
ASSERT((long)-15, -10 - (long)5);
|
||||
ASSERT((long)-50, -10 * (long)5);
|
||||
ASSERT((long)-2, -10 / (long)5);
|
||||
|
||||
ASSERT(1, -2 < (long)-1);
|
||||
ASSERT(1, -2 <= (long)-1);
|
||||
ASSERT(0, -2 > (long)-1);
|
||||
ASSERT(0, -2 >= (long)-1);
|
||||
|
||||
ASSERT(1, (long)-2 < -1);
|
||||
ASSERT(1, (long)-2 <= -1);
|
||||
ASSERT(0, (long)-2 > -1);
|
||||
ASSERT(0, (long)-2 >= -1);
|
||||
|
||||
ASSERT(0, 2147483647 + 2147483647 + 2);
|
||||
ASSERT((long)-1, ({
|
||||
long x;
|
||||
x = -1;
|
||||
x;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
char x[3];
|
||||
x[0] = 0;
|
||||
x[1] = 1;
|
||||
x[2] = 2;
|
||||
char *y = x + 1;
|
||||
y[0];
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
char x[3];
|
||||
x[0] = 0;
|
||||
x[1] = 1;
|
||||
x[2] = 2;
|
||||
char *y = x + 1;
|
||||
y[-1];
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
struct t {
|
||||
char a;
|
||||
} x, y;
|
||||
x.a = 5;
|
||||
y = x;
|
||||
y.a;
|
||||
}));
|
||||
|
||||
ASSERT(10, (1 ? ret10 : (void *)0)());
|
||||
|
||||
return 0;
|
||||
}
|
52
third_party/chibicc/test/varargs_test.c
vendored
Normal file
52
third_party/chibicc/test/varargs_test.c
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int sum1(int x, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, x);
|
||||
|
||||
for (;;) {
|
||||
int y = va_arg(ap, int);
|
||||
if (y == 0) return x;
|
||||
x += y;
|
||||
}
|
||||
}
|
||||
|
||||
int sum2(int x, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, x);
|
||||
|
||||
for (;;) {
|
||||
double y = va_arg(ap, double);
|
||||
x += y;
|
||||
|
||||
int z = va_arg(ap, int);
|
||||
if (z == 0) return x;
|
||||
x += z;
|
||||
}
|
||||
}
|
||||
|
||||
void fmt(char *buf, char *fmt, ...) {
|
||||
va_list ap;
|
||||
va_start(ap, fmt);
|
||||
|
||||
va_list ap2;
|
||||
va_copy(ap2, ap);
|
||||
vsprintf(buf, fmt, ap2);
|
||||
va_end(buf);
|
||||
}
|
||||
|
||||
int main() {
|
||||
ASSERT(6, sum1(1, 2, 3, 0));
|
||||
ASSERT(55, sum1(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0));
|
||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||
ASSERT(21, sum2(1, 2.0, 3, 4.0, 5, 6.0, 0));
|
||||
ASSERT(210, sum2(1, 2.0, 3, 4.0, 5, 6.0, 7, 8.0, 9, 10.0, 11, 12.0, 13, 14.0,
|
||||
15, 16.0, 17, 18.0, 19, 20.0, 0));
|
||||
ASSERT(0, ({
|
||||
char buf[100];
|
||||
fmt(buf, "%d %d", 2, 3);
|
||||
strcmp(buf, "2 3");
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
244
third_party/chibicc/test/variable_test.c
vendored
Normal file
244
third_party/chibicc/test/variable_test.c
vendored
Normal file
|
@ -0,0 +1,244 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int g1, g2[4];
|
||||
static int g3 = 3;
|
||||
|
||||
int main() {
|
||||
ASSERT(3, ({
|
||||
int a;
|
||||
a = 3;
|
||||
a;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int a = 3;
|
||||
a;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int a = 3;
|
||||
int z = 5;
|
||||
a + z;
|
||||
}));
|
||||
|
||||
ASSERT(3, ({
|
||||
int a = 3;
|
||||
a;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int a = 3;
|
||||
int z = 5;
|
||||
a + z;
|
||||
}));
|
||||
ASSERT(6, ({
|
||||
int a;
|
||||
int b;
|
||||
a = b = 3;
|
||||
a + b;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int foo = 3;
|
||||
foo;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int foo123 = 3;
|
||||
int bar = 5;
|
||||
foo123 + bar;
|
||||
}));
|
||||
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x;
|
||||
sizeof x;
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
int *x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
int x[4];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(48, ({
|
||||
int x[3][4];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(16, ({
|
||||
int x[3][4];
|
||||
sizeof(*x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x[3][4];
|
||||
sizeof(**x);
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[3][4];
|
||||
sizeof(**x) + 1;
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int x[3][4];
|
||||
sizeof **x + 1;
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x[3][4];
|
||||
sizeof(**x + 1);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
int x = 1;
|
||||
sizeof(x = 2);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int x = 1;
|
||||
sizeof(x = 2);
|
||||
x;
|
||||
}));
|
||||
|
||||
ASSERT(0, g1);
|
||||
ASSERT(3, ({
|
||||
g1 = 3;
|
||||
g1;
|
||||
}));
|
||||
ASSERT(0, ({
|
||||
g2[0] = 0;
|
||||
g2[1] = 1;
|
||||
g2[2] = 2;
|
||||
g2[3] = 3;
|
||||
g2[0];
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
g2[0] = 0;
|
||||
g2[1] = 1;
|
||||
g2[2] = 2;
|
||||
g2[3] = 3;
|
||||
g2[1];
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
g2[0] = 0;
|
||||
g2[1] = 1;
|
||||
g2[2] = 2;
|
||||
g2[3] = 3;
|
||||
g2[2];
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
g2[0] = 0;
|
||||
g2[1] = 1;
|
||||
g2[2] = 2;
|
||||
g2[3] = 3;
|
||||
g2[3];
|
||||
}));
|
||||
|
||||
ASSERT(4, sizeof(g1));
|
||||
ASSERT(16, sizeof(g2));
|
||||
|
||||
ASSERT(1, ({
|
||||
char x = 1;
|
||||
x;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char x = 1;
|
||||
char y = 2;
|
||||
x;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
char x = 1;
|
||||
char y = 2;
|
||||
y;
|
||||
}));
|
||||
|
||||
ASSERT(1, ({
|
||||
char x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(10, ({
|
||||
char x[10];
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(2, ({
|
||||
int x = 2;
|
||||
{ int x = 3; }
|
||||
x;
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
int x = 2;
|
||||
{ int x = 3; }
|
||||
int y = 4;
|
||||
x;
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
int x = 2;
|
||||
{ x = 3; }
|
||||
x;
|
||||
}));
|
||||
|
||||
ASSERT(7, ({
|
||||
int x;
|
||||
int y;
|
||||
char z;
|
||||
char *a = &y;
|
||||
char *b = &z;
|
||||
b - a;
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
int x;
|
||||
char y;
|
||||
int z;
|
||||
char *a = &y;
|
||||
char *b = &z;
|
||||
b - a;
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
long x;
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(2, ({
|
||||
short x;
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(24, ({
|
||||
char *x[3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(8, ({
|
||||
char(*x)[3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(1, ({
|
||||
char(x);
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char(x)[3];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
char(x[3])[4];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char(x[3])[4];
|
||||
sizeof(x[0]);
|
||||
}));
|
||||
ASSERT(3, ({
|
||||
char *x[3];
|
||||
char y;
|
||||
x[0] = &y;
|
||||
y = 3;
|
||||
x[0][0];
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char x[3];
|
||||
char(*y)[3] = x;
|
||||
y[0][0] = 4;
|
||||
y[0][0];
|
||||
}));
|
||||
|
||||
{ void *x; }
|
||||
|
||||
ASSERT(3, g3);
|
||||
|
||||
return 0;
|
||||
}
|
56
third_party/chibicc/test/vector_test.c
vendored
Normal file
56
third_party/chibicc/test/vector_test.c
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
typedef float float4 __attribute__((__vector_size__(16)));
|
||||
typedef float float4a1 __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef float float4a16 __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
typedef double double2 __attribute__((__vector_size__(16)));
|
||||
typedef double double2a1 __attribute__((__vector_size__(16), __aligned__(1)));
|
||||
typedef double double2a16 __attribute__((__vector_size__(16), __aligned__(16)));
|
||||
|
||||
int main(void) {
|
||||
ASSERT(16, sizeof(float4));
|
||||
ASSERT(16, sizeof(float4a1));
|
||||
ASSERT(16, sizeof(float4a16));
|
||||
ASSERT(16, sizeof(double2));
|
||||
ASSERT(16, sizeof(double2a1));
|
||||
ASSERT(16, sizeof(double2a16));
|
||||
ASSERT(16, _Alignof(float4));
|
||||
ASSERT(1, _Alignof(float4a1));
|
||||
ASSERT(16, _Alignof(float4a16));
|
||||
ASSERT(16, _Alignof(double2));
|
||||
ASSERT(1, _Alignof(double2a1));
|
||||
ASSERT(16, _Alignof(double2a16));
|
||||
|
||||
float4 v1;
|
||||
float4 v2;
|
||||
float x[4] = {1, 2, 3, 4};
|
||||
float y[4] = {1, 1, 1, 1};
|
||||
memcpy(&v1, x, 16);
|
||||
memcpy(&v2, y, 16);
|
||||
v1 = v1 + v2;
|
||||
memcpy(x, &v1, 16);
|
||||
ASSERT(2, x[0]);
|
||||
/* ASSERT(3, x[1]); */
|
||||
/* ASSERT(4, x[2]); */
|
||||
/* ASSERT(5, x[3]); */
|
||||
|
||||
return 0;
|
||||
}
|
86
third_party/chibicc/test/vla_test.c
vendored
Normal file
86
third_party/chibicc/test/vla_test.c
vendored
Normal file
|
@ -0,0 +1,86 @@
|
|||
#include "third_party/chibicc/test/test.h"
|
||||
|
||||
int main() {
|
||||
ASSERT(20, ({
|
||||
int n = 5;
|
||||
int x[n];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT((5 + 1) * (8 * 2) * 4, ({
|
||||
int m = 5, n = 8;
|
||||
int x[m + 1][n * 2];
|
||||
sizeof(x);
|
||||
}));
|
||||
|
||||
ASSERT(8, ({
|
||||
char n = 10;
|
||||
int(*x)[n][n + 2];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(480, ({
|
||||
char n = 10;
|
||||
int(*x)[n][n + 2];
|
||||
sizeof(*x);
|
||||
}));
|
||||
ASSERT(48, ({
|
||||
char n = 10;
|
||||
int(*x)[n][n + 2];
|
||||
sizeof(**x);
|
||||
}));
|
||||
ASSERT(4, ({
|
||||
char n = 10;
|
||||
int(*x)[n][n + 2];
|
||||
sizeof(***x);
|
||||
}));
|
||||
|
||||
ASSERT(60, ({
|
||||
char n = 3;
|
||||
int x[5][n];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(12, ({
|
||||
char n = 3;
|
||||
int x[5][n];
|
||||
sizeof(*x);
|
||||
}));
|
||||
|
||||
ASSERT(60, ({
|
||||
char n = 3;
|
||||
int x[n][5];
|
||||
sizeof(x);
|
||||
}));
|
||||
ASSERT(20, ({
|
||||
char n = 3;
|
||||
int x[n][5];
|
||||
sizeof(*x);
|
||||
}));
|
||||
|
||||
ASSERT(0, ({
|
||||
int n = 10;
|
||||
int x[n + 1][n + 6];
|
||||
int *p = x;
|
||||
for (int i = 0; i < sizeof(x) / 4; i++) p[i] = i;
|
||||
x[0][0];
|
||||
}));
|
||||
ASSERT(5, ({
|
||||
int n = 10;
|
||||
int x[n + 1][n + 6];
|
||||
int *p = x;
|
||||
for (int i = 0; i < sizeof(x) / 4; i++) p[i] = i;
|
||||
x[0][5];
|
||||
}));
|
||||
ASSERT(5 * 16 + 2, ({
|
||||
int n = 10;
|
||||
int x[n + 1][n + 6];
|
||||
int *p = x;
|
||||
for (int i = 0; i < sizeof(x) / 4; i++) p[i] = i;
|
||||
x[5][2];
|
||||
}));
|
||||
|
||||
ASSERT(10, ({
|
||||
int n = 5;
|
||||
sizeof(char[2][n]);
|
||||
}));
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue