Add the trivial methods for the expansion of these macros with: c_alignas, c_alignof, c_generic_selections and c_static_assert. Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@xxxxxxxxx> --- ident-list.h | 4 ++ pre-process.c | 54 +++++++++++++++++++++++++++ validation/preprocessor/has-feature.c | 1 - 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/ident-list.h b/ident-list.h index 75740b9d9f77..a3a282587c67 100644 --- a/ident-list.h +++ b/ident-list.h @@ -61,6 +61,10 @@ IDENT(defined); IDENT(once); IDENT(__has_attribute); IDENT(__has_builtin); +IDENT(c_alignas); +IDENT(c_alignof); +IDENT(c_generic_selections); +IDENT(c_static_assert); __IDENT(pragma_ident, "__pragma__", 0); __IDENT(__VA_ARGS___ident, "__VA_ARGS__", 0); __IDENT(__func___ident, "__func__", 0); diff --git a/pre-process.c b/pre-process.c index d2e13400711e..7a39b1715f31 100644 --- a/pre-process.c +++ b/pre-process.c @@ -2003,6 +2003,58 @@ static int handle_nondirective(struct stream *stream, struct token **line, struc return 1; } +static bool expand_has_extension(struct token *token, struct arg *args) +{ + struct token *arg = args[0].expanded; + struct ident *ident; + bool val = false; + + if (token_type(arg) != TOKEN_IDENT) { + sparse_error(arg->pos, "identifier expected"); + return false; + } + + ident = arg->ident; + if (ident == &c_alignas_ident) + val = true; + else if (ident == &c_alignof_ident) + val = true; + else if (ident == &c_generic_selections_ident) + val = true; + else if (ident == &c_static_assert_ident) + val = true; + + replace_with_bool(token, val); + return 1; +} + +static bool expand_has_feature(struct token *token, struct arg *args) +{ + struct token *arg = args[0].expanded; + struct ident *ident; + bool val = false; + + if (token_type(arg) != TOKEN_IDENT) { + sparse_error(arg->pos, "identifier expected"); + return false; + } + + ident = arg->ident; + if (standard >= STANDARD_C11) { + if (ident == &c_alignas_ident) + val = true; + else if (ident == &c_alignof_ident) + val = true; + else if (ident == &c_generic_selections_ident) + val = true; + else if (ident == &c_static_assert_ident) + val = true; + } + + replace_with_bool(token, val); + return 1; +} + static void create_arglist(struct symbol *sym, int count) { struct token *token; @@ -2081,6 +2133,8 @@ static void init_preprocessor(void) { "__TIME__", expand_time }, { "__COUNTER__", expand_counter }, { "__INCLUDE_LEVEL__", expand_include_level }, + { "__has_extension", NULL, expand_has_extension }, + { "__has_feature", NULL, expand_has_feature }, }; for (i = 0; i < ARRAY_SIZE(normal); i++) { diff --git a/validation/preprocessor/has-feature.c b/validation/preprocessor/has-feature.c index 3ab7c3e039fa..e0f2e7f63cda 100644 --- a/validation/preprocessor/has-feature.c +++ b/validation/preprocessor/has-feature.c @@ -12,7 +12,6 @@ __has_feature()??? Quesako? /* * check-name: has-feature * check-command: sparse -E $file - * check-known-to-fail * * check-output-start -- 2.27.0