Repository navigation
fix(c/cpp): macro shield no longer excludes a real function redefined later as a stub macro - #2251
Merged
Merged
Conversation
… later as a stub macro The KNOWN-MACRO SHIELD collected every `#define NAME(` in the whole file with no positional awareness, then unconditionally skipped any candidate function match whose name appeared anywhere in that set -- including a real function defined BEFORE a same-named `#define`. CPython's common debug-build idiom (a real function, later redefined as a no-op stub for release builds) tripped this, swallowing the real definition entirely. Replaced the frozenset of macro names with a dict mapping name -> first `#define` position, and only exclude a candidate when the matching `#define` appears before that candidate's own position. The original protected case (a function-like macro invocation appearing after its `#define`) is preserved and covered by a new regression test. Confirmed on language-crucible's cpython/gc.c: validate_list, gc_list_validate_space, validate_spaces, validate_consistent_old_space went from missing to found (100 -> 104 functions detected in that file). Closes #2240 Co-Authored-By: Claude Sonnet 5 <[email protected]>
Contributor
squid-protocol
enabled auto-merge (squash)
August 26, 2026 13:34
…ield # Conflicts: # tests/golden_master_audit.json # tests/golden_master_zero_dep_audit.json
Regenerates golden_master_audit.json / golden_master_zero_dep_audit.json on top of the merged main (which already includes #2238's blessed baseline) plus this branch's own c/cpp macro-shield fix, so both are reflected together.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2240.
detector.py's KNOWN-MACRO SHIELD collected every#define NAME(in the whole file with no positional awareness, then unconditionally excluded any candidate function match whose name appeared anywhere in that set -- including a real function defined before a same-named#define. CPython's common debug-build idiom trips this:validate_listis a real function (ctags/tree-sitter both find it) but GitGalaxy missed it entirely.Fix
Replaced the
frozenset[str]of macro names with adict[str, int]mapping name → position of its first#define, and only exclude a candidate when the matching#defineappears before that candidate's own position in the file. The shield's original purpose (excluding a function-like macro invocation such asOPCODE(m_op) { case m_op: }) is preserved and covered by a dedicated regression test. Gated tolang_id in ("c", "cpp"), unchanged scope.Evidence
Real corpus check on
language-crucible/data/c/cpython/gc.c: 100 → 104 functions detected. The 4 newly-found:validate_list,gc_list_validate_space,validate_spaces,validate_consistent_old_space.Verification
pytest tests/extraction/languages/test_c.py tests/extraction/languages/test_cpp.py -q-- 94 passed (6 new regression tests: prior-definition-preserved x2, original-invocation-still-excluded x2, macro-only-still-excluded x2)audit_check.py --ci-- cleancrucible_check.py --mode both-- drift confined to expected global PageRank/spatial-coordinate ripple (cpython isn't even in this corpus; seegolden_master_audit.json/golden_master_zero_dep_audit.jsondiffs, allTopological Coordinates-- no functional mismatches), blessedtree_sitter_accuracy_audit.py --all --ci-- cleantri_comparison_chart.py --all --ci-- cleanThis touches a SHARED c/cpp helper (
_slice_by_braces's macro shield), so the full--all --cisweep (not just c/cpp) was run per repo convention.🤖 Generated with Gemini (via
agy), orchestrated and independently verified by Claude Code.