From c85eface68940368f696807e97ac7d707e8a73eb Mon Sep 17 00:00:00 2001 From: "Jonathan M. Wilbur" Date: Tue, 30 Jul 2024 08:54:00 -0400 Subject: [PATCH] feat: treat unknown macros with arguments as undefined --- tccpp.c | 14 ++++++++++++++ tests/undef_func_macro.c | 13 +++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 tests/undef_func_macro.c diff --git a/tccpp.c b/tccpp.c index 6f2bc173..a59ba814 100644 --- a/tccpp.c +++ b/tccpp.c @@ -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; } diff --git a/tests/undef_func_macro.c b/tests/undef_func_macro.c new file mode 100644 index 00000000..00db8ad0 --- /dev/null +++ b/tests/undef_func_macro.c @@ -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 +} -- 2.11.4.GIT