Skip to content

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

Jul 2026 · arXiv.org · Vol abs/2607.21641 · 0 citations · 8 references
Computer Science

TL;DR

The results show that integrating lightweight analysis tools can improve the safety of LLM-generated code for embedded development by integrating compilation diagnostics, CodeQL static analysis, and KLEE symbolic execution with retrieval of prior repair patterns for iterative refinement.

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. 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 source

Similar papers

#artificial intelligence Preprint Sep 2026

Metrics Failure in LLM-Based Code Vulnerability Repair: An Empirical Study and a Change-Aware Screen

Large language models (LLMs) are increasingly applied to the automated repair of C/C++ security vulnerabilities, and compile rate is a commonly reported proxy for progress: whether the generated patch compiles. We argue that compile rate is a scientifically unreliable metric for single-function vulnerability repair, an...

Om Nepal, Sushant Aryal, Oluseyi Olukola et al. · 0 citations
Review Sep 2026

An Empirical Analysis of CodeQL False Positives and Query Refinements for Java Vulnerabilities

Static application security testing (SAST) tools help developers find vulnerabilities before deployment, but false positives create substantial triage effort. We study whether CodeQL false positives in Java security analysis form recurring, explainable patterns that can be reduced by refining the analysis. We run CodeQ...

Amirali Sajadi, Saikat Dutta, Preetha Chatterjee · 0 citations
#small language model Book Open access Oct 2026

LPR+: Diverse Transformations for LLM-Aided Program Reduction

Program reduction helps compiler and language-tool developers turn large failure-inducing programs into small, shareable bug reports. LPR (Large Language Models-Aided Program Reduction) demonstrated that large language models (LLMs) can complement syntax-guided reducers by proposing language-specific transformations on...

Ze-Hua Zhang, Jia-Tong Liu, Xue-Song Yao et al. · 0 citations
#artificial intelligence Review Sep 2026

Complexity-Aware Evaluation of LLM Comprehension

A complexity-aware framework for evaluating LLM code comprehension using cyclomatic complexity, nesting depth, branching factor, and Halstead volume demonstrates that complexity-aware evaluation provides a more diagnostic assessment of LLM code-comprehension reliability than aggregate accuracy alone.

Ali Mohammadi Esfahani, Nafiseh Kahani, Samuel A.Ajila · 0 citations

We use cookies to run the site and, with your consent, for analytics and to show ads. See our Cookie Policy.