weggli icon indicating copy to clipboard operation
weggli copied to clipboard

Weggli fails to see call in #define in header files

Open pengwinsurf opened this issue 1 year ago • 1 comments

Hi,

I am trying to use weggli to check of usages of an API call.

The API call is wrapped in a macro

#define wrapper_call(arg1) foo(arg1)

When I try to search for foo

weggli foo src/ --unique

It doesn't see the foo usage in that macro.

Can anyone who ran into a similar issue perhaps if this is expected behaviour ?

pengwinsurf avatar Jan 23 '24 20:01 pengwinsurf

weggli operates on the raw sources (so before any preprocessing takes place). At this stage, a preprocessor macro is comparable to a plain search-and-replace operation. This means that foo in this context has no additional meaning (it is just text). Here, you'd search for the wrapper_call instead (as this is used as an call identifier from wegglis point of view):

#define wrapper_call(arg1) foo(arg1)

void helloworld() {
  for (int i = 0; i < 10; i++) {
    printf("Hello World: %d\n", wrapper_call(i));
  }
}

image

If you really need to have the preprocessor macros resolved, you would need to run the source code through a compiler first. For example with gcc -E:

$ gcc -E /tmp/test.c 
# 0 "/tmp/test.c"
# 0 "<built-in>"
# 0 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 0 "<command-line>" 2
# 1 "/tmp/test.c"


void helloworld() {
  for (int i = 0; i < 10; i++) {
    printf("Hello World: %d\n", foo(i));
  }
}

bluec0re avatar Jan 30 '24 08:01 bluec0re