feat: treat unknown macros with arguments as undefined

This commit is contained in:
Jonathan M. Wilbur 2024-07-30 08:54:00 -04:00
parent 08a4c52de3
commit c85eface68
2 changed files with 27 additions and 0 deletions

14
tccpp.c
View file

@ -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;
}

13
tests/undef_func_macro.c Normal file
View file

@ -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
}