Formal semanticsmodels C
CompCert C and Clight semantics
Also known as CompCert C, Clight, Csem
The formal semantics of C, written in Rocq, that the CompCert compiler is proved correct against. VST proves programs against its Clight part.
Stage 0 · Mechanized Written in Rocq Open source · LGPL-2.1-or-later for the sema… 3.18 · 3 months ago
What it covers
- 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
- Usable in
- Rocq
- 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.
- Maintained by
- AbsInt, Inria
Stage
Computed from the evidence below; see the criteria. MechanizedMechanized. Written in a form a computer can check, rather than on paper. means a computer can check the definition.
- Met: Can be executed or tested The reference interpreter, ccomp -interp. evidence
- Not met: Published results against conformance tests or real implementations Only a 2012 test effort on an executable version for CompCert 1.8.2 was found. No current published conformance or differential results. evidence
- Not met: Adopted by the language or ISA owner, or covers the full current version and tracks new ones 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). evidence
Coverage
Which parts of C the model defines.
Common features
| Feature | Support | Notes |
|---|---|---|
| Machine integers Fixed-width integer arithmetic, overflow and bit operations. | SupportedSupported.Two's complement; signed overflow wraps (modulo 2^N) instead of being undefined, which is stricter than ISO C. Source | Two's complement; signed overflow wraps (modulo 2^N) instead of being undefined, which is stricter than ISO C. source |
| Floating point IEEE 754 floating-point arithmetic, including rounding and NaNs. | PartialPartial.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 | 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 |
| Heap and pointers Dynamically allocated memory, pointers or references, and aliasing. | SupportedSupported.Block-based memory model. The byte representation of pointers is kept abstract. Source | Block-based memory model. The byte representation of pointers is kept abstract. source |
| Arrays and buffers Indexed memory such as arrays, slices, vectors and byte buffers. | PartialPartial.Variable-length arrays are not supported. Source | Variable-length arrays are not supported. source |
| Loops Unbounded loops, which need invariants or bounds to verify. | Supported | |
| Recursion Functions that call themselves, directly or through others. | Supported | |
| Higher-order code Function pointers, closures and callbacks. | SupportedSupported.Function pointers are part of the language. | Function pointers are part of the language. |
| Threads and shared memory Concurrent threads with locks, atomics or message passing. | Not supportedNot supported.No threads or atomics; CompCert defines __STDC_NO_THREADS__ and __STDC_NO_ATOMICS__. Source | No threads or atomics; CompCert defines __STDC_NO_THREADS__ and __STDC_NO_ATOMICS__. source |
| I/O and system calls Files, network, system calls and foreign-function calls. | PartialPartial.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 | 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 |
| Standard library Specifications or models for the language's standard library. | PartialPartial.CompCert relies on the system's C library. The reference interpreter only provides printf, malloc and free. Source | CompCert relies on the system's C library. The reference interpreter only provides printf, malloc and free. source |
C-specific features
| Feature | Support | Notes |
|---|---|---|
| Pointer casts and provenance Casting between pointers and integers, pointer arithmetic across objects. | PartialPartial.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 | 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 |
| Unions and type punning Reading a value through a different type than it was written with. | PartialPartial.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 | 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 |
| Bit-fields Struct members narrower than a byte. | SupportedSupported.Since CompCert 3.10 (2021), bit-fields are part of the formal semantics and their compilation is proved. Source | Since CompCert 3.10 (2021), bit-fields are part of the formal semantics and their compilation is proved. source |
| Variadic functions Functions such as printf that take a variable number of arguments. | PartialPartial.Variadic functions are supported, but va_arg is implemented by hand-written assembly helpers in CompCert's runtime library, outside the proof. Source | Variadic functions are supported, but va_arg is implemented by hand-written assembly helpers in CompCert's runtime library, outside the proof. source |
| setjmp / longjmp Non-local jumps out of nested calls. | Not supportedNot supported.setjmp and longjmp are treated as ordinary functions; the manual advises against using them. Source | setjmp and longjmp are treated as ordinary functions; the manual advises against using them. source |
| volatile and MMIO Memory-mapped device registers and volatile accesses. | PartialPartial.Accesses to volatile scalars are observable events. Volatile struct and union accesses are treated as normal accesses. Source | Accesses to volatile scalars are observable events. Volatile struct and union accesses are treated as normal accesses. source |
| Inline assembly Assembly code embedded in C functions. | Not supportedNot 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 | 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 |
Used by
Toolchains in this index whose proofs are about this model.
- Verified Software Toolchain (Verifiable C) Prove in the Rocq proof assistant that a C program meets its specification; compiled with CompCert, the proof carries down to the assembly code.
Sources
- CompCert manual, ch. 1: structure and verified parts · accessed 26 Nov 2026
- CompCert manual, ch. 4: reference interpreter · accessed 26 Nov 2026
- CompCert manual, ch. 5: the CompCert C language · accessed 26 Nov 2026
- CompCert manual, ch. 6: language extensions (inline assembly) · accessed 26 Nov 2026
- CompCert changelog · accessed 26 Nov 2026
- CompCert license (dual-licensed semantics files) · accessed 26 Nov 2026
- Executable semantics for CompCert C (Campbell) · accessed 26 Nov 2026
- Mechanized semantics for the Clight subset of the C language (Blazy, Leroy; JAR 2009) · accessed 26 Nov 2026