SemLoc:将 LLM 自由形式推理结构化为可执行约束用于故障定位
SemLoc: Structured Grounding of Free-Form LLM Reasoning for Fault Localization
AI 导读
SemLoc 把 LLM 的自由形式推理转化为可执行的语义约束,插入运行时检查并结合反事实验证来定位代码缺陷。在 QuixBugs 和含 809 个真实缺陷的 SemBugs 数据集上,99.4% 的约束可成为运行时检查,约束违规将故障行排第一的比例达 40.9%,高于频谱定位的 2.2% 和 Daikon 的 7.0%。
正文 · 原文
Abstract:Large language models (LLMs) can describe what a piece of code should compute, but they do so in free-form text. Such text cannot be checked against program executions, and it does not reveal whether a statement is correct. We present SemLoc, which turns LLM reasoning into executable, verifiable semantic constraints. With structured semantic grounding, the LLM writes each property as a constraint with a fixed category, attached to an anchor in the code graph, such as a variable definition, branch, loop, or return. SemLoc inserts each constraint as a runtime check and runs the tests, which yields a semantic violation spectrum over passing and failing tests. Counterfactual verification then patches the code at an anchor and reruns the tests; a patch that a constraint suggests counts as verified only if all tests then pass.
We study SemLoc on fault localization, where the tests serve as the oracle for verification, with four LLMs on QuixBugs and on SemBugs, a new dataset of 809 real bugs from 750 GitHub projects. The constraints are executable: 99.4% become runtime checks, and on programs where coverage ties the faulty line with at least half of the covered lines, their violations alone rank it first in 40.9% of the cases, compared with 2.2% for spectrum-based fault localization and 7.0% for Daikon invariants. They make the LLM's answers verifiable: 68.4% of SemLoc's top-ranked answers carry a patch that the tests confirm, and 93.6% of these are correct, which the LLM's own confidence cannot match. SemLoc's first-rank accuracy does not differ significantly, for any of the four LLMs, from that of an LLM given the same inputs (81.4% vs. 82.0%), and it far exceeds that of an LLM that sees only the function (50.0%).
| Subjects: | Software Engineering (cs.SE); Artificial Intelligence (cs.AI) |
| ACM classes: | K.6.3; D.2.5 |
| Cite as: | arXiv:2603.29109 [cs.SE] |
| (or arXiv:2603.29109v2 [cs.SE] for this version) | |
| https://doi.org/10.48550/arXiv.2603.29109 arXiv-issued DOI via DataCite |
Submission history
From: Zhaorui Yang [view email]
[v1]
Tue, 31 Mar 2026 00:56:43 UTC (1,087 KB)
[v2]
Tue, 27 Oct 2026 03:31:22 UTC (345 KB)
来源:arXiv cs.AI · arxiv.org