Skip to content

Preprocessor macros interrupt argument extraction for C/C++ functions #1837

Closed

Description

@squid-protocol

name: Preprocessor macros interrupt argument extraction for C/C++ functions

Description

In gitgalaxy/core/detector.py, the regex-based argument extraction fails to correctly count arguments when the parameter list or the area immediately following the signature contains preprocessor directives like #ifdef, #else, and #endif.

Because GitGalaxy slices the args_search_text up to the first open brace { for C, functions whose signatures are duplicated across #if/#else blocks result in an args_search_text string containing multiple conflicting signatures mixed with preprocessor tokens. The strict args regex fails to parse these properly, leading to incorrect argument counts.

Impact

This causes a discrepancy between args_exact_match and args_comparable in C and C++, as GitGalaxy either returns args_count=0 or extracts arguments from the wrong preprocessor branch. Tree-sitter, on the other hand, evaluates the AST and can drop unparsed nodes or resolve the syntax more robustly.

Example

gc_mark_subtree in language-crucible/data/c/micropython/gc.c is defined as:

#if MICROPY_GC_SPLIT_HEAP
static void gc_mark_subtree(mp_state_mem_area_t *area, size_t block)
#else
static void gc_mark_subtree(size_t block)
#endif
{

GitGalaxy incorrectly extracts arguments due to the #else block intersecting the regex search space, leading to an argument mismatch compared to tree-sitter.

Proposed Fix

Implement a preprocessor stripping pass for C/C++ in args_search_text before applying the args_pattern, or update the args regex to tolerate and skip over #if, #else, and #endif boundaries when matching parameter lists.

Activity

  1. added
    bug
    core-engine
    testing
    on Aug 19, 2026
  2. squid-protocol commented on Aug 22, 2026

    @squid-protocol
    OwnerAuthor

    I have verified that this issue is already fully resolved.

    Commit 3bed75a4 introduced a specific re-slicing pass for C/C++ in detector.py (inside _slice_by_braces) that detects when a signature is duplicated across an #if/#else branch immediately preceding the function body (which is exactly the shape of gc_mark_subtree in micropython/gc.c). It isolates the #else branch by stripping everything before the last #else or #elif directive, provided the preceding text ended in a complete signature.

    As a result, GitGalaxy now correctly extracts 1 argument for gc_mark_subtree, matching Tree-sitter's output. The tree_sitter_accuracy_audit.py script confirms 100% argument exact match (1702/1702) for the C language-crucible test set.

    Closing this issue as it is already implemented and verified in main.

  3. 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-enginepriority: mediumtesting

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions