From c16f5d2fe631f847b040f27122e9bfe4f91ce8ec Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Sat, 9 May 2020 00:39:45 +0200 Subject: [PATCH] Fake __has_include handling cctools for MacOS 10.14 (at least) unconditionally uses the __has_include preprocessor directive (i.e. without checking if defined __has_include as normally suggested for portable code). So we need to handle it a little bit. For now we simply say "nope" aka evaluate to 0. --- tccpp.c | 21 +++++++++++++++++++-- tcctok.h | 1 + 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/tccpp.c b/tccpp.c index 1cd6c999..f8b060bf 100644 --- a/tccpp.c +++ b/tccpp.c @@ -1450,6 +1450,7 @@ static int expr_preprocess(void) pp_expr = 1; while (tok != TOK_LINEFEED && tok != TOK_EOF) { next(); /* do macro subst */ + redo: if (tok == TOK_DEFINED) { next_nomacro(); t = tok; @@ -1467,10 +1468,26 @@ static int expr_preprocess(void) } tok = TOK_CINT; tokc.i = c; - } else if (tok >= TOK_IDENT) { - /* if undefined macro */ + } else if (1 && tok == TOK___HAS_INCLUDE) { + next(); /* XXX check if correct to use expansion */ + skip('('); + while (tok != ')' && tok != TOK_EOF) + next(); + if (tok != ')') + expect("')'"); tok = TOK_CINT; tokc.i = 0; + } else if (tok >= TOK_IDENT) { + /* if undefined macro, replace with zero, check for func-like */ + t = tok; + tok = TOK_CINT; + tokc.i = 0; + tok_str_add_tok(str); + next(); + if (tok == '(') + tcc_error("function-like macro '%s' is not defined", + get_tok_str(t, NULL)); + goto redo; } tok_str_add_tok(str); } diff --git a/tcctok.h b/tcctok.h index 7c2c2c14..ee18462d 100644 --- a/tcctok.h +++ b/tcctok.h @@ -91,6 +91,7 @@ DEF(TOK___FUNCTION__, "__FUNCTION__") DEF(TOK___VA_ARGS__, "__VA_ARGS__") DEF(TOK___COUNTER__, "__COUNTER__") + DEF(TOK___HAS_INCLUDE, "__has_include") /* special identifiers */ DEF(TOK___FUNC__, "__func__")