From ad1539d5555a161cf6851de8995641d6dfe792d9 Mon Sep 17 00:00:00 2001 From: Martin Sebor Date: Mon, 28 Oct 2019 22:46:28 +0000 Subject: 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 --- libcpp/include/cpplib.h | 6 +++++- libcpp/init.c | 4 +++- libcpp/macro.c | 4 ++++ libcpp/traditional.c | 6 +++--- 4 files changed, 15 insertions(+), 5 deletions(-) (limited to 'libcpp') diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 224369b..c655d3f 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -676,6 +676,9 @@ struct cpp_callbacks /* Callback to identify whether an attribute exists. */ int (*has_attribute) (cpp_reader *); + /* Callback to determine whether a built-in function is recognized. */ + int (*has_builtin) (cpp_reader *); + /* Callback that can change a user lazy into normal macro. */ void (*user_lazy_macro) (cpp_reader *, cpp_macro *, unsigned); @@ -855,7 +858,8 @@ enum cpp_builtin_type BT_PRAGMA, /* `_Pragma' operator */ BT_TIMESTAMP, /* `__TIMESTAMP__' */ BT_COUNTER, /* `__COUNTER__' */ - BT_HAS_ATTRIBUTE /* `__has_attribute__(x)' */ + BT_HAS_ATTRIBUTE, /* `__has_attribute__(x)' */ + BT_HAS_BUILTIN /* `__has_builtin(x)' */ }; #define CPP_HASHNODE(HNODE) ((cpp_hashnode *) (HNODE)) diff --git a/libcpp/init.c b/libcpp/init.c index 4bcec7b..b094317 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -403,6 +403,7 @@ static const struct builtin_macro builtin_array[] = B("__COUNTER__", BT_COUNTER, true), B("__has_attribute", BT_HAS_ATTRIBUTE, true), B("__has_cpp_attribute", BT_HAS_ATTRIBUTE, true), + B("__has_builtin", BT_HAS_BUILTIN, true), /* Keep builtins not used for -traditional-cpp at the end, and update init_builtins() if any more are added. */ B("_Pragma", BT_PRAGMA, true), @@ -483,7 +484,8 @@ cpp_init_special_builtins (cpp_reader *pfile) for (b = builtin_array; b < builtin_array + n; b++) { - if (b->value == BT_HAS_ATTRIBUTE + if ((b->value == BT_HAS_ATTRIBUTE + || b->value == BT_HAS_BUILTIN) && (CPP_OPTION (pfile, lang) == CLK_ASM || pfile->cb.has_attribute == NULL)) continue; diff --git a/libcpp/macro.c b/libcpp/macro.c index 30d3686..eb8321f 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -568,6 +568,10 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, case BT_HAS_ATTRIBUTE: number = pfile->cb.has_attribute (pfile); break; + + case BT_HAS_BUILTIN: + number = pfile->cb.has_builtin (pfile); + break; } if (result == NULL) diff --git a/libcpp/traditional.c b/libcpp/traditional.c index f1e7279..54738e8 100644 --- a/libcpp/traditional.c +++ b/libcpp/traditional.c @@ -326,9 +326,9 @@ static inline bool fun_like_macro (cpp_hashnode *node) { if (cpp_builtin_macro_p (node)) - return node->value.builtin == BT_HAS_ATTRIBUTE; - else - return node->value.macro->fun_like; + return (node->value.builtin == BT_HAS_ATTRIBUTE + || node->value.builtin == BT_HAS_BUILTIN); + return node->value.macro->fun_like; } /* Set up state for finding the opening '(' of a function-like -- cgit v1.1