一句话:提出 Orca,让 LLM 自主规划沿控制流图预测执行代码片段,从而静态检测运行时错误。
论文针对大型语言模型虽擅长识别代码模式与语义、却难以推理程序执行动态行为的问题展开研究。LLM 主要基于静态代码表示工作,无法捕捉程序执行中的状态变化。作者提出 Orca:指导 LLM 自主制定一份计划,沿控制流图(CFG)对(不)完整代码片段进行预测性执行,使其充当预测解释器来“执行”代码。为抑制误差传播,Orca 让 LLM 在分支点暂停,聚焦于符号表中变量取值的状态;同时指示 LLM 不必在执行计划的每一步都停下,从而使整个预测解释器只需一次提示,显著节省开销。作为下游任务,Orca 被用于在线代码片段中运行时错误的静态检测,以便在缺陷被并入代码库前及早发现。实证评估表明,Orca 在预测执行轨迹与静态检测运行时错误两方面均有效,并优于现有最先进方法。
Large Language Models (LLMs) have been excellent in generating and reasoning about source code and natural-language texts. They can recognize patterns, syntax, and semantics in code, making them effective in several software engineering tasks. However, they exhibit weaknesses in reasoning about the program execution. They primarily operate on static code representations, failing to capture the dynamic behavior and state changes that occur during program execution. In this paper, we advance the capabilities of LLMs in reasoning about dynamic program behaviors. We propose Orca, a novel approach that instructs an LLM to autonomously formulate a plan to navigate through a control flow graph (CFG) for predictive execution of (in)complete code snippets. It acts as a predictive interpreter to “execute” the code. In Orca, we guide the LLM to pause at the branching point, focusing on the state of the symbol tables for variables' values, thus minimizing error propagation in the LLM's computation. We instruct the LLM not to stop at each step in its execution plan, resulting the use of only one prompt for the entire predictive interpreter, thus much cost-saving. As a downstream task, we use Orca to statically identify any runtime errors for online code snippets. Early detection of runtime errors and defects in these snippets is crucial to prevent costly fixes later in the development cycle after they were adapted into a codebase. Our empirical evaluation showed that Orca is effective and improves over the state-of-the-art approaches in predicting the execution traces and in static detection of runtime errors.
DOI 原文 ·
@inproceedings{paperbot8789,
title = {Planning a Large Language Model for Static Detection of Runtime Errors in Code Snippets},
author = {Smit Patel and Aashish Yadavally and Hridya Dhulipala and Tien N. Nguyen},
booktitle = {ICSE},
year = {2025},
doi = {10.1109/icse55347.2025.00102}
}