aboutsummaryrefslogtreecommitdiffhomepage
path: root/c/c.c
Commit message (Collapse)AuthorAgeFilesLines
* c: default enum to unsigned int backing type lemon2026-03-151-1/+3
| | | | Matches GCC behavior.
* c: static eval refactoring lemon2026-03-141-48/+93
| | | | | Explicit node for static symbol (addresses). Should not break with edge cases like the previous ad-hoc approach. And some other bugfixes
* c: relax constexpr constraints, fix alignof lemon2026-03-091-18/+26
| | | | | | | | | | | | - Allow short-circuiting of constant logical expressions where the unevaluated operand is not a constant expression (`1 || 0/0`) - Allow constant integer expressions that evaluate to zero to be used as null pointer constants (GNU extension). + According to the standard, `int *x = 5*0;` should be rejected. But compilers evaluate `5*0 -> 0` and allow it as if a null pointer literal.
* c: recognize another static initializer edge case lemon2026-03-051-3/+2
| | | | | | I think globsym & expr2reloc should be rewritten to be more robust to this kind of thing. Accumulate offsets whilst recursing into the child node that might contain a direct global symbol reference kind of thing.
* add bswap16/32/64 lemon2026-03-021-21/+21
| | | | | - frontend: __builtin_bswapX intrinsics - backend: ObswapX instructions
* c: allow casting of symbol address to intptr_t in static initializers lemon2026-02-251-1/+2
|
* C23 true and false keywords lemon2026-02-241-3/+5
|
* c: fix using string literal as conditional expression conditional lemon2026-02-221-12/+28
|
* c: fix default argument promotion for function types lemon2026-02-211-0/+1
|
* ir: basic inlining pass implementation lemon2026-02-181-1/+2
|
* c: support at least parsing C99 _Complex types lemon2026-01-251-4/+15
|
* c: GNU __attribute__ stubs lemon2026-01-251-10/+68
|
* c: fix use after free lemon2026-01-091-1/+2
| | | | | A silly one, declsbuf.p can be realloc'd in the call to putdecl, but in this statement that pointer could be fetched before the call.
* c: allow 'register' in func parameter lemon2026-01-091-1/+1
|
* c: fix diagnostic with "return <undeclared>" lemon2025-12-311-2/+2
|
* backend: separate instrs for integer/float store lemon2025-12-311-5/+5
|
* c: SYM expr should store decl ref as an index, not pointer lemon2025-12-301-49/+54
| | | | | | | | Because envdecls (now declsbuf) can be resized and invalidate those pointers. I missed this because the default initialization size of that buffer (and the fact that it would mostly only manifest with function-local expressions) made it not really come up in practice. Silly
* avoid GOT relocations in unnecessary instances lemon2025-12-251-1/+1
| | | | | Also change xcon to have a flagset for symbols (whether it's a function, locally defined; later: thread local, etc).
* c: add _Generic lemon2025-12-221-0/+53
|
* c: recognize __attribute__ as decltok, improve diagnostic for expected ↵ lemon2025-12-221-1/+2
| | | | declaration
* c/c.c: cleanup exprparse a little lemon2025-12-221-13/+12
|
* c: allow `return voidfn()` extension lemon2025-12-211-4/+30
|
* c: small typechecking bugfixes lemon2025-12-201-3/+3
|
* backend: unify pass memory allocation strategies lemon2025-12-201-1/+1
| | | | | | It was all over the place for temporary data structures used by individual passes. Now there is an arena specifically for that, which is nicer.
* c: fix a silly C edge case with function redeclaration storage class lemon2025-12-201-14/+21
| | | | | | C (or at least clang and gcc) allows declaring `static int f(...);` and defining it later as `int f(...) {...}`, omitting the 'static' in the latter definition.
* c: factor out to tldecl(), improve error recovery, lemon2025-12-201-73/+97
|
* c: support 0-length arrays as syntax for flexible array members lemon2025-12-191-19/+29
| | | | | Keeping the expr around in the decllist paves the way for VLA support later on
* c: fix incr/decr codegen for floats lemon2025-12-191-2/+2
|
* c: hack to support __FUNCTION__ GNU extension lemon2025-12-191-4/+10
|
* c: fix uninitiliazed field in decltypes lemon2025-12-171-0/+1
|
* c: improve some type error diagnostics lemon2025-12-151-13/+22
|
* create distinct interned string type lemon2025-12-151-50/+51
| | | | | | | | | | | | | | Interned strings are used pervasively, so it's a good idea to add a layer of type safety to differentiate them from general cstrs and avoid potential bugs from comparing non-interned and interned strings. Not that that's happened so far that I can remember, but it could. I'm 90% sure it's legal to alias `struct {char c;}` pointers with `char` pointers. This specific typedef gives type safety but with a simple one-way `internstr -> const char *` typecast (with `&istr->c`). Converting the other way around is more intentional: a straight up cast `(internstr)cstr` which sticks out as unchecked and probably wrong, or calling the intern(cstr) function, which is the right way.
* lexer: use a hashmap to lookup keywords lemon2025-12-151-1/+1
|
* c: error when defining function with incomplete parameter type lemon2025-12-151-0/+4
|
* c: support forward-declared enums lemon2025-12-151-34/+32
| | | | This is a common non-standard GNU extension.
* c: emit data for __func__ lazily lemon2025-12-151-15/+16
|
* c: fix another memory-leak-when-errors case lemon2025-12-141-1/+2
|
* c: as a hack, warn for zero-length array instead of error lemon2025-12-141-1/+1
| | | | | Treated as unsized array T[]. This shows up in some linux headers as a non-standard way to have flexible array members.
* c: fix memory leak if initializer data if error lemon2025-12-141-1/+1
|
* only put dats can in .text now when emitting it lemon2025-12-141-2/+2
|
* various relocation related optimization lemon2025-12-141-3/+3
| | | | | | | | | | With 59ca5a8db, querying if a symbol is defined is cheap. If we're compiling code that calls foo() and we defined foo() in this compilation unit, we already know its offset within the .text section, so use it instead of emitting a relocation for the linker to handle. Also, put small literal data in the .text section instead of .rodata. This seems to improve performance (cache locality?), and as a bonus, it will be good for aarch64's instr encoding with smallish PC-relative offsets.
* c: handle more static eval edgecases for int -> ptr lemon2025-12-131-1/+1
| | | | | sqlite3 was falling back to `((void*)&((char*)0)[X])` for INT_TO_PTR, which this handles now.
* c: case/default labels only create new blocks when necessary lemon2025-12-131-7/+11
|
* fix position independent loads of function symbols. lemon2025-12-131-3/+3
| | | | | | | | For `extern int x[1];`, can use PCREL32 for &x. But for `extern int x(int)`, must use GOTREL, when not being called directly (that's PLT). Therefore the type of an external symbol (actually just whether it denotes a function) matters when deciding what kind of relocation to emit, so keep that information.
* c: switch stmt diagnostics lemon2025-12-121-8/+49
| | | | For duplicate cases, case value overflow
* rename arraylength macro -> countof lemon2025-12-111-23/+23
|
* c: accept C99 `[static N]` style array decls, changes to fn quals lemon2025-12-111-24/+45
| | | | | | Function parameters qualifiers don't matter outside of function definition. `int (const int)` should be compatible with `int(int)` etc. So no need to store them in the typedata.
* _Alignof and stuff lemon2025-12-111-11/+18
|
* c: use a look-up table for isdecltok() lemon2025-12-111-14/+18
|
* c: optimize environment decl lookup lemon2025-12-111-6/+26
| | | | | Use a hashmap for the toplevel, optimizing for the common use case where the file-scope has many more declarations than local scopes do