aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2019-10-16 20:54:02 +0000
committernathan <nathan@138bc75d-0d04-0410-961f-82ee72b054a4>2019-10-16 20:54:02 +0000
commit94aa703cf508e1b342146676ee2da104628802b2 (patch)
tree6f0d2ae0a39a2d1121bc57871178ccfc458727a6
parentd60e1c4fc00b35a16c8e0776ff20cb8ab5355aac (diff)
gcc/cp/
* decl.c (cp_make_fname_decl): Set context to global namespace, outside functions. (builtin_function_1): Merge into ... (cxx_builtin_function): ... here. Nadger the decl before maybe copying it. Set the context. (cxx_builtin_function_ext_scope): Push to top level, then call cxx_builtin_function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/c++-modules@277081 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--ChangeLog.modules9
-rw-r--r--gcc/cp/decl.c81
2 files changed, 40 insertions, 50 deletions
diff --git a/ChangeLog.modules b/ChangeLog.modules
index 684f881f3a4..a76db68543f 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,6 +1,15 @@
2019-10-16 Nathan Sidwell <nathan@acm.org>
gcc/cp/
+ * decl.c (cp_make_fname_decl): Set context to global namespace,
+ outside functions.
+ (builtin_function_1): Merge into ...
+ (cxx_builtin_function): ... here. Nadger the decl before maybe
+ copying it. Set the context.
+ (cxx_builtin_function_ext_scope): Push to top level, then call
+ cxx_builtin_function.
+
+ gcc/cp/
* rtti.c (get_tinfo_desc): Set DECL_CONTEXT.
gcc/testsuite/
* g++.dg/modules/tinfo-1.C: New.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ce1946f0c01..9e173b6744b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -71,7 +71,6 @@ static tree grokvardecl (tree, tree, tree, const cp_decl_specifier_seq *,
int, int, int, bool, int, tree, location_t);
static void check_static_variable_definition (tree, tree);
static void record_unknown_type (tree, const char *);
-static tree builtin_function_1 (tree, tree, bool);
static int member_function_or_else (tree, tree, enum overload_flags);
static tree local_variable_p_walkfn (tree *, int *, void *);
static const char *tag_name (enum tag_types);
@@ -4645,7 +4644,9 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
free (CONST_CAST (char *, name));
/* As we're using pushdecl_with_scope, we must set the context. */
- DECL_CONTEXT (decl) = current_function_decl;
+ DECL_CONTEXT (decl) = (current_function_decl
+ ? current_function_decl
+ : FROB_CONTEXT (global_namespace));
TREE_READONLY (decl) = 1;
DECL_ARTIFICIAL (decl) = 1;
@@ -4678,12 +4679,13 @@ cp_make_fname_decl (location_t loc, tree id, int type_dep)
return decl;
}
-static tree
-builtin_function_1 (tree decl, tree context, bool is_global)
-{
- tree id = DECL_NAME (decl);
- const char *name = IDENTIFIER_POINTER (id);
+/* Install DECL as a builtin function at current global scope. Return
+ the new decl (if we found an existing version). Also installs it
+ into ::std, if it's not '_*'. */
+tree
+cxx_builtin_function (tree decl)
+{
retrofit_lang_decl (decl);
DECL_ARTIFICIAL (decl) = 1;
@@ -4693,47 +4695,35 @@ builtin_function_1 (tree decl, tree context, bool is_global)
DECL_VISIBILITY (decl) = VISIBILITY_DEFAULT;
DECL_VISIBILITY_SPECIFIED (decl) = 1;
- DECL_CONTEXT (decl) = context;
-
- /* A function in the user's namespace should have an explicit
- declaration before it is used. Mark the built-in function as
- anticipated but not actually declared. */
+ tree id = DECL_NAME (decl);
+ const char *name = IDENTIFIER_POINTER (id);
if (name[0] != '_' || name[1] != '_')
+ /* In the user's namespace, it must be declared before use. */
+ DECL_ANTICIPATED (decl) = 1;
+ else if (IDENTIFIER_LENGTH (id) > strlen ("___chk")
+ && 0 != strncmp (name + 2, "builtin_", strlen ("builtin_"))
+ && 0 == memcmp (name + IDENTIFIER_LENGTH (id) - strlen ("_chk"),
+ "_chk", strlen ("_chk") + 1))
+ /* Treat __*_chk fortification functions as anticipated as well,
+ unless they are __builtin_*_chk. */
DECL_ANTICIPATED (decl) = 1;
- else if (strncmp (name + 2, "builtin_", strlen ("builtin_")) != 0)
- {
- size_t len = strlen (name);
-
- /* Treat __*_chk fortification functions as anticipated as well,
- unless they are __builtin_*. */
- if (len > strlen ("___chk")
- && memcmp (name + len - strlen ("_chk"),
- "_chk", strlen ("_chk") + 1) == 0)
- DECL_ANTICIPATED (decl) = 1;
- }
-
- if (is_global)
- return pushdecl_top_level (decl);
- else
- return pushdecl (decl);
-}
-tree
-cxx_builtin_function (tree decl)
-{
- tree id = DECL_NAME (decl);
- const char *name = IDENTIFIER_POINTER (id);
/* All builtins that don't begin with an '_' should additionally
go in the 'std' namespace. */
if (name[0] != '_')
{
- tree decl2 = copy_node(decl);
+ tree std_decl = copy_decl (decl);
+
push_nested_namespace (std_node);
- builtin_function_1 (decl2, std_node, false);
+ DECL_CONTEXT (std_decl) = FROB_CONTEXT (std_node);
+ pushdecl (std_decl);
pop_nested_namespace (std_node);
}
- return builtin_function_1 (decl, NULL_TREE, false);
+ DECL_CONTEXT (decl) = FROB_CONTEXT (global_namespace);
+ decl = pushdecl (decl);
+
+ return decl;
}
/* Like cxx_builtin_function, but guarantee the function is added to the global
@@ -4745,20 +4735,11 @@ cxx_builtin_function (tree decl)
tree
cxx_builtin_function_ext_scope (tree decl)
{
+ push_nested_namespace (global_namespace);
+ decl = cxx_builtin_function (decl);
+ pop_nested_namespace (global_namespace);
- tree id = DECL_NAME (decl);
- const char *name = IDENTIFIER_POINTER (id);
- /* All builtins that don't begin with an '_' should additionally
- go in the 'std' namespace. */
- if (name[0] != '_')
- {
- tree decl2 = copy_node(decl);
- push_nested_namespace (std_node);
- builtin_function_1 (decl2, std_node, true);
- pop_nested_namespace (std_node);
- }
-
- return builtin_function_1 (decl, NULL_TREE, true);
+ return decl;
}
/* Generate a FUNCTION_DECL with the typical flags for a runtime library