public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/c++-modules] Add DECL_LOCAL_DECL_P
@ 2020-09-14 12:54 Nathan Sidwell
0 siblings, 0 replies; only message in thread
From: Nathan Sidwell @ 2020-09-14 12:54 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:065650c9da2076d902599d20efcb8fe9162472db
commit 065650c9da2076d902599d20efcb8fe9162472db
Author: Nathan Sidwell <nathan@acm.org>
Date: Wed Sep 9 08:39:49 2020 -0700
Add DECL_LOCAL_DECL_P
gcc/cp/
* cp-tree.h (DECL_LOCAL_FUNCTION_P): Rename to ...
(DECL_LOCAL_DECL_P): ... here. Apply to VAR_DECLS too.
* decl.c (start_decl): Set DECL_LOCAL_DECL_P as approriate.
(start_decl_1): Reformat.
(omp_declare_variant_finalize_one): Use DECL_LOCAL_DECL_P.
(local_variable_p): Simplify.
* module.cc (trees_out::chained_decls): Stream DECL_LOCAL_DECL_P
by value.
(trees_out::get_merge_kind): DECL_LOCAL_DECL_P decls are unique.
* name-lookup.c (set_decl_context_in_fn): Assert DECL_LOCAL_DECL_P
as expected, don't set it here.
(do_pushdecl): Don't call it for friends or dependent types.
(is_local_extern): Simplify.
* parser.c (cp_parser_postfix_expression): Use DECL_LOCAL_DECL_P.
(cp_parser_omp_declare_reduction): Set DECL_LOCAL_DECL_P.
Refactor.
* pt.c (check_default_tmpl_args): Use DECL_LOCAL_DECL_P.
(tsubst_expr): Adjust omp reduction case.
(tsubst_omp_udr): Add comments.
(type_dependent_expression_p): Adjust.
* call.c (equal_functions): Adjust.
* semantics.c (finish_call_expr): Adjust.
libcc1/
* libcp1plugin.cc (plugin_build_call_expr): Use DECL_LOCAL_DECL_P.
Diff:
---
ChangeLog.modules | 29 +++++++++++++++++++++++++++++
gcc/cp/call.c | 2 +-
gcc/cp/cp-tree.h | 10 +++++-----
gcc/cp/decl.c | 36 +++++++++++++++++++-----------------
gcc/cp/module.cc | 19 ++++++++++++++++++-
gcc/cp/name-lookup.c | 48 ++++++++++++++----------------------------------
gcc/cp/parser.c | 25 ++++++++++++++-----------
gcc/cp/pt.c | 15 +++++++++++----
gcc/cp/semantics.c | 2 +-
libcc1/libcp1plugin.cc | 2 +-
10 files changed, 113 insertions(+), 75 deletions(-)
diff --git a/ChangeLog.modules b/ChangeLog.modules
index 5e87761e803..d66ea696519 100644
--- a/ChangeLog.modules
+++ b/ChangeLog.modules
@@ -1,3 +1,32 @@
+2020-09-09 Nathan Sidwell <nathan@acm.org>
+
+ DECL_LOCAL_DECL_P
+ gcc/cp/
+ * cp-tree.h (DECL_LOCAL_FUNCTION_P): Rename to ...
+ (DECL_LOCAL_DECL_P): ... here. Apply to VAR_DECLS too.
+ * decl.c (start_decl): Set DECL_LOCAL_DECL_P as approriate.
+ (start_decl_1): Reformat.
+ (omp_declare_variant_finalize_one): Use DECL_LOCAL_DECL_P.
+ (local_variable_p): Simplify.
+ * module.cc (trees_out::chained_decls): Stream DECL_LOCAL_DECL_P
+ by value.
+ (trees_out::get_merge_kind): DECL_LOCAL_DECL_P decls are unique.
+ * name-lookup.c (set_decl_context_in_fn): Assert DECL_LOCAL_DECL_P
+ as expected, don't set it here.
+ (do_pushdecl): Don't call it for friends or dependent types.
+ (is_local_extern): Simplify.
+ * parser.c (cp_parser_postfix_expression): Use DECL_LOCAL_DECL_P.
+ (cp_parser_omp_declare_reduction): Set DECL_LOCAL_DECL_P.
+ Refactor.
+ * pt.c (check_default_tmpl_args): Use DECL_LOCAL_DECL_P.
+ (tsubst_expr): Adjust omp reduction case.
+ (tsubst_omp_udr): Add comments.
+ (type_dependent_expression_p): Adjust.
+ * call.c (equal_functions): Adjust.
+ * semantics.c (finish_call_expr): Adjust.
+ libcc1/
+ * libcp1plugin.cc (plugin_build_call_expr): Use DECL_LOCAL_DECL_P.
+
2020-09-08 Nathan Sidwell <nathan@acm.org>
Change cxx_int_tree_map to cxx_decl_tree_map.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 61bbb38bd2b..5606389f4bd 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -3631,7 +3631,7 @@ equal_functions (tree fn1, tree fn2)
return 0;
if (TREE_CODE (fn1) == TEMPLATE_DECL)
return fn1 == fn2;
- if (DECL_LOCAL_FUNCTION_P (fn1) || DECL_LOCAL_FUNCTION_P (fn2)
+ if (DECL_LOCAL_DECL_P (fn1) || DECL_LOCAL_DECL_P (fn2)
|| DECL_EXTERN_C_FUNCTION_P (fn1))
return decls_match (fn1, fn2);
return fn1 == fn2;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index ce4045d5a89..4d2943246aa 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -517,7 +517,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
Usage of DECL_LANG_FLAG_?:
0: DECL_TEMPLATE_PARM_P (in PARM_DECL, CONST_DECL, TYPE_DECL, or TEMPLATE_DECL)
- DECL_LOCAL_FUNCTION_P (in FUNCTION_DECL)
+ DECL_LOCAL_DECL_P (in FUNCTION_DECL, VAR_DECL)
DECL_MUTABLE_P (in FIELD_DECL)
DECL_DEPENDENT_P (in USING_DECL)
LABEL_DECL_BREAK (in LABEL_DECL)
@@ -4185,10 +4185,10 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter)
#define TYPE_CONTAINS_VPTR_P(NODE) \
(TYPE_POLYMORPHIC_P (NODE) || CLASSTYPE_VBASECLASSES (NODE))
-/* Nonzero if NODE is a FUNCTION_DECL (for a function with global
- scope) declared in a local scope. */
-#define DECL_LOCAL_FUNCTION_P(NODE) \
- DECL_LANG_FLAG_0 (FUNCTION_DECL_CHECK (NODE))
+/* Nonzero if NODE is a FUNCTION_DECL or VARIABLE_DECL (for a decl
+ with namespace scope) declared in a local scope. */
+#define DECL_LOCAL_DECL_P(NODE) \
+ DECL_LANG_FLAG_0 (VAR_OR_FUNCTION_DECL_CHECK (NODE))
/* Nonzero if NODE is the target for genericization of 'break' stmts. */
#define LABEL_DECL_BREAK(NODE) \
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 13068f6a172..1560f1ea63c 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5256,8 +5256,8 @@ groktypename (cp_decl_specifier_seq *type_specifiers,
return type;
}
-/* Process a DECLARATOR for a function-scope variable declaration,
- namespace-scope variable declaration, or function declaration.
+/* Process a DECLARATOR for a function-scope or namespace-scope
+ variable or function declaration.
(Function definitions go through start_function; class member
declarations appearing in the body of the class go through
grokfield.) The DECL corresponding to the DECLARATOR is returned.
@@ -5467,6 +5467,12 @@ start_decl (const cp_declarator *declarator,
was_public = TREE_PUBLIC (decl);
+ if ((DECL_EXTERNAL (decl) || TREE_CODE (decl) == FUNCTION_DECL)
+ && current_function_decl)
+ /* A function-scope decl of some namespace-scope decl. */
+ // FIXME: This is ill-formed in a named module
+ DECL_LOCAL_DECL_P (decl) = true;
+
/* Enter this declaration into the symbol table. Don't push the plain
VAR_DECL for a variable template. */
if (!template_parm_scope_p ()
@@ -5534,20 +5540,17 @@ start_decl (const cp_declarator *declarator,
void
start_decl_1 (tree decl, bool initialized)
{
- tree type;
- bool complete_p;
- bool aggregate_definition_p;
-
- gcc_assert (!processing_template_decl);
+ gcc_checking_assert (!processing_template_decl);
if (error_operand_p (decl))
return;
- gcc_assert (VAR_P (decl));
+ gcc_checking_assert (VAR_P (decl));
- type = TREE_TYPE (decl);
- complete_p = COMPLETE_TYPE_P (type);
- aggregate_definition_p = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
+ tree type = TREE_TYPE (decl);
+ bool complete_p = COMPLETE_TYPE_P (type);
+ bool aggregate_definition_p
+ = MAYBE_CLASS_TYPE_P (type) && !DECL_EXTERNAL (decl);
/* If an explicit initializer is present, or if this is a definition
of an aggregate, then we need a complete type at this point.
@@ -5572,6 +5575,7 @@ start_decl_1 (tree decl, bool initialized)
: TCTX_STATIC_STORAGE);
verify_type_context (input_location, context, TREE_TYPE (decl));
}
+
if (initialized)
/* Is it valid for this decl to have an initializer at all? */
{
@@ -7405,7 +7409,7 @@ omp_declare_variant_finalize_one (tree decl, tree attr)
fn = STRIP_TEMPLATE (fn);
if (!((TREE_CODE (fn) == USING_DECL && DECL_DEPENDENT_P (fn))
|| DECL_FUNCTION_MEMBER_P (fn)
- || DECL_LOCAL_FUNCTION_P (fn)))
+ || DECL_LOCAL_DECL_P (fn)))
{
koenig_p = true;
if (!any_type_dependent_arguments_p (args))
@@ -13930,11 +13934,9 @@ int
local_variable_p (const_tree t)
{
if ((VAR_P (t)
- /* A VAR_DECL with a context that is a _TYPE is a static data
- member. */
- && !TYPE_P (CP_DECL_CONTEXT (t))
- /* Any other non-local variable must be at namespace scope. */
- && !DECL_NAMESPACE_SCOPE_P (t))
+ && (DECL_LOCAL_DECL_P (t)
+ || !DECL_CONTEXT (t)
+ || TREE_CODE (DECL_CONTEXT (t)) == FUNCTION_DECL))
|| (TREE_CODE (t) == PARM_DECL))
return 1;
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index a82c46ab7d0..cb8db32de51 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -4852,7 +4852,17 @@ void
trees_out::chained_decls (tree decls)
{
for (; decls; decls = DECL_CHAIN (decls))
- tree_node (decls);
+ {
+ if (TREE_CODE (decls) == VAR_DECL && DECL_LOCAL_DECL_P (decls))
+ {
+ /* Make sure this is the first encounter, and mark for
+ walk-by-value. */
+ gcc_checking_assert (!TREE_VISITED (decls)
+ && !DECL_TEMPLATE_INFO (decls));
+ mark_by_value (decls);
+ }
+ tree_node (decls);
+ }
tree_node (NULL_TREE);
}
@@ -6011,6 +6021,9 @@ trees_out::core_vals (tree t)
case BLOCK:
state->write_location (*this, t->block.locus);
state->write_location (*this, t->block.end_locus);
+
+ // FIXME:This contains VAR_DECLS and FN_DECLS with extern. Those
+ // should be first met here and walked by value
chained_decls (t->block.vars);
/* nonlocalized_vars is a middle-end thing. */
WT (t->block.subblocks);
@@ -9840,6 +9853,10 @@ trees_out::get_merge_kind (tree decl, depset *dep)
{
if (!dep)
{
+ if (TREE_CODE (decl) == VAR_DECL
+ && DECL_LOCAL_DECL_P (decl))
+ return MK_unique;
+
/* Either unique, or some member of a class that cannot have an
out-of-class definition. For instance a FIELD_DECL. */
tree ctx = CP_DECL_CONTEXT (decl);
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index b6625c09a3f..1a58bcfcb2d 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -3457,14 +3457,13 @@ check_local_shadow (tree decl)
static void
set_decl_context_in_fn (tree ctx, tree decl)
{
+ if (TREE_CODE (decl) == FUNCTION_DECL
+ || (VAR_P (decl) && DECL_EXTERNAL (decl)))
+ /* Make sure local externs are marked as such. */
+ gcc_checking_assert (DECL_LOCAL_DECL_P (decl)
+ && DECL_NAMESPACE_SCOPE_P (decl));
+
if (!DECL_CONTEXT (decl)
- /* A local declaration for a function doesn't constitute
- nesting. */
- && TREE_CODE (decl) != FUNCTION_DECL
- /* A local declaration for an `extern' variable is in the
- scope of the current namespace, not the current
- function. */
- && !(VAR_P (decl) && DECL_EXTERNAL (decl))
/* When parsing the parameter list of a function declarator,
don't set DECL_CONTEXT to an enclosing function. When we
push the PARM_DECLs in order to process the function body,
@@ -3473,12 +3472,6 @@ set_decl_context_in_fn (tree ctx, tree decl)
&& current_binding_level->kind == sk_function_parms
&& current_binding_level->this_entity == NULL))
DECL_CONTEXT (decl) = ctx;
-
- /* If this is the declaration for a namespace-scope function,
- but the declaration itself is in a local scope, mark the
- declaration. */
- if (TREE_CODE (decl) == FUNCTION_DECL && DECL_NAMESPACE_SCOPE_P (decl))
- DECL_LOCAL_FUNCTION_P (decl) = 1;
}
/* DECL is a local-scope decl with linkage. SHADOWED is true if the
@@ -3776,7 +3769,7 @@ do_pushdecl (tree decl, bool is_friend)
if (decl == error_mark_node)
return error_mark_node;
- if (!DECL_TEMPLATE_PARM_P (decl) && current_function_decl)
+ if (!DECL_TEMPLATE_PARM_P (decl) && current_function_decl && !is_friend)
set_decl_context_in_fn (current_function_decl, decl);
/* The binding level we will be pushing into. During local class
@@ -3822,7 +3815,8 @@ do_pushdecl (tree decl, bool is_friend)
}
if (current_function_decl && VAR_OR_FUNCTION_DECL_P (decl)
- && DECL_EXTERNAL (decl))
+ && DECL_EXTERNAL (decl)
+ && !dependent_type_p (TREE_TYPE (decl)))
set_local_extern_decl_linkage (decl, old != NULL_TREE);
if (old == error_mark_node)
@@ -8018,29 +8012,15 @@ lookup_type_scope (tree name, tag_scope scope)
}
/* Returns true iff DECL is a block-scope extern declaration of a function
- or variable. */
+ or variable. We will already have determined validity of the decl
+ when pushing it. So we do not have to redo that lookup. */
bool
is_local_extern (tree decl)
{
- cxx_binding *binding;
-
- /* For functions, this is easy. */
- if (TREE_CODE (decl) == FUNCTION_DECL)
- return DECL_LOCAL_FUNCTION_P (decl);
-
- if (!VAR_P (decl))
- return false;
- if (!current_function_decl)
- return false;
-
- /* For variables, this is not easy. We need to look at the binding stack
- for the identifier to see whether the decl we have is a local. */
- for (binding = IDENTIFIER_BINDING (DECL_NAME (decl));
- binding && binding->scope->kind != sk_namespace;
- binding = binding->previous)
- if (binding->value == decl)
- return LOCAL_BINDING_P (binding);
+ if ((TREE_CODE (decl) == FUNCTION_DECL
+ || TREE_CODE (decl) == VAR_DECL))
+ return DECL_LOCAL_DECL_P (decl);
return false;
}
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 09b90effbdb..b633875b700 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -7586,7 +7586,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p,
if ((TREE_CODE (fn) == USING_DECL
&& DECL_DEPENDENT_P (fn))
|| DECL_FUNCTION_MEMBER_P (fn)
- || DECL_LOCAL_FUNCTION_P (fn))
+ || DECL_LOCAL_DECL_P (fn))
{
do_adl_p = false;
break;
@@ -42961,6 +42961,7 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
{
block_scope = true;
DECL_CONTEXT (fndecl) = global_namespace;
+ DECL_LOCAL_DECL_P (fndecl) = true;
if (!processing_template_decl)
pushdecl (fndecl);
}
@@ -42995,16 +42996,9 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
cp_parser_push_lexer_for_tokens (parser, cp);
parser->lexer->in_pragma = true;
}
- if (!cp_parser_omp_declare_reduction_exprs (fndecl, parser))
- {
- if (!block_scope)
- finish_function (/*inline_p=*/false);
- else
- DECL_CONTEXT (fndecl) = current_function_decl;
- if (cp)
- cp_parser_pop_lexer (parser);
- goto fail;
- }
+
+ bool ok = cp_parser_omp_declare_reduction_exprs (fndecl, parser);
+
if (cp)
cp_parser_pop_lexer (parser);
if (!block_scope)
@@ -43012,6 +43006,14 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
else
{
DECL_CONTEXT (fndecl) = current_function_decl;
+ if (DECL_TEMPLATE_INFO (fndecl))
+ DECL_CONTEXT (DECL_TI_TEMPLATE (fndecl)) = current_function_decl;
+ }
+ if (!ok)
+ goto fail;
+
+ if (block_scope)
+ {
block = finish_omp_structured_block (block);
if (TREE_CODE (block) == BIND_EXPR)
DECL_SAVED_TREE (fndecl) = BIND_EXPR_BODY (block);
@@ -43020,6 +43022,7 @@ cp_parser_omp_declare_reduction (cp_parser *parser, cp_token *pragma_tok,
if (processing_template_decl)
add_decl_expr (fndecl);
}
+
cp_check_omp_declare_reduction (fndecl);
if (cp == NULL && types.length () > 1)
cp = cp_token_cache_new (first_token,
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index d82d85615ce..cbb8af3f181 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -5431,7 +5431,7 @@ check_default_tmpl_args (tree decl, tree parms, bool is_primary,
class template. */
if (TREE_CODE (CP_DECL_CONTEXT (decl)) == FUNCTION_DECL
- || (TREE_CODE (decl) == FUNCTION_DECL && DECL_LOCAL_FUNCTION_P (decl)))
+ || (TREE_CODE (decl) == FUNCTION_DECL && DECL_LOCAL_DECL_P (decl)))
/* You can't have a function template declaration in a local
scope, nor you can you define a member of a class template in a
local scope. */
@@ -18155,7 +18155,11 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
&& DECL_OMP_DECLARE_REDUCTION_P (decl)
&& DECL_FUNCTION_SCOPE_P (pattern_decl))
{
- DECL_CONTEXT (decl) = NULL_TREE;
+ gcc_checking_assert (DECL_LOCAL_DECL_P (decl));
+ /* We pretend this is regular local decl of a
+ namespace-scope fn. Then we make it really
+ local, it is a nested function.*/
+ DECL_CONTEXT (decl) = global_namespace;
pushdecl (decl);
DECL_CONTEXT (decl) = current_function_decl;
cp_check_omp_declare_reduction (decl);
@@ -18977,7 +18981,7 @@ tsubst_omp_udr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
if (t == NULL_TREE || t == error_mark_node)
return;
- gcc_assert (TREE_CODE (t) == STATEMENT_LIST);
+ gcc_assert (TREE_CODE (t) == STATEMENT_LIST && current_function_decl);
tree_stmt_iterator tsi;
int i;
@@ -18997,6 +19001,8 @@ tsubst_omp_udr (tree t, tree args, tsubst_flags_t complain, tree in_decl)
args, complain, in_decl);
tree omp_in = tsubst (DECL_EXPR_DECL (stmts[1]),
args, complain, in_decl);
+ /* tsubsting a local var_decl leaves DECL_CONTEXT null, as we
+ expect to be pushing it. */
DECL_CONTEXT (omp_out) = current_function_decl;
DECL_CONTEXT (omp_in) = current_function_decl;
keep_next_level (true);
@@ -25771,6 +25777,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
a full instantiation. */
if (cp_unevaluated_operand != 0)
goto out;
+
/* ??? Historically, we have instantiated inline functions, even
when marked as "extern template". */
if (!(external_p && VAR_P (d)))
@@ -27062,7 +27069,7 @@ type_dependent_expression_p (tree expression)
&& DECL_FRIEND_P (expression)
&& (!DECL_FRIEND_CONTEXT (expression)
|| dependent_type_p (DECL_FRIEND_CONTEXT (expression))))
- && !DECL_LOCAL_FUNCTION_P (expression))
+ && !DECL_LOCAL_DECL_P (expression))
{
gcc_assert (!dependent_type_p (TREE_TYPE (expression))
|| undeduced_auto_decl (expression));
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 9edcd288359..197f038d07a 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -2518,7 +2518,7 @@ finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
{
tree ifn = get_first_fn (fn);
if (TREE_CODE (ifn) == FUNCTION_DECL
- && DECL_LOCAL_FUNCTION_P (ifn))
+ && DECL_LOCAL_DECL_P (ifn))
orig_fn = DECL_NAME (ifn);
}
diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc
index f693571c29d..ddab5b5c771 100644
--- a/libcc1/libcp1plugin.cc
+++ b/libcc1/libcp1plugin.cc
@@ -3291,7 +3291,7 @@ plugin_build_call_expr (cc1_plugin::connection *self,
fn = STRIP_TEMPLATE (fn);
if (!DECL_FUNCTION_MEMBER_P (fn)
- && !DECL_LOCAL_FUNCTION_P (fn))
+ && !DECL_LOCAL_DECL_P (fn))
koenig_p = true;
}
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-09-14 12:54 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-14 12:54 [gcc/devel/c++-modules] Add DECL_LOCAL_DECL_P Nathan Sidwell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).