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

· Source: cs.SE updates on arXiv.org · Field: Technology & Digital — Artificial Intelligence & Machine Learning, Cybersecurity & Data Privacy, Software Development & Engineering · Depth: Advanced, long

Summary

A new tool-guided workflow enhances the reliability and security of C code generated by large language models, particularly for embedded and resource-constrained systems. This approach integrates compilation diagnostics via GCC, CodeQL static analysis, and KLEE symbolic execution with a retrieval-augmented repository of prior repair patterns for iterative refinement. Evaluated on 5,000 C programming tasks, the method significantly improves outcomes for models like CodeLlama 7B and DeepSeek Coder 1.3B. CodeLlama 7B saw security defect rates drop from 49% to 19%, with total CodeQL errors decreasing from 15,088 to 2,463, an 83.7% reduction. DeepSeek Coder 1.3B experienced a reduction in compilation failures from 42% to 22% and security defects from 35% to 15%. These results demonstrate that combining lightweight analysis tools with retrieval can substantially improve LLM-generated C code safety.

Key takeaway

For AI Security Engineers deploying LLM-generated C code in embedded or resource-constrained systems, relying solely on initial generation or manual inspection is insufficient. You should integrate automated, multi-tool validation pipelines that combine compilation, static analysis like CodeQL, and symbolic execution such as KLEE. This approach, augmented by a repository of successful repair patterns, demonstrably reduces security defects and compilation failures, making LLM-generated C code safer for critical applications.

Key insights

Integrating multi-tool feedback and retrieval of repair patterns significantly improves LLM-generated C code security and reliability.

Principles

Method

The workflow involves initial generation, compilation/static analysis (GCC, CodeQL), retrieval-guided repair using a growing pattern repository, and final KLEE symbolic validation.

In practice

Topics

Best for: AI Engineer, Research Scientist, CTO, AI Scientist, Machine Learning Engineer, AI Security Engineer

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by cs.SE updates on arXiv.org.