Use long as implicit type in chibicc

This makes it possible to write 64-bit C without headers and prototypes.
This commit is contained in:
Justine Tunney 2023-07-09 10:10:34 -07:00
parent 42ba9901e4
commit d3cf9d4ef1
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
3 changed files with 77 additions and 5 deletions

View file

@ -0,0 +1,64 @@
add(x, y) {
return x + y;
}
implicit_functions_are_long() {
if (add(0xffffffff, 0xffffffff) != 0x0001fffffffe) {
__builtin_trap();
}
}
external_functions_are_long() {
if (_bsrl(0x0001000000000000) != 48) {
__builtin_trap();
}
}
auto_variables_are_long() {
auto x, y, z;
x = 0x0101fffffffe;
y = 0x0201fffffffe;
z = x + y;
if (z != 0x0303fffffffc) {
__builtin_trap();
}
}
static_variables_are_long() {
static x, y, z;
x = 0x0101fffffffe;
y = 0x0201fffffffe;
z = x + y;
if (z != 0x0303fffffffc) {
__builtin_trap();
}
}
x_ = 0x0101fffffffe;
y_ = 0x0201fffffffe;
z_;
globo_variables_are_long() {
z_ = x_ + y_;
if (z_ != 0x0303fffffffc) {
__builtin_trap();
}
}
implicit_function_string() {
auto lol = strdup("hello");
if (strlen(lol) != 5) {
__builtin_trap();
}
free(lol);
}
main() {
ShowCrashReports();
implicit_functions_are_long();
external_functions_are_long();
auto_variables_are_long();
static_variables_are_long();
globo_variables_are_long();
implicit_function_string();
}