Master's thesis

Learning C++ Class Invariants from Object States with AI Agents

Hochschule München University of Applied SciencesAEMY

Learning C++ Class Invariants from Object States with AI Agents

Hochschule München is among the largest German universities of applied sciences, located at the heart of Munich, Germany. The working group "AEMY" focuses on safe, secure and smart systems. Our main working areas include RISC-V processor design, WebAssembly runtime development and open source chip design tools.

Class invariants are properties that every valid object of a class must satisfy, for example that a container’s size never exceeds its capacity. They are essential for both verification and testing, yet developers rarely write them down explicitly. Our research group has developed two AI-agent-based tools that cover these two sides: ACSLGen generates formal ACSL++ specifications and proves them with Frama-C, while AMSGen generates GoogleTest unit tests for C++ code.

This thesis links the two tools through class invariants. The unit tests generated by AMSGen exercise objects and record traces of their internal state. From these traces and the source code, AI agents infer candidate class invariants. ACSLGen and Frama-C then attempt to formally verify these candidates. Invariants that are proven are fed back into AMSGen, where they serve as test oracles. This closes the loop between testing and formal verification. Potential areas of focus include:

  • Instrumenting C++ classes to record object states at method boundaries during AMSGen test runs
  • Inferring candidate class invariants from state traces using LLM agents and classical invariant mining (e.g., Daikon-style)
  • Verifying candidates as ACSL++ class invariants with ACSLGen and Frama-C
  • Using verified invariants as oracles in AMSGen-generated tests and measuring the effect on fault detection
  • Building a benchmark of C++ classes (e.g., containers, state machines, embedded drivers) with reference invariants This project provides the opportunity to work at the intersection of program analysis, C++ systems programming, and deep learning methods. For further information or to express your interest feel free to reach out.