diff options
author | Martin Sebor <msebor@redhat.com> | 2019-10-28 22:46:28 +0000 |
---|---|---|
committer | Martin Sebor <msebor@gcc.gnu.org> | 2019-10-28 16:46:28 -0600 |
commit | ad1539d5555a161cf6851de8995641d6dfe792d9 (patch) | |
tree | e56e9d15ba5ff4476a38e5269c6163b5dc6a36e9 /gcc/c-family | |
parent | 48b2123f6336ba6c06846d7c8b60bd14eaeae7ec (diff) | |
download | gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.zip gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.tar.gz gcc-ad1539d5555a161cf6851de8995641d6dfe792d9.tar.bz2 |
PR c/66970 - Add __has_builtin() macro
gcc/ChangeLog:
PR c/66970
* doc/cpp.texi (__has_builtin): Document.
* doc/extend.texi (__builtin_frob_return_addr): Correct spelling.
gcc/c/ChangeLog:
PR c/66970
* c-decl.c (names_builtin_p): Define a new function.
gcc/c-family/ChangeLog:
PR c/66970
* c-common.c (c_common_nodes_and_builtins): Call c_define_builtins
even when only preprocessing.
* c-common.h (names_builtin_p): Declare new function.
* c-lex.c (init_c_lex): Set has_builtin.
(c_common_has_builtin): Define a new function.
* c-ppoutput.c (init_pp_output): Set has_builtin.
gcc/cp/ChangeLog:
PR c/66970
* cp-objcp-common.c (names_builtin_p): Define new function.
gcc/testsuite/ChangeLog:
PR c/66970
* c-c++-common/cpp/has-builtin-2.c: New test.
* c-c++-common/cpp/has-builtin-3.c: New test.
* c-c++-common/cpp/has-builtin.c: New test.
From-SVN: r277544
Diffstat (limited to 'gcc/c-family')
-rw-r--r-- | gcc/c-family/ChangeLog | 10 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 3 | ||||
-rw-r--r-- | gcc/c-family/c-common.h | 2 | ||||
-rw-r--r-- | gcc/c-family/c-lex.c | 53 | ||||
-rw-r--r-- | gcc/c-family/c-ppoutput.c | 1 |
5 files changed, 67 insertions, 2 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 3b3d574..cfefb8e 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,13 @@ +2019-10-28 Martin Sebor <msebor@redhat.com> + + PR c/66970 + * c-common.c (c_common_nodes_and_builtins): Call c_define_builtins + even when only preprocessing. + * c-common.h (names_builtin_p): Declare new function. + * c-lex.c (init_c_lex): Set has_builtin. + (c_common_has_builtin): Define a new function. + * c-ppoutput.c (init_pp_output): Set has_builtin. + 2019-10-24 Jakub Jelinek <jakub@redhat.com> * c-common.h (c_omp_context_selector_matches): Remove. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 483d874..79c047c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -4468,8 +4468,7 @@ c_common_nodes_and_builtins (void) va_list_ref_type_node = build_reference_type (va_list_type_node); } - if (!flag_preprocess_only) - c_define_builtins (va_list_ref_type_node, va_list_arg_type_node); + c_define_builtins (va_list_ref_type_node, va_list_arg_type_node); main_identifier_node = get_identifier ("main"); diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 7077183..42426ef 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -801,6 +801,7 @@ extern void c_register_addr_space (const char *str, addr_space_t as); extern bool in_late_binary_op; extern const char *c_addr_space_name (addr_space_t as); extern tree identifier_global_value (tree); +extern bool names_builtin_p (const char *); extern tree c_linkage_bindings (tree); extern void record_builtin_type (enum rid, const char *, tree); extern tree build_void_list_node (void); @@ -1022,6 +1023,7 @@ extern bool c_cpp_diagnostic (cpp_reader *, enum cpp_diagnostic_level, const char *, va_list *) ATTRIBUTE_GCC_DIAG(5,0); extern int c_common_has_attribute (cpp_reader *); +extern int c_common_has_builtin (cpp_reader *); extern bool parse_optimize_options (tree, bool); diff --git a/gcc/c-family/c-lex.c b/gcc/c-family/c-lex.c index fb05b5f..42010a7 100644 --- a/gcc/c-family/c-lex.c +++ b/gcc/c-family/c-lex.c @@ -81,6 +81,7 @@ init_c_lex (void) cb->valid_pch = c_common_valid_pch; cb->read_pch = c_common_read_pch; cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; cb->get_source_date_epoch = cb_get_source_date_epoch; cb->get_suggestion = cb_get_suggestion; cb->remap_filename = remap_macro_filename; @@ -386,6 +387,58 @@ c_common_has_attribute (cpp_reader *pfile) return result; } + +/* Callback for has_builtin. */ + +int +c_common_has_builtin (cpp_reader *pfile) +{ + const cpp_token *token = get_token_no_padding (pfile); + if (token->type != CPP_OPEN_PAREN) + { + cpp_error (pfile, CPP_DL_ERROR, + "missing '(' after \"__has_builtin\""); + return 0; + } + + const char *name = ""; + token = get_token_no_padding (pfile); + if (token->type == CPP_NAME) + { + name = (const char *) cpp_token_as_text (pfile, token); + token = get_token_no_padding (pfile); + if (token->type != CPP_CLOSE_PAREN) + { + cpp_error (pfile, CPP_DL_ERROR, + "expected ')' after \"%s\"", name); + name = ""; + } + } + else + { + cpp_error (pfile, CPP_DL_ERROR, + "macro \"__has_builtin\" requires an identifier"); + if (token->type == CPP_CLOSE_PAREN) + return 0; + } + + /* Consume tokens up to the closing parenthesis, including any nested + pairs of parentheses, to avoid confusing redundant errors. */ + for (unsigned nparen = 1; ; token = get_token_no_padding (pfile)) + { + if (token->type == CPP_OPEN_PAREN) + ++nparen; + else if (token->type == CPP_CLOSE_PAREN) + --nparen; + else if (token->type == CPP_EOF) + break; + if (!nparen) + break; + } + + return names_builtin_p (name); +} + /* Read a token and return its type. Fill *VALUE with its value, if applicable. Fill *CPP_FLAGS with the token's flags, if it is diff --git a/gcc/c-family/c-ppoutput.c b/gcc/c-family/c-ppoutput.c index 5f39198..91fabc7 100644 --- a/gcc/c-family/c-ppoutput.c +++ b/gcc/c-family/c-ppoutput.c @@ -151,6 +151,7 @@ init_pp_output (FILE *out_stream) } cb->has_attribute = c_common_has_attribute; + cb->has_builtin = c_common_has_builtin; cb->get_source_date_epoch = cb_get_source_date_epoch; cb->remap_filename = remap_macro_filename; |