Skip to content

fix(c/cpp): macro shield no longer excludes a real function redefined later as a stub macro - #2251

Merged
squid-protocol merged 3 commits into
mainfrom
fix/cpp-2240-macro-shield
Aug 26, 2026
Merged

squid-protocol merged 3 commits into
mainfrom
fix/cpp-2240-macro-shield

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

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:

static void
validate_list(PyGC_Head *head, enum flagstates flags)
{ ... }
...
#define validate_list(x, y) do{}while(0)   // no-op stub for release builds

validate_list is a real function (ctags/tree-sitter both find it) but GitGalaxy missed it entirely.

Fix

Replaced the frozenset[str] of macro names with a dict[str, int] mapping name → position of its first #define, and only exclude a candidate when the matching #define appears before that candidate's own position in the file. The shield's original purpose (excluding a function-like macro invocation such as OPCODE(m_op) { case m_op: }) is preserved and covered by a dedicated regression test. Gated to lang_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 -- clean
  • crucible_check.py --mode both -- drift confined to expected global PageRank/spatial-coordinate ripple (cpython isn't even in this corpus; see golden_master_audit.json/golden_master_zero_dep_audit.json diffs, all Topological Coordinates -- no functional mismatches), blessed
  • tree_sitter_accuracy_audit.py --all --ci -- clean
  • tri_comparison_chart.py --all --ci -- clean

This touches a SHARED c/cpp helper (_slice_by_braces's macro shield), so the full --all --ci sweep (not just c/cpp) was run per repo convention.

🤖 Generated with Gemini (via agy), orchestrated and independently verified by Claude Code.

… 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]>
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
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.
@squid-protocol
squid-protocol merged commit f4d2229 into main Aug 26, 2026
28 checks passed
@squid-protocol
squid-protocol deleted the fix/cpp-2240-macro-shield branch August 26, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

c/cpp: KNOWN-MACRO SHIELD excludes real functions when the same name is later redefined as a no-op macro (#ifdef debug-fn / #else stub idiom)

1 participant