C Language Support
Mucc compiles C: C17 by default, C23 with -std=c23, and the
GNU extensions real code uses. Its target is simple to state: any C
program that gcc compiles for Linux should compile with mucc and do the
same thing. Where it doesn't, that is a bug, unless it is listed under
What Mucc Does Not Support.
Standards¶
-std= | What you get |
|---|---|
c89, c99, c11 | The older standards. They differ from C17 mostly in what's missing: each later one only adds to the one before it. |
c17 (the default) | C17, the C most code is written in today, with the GNU extensions |
c23 | C23: constexpr, typeof, #embed, nullptr, bool, true and false as keywords, attributes in [[...]], __VA_OPT__, binary literals, digit separators, and the rest of what C23 adds, except _BitInt |
gnu89 ... gnu23 | The same; the GNU extensions are always on |
C Features¶
- Everything in C99 and C11: variable-length arrays, designated
initializers, compound literals,
_Generic,_Static_assert,_Alignas,_Noreturn, anonymous structs and unions, flexible array members. _Atomicand<stdatomic.h>, and threads (<threads.h>,<pthread.h>), with_Thread_local.- Complex numbers (
_Complex,<complex.h>), andlong double(80-bit on x86-64, 128-bit on ARM64). - Bit fields, including packed and
__int128ones. - K&R function definitions.
GNU Extensions¶
- Statement expressions
({ ... }),typeof,__auto_type, the?:with no middle operand, case ranges, labels as values (&&label,goto *p), zero-length arrays, empty structs. __int128andunsigned __int128.- Inline
asm, basic and extended, with operands, constraints, clobbers andasm goto. - Attributes:
packed,aligned,section,weak,alias,visibility,constructor,destructor,cleanup,format,noreturn,unused,vector_size,transparent_union, and more. Unknown attributes only warn. - Vector types (
vector_size) of 4, 8 or 16 bytes, and SSE intrinsics up to SSE4.2 (<immintrin.h>). #pragma once,#pragma pack,#pragma GCC diagnostic,#include_next.
Builtins¶
gcc's builtins that real code uses: __builtin_expect,
__builtin_unreachable, __builtin_constant_p,
__builtin_offsetof, __builtin_types_compatible_p,
__builtin_choose_expr, the overflow checks
(__builtin_add_overflow and the rest), the bit counts
(__builtin_clz, ctz, popcount, ...),
byte swaps, __builtin_va_*, __builtin_alloca,
the __atomic_* and __sync_* families, and others.
fabs, fabsf and fabsl are builtins
too, so they need no -lm.
Predefined Macros¶
Mucc defines what gcc does for the target, so code finds what it
expects: __GNUC__ (4, as clang says), __STDC_VERSION__,
__x86_64__ or __aarch64__, __linux__,
__LP64__, __SIZEOF_*__, __CHAR_UNSIGNED__
on ARM64, and the rest. mucc -dM -E - < /dev/null lists them
all.
What Mucc Does Not Support¶
- Platforms: only x86-64 and ARM64 Linux (on Windows, WSL 2). No macOS, native Windows, or 32-bit targets.
- Optimization: none beyond register allocation and constant
folding. Generated code is in the range of
gcc -O0, not-O2. No LTO, PGO or-marchtuning. - Language: C only, no C++. No
_BitInt, nested functions,__label__, VLAs inside structs or integer_Complex. No AVX or NEON intrinsics (code that checks__AVX__or__ARM_NEONtakes its portable path). - Bundled musl: static programs only, so no shared libraries or
dlopen(use--libc=system). Itsmallocand stdio are slower than glibc's, and its locale support is basic. - Tooling: no sanitizers, coverage or profiling. Shared libraries
(
-shared) and Intel-syntax assembly use the system'sldandas. - Diagnostics: it rejects the common mistakes but is not a strict checker; some invalid programs gcc rejects are accepted. See the open issues.
The Details¶
- Cross-compiling from x86-64 to ARM64,
long doubleconstants are only as precise as x86-64's ownlong double(64 bits of mantissa, not ARM64's 113). At run time, and in a mucc that runs on ARM64, they are exact. - Implicit function declarations are errors, as C99 and later require.
- gcc attributes that change what a program does but that mucc doesn't
implement are errors rather than silently ignored:
ifunc,naked,target,target_clones,symver,weakref,retain,copy,noinit,persistent,scalar_storage_orderandhardbool. - Vectors must be 4, 8 or 16 bytes.
- No unwind tables (
.eh_frame): fine for C, but.cfi_*directives in assembly are dropped. - Objects from gcc that call libgcc's helpers (complex multiplication,
128-bit division) need gcc's
libgcc.ato link. (On ARM64, the bundled musl comes with those.) - With the bundled musl, threads get 128 KB stacks unless a program asks
for more, and
iconvdiffers from glibc's in small ways. -O0to-O3and other flags that only tune optimization, diagnostics or hardening are accepted and ignored. An unknown flag is an error.
Programs Known to Work¶
These build with mucc and pass their own test suites
(test/thirdparty/):
| With the bundled musl | SQLite, Lua, Redis, Tcl, jq, zlib |
|---|---|
| With the system's glibc | Git, libpng, QuickJS, TinyCC, and CPython (nearly all of its tests) |
| And | mucc itself, which rebuilds itself byte for byte |