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 | |
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')
-rw-r--r-- | gcc/c/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c/c-decl.c | 28 |
2 files changed, 33 insertions, 0 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog index 4b051188..087090f 100644 --- a/gcc/c/ChangeLog +++ b/gcc/c/ChangeLog @@ -1,3 +1,8 @@ +2019-10-28 Martin Sebor <msebor@redhat.com> + + PR c/66970 + * c-decl.c (names_builtin_p): Define a new function. + 2019-10-28 Richard Biener <rguenther@suse.de> PR c/92249 diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index c6c4a4d..e76ed26 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -9990,6 +9990,34 @@ identifier_global_value (tree t) return NULL_TREE; } +/* Returns true if NAME refers to a built-in function or function-like + operator. */ + +bool +names_builtin_p (const char *name) +{ + tree id = get_identifier (name); + if (tree decl = identifier_global_value (id)) + return TREE_CODE (decl) == FUNCTION_DECL && DECL_IS_BUILTIN (decl); + + /* Also detect common reserved C words that aren't strictly built-in + functions. */ + switch (C_RID_CODE (id)) + { + case RID_BUILTIN_CONVERTVECTOR: + case RID_BUILTIN_HAS_ATTRIBUTE: + case RID_BUILTIN_SHUFFLE: + case RID_CHOOSE_EXPR: + case RID_OFFSETOF: + case RID_TYPES_COMPATIBLE_P: + return true; + default: + break; + } + + return false; +} + /* In C, the only C-linkage public declaration is at file scope. */ tree |