mlsanityData to 7 Oct 2026

ClassInvGen: Class Invariant Synthesis using Large Language Models

arXiv 2502.18917 ↗First posted 26 Feb 2025cs.AI cs.PL cs.SEcited by 11

Not on the map. Why?

Abstract (arXiv)

Formal program specifications in the form of preconditions, postconditions, and class invariants have several benefits for the construction and maintenance of programs. They not only aid in program understanding due to their unambiguous semantics but can also be enforced dynamically (or even statically when the language supports a formal verifier). However, synthesizing high-quality specifications in an underlying programming language is limited by the expressivity of the specifications or the need to express them in a declarative manner. Prior work has demonstrated the potential of large language models (LLMs) for synthesizing high-quality method pre/postconditions for Python and Java, but does not consider class invariants. In this work, we describe ClassInvGen, a method for co-generating executable class invariants and test inputs to produce high-quality class invariants for a mainstream language such as C++, leveraging LLMs' ability to synthesize pure functions. We show that ClassInvGen outperforms a pure LLM-based technique to generate specifications (from code) as well as prior data-driven invariant inference techniques such as Daikon. We contribute a benchmark of standard C++ data structures along with a harness that can help measure both the correctness and completeness of generated specifications using tests and mutants. We also demonstrate its applicability to real-world code by performing a case study on several classes within a widely used and high-integrity C++ codebase.

Key facts. Cited by 11 papers in the map (data through 7 Oct 2026). Builds on 14 of its 50 references that are in the map. First posted on arXiv 26 Feb 2025.

Builds on

14 of 50 references.

References · 14

  1. 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,383
  2. 2023Retrieval-Augmented Generation for Large Language Models: A Surveycited by 2,185
  3. 2023An Empirical Evaluation of Using Large Language Models for Automated Unit Test Generationcited by 193
  4. 2024Enchanting Program Specification Synthesis by Large Language Models using Static Analysis and Program Verificationcited by 55
  5. 2023Can Large Language Models Transform Natural Language Intent into Formal Method Postconditions?cited by 53
  6. 2024SpecGen: Automated Generation of Formal Program Specifications via Large Language Modelscited by 51
  7. 2023Verus: Verifying Rust Programs using Linear Ghost Types (extended version)cited by 50
  8. 2023WhiteFox: White-Box Compiler Fuzzing Empowered by Large Language Modelscited by 37
  9. 2023Finding Inductive Loop Invariants using Large Language Modelscited by 35
  10. 2024Evaluating LLM-driven User-Intent Formalization for Verification-Aware Languagescited by 16
  11. 2019SLING: Using Dynamic Analysis to Infer Program Invariants in Separation Logiccited by 7
  12. 2022Fuzzing Class Specificationscited by 3
2 more
  1. 2019Are My Invariants Valid? A Learning Approachcited by 1
  2. 2019Using human-in-the-loop synthesis to author functional reactive programscited by 1

Built on by

Cited by year (2026 to 7 Oct)

Citing papers per year: 2025: 3; 2026: 8.

11 papers.