c++: TINFO_VAR_DECLARED_CONSTINIT -> DECL_DECLARED_CONSTINIT_P

We need to record whether template function-scopestatic decls are
constinit.  That's currently held on the var's TEMPLATE_INFO data.
But I want to get rid of such decl's template header as they're not
really templates, and they're never instantiated separately from their
containing function's definition.  (Just like auto vars, which don't
get them for instance).

This patch moves the flag into a spare decl_lang_flag.

	gcc/cp/
	* cp-tree.h (TINFO_VAR_DECLARED_CONSTINIT): Replace with ...
	(DECL_DECLARED_CONSTINIT_P): ... this.
	* decl.c (start_decl): No need to retrofit_lang_decl for constinit
	flag.
	(cp_finish_decl): Use DECL_DECLARED_CONSTINIT_P.
	* pt.c (tsubst_decl): No need to handle constinit flag
	propagation.
	(tsubst_expr): Or here.
This commit is contained in:
Nathan Sidwell 2020-09-10 06:53:31 -07:00
parent 1c68cf348a
commit f9189e1088
3 changed files with 11 additions and 28 deletions

View file

@ -464,7 +464,6 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
SWITCH_STMT_NO_BREAK_P (in SWITCH_STMT)
LAMBDA_EXPR_CAPTURE_OPTIMIZED (in LAMBDA_EXPR)
IMPLICIT_CONV_EXPR_BRACED_INIT (in IMPLICIT_CONV_EXPR)
TINFO_VAR_DECLARED_CONSTINIT (in TEMPLATE_INFO)
CALL_FROM_NEW_OR_DELETE_P (in CALL_EXPR)
3: IMPLICIT_RVALUE_P (in NON_LVALUE_EXPR or STATIC_CAST_EXPR)
ICS_BAD_FLAG (in _CONV)
@ -534,6 +533,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX];
TYPE_DECL_ALIAS_P (in TYPE_DECL)
7: DECL_THUNK_P (in a member FUNCTION_DECL)
DECL_NORMAL_CAPTURE_P (in FIELD_DECL)
DECL_DECLARED_CONSTINIT_P (in VAR_DECL)
8: DECL_DECLARED_CONSTEXPR_P (in VAR_DECL, FUNCTION_DECL)
Usage of language-independent fields in a language-dependent manner:
@ -1462,11 +1462,6 @@ struct GTY (()) tree_lambda_expr
#define TINFO_USED_TEMPLATE_ID(NODE) \
(TREE_LANG_FLAG_1 (TEMPLATE_INFO_CHECK (NODE)))
/* Non-zero if this variable template specialization was declared with the
`constinit' specifier. */
#define TINFO_VAR_DECLARED_CONSTINIT(NODE) \
(TREE_LANG_FLAG_2 (TEMPLATE_INFO_CHECK (NODE)))
/* The representation of a deferred access check. */
struct GTY(()) deferred_access_check {
@ -3224,6 +3219,10 @@ struct GTY(()) lang_decl {
#define DECL_EXTERN_C_FUNCTION_P(NODE) \
(DECL_NON_THUNK_FUNCTION_P (NODE) && DECL_EXTERN_C_P (NODE))
/* Non-zero if this variable is declared `constinit' specifier. */
#define DECL_DECLARED_CONSTINIT_P(NODE) \
(DECL_LANG_FLAG_7 (VAR_DECL_CHECK (NODE)))
/* True if DECL is declared 'constexpr'. */
#define DECL_DECLARED_CONSTEXPR_P(DECL) \
DECL_LANG_FLAG_8 (VAR_OR_FUNCTION_DECL_CHECK (STRIP_TEMPLATE (DECL)))

View file

@ -5422,14 +5422,8 @@ start_decl (const cp_declarator *declarator,
decl = maybe_push_decl (decl);
if (processing_template_decl)
{
/* Make sure that for a `constinit' decl push_template_decl creates
a DECL_TEMPLATE_INFO info for us, so that cp_finish_decl can then set
TINFO_VAR_DECLARED_CONSTINIT. */
if (decl_spec_seq_has_spec_p (declspecs, ds_constinit))
retrofit_lang_decl (decl);
decl = push_template_decl (decl);
}
decl = push_template_decl (decl);
if (decl == error_mark_node)
return error_mark_node;
@ -7683,7 +7677,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
/* Handle `constinit' on variable templates. */
if (flags & LOOKUP_CONSTINIT)
TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (decl)) = true;
DECL_DECLARED_CONSTINIT_P (decl) = true;
/* Generally, initializers in templates are expanded when the
template is instantiated. But, if DECL is a variable constant

View file

@ -14746,10 +14746,6 @@ tsubst_decl (tree t, tree args, tsubst_flags_t complain)
DECL_TEMPLATE_INFO (r) = build_template_info (tmpl, argvec);
SET_DECL_IMPLICIT_INSTANTIATION (r);
/* Remember whether we require constant initialization of
a non-constant template variable. */
TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (r))
= TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (t));
if (!error_operand_p (r) || (complain & tf_error))
register_specialization (r, gen_tmpl, argvec, false, hash);
}
@ -18039,13 +18035,6 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
else
{
init = DECL_INITIAL (decl);
/* The following tsubst call will clear the DECL_TEMPLATE_INFO
for local variables, so save if DECL was declared constinit. */
const bool constinit_p
= (VAR_P (decl)
&& DECL_LANG_SPECIFIC (decl)
&& DECL_TEMPLATE_INFO (decl)
&& TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (decl)));
decl = tsubst (decl, args, complain, in_decl);
if (decl != error_mark_node)
{
@ -18114,6 +18103,8 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl,
now. */
predeclare_vla (decl);
bool constinit_p
= VAR_P (decl) && DECL_DECLARED_CONSTINIT_P (decl);
cp_finish_decl (decl, init, const_init, NULL_TREE,
constinit_p ? LOOKUP_CONSTINIT : 0);
@ -25767,8 +25758,7 @@ instantiate_decl (tree d, bool defer_ok, bool expl_inst_class_mem_p)
push_nested_class (DECL_CONTEXT (d));
const_init = DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (code_pattern);
int flags = (TINFO_VAR_DECLARED_CONSTINIT (DECL_TEMPLATE_INFO (d))
? LOOKUP_CONSTINIT : 0);
int flags = (DECL_DECLARED_CONSTINIT_P (d) ? LOOKUP_CONSTINIT : 0);
cp_finish_decl (d, init, const_init, NULL_TREE, flags);
if (enter_context)