Skip to content

Commit

Permalink
feat: treat unknown macros with arguments as undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanWilbur committed Jul 30, 2024
1 parent 08a4c52 commit c85efac
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
14 changes: 14 additions & 0 deletions tccpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1506,6 +1506,20 @@ static int expr_preprocess(TCCState *s1)
tokc.i = c;
} else {
/* if undefined macro, replace with zero */
next_nomacro();
// If the undefined macro is followed by parens, just skip them.
if (tok == '(') {
int bracket_depth = 1;
while (bracket_depth > 0) {
next();
if (tok == '(')
bracket_depth++;
else if (tok == ')')
bracket_depth--;
}
} else {
unget_tok(tok); // Is this actually the function I want?
}
tok = TOK_CINT;
tokc.i = 0;
}
Expand Down
13 changes: 13 additions & 0 deletions tests/undef_func_macro.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
int main () {
// This used to evaluate to 0 (0), which is invalid.
// Now it should evaluate to 0.
#if WUMBOED(WUMBO)
#endif

// Just trying a more complicated test case.
#if WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
return 0;
#elif WUMBO && defined(WUMBOLOGY) || WUMBOED(WUMBO) && !WUMBOLOGY
return 1;
#endif
}

0 comments on commit c85efac

Please sign in to comment.