Skip to content

C/C++: single-argument function-defining macros are indexed under the wrong symbol, breaking call resolution #1373

Description

@Dshuishui

Summary

A function-defining macro whose only argument is the function name — FN_MACRO(name) { … } — is indexed under the wrong symbol, so calls to that function can't resolve. The multi-argument form MACRO(real_name, typed args…) was recovered in #1172; the single-argument form is still not covered.

Reproduction

#define NATIVE_FN(name) int name(void)
NATIVE_FN(get_version) { return 1; }        // the macro argument IS the function name
int use_it(void) { return get_version(); }  // calls the real name
int plain_func(void) { return 42; }         // control

After codegraph init (1.4.1, latest release; same on current main):

language / file source actual indexed name expected
C .c NATIVE_FN(get_version) (get_version) get_version
C++ .cpp NATIVE_FN(get_version) NATIVE_FN get_version
C/C++ int plain_func(void) plain_func ✅

Because the real function is never stored under get_version:

  • codegraph callers get_version → Symbol "get_version" not found;
  • the use_it → get_version call reference is failed.

So the call edge is actually broken — this is not just a cosmetic name.

Why the #1172 recovery doesn't cover it

recoverCppMacroDefinedName requires the macro to have at least two arguments (the name plus at least one typed parameter, to stay unambiguous):

if (!params || params.namedChildCount < 2) return undefined;

(c-cpp.ts) A single-argument macro has one parameter, so it never reaches recovery and the wrong name is kept.

Impact

Calls to macro-defined functions don't resolve (missing caller/callee edges), so any analysis that relies on the call graph silently drops these functions; consumers that derive a symbol key or filename from the name also carry the stray parentheses (C) or macro name (C++).

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions