Fix bugs and make improvements

- Get clone() working on FreeBSD
- Increase some Python build quotas
- Add more atomic builtins to chibicc
- Fix ASAN poisoning of alloca() memory
- Make MODE= mandatory link path tinier
- Improve the examples folder a little bit
- Start working on some more resource limits
- Make the linenoise auto-complete UI as good as GNU readline
- Update compile.com, avoiding AVX codegen on non-AVX systems
- Make sure empty path to syscalls like opendir raises ENOENT
- Correctly polyfill ENOENT vs. ENOTDIR on the New Technology
- Port bestline's paredit features to //third_party/linenoise
- Remove workarounds for RHEL 5.0 bugs that were fixed in 5.1
This commit is contained in:
Justine Tunney 2022-04-20 09:56:53 -07:00
parent c3fb624647
commit ae638c0850
181 changed files with 2994 additions and 1367 deletions

View file

@ -348,6 +348,8 @@ typedef enum {
ND_LOAD, // Atomic load
ND_TESTANDSET, // Atomic lock test and set
ND_RELEASE, // Atomic lock release
ND_FETCHADD, // Atomic fetch and add
ND_SUBFETCH, // Atomic sub and fetch
ND_FPCLASSIFY, // floating point classify
ND_MOVNTDQ, // Intel MOVNTDQ
ND_PMOVMSKB, // Intel PMOVMSKB

View file

@ -262,6 +262,20 @@ static char *reg_ax(int sz) {
UNREACHABLE();
}
static char *reg_di(int sz) {
switch (sz) {
case 1:
return "%dil";
case 2:
return "%di";
case 4:
return "%edi";
case 8:
return "%rdi";
}
UNREACHABLE();
}
static const char *gotpcrel(void) {
if (opt_pic) {
return "@gotpcrel(%rip)";
@ -1542,6 +1556,26 @@ void gen_expr(Node *node) {
println("\tmov\t%s,(%%rdi)", reg_ax(node->ty->size));
return;
}
case ND_FETCHADD: {
gen_expr(node->lhs);
push();
gen_expr(node->rhs);
pop("%rdi");
println("\txadd\t%s,(%%rdi)", reg_ax(node->ty->size));
return;
}
case ND_SUBFETCH: {
gen_expr(node->lhs);
push();
gen_expr(node->rhs);
pop("%rdi");
push();
println("\tneg\t%s", reg_ax(node->ty->size));
println("\txadd\t%s,(%%rdi)", reg_ax(node->ty->size));
pop("%rdi");
println("\tsub\t%s,%s", reg_di(node->ty->size), reg_ax(node->ty->size));
return;
}
case ND_RELEASE: {
gen_expr(node->lhs);
push();

View file

@ -119,6 +119,8 @@ __builtin_types_compatible_p, KW___BUILTIN_TYPES_COMPATIBLE_P
"->", KW_ARROW
".", KW_DOT
__atomic_load, KW___ATOMIC_LOAD
__atomic_fetch_add, KW___ATOMIC_FETCH_ADD
__atomic_sub_fetch, KW___ATOMIC_SUB_FETCH
__sync_lock_test_and_set, KW___SYNC_LOCK_TEST_AND_SET
__sync_lock_release, KW___SYNC_LOCK_RELEASE
__builtin_ia32_movntdq, KW___BUILTIN_IA32_MOVNTDQ

View file

@ -110,6 +110,8 @@
#define KW___SYNC_LOCK_RELEASE 126
#define KW___BUILTIN_IA32_PMOVMSKB128 127
#define KW___BUILTIN_IA32_MOVNTDQ 128
#define KW___ATOMIC_FETCH_ADD 129
#define KW___ATOMIC_SUB_FETCH 130
#if !(__ASSEMBLER__ + __LINKER__ + 0)
COSMOPOLITAN_C_START_

View file

@ -37,7 +37,7 @@
#line 10 "kw.gperf"
struct thatispacked KwSlot { char *name; unsigned char code; };
#define TOTAL_KEYWORDS 114
#define TOTAL_KEYWORDS 116
#define MIN_WORD_LENGTH 1
#define MAX_WORD_LENGTH 28
#define MIN_HASH_VALUE 1
@ -230,7 +230,7 @@ LookupKw (register const char *str, register size_t len)
{"||", KW_LOGOR},
#line 67 "kw.gperf"
{"_Alignof", KW__ALIGNOF},
#line 122 "kw.gperf"
#line 124 "kw.gperf"
{"__sync_lock_test_and_set", KW___SYNC_LOCK_TEST_AND_SET},
#line 49 "kw.gperf"
{"error", KW_ERROR},
@ -249,7 +249,7 @@ LookupKw (register const char *str, register size_t len)
{""},
#line 66 "kw.gperf"
{"_Alignas", KW__ALIGNAS},
#line 123 "kw.gperf"
#line 125 "kw.gperf"
{"__sync_lock_release", KW___SYNC_LOCK_RELEASE},
{""},
#line 39 "kw.gperf"
@ -340,20 +340,22 @@ LookupKw (register const char *str, register size_t len)
{""}, {""}, {""},
#line 100 "kw.gperf"
{"__builtin_strlen", KW___BUILTIN_STRLEN},
#line 124 "kw.gperf"
#line 126 "kw.gperf"
{"__builtin_ia32_movntdq", KW___BUILTIN_IA32_MOVNTDQ},
{""}, {""}, {""},
#line 120 "kw.gperf"
{".", KW_DOT},
#line 36 "kw.gperf"
{"include", KW_INCLUDE},
{""}, {""}, {""},
#line 122 "kw.gperf"
{"__atomic_fetch_add", KW___ATOMIC_FETCH_ADD},
{""}, {""},
#line 14 "kw.gperf"
{"return", KW_RETURN},
{""}, {""}, {""},
#line 26 "kw.gperf"
{"union", KW_UNION},
#line 125 "kw.gperf"
#line 127 "kw.gperf"
{"__builtin_ia32_pmovmskb128", KW___BUILTIN_IA32_PMOVMSKB128},
{""}, {""}, {""}, {""}, {""}, {""}, {""}, {""}, {""},
#line 112 "kw.gperf"
@ -373,7 +375,10 @@ LookupKw (register const char *str, register size_t len)
{""}, {""}, {""}, {""},
#line 53 "kw.gperf"
{"inline", KW_INLINE},
{""}, {""}, {""}, {""},
{""},
#line 123 "kw.gperf"
{"__atomic_sub_fetch", KW___ATOMIC_SUB_FETCH},
{""}, {""},
#line 113 "kw.gperf"
{"!", KW_EXCLAIM}
};

View file

@ -3243,6 +3243,32 @@ static Node *primary(Token **rest, Token *tok) {
*rest = skip(tok, ')');
return node;
}
if (kw == KW___ATOMIC_FETCH_ADD) {
Node *node = new_node(ND_FETCHADD, tok);
tok = skip(tok->next, '(');
node->lhs = assign(&tok, tok);
add_type(node->lhs);
node->ty = node->lhs->ty->base;
tok = skip(tok, ',');
node->rhs = assign(&tok, tok);
tok = skip(tok, ',');
const_expr(&tok, tok);
*rest = skip(tok, ')');
return node;
}
if (kw == KW___ATOMIC_SUB_FETCH) {
Node *node = new_node(ND_SUBFETCH, tok);
tok = skip(tok->next, '(');
node->lhs = assign(&tok, tok);
add_type(node->lhs);
node->ty = node->lhs->ty->base;
tok = skip(tok, ',');
node->rhs = assign(&tok, tok);
tok = skip(tok, ',');
const_expr(&tok, tok);
*rest = skip(tok, ')');
return node;
}
if (kw == KW___SYNC_LOCK_TEST_AND_SET) {
Node *node = new_node(ND_TESTANDSET, tok);
tok = skip(tok->next, '(');