Skip to content

GCC Compatibility

Derek Snider edited this page May 19, 2026 · 2 revisions

GCC Compatibility

madc aims for broad compatibility with real-world C code. The primary benchmark is the GCC torture test suite — a collection of 1685 C programs designed to stress-test compilers.

Current status

~80% parity — 1327 of 1685 torture tests pass (as of v0.17.0+).

This means most standard C constructs compile and run correctly in madc, including:

  • Structs, unions, enums, typedefs
  • Pointers, pointer arithmetic, multi-level indirection
  • Fixed-size arrays, multi-dimensional arrays
  • Function pointers, indirect calls
  • Variadic functions (va_list, va_arg)
  • K&R-style function definitions
  • Cast chains, integer promotions
  • Bitwise operations, shifts
  • Comma operator, compound assignment
  • goto, labels
  • Preprocessor conditionals, macros

What works well

  • Standard C control flow — if, for, while, switch, goto
  • Struct layout — C ABI-compatible alignment, packing, nested structs
  • Pointer semantics — address-of, dereference, pointer subscript, -> chains
  • Standard library calls — printf, sprintf, strlen, memcpy, etc. via dlsym fallback
  • Preprocessor#define, #ifdef, #if/#elif/#else, #pragma pack

Known gaps

These C features are not yet fully supported:

  • Struct pass-by-value for function arguments (~8 remaining failures)
  • __builtin_return_address and similar GCC builtins
  • __real__ / __imag__ — fuller complex number support
  • VLA members in local anonymous structs
  • 32-bit arithmetic wrapping in widening cast contexts
  • -0.0 preservation in floating-point operations
  • Triple dereference (***p)
  • Inline assembly (asm)

Approach

When debugging JIT vs compiled parity, madc uses GCC as the reference compiler:

  1. Reduce the failing case to the closest valid GCC analogue
  2. Inspect GCC's emitted code shape
  3. Prefer fixes that move madc toward GCC's lowering shape

When madc intentionally diverges from GCC (e.g., 64-bit default int), the divergence is documented.

What's next?

Clone this wiki locally