Formal semanticsmodels C

Cerberus C semantics

Also known as Cerberus

An executable semantics of a large part of ISO C11 that explores all behaviors a small C program may have, including pointer provenance. CN is built on it.

Stage 1 · Validated Written in Lem (translated to OCaml) Open source · BSD-2-Clause Last commit · 2 days ago

What it covers

Models
C, ISO C11 (fragment)
Fragment
A substantial fragment of ISO C11, single-threaded in the base version. Not supported: bit-fields, variable-length arrays, C11 generic selection, C11 character-set types, setjmp/longjmp and signals. Only modeled informally or partly: floating point (float and double via OCaml floats), volatile, restrict and register (syntax checks only), the standard library (an adapted musl libc plus a formal printf). The preprocessor is not modeled; GCC or Clang preprocess the input.
Written in
Lem (translated to OCaml)
Usable in
—
Validation
Published test results. Memarian's 2023 thesis reports differential testing against Clang on Csmith programs (1186 of 1192 and 463 of 470 tests agree; the rest time out) and the GCC torture tests (1148 of 1160 supported tests executed correctly, after manual adaptation; 363 tests use unsupported features). The POPL 2019 paper reports earlier GCC torture results (948 of 974) and results on the ITC Toyota benchmark and a pointer-provenance test suite.
Maintained by
University of Cambridge (REMS project)

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.

Stage 0 Mechanized Met
  • Met: Machine-checked or machine-readable definition A machine-readable definition in Lem (about 20,000 lines in 2019), compiled to OCaml. It is not available as definitions in a proof assistant. evidence
  • Met: Fragment and version are stated The thesis introduction lists missing and simplified features. evidence
Stage 1 Validated Met
  • Met: Can be executed or tested cerberus --exec runs C programs; a web interface explores all allowed behaviors of small tests. evidence
  • Met: Published results against conformance tests or real implementations Chapter 12: Csmith differential testing against Clang and the GCC torture tests. evidence
Stage 2 Authoritative Next
  • 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. Not an official reference for C. Its authors worked with ISO WG14 on pointer provenance; WG14 has since published ISO/IEC TS 6010:2025, a provenance-aware memory object model for C. Several C11 features are missing (see fragment). No stated policy for following new C standards (C17, C23). evidence

Coverage

Which parts of C the model defines.

Common features

Common features
FeatureSupportNotes
Machine integers Fixed-width integer arithmetic, overflow and bit operations. SupportedSupported.Integer undefined behavior is detected. Implementation-defined sizes follow LP64 for testing.
Source
Integer undefined behavior is detected. Implementation-defined sizes follow LP64 for testing. source
Floating point IEEE 754 floating-point arithmetic, including rounding and NaNs. PartialPartial.Informal: only float and double, computed with OCaml's floats. Floating-point undefined behavior and the floating-point environment are not modeled.
Source
Informal: only float and double, computed with OCaml's floats. Floating-point undefined behavior and the floating-point environment are not modeled. source
Heap and pointers Dynamically allocated memory, pointers or references, and aliasing. SupportedSupported.Memory object models with pointer provenance are the core of the work.
Source
Memory object models with pointer provenance are the core of the work. source
Arrays and buffers Indexed memory such as arrays, slices, vectors and byte buffers. PartialPartial.Variable-length arrays are not supported; flexible array members are supported but need more validation.
Source
Variable-length arrays are not supported; flexible array members are supported but need more validation. 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 supported.
Source
Function pointers are supported. source
Threads and shared memory Concurrent threads with locks, atomics or message passing. PartialPartial.The base semantics is single-threaded. Extensions by collaborators add the C11 concurrency model; Cerberus-BMC handles small concurrent examples.
Source
The base semantics is single-threaded. Extensions by collaborators add the C11 concurrency model; Cerberus-BMC handles small concurrent examples. source
I/O and system calls Files, network, system calls and foreign-function calls. PartialPartial.printf is modeled formally. The 2019 paper notes there is no file system support (for example scanf).
Source
printf is modeled formally. The 2019 paper notes there is no file system support (for example scanf). source
Standard library Specifications or models for the language's standard library. PartialPartial.Library headers come from an adapted musl libc, so undefined behavior inside library functions is only detected as far as musl's own code triggers it.
Source
Library headers come from an adapted musl libc, so undefined behavior inside library functions is only detected as far as musl's own code triggers it. source

C-specific features

C-specific features
FeatureSupportNotes
Pointer casts and provenance Casting between pointers and integers, pointer arithmetic across objects. SupportedSupported.Implements provenance-aware memory models (PNVI variants) including integer-pointer casts. Provenance of sub-objects is not modeled; the thesis calls its semantics an open problem.
Source
Implements provenance-aware memory models (PNVI variants) including integer-pointer casts. Provenance of sub-objects is not modeled; the thesis calls its semantics an open problem. source
Unions and type punning Reading a value through a different type than it was written with. PartialPartial.Unions and union type punning are modeled. C's effective-type (strict aliasing) rules are not: the model targets code built with -fno-strict-aliasing.
Source
Unions and union type punning are modeled. C's effective-type (strict aliasing) rules are not: the model targets code built with -fno-strict-aliasing. source
Bit-fields Struct members narrower than a byte. Not supportedNot supported.The front end rejects bit-fields as not yet supported.
Source
The front end rejects bit-fields as not yet supported. source
Variadic functions Functions such as printf that take a variable number of arguments. PartialPartial.User-defined variadic functions are supported, but undefined behavior from misusing stdarg.h is not detected.
Source
User-defined variadic functions are supported, but undefined behavior from misusing stdarg.h is not detected. source
setjmp / longjmp Non-local jumps out of nested calls. Not supportedNot supported.Non-local jumps (setjmp.h) and signals are not supported.
Source
Non-local jumps (setjmp.h) and signals are not supported. source
volatile and MMIO Memory-mapped device registers and volatile accesses. Not supportedNot supported.volatile is checked only as syntax; its meaning is not modeled.
Source
volatile is checked only as syntax; its meaning is not modeled. source
Inline assembly Assembly code embedded in C functions. Not supportedNot supported.Not supported; the thesis lists 26 GCC torture tests excluded for using inline assembly.
Source
Not supported; the thesis lists 26 GCC torture tests excluded for using inline assembly. source

Used by

Toolchains in this index whose proofs are about this model.

  • CN Write ownership and correctness specifications as comments in C code; CN checks them with an SMT solver, or turns them into runtime checks for testing.

Sources

esc