Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Code

Vidyut Sriram, Saatvik Pradhan, Suman Saha
7/21/2026
cs.SEcs.AI
rag

No confident code implementation found for this paper.

Abstract

Large language models can generate C code from natural-language descriptions, but resulting programs often contain security vulnerabilities and compilation errors, posing risks for embedded and resource-constrained systems. This work investigates how feedback and retrieval improve reliability of LLM-generated C code.

Show full abstract

We present an analysis-and-repair workflow that combines compilation diagnostics, CodeQL static analysis, and KLEE symbolic execution with retrieval of prior repair patterns for iterative refinement. Evaluated on 5,000 C programming tasks exercising embedded relevant vulnerabilities, baseline models show substantial reliability gaps, with compilation failure rates up to 46% and security defect rates up to 49%. Our approach improves both metrics. For CodeLlama 7B, security defect rates decrease from 49% to 19% and total CodeQL errors drop from 15,088 to 2,463 (83.7%). For DeepSeek Coder 1.3B, compilation failures are reduced from 42% to 22% and security defects from 35% to 15%. These results show that integrating lightweight analysis tools can improve the safety of LLM-generated code for embedded development.

View on arXivView PDF

Code Implementations

No confident code match yet

We couldn't find an author-owned or strongly-evidenced community implementation for this paper. Any repos shown below are weak matches — verify before relying on them.

No code implementations found yet.

Know of an implementation? Let us know in the comments below!

Similar Papers

Cite this paper

@article{sriram2026toolguided,
  title  = {Tool-Guided Retrieval-Augmented Repair for Securing LLM-Generated C Code},
  author = {Vidyut Sriram and Saatvik Pradhan and Suman Saha},
  year   = {2026},
  eprint = {2607.21641},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2607.21641v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2607.21641.svg)](https://codeofpaper.com/paper/2607.21641)

Discussion