CrossCheck II: A Compiler Plugin for Certified Cost Bounds of Real-Time C and C++ Code, and its Evaluation
## Research Summary
CrossCheck II is a Clang compiler plugin designed to derive and certify cost bounds for C and C++ functions intended for real-time use. It automatically rejects functions that allocate memory, throw exceptions, call through pointers, or contain unbounded loops or recursion. For functions within a linear fragment, the plugin generates a cost certificate that a Lean 4-defined, sound-proved checker validates using integer arithmetic, making the bound independent of the analyzer or SMT solver. Evaluation on 29 TACLeBench kernels demonstrated that the plugin bounded 142 of 220 loops in calling contexts, with 131 matching benchmark flow facts, and 161 of 165 bounded functions received accepted certificates. On the CMSIS-DSP library, 616 functions were bounded with assumed input ranges. While effective for real-time code, the tool proved weaker than specialized complexity analyzers on programs designed for general complexity analysis, bounding 147 of 553 programs compared to 288 and 264 by KoAT2 and CoFloCo, respectively. The bounds are in abstract units and do not represent actual execution time, and the analysis relies on assumptions like the absence of signed overflow and aliasing. The tool's development and initial paper drafting were assisted by an AI coding assistant, with the author verifying the content.
## Background and Problem
Luca Dall’Olio, affiliated with Alter Ego Engineering, published a preprint on arXiv Programming Languages describing CrossCheck II. This work addresses a critical challenge in hard real-time software development, where programs must complete execution within strict time budgets. A fundamental requirement for ensuring such predictability is the accurate determination of loop and recursion bounds, which in practice are often manually specified.
Existing compiler tools can check certain properties of real-time code, such as the absence of blocking calls, but typically do not provide automated, verifiable bounds on iterative or recursive constructs. This gap necessitates manual intervention, which is prone to error and lacks formal guarantees, posing a significant risk in safety-critical embedded systems where timing failures can have severe consequences.
CrossCheck II aims to fill this gap by integrating a cost bounding mechanism directly into the Clang compiler. The system introduces a "cost norm" as a weighted count of source-level operations, and employs "ranking potentials"—mathematical functions derived using SMT solvers and Farkas’ Lemma—to establish upper bounds on loop iterations and recursion depth. A key innovation is the generation of "certificates," which are annotated program representations that a small, formally verified checker can validate, thereby reducing the trusted computing base.
The target users are developers and engineers working on embedded systems and real-time operating systems, particularly those involved in safety-critical applications where predictable execution time and formal verification of timing properties are paramount. The tool seeks to automate and certify a crucial aspect of real-time software analysis, moving beyond manual annotations and unverified analyses.
## Research Question and Contribution
* CrossCheck II is a Clang plugin that automatically derives and certifies cost bounds for real-time C and C++ functions at compile time.
* It rejects functions that use dynamic allocation, exceptions, indirect calls, or contain loops or recursion for which no bound can be derived.
* For functions in a linear fragment, the plugin emits a cost certificate validated by a Lean 4-defined checker, which is proved sound, making the bound independent of the analyzer or SMT solver.
* On 29 TACLeBench kernels, the plugin bounded 142 of 220 loops in calling contexts, with 131 bounds matching the benchmarks’ flow facts, and 161 of 165 bounded functions received accepted certificates.
* The tool successfully bounded 616 functions in the CMSIS-DSP library when provided with assumed input ranges.
* A Rust front-end translates Rust MIR to C, allowing the plugin to analyze and certify Rust code, assuming no panics on overflow.
* The development of the Clang plugin, certificate generator, and other components, as well as the initial drafting of the paper, was significantly assisted by an AI coding assistant, with the author verifying the content.
## Methods and Evidence
* CrossCheck II is implemented as a plugin for the Clang compiler, comprising approximately 3,400 lines of C++ code and 1,100 lines of tests. It processes functions marked with a source annotation, optionally including a deadline, and treats violations as compilation errors.
* The analysis profile rejects dynamic memory allocation, exceptions, virtual and indirect calls, unstructured jumps, and any loop or recursion without a derived or stated bound. Calls are followed into their definitions, including library code.
* Cost is measured using a configurable weighted count of source-level operations (arithmetic, assignments, memory accesses, calls, branches). Loop bounds are derived using affine ranking potentials synthesized by the Z3 SMT solver via Farkas’ Lemma, or logarithmic potentials for specific loop types. Recursion is bounded by depth and size potentials. The analysis is context-sensitive, evaluating callees under argument intervals derived from calling contexts.
* For functions within a linear fragment, the plugin generates a linear cost certificate, which is an annotated program with assertions, loop invariants, potentials, and Farkas multipliers. This certificate is validated by a checker compiled from a Lean 4 definition, which has been formally proved sound. An optional `minic` mode exports functions as a mini-C statement, allowing the checker to validate the certificate against an independent, syntactic description of the source, reducing trust in the certificate generator.
* A Rust front-end translates Rust MIR (Mid-level Intermediate Representation) into C, enabling the plugin to analyze Rust code. This translation assumes that checked arithmetic operations do not panic on overflow, and other assertions or non-returning calls are treated as early returns.
* The tool supports analysis of interrupt handlers, annotated with `CROSSCHECK_INTERRUPT(T)`, and calculates response-time bounds for other functions based on handler costs and activation overheads.
* Derived loop bounds can be exported as flow facts in FFX (OTAWA) or AIS/AIS2 (aiT) formats, and results can be written in SARIF for code-scanning interfaces. The tool can also generate ACSL annotations (requires, loop invariant, loop variant) for independent verification by deductive verifiers.
* Evaluation on 29 TACLeBench kernels, without annotations, showed 142 of 220 loops bounded in context, with 131 bounds matching the benchmarks' flow facts. 161 of 165 bounded functions received accepted certificates, and 152 of these were validated against their mini-C description. No derived bound was found to be below observed loop counts from program executions.
* Comparison with other tools on TACLeBench kernels revealed that CrossCheck's in-context loop bounds largely agreed with oRange (114 of 115 common loops). On functions, Infer found the most bounds (190), followed by CrossCheck (165). On the Termination and Complexity Competition benchmarks, CrossCheck, in symbolic mode, certified 147 of 553 programs, while KoAT2 and CoFloCo bounded 288 and 264, respectively, highlighting CrossCheck's relative weakness on general complexity analysis.
* The analysis relies on several assumptions, including the absence of signed overflow, no aliasing of tracked variables, and no concurrent writes to global variables by interrupts. The cost units are abstract and do not directly correspond to execution time without a micro-architectural model.
## What the Results Mean
* CrossCheck II provides a practical and verifiable method for automatically deriving cost bounds for real-time C and C++ code at compile time, addressing a long-standing challenge in hard real-time system development.
* The use of a formally verified Lean 4 checker for certificate validation significantly enhances the trustworthiness of the derived bounds by reducing the trusted computing base to a small, proven-sound component, rather than relying on the complex, unverified analyzer.
* Its integration as a Clang plugin allows for seamless adoption into existing C/C++ development workflows, enabling developers to incorporate cost analysis and certification early in the development cycle.
* The Rust front-end extends the applicability of certified cost analysis to the growing ecosystem of Rust-based real-time and embedded systems, promoting safer and more predictable software in these domains.
* The ability to export bounds in standard formats (FFX, AIS/AIS2, SARIF, ACSL) facilitates interoperability with other WCET analysis tools and code-scanning interfaces, enhancing the overall toolchain for real-time software verification.
* The explicit disclosure of AI assistance in the tool's development and paper drafting sets a precedent for transparency in research, particularly as AI tools become more integrated into scientific and engineering processes.
## Limitations and Open Questions
* The cost bounds provided by CrossCheck II are in abstract units and do not directly represent actual execution time. The tool lacks a micro-architectural model, meaning instruction durations are not adjusted for context-dependent factors like caches, pipelines, or branch prediction, which are critical for accurate Worst-Case Execution Time (WCET) analysis.
* The analysis has limitations in its precision and coverage. Potentials are restricted to affine or logarithmic forms, which may lead to looser linear bounds or no bounds for more complex loop types (e.g., binary search, multi-phase loops, or those requiring disjunctive invariants). Nested loops are generally bounded by products, with limited amortization in certificates for only two specific triangular shapes.
* Calling contexts are modeled as intervals of integer arguments, without propagating relations between arguments, values of global variables, or the memory effects of callees. The analysis does not track pointers, iterators, or floating-point values as loop counters.
* The certificate fragment, for which certified bounds are generated, excludes complex constructs such as recursion, `do` loops with jumps or switches in their body, `goto` statements, and trusted annotations. The fragment supported for validation against the source (mini-C) is even smaller, excluding calls in tests, calls inlined by the generator, and specific conditions for `do` loop elimination.
* The analysis relies on several critical assumptions for validated certificates, including the absence of signed integer overflow, no aliasing of tracked variables, and no concurrent writes to global variables by interrupt handlers. The Rust front-end also assumes that checked arithmetic operations do not panic on overflow.
* The evaluation has scope limitations: TACLeBench kernels are small programs, and for larger TACLeBench programs and the CMSIS-DSP library, loop counts were not observed, and assumed input ranges were used. The tool's performance on programs designed for general complexity analysis is weaker than specialized tools like KoAT2 and CoFloCo. Furthermore, the random programs used for testing were generated by the same author, and the tool has not been specifically evaluated on RISC-V targets.
* The ACSL export was not given to a deductive verifier, and the generated flow facts were not loaded into aiT for independent verification. The implementation itself is not formally verified; only the underlying mathematics of the certificate checker is machine-checked. The translation from C++ to the certificate's program is not verified unless the certificate is validated against the mini-C description.
Source: arxiv.org/abs/2611.31449
### This post is for subscribers only
Become a member to get access to all content
Subscribe now