LLM For Loop Invariant Generation and Fixing: How Far Are We?
Not on the map. Why?
Abstract (arXiv)
A loop invariant is a property of a loop that remains true before and after each execution of the loop. The identification of loop invariants is a critical step to support automated program safety assessment. Recent advancements in Large Language Models (LLMs) have demonstrated potential in diverse software engineering (SE) and formal verification tasks. However, we are not aware of the performance of LLMs to infer loop invariants. We report an empirical study of both open-source and closed-source LLMs of varying sizes to assess their proficiency in inferring inductive loop invariants for programs and in fixing incorrect invariants. Our findings reveal that while LLMs exhibit some utility in inferring and repairing loop invariants, their performance is substantially enhanced when supplemented with auxiliary information such as domain knowledge and illustrative examples. LLMs achieve a maximum success rate of 78% in generating, but are limited to 16% in repairing the invariant.
Key facts. Cited by 1 paper in the map (data through 7 Oct 2026). Builds on 22 of its 58 references that are in the map. First posted on arXiv 9 Nov 2025.
Builds on
22 of 58 references.
References · 22
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023GPT-4 Technical Reportcited by 18,132
- 2021Evaluating Large Language Models Trained on Codecited by 8,053
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
- 2023A Survey on Evaluation of Large Language Modelscited by 1,227
- 2021Prompt Programming for Large Language Models: Beyond the Few-Shot Paradigmcited by 599
- 2023Evaluating Large Language Models at Evaluating Instruction Followingcited by 290
- 2024Towards AI-Assisted Synthesis of Verified Dafny Methodscited by 58
- 2023Lemur: Integrating Large Language Models in Automated Program Verificationcited by 49
- 2023Finding Inductive Loop Invariants using Large Language Modelscited by 35
- 2023Ranking LLM-Generated Loop Invariants for Program Verificationcited by 33
- 2024Customizing Language Model Responses with Contrastive In-Context Learningcited by 19
10 more
- 2020Learning Nonlinear Loop Invariants with Gated Continuous Logic Networks (Extended Version)cited by 17
- 2024Divide-or-Conquer? Which Part Should You Distill Your LLM?cited by 17
- 2017Horn-ICE Learning for Synthesizing Invariants and Contractscited by 11
- 2024The Impact of Example Selection in Few-Shot Prompting on Automated Essay Scoring Using GPT Modelscited by 8
- 2019SLING: Using Dynamic Analysis to Infer Program Invariants in Separation Logiccited by 7
- 2024Enhancing Automated Loop Invariant Generation for Complex Programs with Large Language Modelscited by 7
- 2025How much do LLMs learn from negative examples?cited by 6
- 2017LoopInvGen: A Loop Invariant Generator based on Precondition Inferencecited by 3
- 2019Ilinva: Using Abduction to Generate Loop Invariantscited by 3
- 2021An Empirical Study of the Effectiveness of an Ensemble of Stand-alone Sentiment Detection Tools for Software Engineering Datasetscited by 3
Built on by
Citing papers per year: 2025: 1.
1 paper.