This is a fork of Rui Ueyama's chibicc with fixes and improvements, including:
- C99 features: VLA parameters, VLA de-allocation, K&R old-style functions.
- C11 features:
_Static_assert()
, over-aligned locals,_Generic
with qualifiers. - C23 features:
constexpr
,enum:T{}
,#embed
,auto
type-inference, etc. - C2Y/TS features:
defer
(as_Defer
),__VA_TAIL__
- GNU features: inline asm,
cleanup
- Basic optimizations: const folding, reg-alloc for temporaries, instruction selection.
- Compile correct code correctly.
- Code readability.
- Build real world projects, test with their suites.
- Implement GNU extensions and C23 features if doable.
- Match GCC / Clang's behavior to improve compatibility with existing code in the wild.
- Should just work on recent glibc-based (2.28+) x86-64 Linux. Also see porting
- Test script needs
bash
; depending on the distro,file
and/orglibc-static
packages may be required.
git clone --depth 1 https://github.com/fuhsnn/slimcc
cd slimcc
make test-stage2 -j4
Run it in base directory like CC=~/slimcc/slimcc
, since internal header path is hardcoded for simplicity.
slimcc
should be able to compile most C89 to C11 projects not requiring optional or compiler-specific features.
A CI workflow is set up to make test
real-world projects in a Debian container with cc
gcc
cpp
uninstalled. The lineup includes Curl, Git, OpenSSL, PHP, Perl, Python, PostgreSQL, and continues to grow. Please have a look a the workflow, dockerfile, and build instructions to verify this claim.
musl
is also buildable sans complex numbers, it's a goal to set up a self-hosted slimcc-musl
environment.
1M tests were run with --no-packed-struct
flag, all issues found were fixed.
Binary size is roughly among TinyCC's and GCC/Clang at -O0
, no claims about speed.
The compiler leaks all allocations, it gets bad for large translation units, I'm looking for a clean way to remedy this.
Here's some I've tried:
- TinyCC, kefir, vanilla chibicc: can build with
cc *.c
,make test
will fail but not big deal. - pcc: has a bug parsing escaped sequence in a comment, otherwise can build.
- cproc: can't build, lacks long double support.
- mir, xcc: missing header.
musl Linux and BSDs should be doable. Check hard-coded paths in main.c
, and pre-defined macros in preprocessor.c
.
The widcc
branch is a less noisy codebase than slimcc
that should be more appealing for developers to hack on.