Skip to content

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) #2240

Closed

Description

@squid-protocol

Found during a tri-comparison ledger sweep of c/function/existence/agree[tree_sitter]_vs[gitgalaxy].

Confirmed real, currently-reproducing GitGalaxy defect. These real, ordinary static ... name(...) { ... } functions are missed entirely — both ctags and tree-sitter correctly find them, GitGalaxy doesn't:

  • ASSERT_DICT_LOCKED (cpython/dictobject.c:163)
  • validate_list, gc_list_validate_space, validate_spaces, validate_consistent_old_space (cpython/gc.c:393,437,447,459)
  • types_world_is_stopped, types_stop_world, types_start_world, type_lock_prevent_release, type_lock_allow_release (cpython/typeobject.c:89,123,132,143,165)

Root cause: gitgalaxy/core/detector.py's "KNOWN-MACRO SHIELD" (known_macro_names, built around line 2837 via re.finditer(r"^[ \t]*#[ \t]*define[ \t]+([A-Za-z_]\w*)\(", code, re.M), applied around line 3693 as if name in known_macro_names: continue) collects every #define NAME( in the whole file with no positional awareness — it doesn't check whether the #define comes before or after a real function definition of the same name. CPython's common debug-build idiom trips it:

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

The shield was written to stop a function-like macro invocation elsewhere in the file (e.g. OPCODE(m_op) { case m_op: }) from being misread as a definition, but it has no way to distinguish that from a real prior definition whose name happens to be redefined as a stub later.

Suggested fix: only apply the shield when the candidate match is itself shaped like a bare invocation (no preceding storage-class/return-type tokens), not a full static/inline ... name(...) { signature — or check that the #define doesn't sit inside the same conditional-compilation branch as the definition it's about to exclude.

Activity

  1. added
    bug
    core-engine
    threat: false-negative
    on Aug 26, 2026
  2. added this to the v2.4.9 milestone on Aug 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugcore-enginethreat: false-negative

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions