mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-07 03:38:31 +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
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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue