Promptly porting patches from a source codebase to its variants (e.g., forks and branches) is essential for mitigating propagated defects and vulnerabilities. Recent studies have explored automated patch porting to reduce manual effort and delay, but existing approaches mainly handle inconsistencies visible in a patch's local context and struggle with those requiring global mapping knowledge between codebases. We refer to such non-local inconsistencies as implicit inconsistencies. Implicit inconsistencies pose greater challenges for developers to resolve due to their non-local nature. To address them, we propose MIP, which enables collaboration among an LLM, a compiler, and code analysis utilities. MIP adopts different strategies for different cases: when source identifiers exist in the target codebase, it leverages compiler diagnostics; otherwise, it retrieves matched code segment pairs from the two codebases as mapping knowledge for mitigation. Experiments on two representative scenarios, cross-fork and cross-branch patch porting, show that MIP successfully resolves more than twice as many patches as the best-performing baseline in both settings. A user study with our industry partner further demonstrates its practical effectiveness.
翻译:及时将补丁从源代码库移植到其变体(如分支和派生版本)对于减轻传播的缺陷和漏洞至关重要。近期研究探索了自动化补丁移植以减少人工成本和延迟,但现有方法主要处理补丁局部上下文中可见的不一致,难以应对需要跨代码库全局映射知识的问题。我们将这类非局部不一致称为隐式不一致。由于其跨局部特性,隐式不一致给开发者带来更大的解决挑战。为此,我们提出MIP方法,该方法能够协调大语言模型、编译器和代码分析工具协同工作。MIP针对不同场景采用差异化策略:当源标识符在目标代码库中存在时,利用编译器诊断信息;否则,从两个代码库中检索匹配的代码段对作为映射知识进行缓解。在跨分支和跨派生版本补丁移植两类典型场景的实验表明,MIP在两个实验设置中成功解决的补丁数量均为最优基线的两倍以上。与行业合作伙伴开展的用户研究进一步验证了其实际有效性。