一句话:把 GCC、Clang 静态分析器与 Valgrind 嵌入 LLM 生成回路,以结构化三维反馈修复 C 程序的内存安全缺陷。
自动程序修复在 Java、Python 等托管语言上进展迅速,但 C 语言由于手动内存管理,补丁可能在通过编译与功能测试的同时悄悄引入泄漏、释放后使用或双重释放等内存安全缺陷。已有 LLM 修复方法反馈贫乏:或完全无执行反馈,或仅有通过/失败二值信号,或仅使用非结构化、未打分的 sanitizer 文本。本文提出 CiL-Agent,将 GCC、Clang 静态分析器与 Valgrind 紧耦合进 LLM 生成循环,把工具诊断解析为编译可达性、静态可证性与动态内存安全三维结构化反馈;并采用两阶段策略,先采样候选补丁并综合打分(Best-of-N),再在精确工具反馈下对最优候选进行迭代精化。在覆盖 11 类 CWE 的 1000 个真实 C 漏洞上,CiL-Agent 达到 88.2% Pass@1,其中 87.3% 的补丁内存安全,显著优于五个修复基线与五个现代编程智能体;1000 任务消融显示工具链集成与迭代精化各自不可或缺(分别下降 44.3 与 35.2 个百分点),且工具链集成是最关键组件;post-cutoff 基准进一步表明增益并非源于训练数据记忆。
Automated Program Repair (APR) has advanced rapidly on managed languages such as Java and Python, yet C—the bedrock of systems software—remains far harder to repair safely. The difficulty is specific to C: as an unmanaged language with manual memory management, a patch can compile and pass every functional test while silently introducing a memory-safety defect (a leak, use-after-free, or double free) that managed-language tests would never expose, making such “fixes” potentially worse than no fix. Existing LLM-based repair offers little defense, as it learns from impoverished feedback—no execution at all (APPATCH), binary pass/fail signals (ChatRepair), or loosely-structured, unscored sanitizer text (VRpilot). We present CiL-Agent (Compiler-in-the-Loop Agent), which tightly integrates GCC, the Clang Static Analyzer, and Valgrind into the LLM generation loop, parsing their diagnostics into structured, three-dimensional feedback: compilation reachability, static provability, and dynamic memory safety. A two-phase strategy first samples and composite-scores candidate patches (Best-of-N), then refines the best under precise tool feedback. On 1,000 real-world C vulnerabilities spanning 11 CWE categories, CiL-Agent attains 88.2% Pass@1 with 87.3% memory-safe patches, outperforming five repair baselines (by 8.3–58.4pp, all p<0.001, McNemar’s test) and five modern coding agents by a wide margin. A full 1,000-task ablation shows toolchain integration and iterative refinement are independently essential (−44.3 and −35.2 percentage points), with toolchain integration the single most critical component, and a post-cutoff benchmark confirms the gains are not due to training-data memorization.
@inproceedings{paperbot12260,
title = {CiL-Agent: Compiler-in-the-Loop LLM Agent for Memory-Safe C Program Repair},
author = {Yang Shen and Yating Zhang and Jiaqiang Yao and Minghao Liu and Wei Dong},
booktitle = {ASE},
year = {2026},
doi = {10.1145/3832783.3837493}
}