Software Engineering
Compiler Plugin Certifies Execution-Time Bounds for Real-Time C/C++ Code
A new Clang compiler plugin automatically verifies that C and C++ functions meet timing constraints through mathematical proofs, with results validated independently at compile time.
Researchers have developed a Clang compiler plugin that automatically determines and verifies the maximum execution cost of C and C++ functions designed for real-time systems, rejecting any code at compile time that could violate timing requirements.
How the tool works#
The plugin analyzes functions to establish provable limits on their computational expense. It rejects code containing operations that threaten predictability—memory allocation, exception throwing, indirect function calls, and loops or recursive calls without computable bounds. For analyzable functions, the tool synthesizes mathematical proofs of correctness using an SMT solver and Farkas' Lemma to compute loop bounds via affine ranking potentials, logarithmic bounds for certain patterns, and depth/size potentials for recursion.
A distinctive feature is cost certification: for functions meeting a linear subset of C/C++, the plugin generates a machine-verifiable proof compiled from a formally verified Lean 4 definition. This certificate can be checked using only integer arithmetic, making the final timing guarantee independent of both the analyzer and the solver itself.
Evaluation results#
The plugin underwent extensive testing on multiple benchmarks. When applied to the 29 TACLeBench kernel collection programs without manual annotations, it bounded 142 of 220 loops (with 131 matching the reference flow facts exactly), and produced certificates accepted by the checker for 161 of 165 bounded functions. On the CMSIS-DSP library for Cortex-M processors, containing 786 functions, the tool successfully bounded 616 when given assumed input ranges.
Comparative testing against five existing tools—LLVM's ScalarEvolution, KoAT2, CoFloCo, Infer, and oRange—showed competitive performance on loop counting. When evaluated on the C programs from the Termination and Complexity Competition, the plugin certified 147 of 553 programs without annotations, whereas leading competitors achieved 288 and 264 respectively.
Why it matters#
Verifying execution time guarantees is critical for safety-critical embedded systems where missing deadlines can cause failures. By automating cost analysis and providing independently checkable proofs, this tool shifts the burden of verification from developers to mathematics, reducing the risk of hidden timing violations in production code.