# CompCert C and Clight semantics

> The formal semantics of C, written in Rocq, that the CompCert compiler is proved correct against. VST proves programs against its Clight part.

- Kind: formal semantics
- Models: C (CompCert 3.18; ISO C99 with some C11 features)
- Fragment: CompCert C, a large subset of ISO C99 with some C11 additions, and Clight, a simpler form without side effects inside expressions. Not covered: variable-length arrays, complex numbers, long double (by default), threads and atomics, and setjmp/longjmp (treated as ordinary calls). Preprocessing and some elaboration happen before the formal semantics applies.
- Written in: Rocq
- Available in: Rocq
- Stage: 0 (Mechanized)
- Licence: open-source, LGPL-2.1-or-later for the semantics files (dual-licensed); the rest of CompCert is under the INRIA non-commercial license
- Validation: The reference interpreter (ccomp -interp) runs a C program directly on the formal semantics and stops at the first undefined behavior, so programs can be tested against the semantics; the manual presents it as a way to validate the semantics by testing. In 2012 an executable version of the semantics (for CompCert 1.8.2) was built so that test suites could be run against it (Campbell, CPP 2012). No current published conformance or differential-testing results were found. The strongest check is indirect: CompCert is proved to preserve this semantics, so for CompCert-compiled code it is the meaning that the binary has.
- Latest release: 3.18 (2026-08-30) https://github.com/AbsInt/CompCert/releases/tag/v3.18
- Used by toolchains: vst

## Stage

**Stage 0: Mechanized.**

| Stage | Criterion | Met | Evidence / note |
|---|---|---|---|
| 0 | Machine-checked or machine-readable definition | yes | [evidence](https://github.com/AbsInt/CompCert/tree/master/cfrontend) Defined in Rocq (cfrontend/Csem.v, Clight.v and the shared memory model). |
| 0 | Fragment and version are stated | yes | [evidence](https://compcert.org/man/manual005.html) The manual lists the supported dialect section by section against the C99 standard. |
| 1 | Can be executed or tested | yes | [evidence](https://compcert.org/man/manual004.html) The reference interpreter, ccomp -interp. |
| 1 | Published results against conformance tests or real implementations | no | [evidence](https://homepages.inf.ed.ac.uk/bcampbe2/compcert) Only a 2012 test effort on an executable version for CompCert 1.8.2 was found. No current published conformance or differential results. |
| 2 | Adopted by the language or ISA owner, or covers the full current version and tracks new ones | no | [evidence](https://compcert.org/man/manual005.html) Adopted by the owner: no; full coverage: no; tracks new versions: no. ISO WG14 has not adopted or endorsed it. Targets C99, not the current C standard, and excludes several features (see fragment). No stated policy for following new C standards (C17, C23). |

Missing for Stage 1: Published results against conformance tests or real implementations.

## Common features

| Feature | Coverage |
|---|---|
| Machine integers | Supported — Two's complement; signed overflow wraps (modulo 2^N) instead of being undefined, which is stricter than ISO C. ([source](https://compcert.org/man/manual005.html)) |
| Floating point | Partial — IEEE 754 single and double precision with round-to-nearest. long double is unsupported by default (treated as double with -flongdouble); changing the rounding mode at run time is outside the semantics' assumptions. ([source](https://compcert.org/man/manual005.html)) |
| Heap and pointers | Supported — Block-based memory model. The byte representation of pointers is kept abstract. ([source](https://compcert.org/man/manual005.html)) |
| Arrays and buffers | Partial — Variable-length arrays are not supported. ([source](https://compcert.org/man/manual005.html)) |
| Loops | Supported |
| Recursion | Supported |
| Higher-order code | Supported — Function pointers are part of the language. |
| Threads and shared memory | Not supported — No threads or atomics; CompCert defines __STDC_NO_THREADS__ and __STDC_NO_ATOMICS__. ([source](https://compcert.org/man/manual005.html)) |
| I/O and system calls | Partial — Calls to library functions that do I/O, and volatile accesses, are recorded as observable events in a trace; what those functions do is not modeled. ([source](https://compcert.org/man/manual001.html)) |
| Standard library | Partial — CompCert relies on the system's C library. The reference interpreter only provides printf, malloc and free. ([source](https://compcert.org/man/manual004.html)) |

## C-specific features

| Feature | Coverage |
|---|---|
| Pointer casts and provenance | Partial — A pointer may be cast to a same-size integer and back. The bytes of a stored pointer cannot be inspected, and pointer arithmetic outside an object is undefined when dereferenced or compared. ([source](https://compcert.org/man/manual005.html)) |
| Unions and type punning | Partial — Reading a union member other than the one last written is defined for integers and floats (bit-level). It is undefined when a stored pointer would be read as a non-pointer type. ([source](https://compcert.org/man/manual005.html)) |
| Bit-fields | Supported — Since CompCert 3.10 (2021), bit-fields are part of the formal semantics and their compilation is proved. ([source](https://github.com/AbsInt/CompCert/blob/master/Changelog.md)) |
| Variadic functions | Partial — Variadic functions are supported, but va_arg is implemented by hand-written assembly helpers in CompCert's runtime library, outside the proof. ([source](https://github.com/AbsInt/CompCert/blob/master/runtime/README)) |
| setjmp / longjmp | Not supported — setjmp and longjmp are treated as ordinary functions; the manual advises against using them. ([source](https://compcert.org/man/manual005.html)) |
| volatile and MMIO | Partial — Accesses to volatile scalars are observable events. Volatile struct and union accesses are treated as normal accesses. ([source](https://compcert.org/man/manual005.html)) |
| Inline assembly | Not supported — asm statements are off by default (-finline-asm). What the assembly does is not modeled, and the manual warns asm can break CompCert's guarantees. ([source](https://compcert.org/man/manual006.html)) |

## Sources
- [CompCert manual, ch. 1: structure and verified parts](https://compcert.org/man/manual001.html)
- [CompCert manual, ch. 4: reference interpreter](https://compcert.org/man/manual004.html)
- [CompCert manual, ch. 5: the CompCert C language](https://compcert.org/man/manual005.html)
- [CompCert manual, ch. 6: language extensions (inline assembly)](https://compcert.org/man/manual006.html)
- [CompCert changelog](https://github.com/AbsInt/CompCert/blob/master/Changelog.md)
- [CompCert license (dual-licensed semantics files)](https://github.com/AbsInt/CompCert/blob/master/LICENSE)
- [Executable semantics for CompCert C (Campbell)](https://homepages.inf.ed.ac.uk/bcampbe2/compcert)
- [Mechanized semantics for the Clight subset of the C language (Blazy, Leroy; JAR 2009)](https://xavierleroy.org/publi/Clight.pdf)

---
Last checked 2026-11-26. Data: [JSON](/semantics/compcert-c.json) · Page: [HTML](/semantics/compcert-c/) · Methodology v0.1: [/methodology/](/methodology/) · Corrections: [/contribute/](/contribute/)
