arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2306.07487cs.SE
收藏

TRACED:面向源代码的执行感知预训练

TRACED: Execution-aware Pre-training for Source Code

Yangruibo Ding, Ben Steenhoek, Kexin Pei, Gail Kaiser, Wei Le, Baishakhi Ray

AI总结:

针对静态预训练代码模型难以捕捉动态程序属性的问题,提出结合执行轨迹的执行感知预训练策略TRACED,在多个代码理解任务上显著优于静态预训练模型。

摘要:

现有的大多数源代码预训练语言模型专注于学习静态代码文本,通常还会辅以静态代码结构(如抽象语法树、依赖图等)。然而,程序语义在实际执行前无法被完全揭示。若不理解程序执行过程,静态预训练模型无法全面捕捉动态代码属性,例如分支覆盖率和运行时变量值,因此在代码理解任务(如语义克隆检索、软件漏洞检测)中的效果较差。\n为弥合语言模型的静态特性与程序动态特征之间的差距,我们提出了TRACED——一种面向源代码的执行感知预训练策略。具体而言,我们结合源代码、可执行输入及对应的执行轨迹来预训练代码语言模型。我们的目标是在预训练阶段让代码模型学习复杂的执行逻辑,使模型在下游任务微调过程中无需重复执行代码,就能静态估算动态代码属性。\n为验证所提方法的有效性,我们在三个下游任务上对TRACED进行微调与评估:静态执行估算、克隆检索和漏洞检测。实验结果表明,在完整执行路径预测任务上,TRACED相比静态预训练代码模型相对提升12.4%;在运行时变量值预测任务上相对提升25.2%。在四个公开基准上,TRACED在克隆检索和漏洞检测任务中也显著优于静态预训练模型。

英文摘要:

Most existing pre-trained language models for source code focus on learning the static code text, typically augmented with static code structures (abstract syntax tree, dependency graphs, etc.). However, program semantics will not be fully exposed before the real execution. Without an understanding of the program execution, statically pre-trained models fail to comprehensively capture the dynamic code properties, such as the branch coverage and the runtime variable values, and they are consequently less effective at code understanding tasks, such as retrieving semantic clones and detecting software vulnerabilities. To close the gap between the static nature of language models and the dynamic characteristics of programs, we introduce TRACED, an execution-aware pre-training strategy for source code. Specifically, we pre-train code language models with a combination of source code, executable inputs, and corresponding execution traces. Our goal is to teach code models the complicated execution logic during the pre-training, enabling the model to statically estimate the dynamic code properties without repeatedly executing code during task-specific fine-tuning. To illustrate the effectiveness of our proposed approach, we fine-tune and evaluate TRACED on three downstream tasks: static execution estimation, clone retrieval, and vulnerability detection. The empirical results show that TRACED relatively improves the statically pre-trained code models by 12.4% for complete execution path prediction and by 25.2% for runtime variable value predictions. TRACED also significantly outperforms statically pre-trained models in clone retrieval and vulnerability detection across four public benchmarks.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑