Repository navigation
fix(fortran): map source_location back through cpp linemarkers (#2092) - #2105
SinghAman21 wants to merge 2 commits into
Conversation
nothariharan
left a comment
There was a problem hiding this comment.
Diagnosis is right and the bug is live. On current v8, module shapes on L6 is reported as L1 and compute_volume() on L9 as L4, so cpp -P is still mislocating every symbol in a capital-F file.
The problem is that the change does not currently do what it says it does, and it needs a rebase.
v8 has moved _cpp_preprocess on since this branch was cut: #include directives are stripped and the sanitized source is fed to cpp on stdin, to close the arbitrary-read vector. That is what the diff conflicts with (fortran.py, test_cpp_preprocess.py, test_languages.py).
Once resolved onto that version, the linemarker mapping turns out to be dead code. With stdin input cpp emits # 1 "<stdin>", and _strip_linemarkers compares the decoded marker path against str(path.resolve()), so in_target is False on every row and line_map comes back all zeros. _orig_line then falls through to the preprocessed line. I checked this directly against a rebuilt merge: the map comes back [0, 0, ...] while the reported locations are still correct, because dropping -P alone is enough to make cpp preserve the line count.
So the fix works, but by dropping -P rather than by the machinery, and the mapping is silently inert as shipped against v8. That matters because the linemarkers are precisely what is supposed to rescue a line-count-changing case, and right now nothing exercises that path.
Could you rebase onto v8 and pick one of:
- match the stdin filename too (
<stdin>,-) so the map is actually populated, or - drop
_strip_linemarkers/_orig_lineentirely and state in the comment that line preservation now comes from not passing-P.
Either is fine, I just do not want the second option to look like it is doing something it is not.
Also the CHANGELOG entry lands under ## 0.9.24 (2026-07-22), already released, so it needs the unreleased heading.
…ify-Labs#2092) The preprocessor removes directives and inactive branches, so parser rows after them no longer identify the original Fortran lines. Keep cpp linemarkers and translate each emitted row back to the source line while continuing to pass sanitized source through stdin; passing a filename would re-open the include-read and option-injection risks addressed in current v8.
bee3db8 to
f4fc0fb
Compare
Add a real-cpp regression using #line to prove stdin linemarkers populate the original source map, rather than relying on preserved output row counts. Move the Graphify-Labs#2092 changelog entry into Unreleased.

What
Capital-F Fortran files (
.F.F90.F95.F03.F08) are run throughcpp,which was invoked with
-P.-Psuppresses linemarkers, and sincecppblanksdirective lines, drops inactive
#ifdefblocks, and collapses blank runs, theline numbers tree-sitter sees no longer match the original file.
Result: every symbol got a wrong
source_location— including files with nopreprocessor directives at all (blank-line collapse). A confidently wrong line
sends
explain/affected/ the MCP read surface to unrelated code.How
-Psocppkeeps its# <n> "<file>"linemarkers._cpp_preprocessnow returns(source, line_map);_strip_linemarkersconsumes the markers to build a preprocessed-line → original-line map and
hands tree-sitter marker-free source (blanks kept, so rows stay in lockstep).
add_node/add_edgetranslate each line through_orig_line.-nostdinc -I /dev/nullsecurity flags, and the raw-bytesfallback for lowercase
.f90and whencppis absent (line_map = None).Verified on the issue's example:
module solver→ L9,compute_volume→ L12,zebrafunc(after 5 blank lines) → L6.Files
graphify/extractors/fortran.py— run cpp without-P, parse linemarkers,translate node/edge lines.
tests/test_languages.py— 2 location tests (directive case + blank-line case).tests/test_cpp_preprocess.py— updated for the new(bytes, line_map)signature; keeps the argument-injection check and adds a
-Pguard.CHANGELOG.md— entry under0.9.24 (unreleased).Reference
.F/.F90/.F95/.F03/.F08file gets a wrongsource_location—cpp -Prenumbers lines with no way back #2092graphify/extractors/fortran.py(cpp -Pinvocation).Conclusion
Fortran symbols now report their true source line regardless of extension or
preprocessor directives. Full suite green (pre-existing unrelated
test_ollama_retry_cap.pyfailures aside).