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/cp/cp-objcp-common.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/cp/cp-objcp-common.c')
-rw-r--r-- | gcc/cp/cp-objcp-common.c | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index f38b4e8..60dcbe4 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -24,6 +24,7 @@ along with GCC; see the file COPYING3. If not see #include "cp-tree.h" #include "cp-objcp-common.h" #include "dwarf2.h" +#include "stringpool.h" /* Special routine to get the alias set for C++. */ @@ -348,6 +349,77 @@ identifier_global_value (tree name) return get_global_binding (name); } +/* 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 binding = get_global_binding (id)) + { + if (TREE_CODE (binding) == FUNCTION_DECL && DECL_IS_BUILTIN (binding)) + return true; + + /* Handle the case when an overload for a built-in name exists. */ + if (TREE_CODE (binding) != OVERLOAD) + return false; + + for (ovl_iterator it (binding); it; ++it) + { + tree decl = *it; + if (DECL_IS_BUILTIN (decl)) + return true; + } + } + + /* Also detect common reserved C++ words that aren't strictly built-in + functions. */ + switch (C_RID_CODE (id)) + { + case RID_ADDRESSOF: + case RID_BUILTIN_CONVERTVECTOR: + case RID_BUILTIN_HAS_ATTRIBUTE: + case RID_BUILTIN_SHUFFLE: + case RID_BUILTIN_LAUNDER: + case RID_OFFSETOF: + case RID_HAS_NOTHROW_ASSIGN: + case RID_HAS_NOTHROW_CONSTRUCTOR: + case RID_HAS_NOTHROW_COPY: + case RID_HAS_TRIVIAL_ASSIGN: + case RID_HAS_TRIVIAL_CONSTRUCTOR: + case RID_HAS_TRIVIAL_COPY: + case RID_HAS_TRIVIAL_DESTRUCTOR: + case RID_HAS_UNIQUE_OBJ_REPRESENTATIONS: + case RID_HAS_VIRTUAL_DESTRUCTOR: + case RID_IS_ABSTRACT: + case RID_IS_AGGREGATE: + case RID_IS_BASE_OF: + case RID_IS_CLASS: + case RID_IS_EMPTY: + case RID_IS_ENUM: + case RID_IS_FINAL: + case RID_IS_LITERAL_TYPE: + case RID_IS_POD: + case RID_IS_POLYMORPHIC: + case RID_IS_SAME_AS: + case RID_IS_STD_LAYOUT: + case RID_IS_TRIVIAL: + case RID_IS_TRIVIALLY_ASSIGNABLE: + case RID_IS_TRIVIALLY_CONSTRUCTIBLE: + case RID_IS_TRIVIALLY_COPYABLE: + case RID_IS_UNION: + case RID_IS_ASSIGNABLE: + case RID_IS_CONSTRUCTIBLE: + case RID_UNDERLYING_TYPE: + return true; + default: + break; + } + + return false; +} + /* Register c++-specific dumps. */ void |