1 /* Process declarations and variables for C++ compiler.
2 Copyright (C) 1988-2021 Free Software Foundation, Inc.
3 Hacked by Michael Tiemann (tiemann@cygnus.com)
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GCC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
22 /* Process declarations and symbol lookup for C++ front end.
23 Also constructs types; the standard scalar types at initialization,
24 and structure, union, array and enum types when they are declared. */
26 /* ??? not all decl nodes are given the most useful possible
27 line numbers. For example, the CONST_DECLs for enum values. */
31 #include "coretypes.h"
35 #include "c-family/c-common.h"
37 #include "stringpool.h"
41 #include "stor-layout.h"
45 #include "c-family/c-objc.h"
46 #include "c-family/c-pragma.h"
49 #include "c-family/c-ada-spec.h"
51 #include "optabs-query.h"
53 /* Id for dumping the raw trees. */
56 extern cpp_reader
*parse_in
;
58 /* This structure contains information about the initializations
59 and/or destructions required for a particular priority level. */
60 typedef struct priority_info_s
{
61 /* Nonzero if there have been any initializations at this priority
62 throughout the translation unit. */
63 int initializations_p
;
64 /* Nonzero if there have been any destructions at this priority
65 throughout the translation unit. */
69 static tree
start_objects (int, int);
70 static void finish_objects (int, int, tree
);
71 static tree
start_static_storage_duration_function (unsigned);
72 static void finish_static_storage_duration_function (tree
);
73 static priority_info
get_priority_info (int);
74 static void do_static_initialization_or_destruction (tree
, bool);
75 static void one_static_initialization_or_destruction (tree
, tree
, bool);
76 static void generate_ctor_or_dtor_function (bool, int, location_t
*);
77 static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node
,
79 static tree
prune_vars_needing_no_initialization (tree
*);
80 static void write_out_vars (tree
);
81 static void import_export_class (tree
);
82 static tree
get_guard_bits (tree
);
83 static void determine_visibility_from_class (tree
, tree
);
84 static bool determine_hidden_inline (tree
);
86 /* A list of static class variables. This is needed, because a
87 static class variable can be declared inside the class without
88 an initializer, and then initialized, statically, outside the class. */
89 static GTY(()) vec
<tree
, va_gc
> *pending_statics
;
91 /* A list of functions which were declared inline, but which we
92 may need to emit outline anyway. */
93 static GTY(()) vec
<tree
, va_gc
> *deferred_fns
;
95 /* A list of decls that use types with no linkage, which we need to make
97 static GTY(()) vec
<tree
, va_gc
> *no_linkage_decls
;
99 /* A vector of alternating decls and identifiers, where the latter
100 is to be an alias for the former if the former is defined. */
101 static GTY(()) vec
<tree
, va_gc
> *mangling_aliases
;
103 /* hash traits for declarations. Hashes single decls via
104 DECL_ASSEMBLER_NAME_RAW. */
106 struct mangled_decl_hash
: ggc_remove
<tree
>
108 typedef tree value_type
; /* A DECL. */
109 typedef tree compare_type
; /* An identifier. */
111 static hashval_t
hash (const value_type decl
)
113 return IDENTIFIER_HASH_VALUE (DECL_ASSEMBLER_NAME_RAW (decl
));
115 static bool equal (const value_type existing
, compare_type candidate
)
117 tree name
= DECL_ASSEMBLER_NAME_RAW (existing
);
118 return candidate
== name
;
121 static const bool empty_zero_p
= true;
122 static inline void mark_empty (value_type
&p
) {p
= NULL_TREE
;}
123 static inline bool is_empty (value_type p
) {return !p
;}
125 static bool is_deleted (value_type e
)
127 return e
== reinterpret_cast <value_type
> (1);
129 static void mark_deleted (value_type
&e
)
131 e
= reinterpret_cast <value_type
> (1);
135 /* A hash table of decls keyed by mangled name. Used to figure out if
136 we need compatibility aliases. */
137 static GTY(()) hash_table
<mangled_decl_hash
> *mangled_decls
;
139 /* Nonzero if we're done parsing and into end-of-file activities. */
143 /* True if note_mangling_alias should enqueue mangling aliases for
144 later generation, rather than emitting them right away. */
146 bool defer_mangling_aliases
= true;
149 /* Return a member function type (a METHOD_TYPE), given FNTYPE (a
150 FUNCTION_TYPE), CTYPE (class type), and QUALS (the cv-qualifiers
151 that apply to the function). */
154 build_memfn_type (tree fntype
, tree ctype
, cp_cv_quals quals
,
155 cp_ref_qualifier rqual
)
157 if (fntype
== error_mark_node
|| ctype
== error_mark_node
)
158 return error_mark_node
;
160 gcc_assert (FUNC_OR_METHOD_TYPE_P (fntype
));
162 cp_cv_quals type_quals
= quals
& ~TYPE_QUAL_RESTRICT
;
163 ctype
= cp_build_qualified_type (ctype
, type_quals
);
166 = build_method_type_directly (ctype
, TREE_TYPE (fntype
),
167 (TREE_CODE (fntype
) == METHOD_TYPE
168 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
169 : TYPE_ARG_TYPES (fntype
)));
170 if (tree attrs
= TYPE_ATTRIBUTES (fntype
))
171 newtype
= cp_build_type_attribute_variant (newtype
, attrs
);
172 newtype
= build_cp_fntype_variant (newtype
, rqual
,
173 TYPE_RAISES_EXCEPTIONS (fntype
),
174 TYPE_HAS_LATE_RETURN_TYPE (fntype
));
179 /* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
180 return type changed to NEW_RET. */
183 change_return_type (tree new_ret
, tree fntype
)
185 if (new_ret
== error_mark_node
)
188 if (same_type_p (new_ret
, TREE_TYPE (fntype
)))
192 tree args
= TYPE_ARG_TYPES (fntype
);
194 if (TREE_CODE (fntype
) == FUNCTION_TYPE
)
196 newtype
= build_function_type (new_ret
, args
);
197 newtype
= apply_memfn_quals (newtype
,
198 type_memfn_quals (fntype
));
201 newtype
= build_method_type_directly
202 (class_of_this_parm (fntype
), new_ret
, TREE_CHAIN (args
));
204 if (tree attrs
= TYPE_ATTRIBUTES (fntype
))
205 newtype
= cp_build_type_attribute_variant (newtype
, attrs
);
206 newtype
= cxx_copy_lang_qualifiers (newtype
, fntype
);
211 /* Build a PARM_DECL of FN with NAME and TYPE, and set DECL_ARG_TYPE
215 cp_build_parm_decl (tree fn
, tree name
, tree type
)
217 tree parm
= build_decl (input_location
,
218 PARM_DECL
, name
, type
);
219 DECL_CONTEXT (parm
) = fn
;
221 /* DECL_ARG_TYPE is only used by the back end and the back end never
223 if (!processing_template_decl
)
224 DECL_ARG_TYPE (parm
) = type_passed_as (type
);
229 /* Returns a PARM_DECL of FN for a parameter of the indicated TYPE, with the
233 build_artificial_parm (tree fn
, tree name
, tree type
)
235 tree parm
= cp_build_parm_decl (fn
, name
, type
);
236 DECL_ARTIFICIAL (parm
) = 1;
237 /* All our artificial parms are implicitly `const'; they cannot be
239 TREE_READONLY (parm
) = 1;
243 /* Constructors for types with virtual baseclasses need an "in-charge" flag
244 saying whether this constructor is responsible for initialization of
245 virtual baseclasses or not. All destructors also need this "in-charge"
246 flag, which additionally determines whether or not the destructor should
247 free the memory for the object.
249 This function adds the "in-charge" flag to member function FN if
250 appropriate. It is called from grokclassfn and tsubst.
251 FN must be either a constructor or destructor.
253 The in-charge flag follows the 'this' parameter, and is followed by the
254 VTT parm (if any), then the user-written parms. */
257 maybe_retrofit_in_chrg (tree fn
)
259 tree basetype
, arg_types
, parms
, parm
, fntype
;
261 /* If we've already add the in-charge parameter don't do it again. */
262 if (DECL_HAS_IN_CHARGE_PARM_P (fn
))
265 /* When processing templates we can't know, in general, whether or
266 not we're going to have virtual baseclasses. */
267 if (processing_template_decl
)
270 /* We don't need an in-charge parameter for constructors that don't
271 have virtual bases. */
272 if (DECL_CONSTRUCTOR_P (fn
)
273 && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn
)))
276 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
277 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
278 arg_types
= TREE_CHAIN (arg_types
);
280 parms
= DECL_CHAIN (DECL_ARGUMENTS (fn
));
282 /* If this is a subobject constructor or destructor, our caller will
283 pass us a pointer to our VTT. */
284 if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn
)))
286 parm
= build_artificial_parm (fn
, vtt_parm_identifier
, vtt_parm_type
);
288 /* First add it to DECL_ARGUMENTS between 'this' and the real args... */
289 DECL_CHAIN (parm
) = parms
;
292 /* ...and then to TYPE_ARG_TYPES. */
293 arg_types
= hash_tree_chain (vtt_parm_type
, arg_types
);
295 DECL_HAS_VTT_PARM_P (fn
) = 1;
298 /* Then add the in-charge parm (before the VTT parm). */
299 parm
= build_artificial_parm (fn
, in_charge_identifier
, integer_type_node
);
300 DECL_CHAIN (parm
) = parms
;
302 arg_types
= hash_tree_chain (integer_type_node
, arg_types
);
304 /* Insert our new parameter(s) into the list. */
305 DECL_CHAIN (DECL_ARGUMENTS (fn
)) = parms
;
307 /* And rebuild the function type. */
308 fntype
= build_method_type_directly (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
310 if (TYPE_ATTRIBUTES (TREE_TYPE (fn
)))
311 fntype
= (cp_build_type_attribute_variant
312 (fntype
, TYPE_ATTRIBUTES (TREE_TYPE (fn
))));
313 fntype
= cxx_copy_lang_qualifiers (fntype
, TREE_TYPE (fn
));
314 TREE_TYPE (fn
) = fntype
;
316 /* Now we've got the in-charge parameter. */
317 DECL_HAS_IN_CHARGE_PARM_P (fn
) = 1;
320 /* Classes overload their constituent function names automatically.
321 When a function name is declared in a record structure,
322 its name is changed to it overloaded name. Since names for
323 constructors and destructors can conflict, we place a leading
326 CNAME is the name of the class we are grokking for.
328 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
330 FLAGS contains bits saying what's special about today's
331 arguments. DTOR_FLAG == DESTRUCTOR.
333 If FUNCTION is a destructor, then we must add the `auto-delete' field
334 as a second parameter. There is some hair associated with the fact
335 that we must "declare" this variable in the manner consistent with the
336 way the rest of the arguments were declared.
338 QUALS are the qualifiers for the this pointer. */
341 grokclassfn (tree ctype
, tree function
, enum overload_flags flags
)
343 tree fn_name
= DECL_NAME (function
);
345 /* Even within an `extern "C"' block, members get C++ linkage. See
346 [dcl.link] for details. */
347 SET_DECL_LANGUAGE (function
, lang_cplusplus
);
349 if (fn_name
== NULL_TREE
)
351 error ("name missing for member function");
352 fn_name
= get_identifier ("<anonymous>");
353 DECL_NAME (function
) = fn_name
;
356 DECL_CONTEXT (function
) = ctype
;
358 if (flags
== DTOR_FLAG
)
359 DECL_CXX_DESTRUCTOR_P (function
) = 1;
361 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
362 maybe_retrofit_in_chrg (function
);
365 /* Create an ARRAY_REF, checking for the user doing things backwards
366 along the way. DECLTYPE_P is for N3276, as in the parser. */
369 grok_array_decl (location_t loc
, tree array_expr
, tree index_exp
,
374 tree orig_array_expr
= array_expr
;
375 tree orig_index_exp
= index_exp
;
376 tree overload
= NULL_TREE
;
378 if (error_operand_p (array_expr
) || error_operand_p (index_exp
))
379 return error_mark_node
;
381 if (processing_template_decl
)
383 if (type_dependent_expression_p (array_expr
)
384 || type_dependent_expression_p (index_exp
))
385 return build_min_nt_loc (loc
, ARRAY_REF
, array_expr
, index_exp
,
386 NULL_TREE
, NULL_TREE
);
387 array_expr
= build_non_dependent_expr (array_expr
);
388 index_exp
= build_non_dependent_expr (index_exp
);
391 type
= TREE_TYPE (array_expr
);
393 type
= non_reference (type
);
395 /* If they have an `operator[]', use that. */
396 if (MAYBE_CLASS_TYPE_P (type
) || MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp
)))
398 tsubst_flags_t complain
= tf_warning_or_error
;
400 complain
|= tf_decltype
;
401 expr
= build_new_op (loc
, ARRAY_REF
, LOOKUP_NORMAL
, array_expr
,
402 index_exp
, NULL_TREE
, &overload
, complain
);
407 bool swapped
= false;
409 /* Otherwise, create an ARRAY_REF for a pointer or array type.
410 It is a little-known fact that, if `a' is an array and `i' is
411 an int, you can write `i[a]', which means the same thing as
413 if (TREE_CODE (type
) == ARRAY_TYPE
|| VECTOR_TYPE_P (type
))
416 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, false);
418 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
421 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, false);
423 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
,
425 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
,
428 if ((p1
&& i2
) && (i1
&& p2
))
429 error ("ambiguous conversion for array subscript");
432 array_expr
= p1
, index_exp
= i2
;
434 swapped
= true, array_expr
= p2
, index_exp
= i1
;
437 error_at (loc
, "invalid types %<%T[%T]%> for array subscript",
438 type
, TREE_TYPE (index_exp
));
439 return error_mark_node
;
442 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
443 error ("ambiguous conversion for array subscript");
445 if (TYPE_PTR_P (TREE_TYPE (array_expr
)))
446 array_expr
= mark_rvalue_use (array_expr
);
448 array_expr
= mark_lvalue_use_nonread (array_expr
);
449 index_exp
= mark_rvalue_use (index_exp
);
451 && flag_strong_eval_order
== 2
452 && (TREE_SIDE_EFFECTS (array_expr
) || TREE_SIDE_EFFECTS (index_exp
)))
453 expr
= build_array_ref (input_location
, index_exp
, array_expr
);
455 expr
= build_array_ref (input_location
, array_expr
, index_exp
);
457 if (processing_template_decl
&& expr
!= error_mark_node
)
459 if (overload
!= NULL_TREE
)
460 return (build_min_non_dep_op_overload
461 (ARRAY_REF
, expr
, overload
, orig_array_expr
, orig_index_exp
));
463 return build_min_non_dep (ARRAY_REF
, expr
, orig_array_expr
, orig_index_exp
,
464 NULL_TREE
, NULL_TREE
);
469 /* Given the cast expression EXP, checking out its validity. Either return
470 an error_mark_node if there was an unavoidable error, return a cast to
471 void for trying to delete a pointer w/ the value 0, or return the
472 call to delete. If DOING_VEC is true, we handle things differently
473 for doing an array delete.
474 Implements ARM $5.3.4. This is called from the parser. */
477 delete_sanity (location_t loc
, tree exp
, tree size
, bool doing_vec
,
478 int use_global_delete
, tsubst_flags_t complain
)
482 if (exp
== error_mark_node
)
485 if (processing_template_decl
)
487 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
488 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
489 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
490 TREE_SIDE_EFFECTS (t
) = 1;
491 SET_EXPR_LOCATION (t
, loc
);
495 location_t exp_loc
= cp_expr_loc_or_loc (exp
, loc
);
497 /* An array can't have been allocated by new, so complain. */
498 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
499 && (complain
& tf_warning
))
500 warning_at (exp_loc
, 0, "deleting array %q#E", exp
);
502 t
= build_expr_type_conversion (WANT_POINTER
, exp
, true);
504 if (t
== NULL_TREE
|| t
== error_mark_node
)
506 if (complain
& tf_error
)
508 "type %q#T argument given to %<delete%>, expected pointer",
510 return error_mark_node
;
513 type
= TREE_TYPE (t
);
515 /* As of Valley Forge, you can delete a pointer to const. */
517 /* You can't delete functions. */
518 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
520 if (complain
& tf_error
)
522 "cannot delete a function. Only pointer-to-objects are "
523 "valid arguments to %<delete%>");
524 return error_mark_node
;
527 /* Deleting ptr to void is undefined behavior [expr.delete/3]. */
528 if (VOID_TYPE_P (TREE_TYPE (type
)))
530 if (complain
& tf_warning
)
531 warning_at (exp_loc
, OPT_Wdelete_incomplete
,
532 "deleting %qT is undefined", type
);
536 /* Deleting a pointer with the value zero is valid and has no effect. */
537 if (integer_zerop (t
))
538 return build1_loc (loc
, NOP_EXPR
, void_type_node
, t
);
541 return build_vec_delete (loc
, t
, /*maxindex=*/NULL_TREE
,
542 sfk_deleting_destructor
,
543 use_global_delete
, complain
);
545 return build_delete (loc
, type
, t
, sfk_deleting_destructor
,
546 LOOKUP_NORMAL
, use_global_delete
,
550 /* Report an error if the indicated template declaration is not the
551 sort of thing that should be a member template. */
554 check_member_template (tree tmpl
)
558 gcc_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
);
559 decl
= DECL_TEMPLATE_RESULT (tmpl
);
561 if (TREE_CODE (decl
) == FUNCTION_DECL
562 || DECL_ALIAS_TEMPLATE_P (tmpl
)
563 || (TREE_CODE (decl
) == TYPE_DECL
564 && MAYBE_CLASS_TYPE_P (TREE_TYPE (decl
))))
566 /* The parser rejects template declarations in local classes
567 (with the exception of generic lambdas). */
568 gcc_assert (!current_function_decl
|| LAMBDA_FUNCTION_P (decl
));
569 /* The parser rejects any use of virtual in a function template. */
570 gcc_assert (!(TREE_CODE (decl
) == FUNCTION_DECL
571 && DECL_VIRTUAL_P (decl
)));
573 /* The debug-information generating code doesn't know what to do
574 with member templates. */
575 DECL_IGNORED_P (tmpl
) = 1;
577 else if (variable_template_p (tmpl
))
580 error ("template declaration of %q#D", decl
);
583 /* Sanity check: report error if this function FUNCTION is not
584 really a member of the class (CTYPE) it is supposed to belong to.
585 TEMPLATE_PARMS is used to specify the template parameters of a member
586 template passed as FUNCTION_DECL. If the member template is passed as a
587 TEMPLATE_DECL, it can be NULL since the parameters can be extracted
588 from the declaration. If the function is not a function template, it
590 It returns the original declaration for the function, NULL_TREE if
591 no declaration was found, error_mark_node if an error was emitted. */
594 check_classfn (tree ctype
, tree function
, tree template_parms
)
596 if (DECL_USE_TEMPLATE (function
)
597 && !(TREE_CODE (function
) == TEMPLATE_DECL
598 && DECL_TEMPLATE_SPECIALIZATION (function
))
599 && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (function
)))
600 /* Since this is a specialization of a member template,
601 we're not going to find the declaration in the class.
604 struct S { template <typename T> void f(T); };
605 template <> void S::f(int);
607 we're not going to find `S::f(int)', but there's no
608 reason we should, either. We let our callers know we didn't
609 find the method, but we don't complain. */
612 /* Basic sanity check: for a template function, the template parameters
613 either were not passed, or they are the same of DECL_TEMPLATE_PARMS. */
614 if (TREE_CODE (function
) == TEMPLATE_DECL
)
617 && !comp_template_parms (template_parms
,
618 DECL_TEMPLATE_PARMS (function
)))
620 error ("template parameter lists provided don%'t match the "
621 "template parameters of %qD", function
);
622 return error_mark_node
;
624 template_parms
= DECL_TEMPLATE_PARMS (function
);
627 /* OK, is this a definition of a member template? */
628 bool is_template
= (template_parms
!= NULL_TREE
);
632 A destructor shall not be a member template. */
633 if (DECL_DESTRUCTOR_P (function
) && is_template
)
635 error ("destructor %qD declared as member template", function
);
636 return error_mark_node
;
639 /* We must enter the scope here, because conversion operators are
640 named by target type, and type equivalence relies on typenames
641 resolving within the scope of CTYPE. */
642 tree pushed_scope
= push_scope (ctype
);
643 tree matched
= NULL_TREE
;
644 tree fns
= get_class_binding (ctype
, DECL_NAME (function
));
646 for (ovl_iterator
iter (fns
); !matched
&& iter
; ++iter
)
650 /* A member template definition only matches a member template
652 if (is_template
!= (TREE_CODE (fndecl
) == TEMPLATE_DECL
))
655 if (!DECL_DECLARES_FUNCTION_P (fndecl
))
658 tree p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
659 tree p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
661 /* We cannot simply call decls_match because this doesn't work
662 for static member functions that are pretending to be
663 methods, and because the name may have been changed by
666 /* Get rid of the this parameter on functions that become
668 if (DECL_STATIC_FUNCTION_P (fndecl
)
669 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
670 p1
= TREE_CHAIN (p1
);
672 /* ref-qualifier or absence of same must match. */
673 if (type_memfn_rqual (TREE_TYPE (function
))
674 != type_memfn_rqual (TREE_TYPE (fndecl
)))
677 // Include constraints in the match.
678 tree c1
= get_constraints (function
);
679 tree c2
= get_constraints (fndecl
);
681 /* While finding a match, same types and params are not enough
682 if the function is versioned. Also check version ("target")
684 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
685 TREE_TYPE (TREE_TYPE (fndecl
)))
686 && compparms (p1
, p2
)
687 && !targetm
.target_option
.function_versions (function
, fndecl
)
689 || comp_template_parms (template_parms
,
690 DECL_TEMPLATE_PARMS (fndecl
)))
691 && equivalent_constraints (c1
, c2
)
692 && (DECL_TEMPLATE_SPECIALIZATION (function
)
693 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
694 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
695 || (DECL_TI_TEMPLATE (function
) == DECL_TI_TEMPLATE (fndecl
))))
701 if (!COMPLETE_TYPE_P (ctype
))
702 cxx_incomplete_type_error (DECL_SOURCE_LOCATION (function
),
706 if (DECL_CONV_FN_P (function
))
707 fns
= get_class_binding (ctype
, conv_op_identifier
);
709 error_at (DECL_SOURCE_LOCATION (function
),
710 "no declaration matches %q#D", function
);
712 print_candidates (fns
);
713 else if (DECL_CONV_FN_P (function
))
714 inform (DECL_SOURCE_LOCATION (function
),
715 "no conversion operators declared");
717 inform (DECL_SOURCE_LOCATION (function
),
718 "no functions named %qD", function
);
719 inform (DECL_SOURCE_LOCATION (TYPE_NAME (ctype
)),
720 "%#qT defined here", ctype
);
722 matched
= error_mark_node
;
726 pop_scope (pushed_scope
);
731 /* DECL is a function with vague linkage. Remember it so that at the
732 end of the translation unit we can decide whether or not to emit
736 note_vague_linkage_fn (tree decl
)
738 if (processing_template_decl
)
741 DECL_DEFER_OUTPUT (decl
) = 1;
742 vec_safe_push (deferred_fns
, decl
);
745 /* As above, but for variable template instantiations. */
748 note_variable_template_instantiation (tree decl
)
750 vec_safe_push (pending_statics
, decl
);
753 /* We have just processed the DECL, which is a static data member.
754 The other parameters are as for cp_finish_decl. */
757 finish_static_data_member_decl (tree decl
,
758 tree init
, bool init_const_expr_p
,
762 if (DECL_TEMPLATE_INSTANTIATED (decl
))
763 /* We already needed to instantiate this, so the processing in this
764 function is unnecessary/wrong. */
767 DECL_CONTEXT (decl
) = current_class_type
;
769 /* We cannot call pushdecl here, because that would fill in the
770 TREE_CHAIN of our decl. Instead, we modify cp_finish_decl to do
771 the right thing, namely, to put this decl out straight away. */
773 if (! processing_template_decl
)
774 vec_safe_push (pending_statics
, decl
);
776 if (LOCAL_CLASS_P (current_class_type
)
777 /* We already complained about the template definition. */
778 && !DECL_TEMPLATE_INSTANTIATION (decl
))
779 permerror (DECL_SOURCE_LOCATION (decl
),
780 "local class %q#T shall not have static data member %q#D",
781 current_class_type
, decl
);
783 for (tree t
= current_class_type
; TYPE_P (t
);
784 t
= CP_TYPE_CONTEXT (t
))
785 if (TYPE_UNNAMED_P (t
))
787 auto_diagnostic_group d
;
788 if (permerror (DECL_SOURCE_LOCATION (decl
),
789 "static data member %qD in unnamed class", decl
))
790 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)),
791 "unnamed class defined here");
795 if (DECL_INLINE_VAR_P (decl
) && !DECL_TEMPLATE_INSTANTIATION (decl
))
796 /* An inline variable is immediately defined, so don't set DECL_IN_AGGR_P.
797 Except that if decl is a template instantiation, it isn't defined until
798 instantiate_decl. */;
800 DECL_IN_AGGR_P (decl
) = 1;
802 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
803 && TYPE_DOMAIN (TREE_TYPE (decl
)) == NULL_TREE
)
804 SET_VAR_HAD_UNKNOWN_BOUND (decl
);
808 /* Similarly to start_decl_1, we want to complete the type in order
809 to do the right thing in cp_apply_type_quals_to_decl, possibly
810 clear TYPE_QUAL_CONST (c++/65579). */
811 tree type
= TREE_TYPE (decl
) = complete_type (TREE_TYPE (decl
));
812 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
815 cp_finish_decl (decl
, init
, init_const_expr_p
, asmspec_tree
, flags
);
818 /* DECLARATOR and DECLSPECS correspond to a class member. The other
819 parameters are as for cp_finish_decl. Return the DECL for the
820 class member declared. */
823 grokfield (const cp_declarator
*declarator
,
824 cp_decl_specifier_seq
*declspecs
,
825 tree init
, bool init_const_expr_p
,
830 const char *asmspec
= 0;
834 && TREE_CODE (init
) == TREE_LIST
835 && TREE_VALUE (init
) == error_mark_node
836 && TREE_CHAIN (init
) == NULL_TREE
)
840 if (init
== ridpointers
[(int)RID_DELETE
])
841 initialized
= SD_DELETED
;
842 else if (init
== ridpointers
[(int)RID_DEFAULT
])
843 initialized
= SD_DEFAULTED
;
845 initialized
= SD_INITIALIZED
;
847 initialized
= SD_UNINITIALIZED
;
849 value
= grokdeclarator (declarator
, declspecs
, FIELD
, initialized
, &attrlist
);
850 if (! value
|| value
== error_mark_node
)
851 /* friend or constructor went bad. */
852 return error_mark_node
;
853 if (TREE_TYPE (value
) == error_mark_node
)
856 if (TREE_CODE (value
) == TYPE_DECL
&& init
)
858 error_at (cp_expr_loc_or_loc (init
, DECL_SOURCE_LOCATION (value
)),
859 "typedef %qD is initialized (use %qs instead)",
864 /* Pass friendly classes back. */
865 if (value
== void_type_node
)
868 if (DECL_NAME (value
)
869 && TREE_CODE (DECL_NAME (value
)) == TEMPLATE_ID_EXPR
)
871 error_at (declarator
->id_loc
,
872 "explicit template argument list not allowed");
873 return error_mark_node
;
876 /* Stash away type declarations. */
877 if (TREE_CODE (value
) == TYPE_DECL
)
879 DECL_NONLOCAL (value
) = 1;
880 DECL_CONTEXT (value
) = current_class_type
;
886 /* If this is a typedef that names the class for linkage purposes
887 (7.1.3p8), apply any attributes directly to the type. */
888 if (OVERLOAD_TYPE_P (TREE_TYPE (value
))
889 && value
== TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value
))))
890 attrflags
= ATTR_FLAG_TYPE_IN_PLACE
;
892 cplus_decl_attributes (&value
, attrlist
, attrflags
);
895 if (decl_spec_seq_has_spec_p (declspecs
, ds_typedef
)
896 && TREE_TYPE (value
) != error_mark_node
897 && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value
))) != value
)
898 set_underlying_type (value
);
900 /* It's important that push_template_decl below follows
901 set_underlying_type above so that the created template
902 carries the properly set type of VALUE. */
903 if (processing_template_decl
)
904 value
= push_template_decl (value
);
906 record_locally_defined_typedef (value
);
910 int friendp
= decl_spec_seq_has_spec_p (declspecs
, ds_friend
);
912 if (!friendp
&& DECL_IN_AGGR_P (value
))
914 error ("%qD is already defined in %qT", value
, DECL_CONTEXT (value
));
915 return void_type_node
;
918 if (asmspec_tree
&& asmspec_tree
!= error_mark_node
)
919 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
923 if (TREE_CODE (value
) == FUNCTION_DECL
)
925 if (init
== ridpointers
[(int)RID_DELETE
])
927 DECL_DELETED_FN (value
) = 1;
928 DECL_DECLARED_INLINE_P (value
) = 1;
930 else if (init
== ridpointers
[(int)RID_DEFAULT
])
932 if (defaultable_fn_check (value
))
934 DECL_DEFAULTED_FN (value
) = 1;
935 DECL_INITIALIZED_IN_CLASS_P (value
) = 1;
936 DECL_DECLARED_INLINE_P (value
) = 1;
937 /* grokfndecl set this to error_mark_node, but we want to
938 leave it unset until synthesize_method. */
939 DECL_INITIAL (value
) = NULL_TREE
;
942 else if (TREE_CODE (init
) == DEFERRED_PARSE
)
943 error ("invalid initializer for member function %qD", value
);
944 else if (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
)
946 if (integer_zerop (init
))
947 DECL_PURE_VIRTUAL_P (value
) = 1;
948 else if (error_operand_p (init
))
949 ; /* An error has already been reported. */
951 error ("invalid initializer for member function %qD",
956 gcc_assert (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
);
958 = cp_expr_loc_or_loc (init
, DECL_SOURCE_LOCATION (value
));
960 error_at (iloc
, "initializer specified for friend "
961 "function %qD", value
);
963 error_at (iloc
, "initializer specified for static "
964 "member function %qD", value
);
967 else if (TREE_CODE (value
) == FIELD_DECL
)
968 /* C++11 NSDMI, keep going. */;
969 else if (!VAR_P (value
))
973 /* Pass friend decls back. */
974 if ((TREE_CODE (value
) == FUNCTION_DECL
975 || TREE_CODE (value
) == TEMPLATE_DECL
)
976 && DECL_CONTEXT (value
) != current_class_type
)
979 cplus_decl_attributes (&value
, attrlist
, 0);
983 /* Need to set this before push_template_decl. */
985 DECL_CONTEXT (value
) = current_class_type
;
987 if (processing_template_decl
&& VAR_OR_FUNCTION_DECL_P (value
))
989 value
= push_template_decl (value
);
990 if (error_operand_p (value
))
991 return error_mark_node
;
995 cplus_decl_attributes (&value
, attrlist
, 0);
997 if (init
&& DIRECT_LIST_INIT_P (init
))
998 flags
= LOOKUP_NORMAL
;
1000 flags
= LOOKUP_IMPLICIT
;
1002 switch (TREE_CODE (value
))
1005 finish_static_data_member_decl (value
, init
, init_const_expr_p
,
1006 asmspec_tree
, flags
);
1011 error ("%<asm%> specifiers are not permitted on non-static data members");
1012 if (DECL_INITIAL (value
) == error_mark_node
)
1013 init
= error_mark_node
;
1014 cp_finish_decl (value
, init
, /*init_const_expr_p=*/false,
1016 DECL_IN_AGGR_P (value
) = 1;
1021 set_user_assembler_name (value
, asmspec
);
1023 cp_finish_decl (value
,
1025 /*init_const_expr_p=*/false,
1026 asmspec_tree
, flags
);
1028 /* Pass friends back this way. */
1029 if (DECL_UNIQUE_FRIEND_P (value
))
1030 return void_type_node
;
1032 DECL_IN_AGGR_P (value
) = 1;
1041 /* Like `grokfield', but for bitfields.
1042 WIDTH is the width of the bitfield, a constant expression.
1043 The other parameters are as for grokfield. */
1046 grokbitfield (const cp_declarator
*declarator
,
1047 cp_decl_specifier_seq
*declspecs
, tree width
, tree init
,
1050 tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
,
1051 init
!= NULL_TREE
, &attrlist
);
1053 if (value
== error_mark_node
)
1054 return NULL_TREE
; /* friends went bad. */
1056 tree type
= TREE_TYPE (value
);
1057 if (type
== error_mark_node
)
1060 /* Pass friendly classes back. */
1061 if (VOID_TYPE_P (value
))
1062 return void_type_node
;
1064 if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type
)
1065 && (INDIRECT_TYPE_P (type
) || !dependent_type_p (type
)))
1067 error_at (DECL_SOURCE_LOCATION (value
),
1068 "bit-field %qD with non-integral type %qT",
1070 return error_mark_node
;
1073 if (TREE_CODE (value
) == TYPE_DECL
)
1075 error_at (DECL_SOURCE_LOCATION (value
),
1076 "cannot declare %qD to be a bit-field type", value
);
1080 /* Usually, finish_struct_1 catches bitfields with invalid types.
1081 But, in the case of bitfields with function type, we confuse
1082 ourselves into thinking they are member functions, so we must
1084 if (TREE_CODE (value
) == FUNCTION_DECL
)
1086 error_at (DECL_SOURCE_LOCATION (value
),
1087 "cannot declare bit-field %qD with function type", value
);
1091 if (TYPE_WARN_IF_NOT_ALIGN (type
))
1093 error_at (DECL_SOURCE_LOCATION (value
), "cannot declare bit-field "
1094 "%qD with %<warn_if_not_aligned%> type", value
);
1098 if (DECL_IN_AGGR_P (value
))
1100 error ("%qD is already defined in the class %qT", value
,
1101 DECL_CONTEXT (value
));
1102 return void_type_node
;
1105 if (TREE_STATIC (value
))
1107 error_at (DECL_SOURCE_LOCATION (value
),
1108 "static member %qD cannot be a bit-field", value
);
1112 int flags
= LOOKUP_IMPLICIT
;
1113 if (init
&& DIRECT_LIST_INIT_P (init
))
1114 flags
= LOOKUP_NORMAL
;
1115 cp_finish_decl (value
, init
, false, NULL_TREE
, flags
);
1117 if (width
!= error_mark_node
)
1119 /* The width must be an integer type. */
1120 if (!type_dependent_expression_p (width
)
1121 && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width
)))
1122 error ("width of bit-field %qD has non-integral type %qT", value
,
1124 else if (!check_for_bare_parameter_packs (width
))
1126 /* Temporarily stash the width in DECL_BIT_FIELD_REPRESENTATIVE.
1127 check_bitfield_decl picks it from there later and sets DECL_SIZE
1129 DECL_BIT_FIELD_REPRESENTATIVE (value
) = width
;
1130 SET_DECL_C_BIT_FIELD (value
);
1134 DECL_IN_AGGR_P (value
) = 1;
1137 cplus_decl_attributes (&value
, attrlist
, /*flags=*/0);
1143 /* Returns true iff ATTR is an attribute which needs to be applied at
1144 instantiation time rather than template definition time. */
1147 is_late_template_attribute (tree attr
, tree decl
)
1149 tree name
= get_attribute_name (attr
);
1150 tree args
= TREE_VALUE (attr
);
1151 const struct attribute_spec
*spec
= lookup_attribute_spec (name
);
1155 /* Unknown attribute. */
1158 /* Attribute weak handling wants to write out assembly right away. */
1159 if (is_attribute_p ("weak", name
))
1162 /* Attributes used and unused are applied directly to typedefs for the
1163 benefit of maybe_warn_unused_local_typedefs. */
1164 if (TREE_CODE (decl
) == TYPE_DECL
1165 && (is_attribute_p ("unused", name
)
1166 || is_attribute_p ("used", name
)))
1169 /* Attribute tls_model wants to modify the symtab. */
1170 if (is_attribute_p ("tls_model", name
))
1173 /* #pragma omp declare simd attribute needs to be always deferred. */
1175 && is_attribute_p ("omp declare simd", name
))
1178 if (args
== error_mark_node
)
1181 /* An attribute pack is clearly dependent. */
1182 if (args
&& PACK_EXPANSION_P (args
))
1185 /* If any of the arguments are dependent expressions, we can't evaluate
1186 the attribute until instantiation time. */
1187 for (arg
= args
; arg
; arg
= TREE_CHAIN (arg
))
1189 tree t
= TREE_VALUE (arg
);
1191 /* If the first attribute argument is an identifier, only consider
1192 second and following arguments. Attributes like mode, format,
1193 cleanup and several target specific attributes aren't late
1194 just because they have an IDENTIFIER_NODE as first argument. */
1195 if (arg
== args
&& attribute_takes_identifier_p (name
)
1196 && identifier_p (t
))
1199 if (value_dependent_expression_p (t
))
1203 if (TREE_CODE (decl
) == TYPE_DECL
1205 || spec
->type_required
)
1207 tree type
= TYPE_P (decl
) ? decl
: TREE_TYPE (decl
);
1209 /* We can't apply any attributes to a completely unknown type until
1210 instantiation time. */
1211 enum tree_code code
= TREE_CODE (type
);
1212 if (code
== TEMPLATE_TYPE_PARM
1213 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
1214 || code
== TYPENAME_TYPE
)
1216 /* Also defer most attributes on dependent types. This is not
1217 necessary in all cases, but is the better default. */
1218 else if (dependent_type_p (type
)
1219 /* But some attributes specifically apply to templates. */
1220 && !is_attribute_p ("abi_tag", name
)
1221 && !is_attribute_p ("deprecated", name
)
1222 && !is_attribute_p ("visibility", name
))
1231 /* ATTR_P is a list of attributes. Remove any attributes which need to be
1232 applied at instantiation time and return them. If IS_DEPENDENT is true,
1233 the declaration itself is dependent, so all attributes should be applied
1234 at instantiation time. */
1237 splice_template_attributes (tree
*attr_p
, tree decl
)
1240 tree late_attrs
= NULL_TREE
;
1241 tree
*q
= &late_attrs
;
1248 if (is_late_template_attribute (*p
, decl
))
1250 ATTR_IS_DEPENDENT (*p
) = 1;
1252 *p
= TREE_CHAIN (*p
);
1253 q
= &TREE_CHAIN (*q
);
1257 p
= &TREE_CHAIN (*p
);
1263 /* Remove any late attributes from the list in ATTR_P and attach them to
1267 save_template_attributes (tree
*attr_p
, tree
*decl_p
, int flags
)
1271 if (attr_p
&& *attr_p
== error_mark_node
)
1274 tree late_attrs
= splice_template_attributes (attr_p
, *decl_p
);
1278 if (DECL_P (*decl_p
))
1279 q
= &DECL_ATTRIBUTES (*decl_p
);
1281 q
= &TYPE_ATTRIBUTES (*decl_p
);
1283 tree old_attrs
= *q
;
1285 /* Place the late attributes at the beginning of the attribute
1287 late_attrs
= chainon (late_attrs
, *q
);
1288 if (*q
!= late_attrs
1289 && !DECL_P (*decl_p
)
1290 && !(flags
& ATTR_FLAG_TYPE_IN_PLACE
))
1292 if (!dependent_type_p (*decl_p
))
1293 *decl_p
= cp_build_type_attribute_variant (*decl_p
, late_attrs
);
1296 *decl_p
= build_variant_type_copy (*decl_p
);
1297 TYPE_ATTRIBUTES (*decl_p
) = late_attrs
;
1303 if (!DECL_P (*decl_p
) && *decl_p
== TYPE_MAIN_VARIANT (*decl_p
))
1305 /* We've added new attributes directly to the main variant, so
1306 now we need to update all of the other variants to include
1307 these new attributes. */
1309 for (variant
= TYPE_NEXT_VARIANT (*decl_p
); variant
;
1310 variant
= TYPE_NEXT_VARIANT (variant
))
1312 gcc_assert (TYPE_ATTRIBUTES (variant
) == old_attrs
);
1313 TYPE_ATTRIBUTES (variant
) = TYPE_ATTRIBUTES (*decl_p
);
1318 /* True if ATTRS contains any dependent attributes that affect type
1322 any_dependent_type_attributes_p (tree attrs
)
1324 for (tree a
= attrs
; a
; a
= TREE_CHAIN (a
))
1325 if (ATTR_IS_DEPENDENT (a
))
1327 const attribute_spec
*as
= lookup_attribute_spec (TREE_PURPOSE (a
));
1328 if (as
&& as
->affects_type_identity
)
1334 /* Return true iff ATTRS are acceptable attributes to be applied in-place
1335 to a typedef which gives a previously unnamed class or enum a name for
1336 linkage purposes. */
1339 attributes_naming_typedef_ok (tree attrs
)
1341 for (; attrs
; attrs
= TREE_CHAIN (attrs
))
1343 tree name
= get_attribute_name (attrs
);
1344 if (is_attribute_p ("vector_size", name
))
1350 /* Like reconstruct_complex_type, but handle also template trees. */
1353 cp_reconstruct_complex_type (tree type
, tree bottom
)
1357 if (TYPE_PTR_P (type
))
1359 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1360 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
1361 TYPE_REF_CAN_ALIAS_ALL (type
));
1363 else if (TYPE_REF_P (type
))
1365 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1366 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
1367 TYPE_REF_CAN_ALIAS_ALL (type
));
1369 else if (TREE_CODE (type
) == ARRAY_TYPE
)
1371 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1372 outer
= build_cplus_array_type (inner
, TYPE_DOMAIN (type
));
1373 /* Don't call cp_build_qualified_type on ARRAY_TYPEs, the
1374 element type qualification will be handled by the recursive
1375 cp_reconstruct_complex_type call and cp_build_qualified_type
1376 for ARRAY_TYPEs changes the element type. */
1379 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
1381 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1382 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
1383 outer
= apply_memfn_quals (outer
, type_memfn_quals (type
));
1385 else if (TREE_CODE (type
) == METHOD_TYPE
)
1387 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1388 /* The build_method_type_directly() routine prepends 'this' to argument list,
1389 so we must compensate by getting rid of it. */
1391 = build_method_type_directly
1392 (class_of_this_parm (type
), inner
,
1393 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
1395 else if (TREE_CODE (type
) == OFFSET_TYPE
)
1397 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1398 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
1403 if (TYPE_ATTRIBUTES (type
))
1404 outer
= cp_build_type_attribute_variant (outer
, TYPE_ATTRIBUTES (type
));
1405 outer
= cp_build_qualified_type (outer
, cp_type_quals (type
));
1406 outer
= cxx_copy_lang_qualifiers (outer
, type
);
1411 /* Replaces any constexpr expression that may be into the attributes
1412 arguments with their reduced value. */
1415 cp_check_const_attributes (tree attributes
)
1417 if (attributes
== error_mark_node
)
1421 for (attr
= attributes
; attr
; attr
= TREE_CHAIN (attr
))
1424 for (arg
= TREE_VALUE (attr
); arg
&& TREE_CODE (arg
) == TREE_LIST
;
1425 arg
= TREE_CHAIN (arg
))
1427 tree expr
= TREE_VALUE (arg
);
1429 TREE_VALUE (arg
) = fold_non_dependent_expr (expr
);
1434 /* Return true if TYPE is an OpenMP mappable type.
1435 If NOTES is non-zero, emit a note message for each problem. */
1437 cp_omp_mappable_type_1 (tree type
, bool notes
)
1441 /* Mappable type has to be complete. */
1442 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1444 if (notes
&& type
!= error_mark_node
)
1446 tree decl
= TYPE_MAIN_DECL (type
);
1447 inform ((decl
? DECL_SOURCE_LOCATION (decl
) : input_location
),
1448 "incomplete type %qT is not mappable", type
);
1452 /* Arrays have mappable type if the elements have mappable type. */
1453 while (TREE_CODE (type
) == ARRAY_TYPE
)
1454 type
= TREE_TYPE (type
);
1455 /* A mappable type cannot contain virtual members. */
1456 if (CLASS_TYPE_P (type
) && CLASSTYPE_VTABLES (type
))
1459 inform (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
)),
1460 "type %qT with virtual members is not mappable", type
);
1463 /* All data members must be non-static. */
1464 if (CLASS_TYPE_P (type
))
1467 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1471 inform (DECL_SOURCE_LOCATION (field
),
1472 "static field %qD is not mappable", field
);
1475 /* All fields must have mappable types. */
1476 else if (TREE_CODE (field
) == FIELD_DECL
1477 && !cp_omp_mappable_type_1 (TREE_TYPE (field
), notes
))
1483 /* Return true if TYPE is an OpenMP mappable type. */
1485 cp_omp_mappable_type (tree type
)
1487 return cp_omp_mappable_type_1 (type
, false);
1490 /* Return true if TYPE is an OpenMP mappable type.
1491 Emit an error messages if not. */
1493 cp_omp_emit_unmappable_type_notes (tree type
)
1495 return cp_omp_mappable_type_1 (type
, true);
1498 /* Return the last pushed declaration for the symbol DECL or NULL
1499 when no such declaration exists. */
1502 find_last_decl (tree decl
)
1504 tree last_decl
= NULL_TREE
;
1506 if (tree name
= DECL_P (decl
) ? DECL_NAME (decl
) : NULL_TREE
)
1508 /* Look up the declaration in its scope. */
1509 tree pushed_scope
= NULL_TREE
;
1510 if (tree ctype
= DECL_CONTEXT (decl
))
1511 pushed_scope
= push_scope (ctype
);
1513 last_decl
= lookup_name (name
);
1516 pop_scope (pushed_scope
);
1518 /* The declaration may be a member conversion operator
1519 or a bunch of overfloads (handle the latter below). */
1520 if (last_decl
&& BASELINK_P (last_decl
))
1521 last_decl
= BASELINK_FUNCTIONS (last_decl
);
1527 if (DECL_P (last_decl
) || TREE_CODE (last_decl
) == OVERLOAD
)
1529 /* A set of overloads of the same function. */
1530 for (lkp_iterator
iter (last_decl
); iter
; ++iter
)
1532 if (TREE_CODE (*iter
) == OVERLOAD
)
1535 if (decls_match (decl
, *iter
, /*record_decls=*/false))
1544 /* Like decl_attributes, but handle C++ complexity. */
1547 cplus_decl_attributes (tree
*decl
, tree attributes
, int flags
)
1549 if (*decl
== NULL_TREE
|| *decl
== void_type_node
1550 || *decl
== error_mark_node
)
1553 /* Add implicit "omp declare target" attribute if requested. */
1554 if (vec_safe_length (scope_chain
->omp_declare_target_attribute
)
1556 && (TREE_STATIC (*decl
) || DECL_EXTERNAL (*decl
)))
1557 || TREE_CODE (*decl
) == FUNCTION_DECL
))
1560 && DECL_CLASS_SCOPE_P (*decl
))
1561 error ("%q+D static data member inside of declare target directive",
1563 else if (VAR_P (*decl
)
1564 && (processing_template_decl
1565 || !cp_omp_mappable_type (TREE_TYPE (*decl
))))
1566 attributes
= tree_cons (get_identifier ("omp declare target implicit"),
1567 NULL_TREE
, attributes
);
1570 attributes
= tree_cons (get_identifier ("omp declare target"),
1571 NULL_TREE
, attributes
);
1572 attributes
= tree_cons (get_identifier ("omp declare target block"),
1573 NULL_TREE
, attributes
);
1577 if (processing_template_decl
)
1579 if (check_for_bare_parameter_packs (attributes
))
1582 save_template_attributes (&attributes
, decl
, flags
);
1585 cp_check_const_attributes (attributes
);
1587 if ((flag_openmp
|| flag_openmp_simd
) && attributes
!= error_mark_node
)
1589 bool diagnosed
= false;
1590 for (tree
*pa
= &attributes
; *pa
; )
1592 if (get_attribute_namespace (*pa
) == omp_identifier
)
1594 tree name
= get_attribute_name (*pa
);
1595 if (is_attribute_p ("directive", name
)
1596 || is_attribute_p ("sequence", name
))
1600 error ("%<omp::%E%> not allowed to be specified in this "
1604 *pa
= TREE_CHAIN (*pa
);
1608 pa
= &TREE_CHAIN (*pa
);
1612 if (TREE_CODE (*decl
) == TEMPLATE_DECL
)
1613 decl
= &DECL_TEMPLATE_RESULT (*decl
);
1615 if (TREE_TYPE (*decl
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl
)))
1618 = decl_attributes (decl
, attributes
, flags
| ATTR_FLAG_FUNCTION_NEXT
);
1619 decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE_RAW (TREE_TYPE (*decl
)),
1624 tree last_decl
= find_last_decl (*decl
);
1625 decl_attributes (decl
, attributes
, flags
, last_decl
);
1628 /* Propagate deprecation out to the template. */
1629 if (TREE_DEPRECATED (*decl
))
1630 if (tree ti
= get_template_info (*decl
))
1632 tree tmpl
= TI_TEMPLATE (ti
);
1633 tree pattern
= (TYPE_P (*decl
) ? TREE_TYPE (tmpl
)
1634 : DECL_TEMPLATE_RESULT (tmpl
));
1635 if (*decl
== pattern
)
1636 TREE_DEPRECATED (tmpl
) = true;
1639 /* Likewise, propagate unavailability out to the template. */
1640 if (TREE_UNAVAILABLE (*decl
))
1641 if (tree ti
= get_template_info (*decl
))
1643 tree tmpl
= TI_TEMPLATE (ti
);
1644 tree pattern
= (TYPE_P (*decl
) ? TREE_TYPE (tmpl
)
1645 : DECL_TEMPLATE_RESULT (tmpl
));
1646 if (*decl
== pattern
)
1647 TREE_UNAVAILABLE (tmpl
) = true;
1651 /* Walks through the namespace- or function-scope anonymous union
1652 OBJECT, with the indicated TYPE, building appropriate VAR_DECLs.
1653 Returns one of the fields for use in the mangled name. */
1656 build_anon_union_vars (tree type
, tree object
)
1658 tree main_decl
= NULL_TREE
;
1661 /* Rather than write the code to handle the non-union case,
1662 just give an error. */
1663 if (TREE_CODE (type
) != UNION_TYPE
)
1665 error_at (DECL_SOURCE_LOCATION (TYPE_MAIN_DECL (type
)),
1666 "anonymous struct not inside named type");
1667 return error_mark_node
;
1670 for (field
= TYPE_FIELDS (type
);
1672 field
= DECL_CHAIN (field
))
1677 if (DECL_ARTIFICIAL (field
))
1679 if (TREE_CODE (field
) != FIELD_DECL
)
1681 permerror (DECL_SOURCE_LOCATION (field
),
1682 "%q#D invalid; an anonymous union can only "
1683 "have non-static data members", field
);
1687 if (TREE_PRIVATE (field
))
1688 permerror (DECL_SOURCE_LOCATION (field
),
1689 "private member %q#D in anonymous union", field
);
1690 else if (TREE_PROTECTED (field
))
1691 permerror (DECL_SOURCE_LOCATION (field
),
1692 "protected member %q#D in anonymous union", field
);
1694 if (processing_template_decl
)
1695 ref
= build_min_nt_loc (UNKNOWN_LOCATION
, COMPONENT_REF
, object
,
1696 DECL_NAME (field
), NULL_TREE
);
1698 ref
= build_class_member_access_expr (object
, field
, NULL_TREE
,
1699 false, tf_warning_or_error
);
1701 if (DECL_NAME (field
))
1705 decl
= build_decl (input_location
,
1706 VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
1707 DECL_ANON_UNION_VAR_P (decl
) = 1;
1708 DECL_ARTIFICIAL (decl
) = 1;
1710 base
= get_base_address (object
);
1711 TREE_PUBLIC (decl
) = TREE_PUBLIC (base
);
1712 TREE_STATIC (decl
) = TREE_STATIC (base
);
1713 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (base
);
1715 SET_DECL_VALUE_EXPR (decl
, ref
);
1716 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1718 decl
= pushdecl (decl
);
1720 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1721 decl
= build_anon_union_vars (TREE_TYPE (field
), ref
);
1725 if (main_decl
== NULL_TREE
)
1732 /* Finish off the processing of a UNION_TYPE structure. If the union is an
1733 anonymous union, then all members must be laid out together. PUBLIC_P
1734 is nonzero if this union is not declared static. */
1737 finish_anon_union (tree anon_union_decl
)
1743 if (anon_union_decl
== error_mark_node
)
1746 type
= TREE_TYPE (anon_union_decl
);
1747 public_p
= TREE_PUBLIC (anon_union_decl
);
1749 /* The VAR_DECL's context is the same as the TYPE's context. */
1750 DECL_CONTEXT (anon_union_decl
) = DECL_CONTEXT (TYPE_NAME (type
));
1752 if (TYPE_FIELDS (type
) == NULL_TREE
)
1757 error ("namespace-scope anonymous aggregates must be static");
1761 main_decl
= build_anon_union_vars (type
, anon_union_decl
);
1762 if (main_decl
== error_mark_node
)
1764 if (main_decl
== NULL_TREE
)
1766 pedwarn (input_location
, 0, "anonymous union with no members");
1770 if (!processing_template_decl
)
1772 /* Use main_decl to set the mangled name. */
1773 DECL_NAME (anon_union_decl
) = DECL_NAME (main_decl
);
1774 maybe_commonize_var (anon_union_decl
);
1775 if (TREE_STATIC (anon_union_decl
) || DECL_EXTERNAL (anon_union_decl
))
1777 if (DECL_DISCRIMINATOR_P (anon_union_decl
))
1778 determine_local_discriminator (anon_union_decl
);
1779 mangle_decl (anon_union_decl
);
1781 DECL_NAME (anon_union_decl
) = NULL_TREE
;
1784 pushdecl (anon_union_decl
);
1785 cp_finish_decl (anon_union_decl
, NULL_TREE
, false, NULL_TREE
, 0);
1788 /* Auxiliary functions to make type signatures for
1789 `operator new' and `operator delete' correspond to
1790 what compiler will be expecting. */
1793 coerce_new_type (tree type
, location_t loc
)
1796 tree args
= TYPE_ARG_TYPES (type
);
1798 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
1800 if (!same_type_p (TREE_TYPE (type
), ptr_type_node
))
1803 error_at (loc
, "%<operator new%> must return type %qT",
1807 if (args
&& args
!= void_list_node
)
1809 if (TREE_PURPOSE (args
))
1811 /* [basic.stc.dynamic.allocation]
1813 The first parameter shall not have an associated default
1815 error_at (loc
, "the first parameter of %<operator new%> cannot "
1816 "have a default argument");
1817 /* Throw away the default argument. */
1818 TREE_PURPOSE (args
) = NULL_TREE
;
1821 if (!same_type_p (TREE_VALUE (args
), size_type_node
))
1824 args
= TREE_CHAIN (args
);
1831 permerror (loc
, "%<operator new%> takes type %<size_t%> (%qT) "
1832 "as first parameter", size_type_node
);
1837 args
= tree_cons (NULL_TREE
, size_type_node
, args
);
1840 type
= (cxx_copy_lang_qualifiers
1841 (build_function_type (ptr_type_node
, args
),
1850 coerce_delete_type (tree decl
, location_t loc
)
1853 tree type
= TREE_TYPE (decl
);
1854 tree args
= TYPE_ARG_TYPES (type
);
1856 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
1858 if (!same_type_p (TREE_TYPE (type
), void_type_node
))
1861 error_at (loc
, "%<operator delete%> must return type %qT",
1865 tree ptrtype
= ptr_type_node
;
1866 if (destroying_delete_p (decl
))
1868 if (DECL_CLASS_SCOPE_P (decl
))
1869 /* If the function is a destroying operator delete declared in class
1870 type C, the type of its first parameter shall be C*. */
1871 ptrtype
= build_pointer_type (DECL_CONTEXT (decl
));
1873 /* A destroying operator delete shall be a class member function named
1876 "destroying %<operator delete%> must be a member function");
1877 const ovl_op_info_t
*op
= IDENTIFIER_OVL_OP_INFO (DECL_NAME (decl
));
1878 if (op
->flags
& OVL_OP_FLAG_VEC
)
1879 error_at (loc
, "%<operator delete[]%> cannot be a destroying delete");
1880 if (!usual_deallocation_fn_p (decl
))
1881 error_at (loc
, "destroying %<operator delete%> must be a usual "
1882 "deallocation function");
1885 if (!args
|| args
== void_list_node
1886 || !same_type_p (TREE_VALUE (args
), ptrtype
))
1889 if (args
&& args
!= void_list_node
)
1890 args
= TREE_CHAIN (args
);
1891 error_at (loc
, "%<operator delete%> takes type %qT as first parameter",
1897 args
= tree_cons (NULL_TREE
, ptrtype
, args
);
1900 type
= (cxx_copy_lang_qualifiers
1901 (build_function_type (void_type_node
, args
),
1907 TREE_TYPE (decl
) = type
;
1910 /* DECL is a VAR_DECL for a vtable: walk through the entries in the vtable
1911 and mark them as needed. */
1914 mark_vtable_entries (tree decl
, vec
<tree
> &consteval_vtables
)
1917 unsigned HOST_WIDE_INT idx
;
1919 /* It's OK for the vtable to refer to deprecated virtual functions. */
1920 warning_sentinel
w(warn_deprecated_decl
);
1922 bool consteval_seen
= false;
1924 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)),
1929 STRIP_NOPS (fnaddr
);
1931 if (TREE_CODE (fnaddr
) != ADDR_EXPR
1932 && TREE_CODE (fnaddr
) != FDESC_EXPR
)
1933 /* This entry is an offset: a virtual base class offset, a
1934 virtual call offset, an RTTI offset, etc. */
1937 fn
= TREE_OPERAND (fnaddr
, 0);
1938 if (TREE_CODE (fn
) == FUNCTION_DECL
&& DECL_IMMEDIATE_FUNCTION_P (fn
))
1940 if (!consteval_seen
)
1942 consteval_seen
= true;
1943 consteval_vtables
.safe_push (decl
);
1947 TREE_ADDRESSABLE (fn
) = 1;
1948 /* When we don't have vcall offsets, we output thunks whenever
1949 we output the vtables that contain them. With vcall offsets,
1950 we know all the thunks we'll need when we emit a virtual
1951 function, so we emit the thunks there instead. */
1952 if (DECL_THUNK_P (fn
))
1953 use_thunk (fn
, /*emit_p=*/0);
1954 /* Set the location, as marking the function could cause
1955 instantiation. We do not need to preserve the incoming
1956 location, as we're called from c_parse_final_cleanups, which
1957 takes care of that. */
1958 input_location
= DECL_SOURCE_LOCATION (fn
);
1963 /* Replace any consteval functions in vtables with null pointers. */
1966 clear_consteval_vfns (vec
<tree
> &consteval_vtables
)
1968 for (tree vtable
: consteval_vtables
)
1969 for (constructor_elt
&elt
: CONSTRUCTOR_ELTS (DECL_INITIAL (vtable
)))
1971 tree fn
= cp_get_fndecl_from_callee (elt
.value
, /*fold*/false);
1972 if (fn
&& DECL_IMMEDIATE_FUNCTION_P (fn
))
1973 elt
.value
= build_zero_cst (vtable_entry_type
);
1977 /* Adjust the TLS model on variable DECL if need be, typically after
1978 the linkage of DECL has been modified. */
1981 adjust_var_decl_tls_model (tree decl
)
1983 if (CP_DECL_THREAD_LOCAL_P (decl
)
1984 && !lookup_attribute ("tls_model", DECL_ATTRIBUTES (decl
)))
1985 set_decl_tls_model (decl
, decl_default_tls_model (decl
));
1988 /* Set DECL up to have the closest approximation of "initialized common"
1989 linkage available. */
1992 comdat_linkage (tree decl
)
1995 make_decl_one_only (decl
, cxx_comdat_group (decl
));
1996 else if (TREE_CODE (decl
) == FUNCTION_DECL
1997 || (VAR_P (decl
) && DECL_ARTIFICIAL (decl
)))
1998 /* We can just emit function and compiler-generated variables
1999 statically; having multiple copies is (for the most part) only
2002 There are two correctness issues, however: the address of a
2003 template instantiation with external linkage should be the
2004 same, independent of what translation unit asks for the
2005 address, and this will not hold when we emit multiple copies of
2006 the function. However, there's little else we can do.
2008 Also, by default, the typeinfo implementation assumes that
2009 there will be only one copy of the string used as the name for
2010 each type. Therefore, if weak symbols are unavailable, the
2011 run-time library should perform a more conservative check; it
2012 should perform a string comparison, rather than an address
2014 TREE_PUBLIC (decl
) = 0;
2017 /* Static data member template instantiations, however, cannot
2018 have multiple copies. */
2019 if (DECL_INITIAL (decl
) == 0
2020 || DECL_INITIAL (decl
) == error_mark_node
)
2021 DECL_COMMON (decl
) = 1;
2022 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
2024 DECL_COMMON (decl
) = 1;
2025 DECL_INITIAL (decl
) = error_mark_node
;
2027 else if (!DECL_EXPLICIT_INSTANTIATION (decl
))
2029 /* We can't do anything useful; leave vars for explicit
2031 DECL_EXTERNAL (decl
) = 1;
2032 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2036 if (TREE_PUBLIC (decl
))
2037 DECL_COMDAT (decl
) = 1;
2040 adjust_var_decl_tls_model (decl
);
2043 /* For win32 we also want to put explicit instantiations in
2044 linkonce sections, so that they will be merged with implicit
2045 instantiations; otherwise we get duplicate symbol errors.
2046 For Darwin we do not want explicit instantiations to be
2050 maybe_make_one_only (tree decl
)
2052 /* We used to say that this was not necessary on targets that support weak
2053 symbols, because the implicit instantiations will defer to the explicit
2054 one. However, that's not actually the case in SVR4; a strong definition
2055 after a weak one is an error. Also, not making explicit
2056 instantiations one_only means that we can end up with two copies of
2057 some template instantiations. */
2061 /* We can't set DECL_COMDAT on functions, or cp_finish_file will think
2062 we can get away with not emitting them if they aren't used. We need
2063 to for variables so that cp_finish_decl will update their linkage,
2064 because their DECL_INITIAL may not have been set properly yet. */
2066 if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
2067 || (! DECL_EXPLICIT_INSTANTIATION (decl
)
2068 && ! DECL_TEMPLATE_SPECIALIZATION (decl
)))
2070 make_decl_one_only (decl
, cxx_comdat_group (decl
));
2074 varpool_node
*node
= varpool_node::get_create (decl
);
2075 DECL_COMDAT (decl
) = 1;
2076 /* Mark it needed so we don't forget to emit it. */
2077 node
->forced_by_abi
= true;
2078 TREE_USED (decl
) = 1;
2080 adjust_var_decl_tls_model (decl
);
2085 /* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
2086 This predicate will give the right answer during parsing of the
2087 function, which other tests may not. */
2090 vague_linkage_p (tree decl
)
2092 if (!TREE_PUBLIC (decl
))
2094 /* maybe_thunk_body clears TREE_PUBLIC and DECL_ABSTRACT_P on the
2095 maybe-in-charge 'tor variants; in that case we need to check one of
2096 the "clones" for the real linkage. But only in that case; before
2097 maybe_clone_body we haven't yet copied the linkage to the clones. */
2098 if (DECL_MAYBE_IN_CHARGE_CDTOR_P (decl
)
2099 && !DECL_ABSTRACT_P (decl
)
2100 && DECL_CHAIN (decl
)
2101 && DECL_CLONED_FUNCTION_P (DECL_CHAIN (decl
)))
2102 return vague_linkage_p (DECL_CHAIN (decl
));
2104 gcc_checking_assert (!DECL_COMDAT (decl
));
2107 /* Unfortunately, import_export_decl has not always been called
2108 before the function is processed, so we cannot simply check
2110 if (DECL_COMDAT (decl
)
2111 || (TREE_CODE (decl
) == FUNCTION_DECL
2112 && DECL_DECLARED_INLINE_P (decl
))
2113 || (DECL_LANG_SPECIFIC (decl
)
2114 && DECL_TEMPLATE_INSTANTIATION (decl
))
2115 || (VAR_P (decl
) && DECL_INLINE_VAR_P (decl
)))
2117 else if (DECL_FUNCTION_SCOPE_P (decl
))
2118 /* A local static in an inline effectively has vague linkage. */
2119 return (TREE_STATIC (decl
)
2120 && vague_linkage_p (DECL_CONTEXT (decl
)));
2125 /* Determine whether or not we want to specifically import or export CTYPE,
2126 using various heuristics. */
2129 import_export_class (tree ctype
)
2131 /* -1 for imported, 1 for exported. */
2132 int import_export
= 0;
2134 /* It only makes sense to call this function at EOF. The reason is
2135 that this function looks at whether or not the first non-inline
2136 non-abstract virtual member function has been defined in this
2137 translation unit. But, we can't possibly know that until we've
2138 seen the entire translation unit. */
2139 gcc_assert (at_eof
);
2141 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2144 /* If MULTIPLE_SYMBOL_SPACES is set and we saw a #pragma interface,
2145 we will have CLASSTYPE_INTERFACE_ONLY set but not
2146 CLASSTYPE_INTERFACE_KNOWN. In that case, we don't want to use this
2147 heuristic because someone will supply a #pragma implementation
2148 elsewhere, and deducing it here would produce a conflict. */
2149 if (CLASSTYPE_INTERFACE_ONLY (ctype
))
2152 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
2154 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
2156 else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
2157 && !flag_implicit_templates
)
2158 /* For a template class, without -fimplicit-templates, check the
2159 repository. If the virtual table is assigned to this
2160 translation unit, then export the class; otherwise, import
2163 else if (TYPE_POLYMORPHIC_P (ctype
))
2165 /* The ABI specifies that the virtual table and associated
2166 information are emitted with the key method, if any. */
2167 tree method
= CLASSTYPE_KEY_METHOD (ctype
);
2168 /* If weak symbol support is not available, then we must be
2169 careful not to emit the vtable when the key function is
2170 inline. An inline function can be defined in multiple
2171 translation units. If we were to emit the vtable in each
2172 translation unit containing a definition, we would get
2173 multiple definition errors at link-time. */
2174 if (method
&& (flag_weak
|| ! DECL_DECLARED_INLINE_P (method
)))
2175 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
2178 /* When MULTIPLE_SYMBOL_SPACES is set, we cannot count on seeing
2179 a definition anywhere else. */
2180 if (MULTIPLE_SYMBOL_SPACES
&& import_export
== -1)
2183 /* Allow back ends the chance to overrule the decision. */
2184 if (targetm
.cxx
.import_export_class
)
2185 import_export
= targetm
.cxx
.import_export_class (ctype
, import_export
);
2189 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
2190 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
2194 /* Return true if VAR has already been provided to the back end; in that
2195 case VAR should not be modified further by the front end. */
2197 var_finalized_p (tree var
)
2199 return varpool_node::get_create (var
)->definition
;
2202 /* DECL is a VAR_DECL or FUNCTION_DECL which, for whatever reason,
2203 must be emitted in this translation unit. Mark it as such. */
2206 mark_needed (tree decl
)
2208 TREE_USED (decl
) = 1;
2209 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2211 /* Extern inline functions don't become needed when referenced.
2212 If we know a method will be emitted in other TU and no new
2213 functions can be marked reachable, just use the external
2215 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
2216 node
->forced_by_abi
= true;
2218 /* #pragma interface can call mark_needed for
2219 maybe-in-charge 'tors; mark the clones as well. */
2221 FOR_EACH_CLONE (clone
, decl
)
2222 mark_needed (clone
);
2224 else if (VAR_P (decl
))
2226 varpool_node
*node
= varpool_node::get_create (decl
);
2227 /* C++ frontend use mark_decl_references to force COMDAT variables
2228 to be output that might appear dead otherwise. */
2229 node
->forced_by_abi
= true;
2233 /* DECL is either a FUNCTION_DECL or a VAR_DECL. This function
2234 returns true if a definition of this entity should be provided in
2235 this object file. Callers use this function to determine whether
2236 or not to let the back end know that a definition of DECL is
2237 available in this translation unit. */
2240 decl_needed_p (tree decl
)
2242 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
2243 /* This function should only be called at the end of the translation
2244 unit. We cannot be sure of whether or not something will be
2245 COMDAT until that point. */
2246 gcc_assert (at_eof
);
2248 /* All entities with external linkage that are not COMDAT/EXTERN should be
2249 emitted; they may be referred to from other object files. */
2250 if (TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
) && !DECL_REALLY_EXTERN (decl
))
2253 /* Functions marked "dllexport" must be emitted so that they are
2254 visible to other DLLs. */
2255 if (flag_keep_inline_dllexport
2256 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))
2259 /* When not optimizing, do not bother to produce definitions for extern
2261 if (DECL_REALLY_EXTERN (decl
)
2262 && ((TREE_CODE (decl
) != FUNCTION_DECL
2264 || (TREE_CODE (decl
) == FUNCTION_DECL
2265 && !opt_for_fn (decl
, optimize
)))
2266 && !lookup_attribute ("always_inline", decl
))
2269 /* If this entity was used, let the back end see it; it will decide
2270 whether or not to emit it into the object file. */
2271 if (TREE_USED (decl
))
2274 /* Virtual functions might be needed for devirtualization. */
2275 if (flag_devirtualize
2276 && TREE_CODE (decl
) == FUNCTION_DECL
2277 && DECL_VIRTUAL_P (decl
))
2280 /* Otherwise, DECL does not need to be emitted -- yet. A subsequent
2281 reference to DECL might cause it to be emitted later. */
2285 /* If necessary, write out the vtables for the dynamic class CTYPE.
2286 Returns true if any vtables were emitted. */
2289 maybe_emit_vtables (tree ctype
, vec
<tree
> &consteval_vtables
)
2294 varpool_node
*current
= NULL
, *last
= NULL
;
2296 /* If the vtables for this class have already been emitted there is
2297 nothing more to do. */
2298 primary_vtbl
= CLASSTYPE_VTABLES (ctype
);
2299 if (var_finalized_p (primary_vtbl
))
2301 /* Ignore dummy vtables made by get_vtable_decl. */
2302 if (TREE_TYPE (primary_vtbl
) == void_type_node
)
2305 /* On some targets, we cannot determine the key method until the end
2306 of the translation unit -- which is when this function is
2308 if (!targetm
.cxx
.key_method_may_be_inline ())
2309 determine_key_method (ctype
);
2311 /* See if any of the vtables are needed. */
2312 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= DECL_CHAIN (vtbl
))
2314 import_export_decl (vtbl
);
2315 if (DECL_NOT_REALLY_EXTERN (vtbl
) && decl_needed_p (vtbl
))
2320 /* If the references to this class' vtables are optimized away,
2321 still emit the appropriate debugging information. See
2323 if (DECL_COMDAT (primary_vtbl
)
2324 && CLASSTYPE_DEBUG_REQUESTED (ctype
))
2325 note_debug_info_needed (ctype
);
2329 /* The ABI requires that we emit all of the vtables if we emit any
2331 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= DECL_CHAIN (vtbl
))
2333 /* Mark entities references from the virtual table as used. */
2334 mark_vtable_entries (vtbl
, consteval_vtables
);
2336 if (TREE_TYPE (DECL_INITIAL (vtbl
)) == 0)
2338 vec
<tree
, va_gc
> *cleanups
= NULL
;
2339 tree expr
= store_init_value (vtbl
, DECL_INITIAL (vtbl
), &cleanups
,
2342 /* It had better be all done at compile-time. */
2343 gcc_assert (!expr
&& !cleanups
);
2347 DECL_EXTERNAL (vtbl
) = 0;
2348 rest_of_decl_compilation (vtbl
, 1, 1);
2350 /* Because we're only doing syntax-checking, we'll never end up
2351 actually marking the variable as written. */
2352 if (flag_syntax_only
)
2353 TREE_ASM_WRITTEN (vtbl
) = 1;
2354 else if (DECL_ONE_ONLY (vtbl
))
2356 current
= varpool_node::get_create (vtbl
);
2358 current
->add_to_same_comdat_group (last
);
2363 /* For abstract classes, the destructor has been removed from the
2364 vtable (in class.c's build_vtbl_initializer). For a compiler-
2365 generated destructor, it hence might not have been generated in
2366 this translation unit - and with '#pragma interface' it might
2367 never get generated. */
2368 if (CLASSTYPE_PURE_VIRTUALS (ctype
)
2369 && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (ctype
)
2370 && !CLASSTYPE_LAZY_DESTRUCTOR (ctype
)
2371 && DECL_DEFAULTED_IN_CLASS_P (CLASSTYPE_DESTRUCTOR (ctype
)))
2372 note_vague_linkage_fn (CLASSTYPE_DESTRUCTOR (ctype
));
2374 /* Since we're writing out the vtable here, also write the debug
2376 note_debug_info_needed (ctype
);
2381 /* A special return value from type_visibility meaning internal
2384 enum { VISIBILITY_ANON
= VISIBILITY_INTERNAL
+1 };
2386 static int expr_visibility (tree
);
2387 static int type_visibility (tree
);
2389 /* walk_tree helper function for type_visibility. */
2392 min_vis_r (tree
*tp
, int *walk_subtrees
, void *data
)
2394 int *vis_p
= (int *)data
;
2395 int this_vis
= VISIBILITY_DEFAULT
;
2398 else if (OVERLOAD_TYPE_P (*tp
)
2399 && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp
)))
2401 this_vis
= VISIBILITY_ANON
;
2404 else if (CLASS_TYPE_P (*tp
))
2406 this_vis
= CLASSTYPE_VISIBILITY (*tp
);
2409 else if (TREE_CODE (*tp
) == ARRAY_TYPE
2410 && uses_template_parms (TYPE_DOMAIN (*tp
)))
2411 this_vis
= expr_visibility (TYPE_MAX_VALUE (TYPE_DOMAIN (*tp
)));
2413 if (this_vis
> *vis_p
)
2416 /* Tell cp_walk_subtrees to look through typedefs. */
2417 if (*walk_subtrees
== 1)
2423 /* walk_tree helper function for expr_visibility. */
2426 min_vis_expr_r (tree
*tp
, int */
*walk_subtrees*/
, void *data
)
2428 int *vis_p
= (int *)data
;
2429 int tpvis
= VISIBILITY_DEFAULT
;
2431 switch (TREE_CODE (*tp
))
2434 case IMPLICIT_CONV_EXPR
:
2435 case STATIC_CAST_EXPR
:
2436 case REINTERPRET_CAST_EXPR
:
2437 case CONST_CAST_EXPR
:
2438 case DYNAMIC_CAST_EXPR
:
2442 tpvis
= type_visibility (TREE_TYPE (*tp
));
2447 if (! TREE_PUBLIC (*tp
))
2448 tpvis
= VISIBILITY_ANON
;
2450 tpvis
= DECL_VISIBILITY (*tp
);
2463 /* Returns the visibility of TYPE, which is the minimum visibility of its
2467 type_visibility (tree type
)
2469 int vis
= VISIBILITY_DEFAULT
;
2470 cp_walk_tree_without_duplicates (&type
, min_vis_r
, &vis
);
2474 /* Returns the visibility of an expression EXPR that appears in the signature
2475 of a function template, which is the minimum visibility of names that appear
2479 expr_visibility (tree expr
)
2481 int vis
= VISIBILITY_DEFAULT
;
2482 cp_walk_tree_without_duplicates (&expr
, min_vis_expr_r
, &vis
);
2486 /* Limit the visibility of DECL to VISIBILITY, if not explicitly
2487 specified (or if VISIBILITY is static). If TMPL is true, this
2488 constraint is for a template argument, and takes precedence
2489 over explicitly-specified visibility on the template. */
2492 constrain_visibility (tree decl
, int visibility
, bool tmpl
)
2494 if (visibility
== VISIBILITY_ANON
)
2496 /* extern "C" declarations aren't affected by the anonymous
2498 if (!DECL_EXTERN_C_P (decl
))
2500 TREE_PUBLIC (decl
) = 0;
2501 DECL_WEAK (decl
) = 0;
2502 DECL_COMMON (decl
) = 0;
2503 DECL_COMDAT (decl
) = false;
2504 if (VAR_OR_FUNCTION_DECL_P (decl
))
2506 struct symtab_node
*snode
= symtab_node::get (decl
);
2509 snode
->set_comdat_group (NULL
);
2511 DECL_INTERFACE_KNOWN (decl
) = 1;
2512 if (DECL_LANG_SPECIFIC (decl
))
2513 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2516 else if (visibility
> DECL_VISIBILITY (decl
)
2517 && (tmpl
|| !DECL_VISIBILITY_SPECIFIED (decl
)))
2519 DECL_VISIBILITY (decl
) = (enum symbol_visibility
) visibility
;
2520 /* This visibility was not specified. */
2521 DECL_VISIBILITY_SPECIFIED (decl
) = false;
2525 /* Constrain the visibility of DECL based on the visibility of its template
2529 constrain_visibility_for_template (tree decl
, tree targs
)
2531 /* If this is a template instantiation, check the innermost
2532 template args for visibility constraints. The outer template
2533 args are covered by the class check. */
2534 tree args
= INNERMOST_TEMPLATE_ARGS (targs
);
2536 for (i
= TREE_VEC_LENGTH (args
); i
> 0; --i
)
2540 tree arg
= TREE_VEC_ELT (args
, i
-1);
2542 vis
= type_visibility (arg
);
2544 vis
= expr_visibility (arg
);
2546 constrain_visibility (decl
, vis
, true);
2550 /* Like c_determine_visibility, but with additional C++-specific
2553 Function-scope entities can rely on the function's visibility because
2554 it is set in start_preparsed_function.
2556 Class-scope entities cannot rely on the class's visibility until the end
2557 of the enclosing class definition.
2559 Note that because namespaces have multiple independent definitions,
2560 namespace visibility is handled elsewhere using the #pragma visibility
2561 machinery rather than by decorating the namespace declaration.
2563 The goal is for constraints from the type to give a diagnostic, and
2564 other constraints to be applied silently. */
2567 determine_visibility (tree decl
)
2569 /* Remember that all decls get VISIBILITY_DEFAULT when built. */
2571 /* Only relevant for names with external linkage. */
2572 if (!TREE_PUBLIC (decl
))
2575 /* Cloned constructors and destructors get the same visibility as
2576 the underlying function. That should be set up in
2577 maybe_clone_body. */
2578 gcc_assert (!DECL_CLONED_FUNCTION_P (decl
));
2580 bool orig_visibility_specified
= DECL_VISIBILITY_SPECIFIED (decl
);
2581 enum symbol_visibility orig_visibility
= DECL_VISIBILITY (decl
);
2583 /* The decl may be a template instantiation, which could influence
2585 tree template_decl
= NULL_TREE
;
2586 if (TREE_CODE (decl
) == TYPE_DECL
)
2588 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
2590 if (CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl
)))
2591 template_decl
= decl
;
2593 else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl
)))
2594 template_decl
= decl
;
2596 else if (DECL_LANG_SPECIFIC (decl
) && DECL_USE_TEMPLATE (decl
))
2597 template_decl
= decl
;
2599 if (TREE_CODE (decl
) == TYPE_DECL
2600 && LAMBDA_TYPE_P (TREE_TYPE (decl
))
2601 && CLASSTYPE_LAMBDA_EXPR (TREE_TYPE (decl
)) != error_mark_node
)
2602 if (tree extra
= LAMBDA_TYPE_EXTRA_SCOPE (TREE_TYPE (decl
)))
2604 /* The lambda's visibility is limited by that of its extra
2608 vis
= type_visibility (extra
);
2610 vis
= expr_visibility (extra
);
2611 constrain_visibility (decl
, vis
, false);
2614 /* If DECL is a member of a class, visibility specifiers on the
2615 class can influence the visibility of the DECL. */
2616 tree class_type
= NULL_TREE
;
2617 if (DECL_CLASS_SCOPE_P (decl
))
2618 class_type
= DECL_CONTEXT (decl
);
2621 /* Not a class member. */
2623 /* Virtual tables have DECL_CONTEXT set to their associated class,
2624 so they are automatically handled above. */
2625 gcc_assert (!VAR_P (decl
)
2626 || !DECL_VTABLE_OR_VTT_P (decl
));
2628 if (DECL_FUNCTION_SCOPE_P (decl
) && ! DECL_VISIBILITY_SPECIFIED (decl
))
2630 /* Local statics and classes get the visibility of their
2631 containing function by default, except that
2632 -fvisibility-inlines-hidden doesn't affect them. */
2633 tree fn
= DECL_CONTEXT (decl
);
2634 if (DECL_VISIBILITY_SPECIFIED (fn
))
2636 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (fn
);
2637 DECL_VISIBILITY_SPECIFIED (decl
) =
2638 DECL_VISIBILITY_SPECIFIED (fn
);
2642 if (DECL_CLASS_SCOPE_P (fn
))
2643 determine_visibility_from_class (decl
, DECL_CONTEXT (fn
));
2644 else if (determine_hidden_inline (fn
))
2646 DECL_VISIBILITY (decl
) = default_visibility
;
2647 DECL_VISIBILITY_SPECIFIED (decl
) =
2648 visibility_options
.inpragma
;
2652 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (fn
);
2653 DECL_VISIBILITY_SPECIFIED (decl
) =
2654 DECL_VISIBILITY_SPECIFIED (fn
);
2658 /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
2659 but have no TEMPLATE_INFO, so don't try to check it. */
2660 template_decl
= NULL_TREE
;
2662 else if (VAR_P (decl
) && DECL_TINFO_P (decl
)
2663 && flag_visibility_ms_compat
)
2665 /* Under -fvisibility-ms-compat, types are visible by default,
2666 even though their contents aren't. */
2667 tree underlying_type
= TREE_TYPE (DECL_NAME (decl
));
2668 int underlying_vis
= type_visibility (underlying_type
);
2669 if (underlying_vis
== VISIBILITY_ANON
2670 || (CLASS_TYPE_P (underlying_type
)
2671 && CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type
)))
2672 constrain_visibility (decl
, underlying_vis
, false);
2674 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
2676 else if (VAR_P (decl
) && DECL_TINFO_P (decl
))
2678 /* tinfo visibility is based on the type it's for. */
2679 constrain_visibility
2680 (decl
, type_visibility (TREE_TYPE (DECL_NAME (decl
))), false);
2682 /* Give the target a chance to override the visibility associated
2684 if (TREE_PUBLIC (decl
)
2685 && !DECL_REALLY_EXTERN (decl
)
2686 && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl
)))
2687 && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl
))))
2688 targetm
.cxx
.determine_class_data_visibility (decl
);
2690 else if (template_decl
)
2691 /* Template instantiations and specializations get visibility based
2692 on their template unless they override it with an attribute. */;
2693 else if (! DECL_VISIBILITY_SPECIFIED (decl
))
2695 if (determine_hidden_inline (decl
))
2696 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2699 /* Set default visibility to whatever the user supplied with
2700 #pragma GCC visibility or a namespace visibility attribute. */
2701 DECL_VISIBILITY (decl
) = default_visibility
;
2702 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
2709 /* If the specialization doesn't specify visibility, use the
2710 visibility from the template. */
2711 tree tinfo
= get_template_info (template_decl
);
2712 tree args
= TI_ARGS (tinfo
);
2713 tree attribs
= (TREE_CODE (decl
) == TYPE_DECL
2714 ? TYPE_ATTRIBUTES (TREE_TYPE (decl
))
2715 : DECL_ATTRIBUTES (decl
));
2716 tree attr
= lookup_attribute ("visibility", attribs
);
2718 if (args
!= error_mark_node
)
2720 tree pattern
= DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo
));
2722 if (!DECL_VISIBILITY_SPECIFIED (decl
))
2725 && determine_hidden_inline (decl
))
2726 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2729 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (pattern
);
2730 DECL_VISIBILITY_SPECIFIED (decl
)
2731 = DECL_VISIBILITY_SPECIFIED (pattern
);
2736 /* Template argument visibility outweighs #pragma or namespace
2737 visibility, but not an explicit attribute. */
2740 int depth
= TMPL_ARGS_DEPTH (args
);
2741 if (DECL_VISIBILITY_SPECIFIED (decl
))
2743 /* A class template member with explicit visibility
2744 overrides the class visibility, so we need to apply
2745 all the levels of template args directly. */
2747 for (i
= 1; i
<= depth
; ++i
)
2749 tree lev
= TMPL_ARGS_LEVEL (args
, i
);
2750 constrain_visibility_for_template (decl
, lev
);
2753 else if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo
)))
2754 /* Limit visibility based on its template arguments. */
2755 constrain_visibility_for_template (decl
, args
);
2761 determine_visibility_from_class (decl
, class_type
);
2763 if (decl_anon_ns_mem_p (decl
))
2764 /* Names in an anonymous namespace get internal linkage. */
2765 constrain_visibility (decl
, VISIBILITY_ANON
, false);
2766 else if (TREE_CODE (decl
) != TYPE_DECL
)
2768 /* Propagate anonymity from type to decl. */
2769 int tvis
= type_visibility (TREE_TYPE (decl
));
2770 if (tvis
== VISIBILITY_ANON
2771 || ! DECL_VISIBILITY_SPECIFIED (decl
))
2772 constrain_visibility (decl
, tvis
, false);
2774 else if (no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/true))
2775 /* DR 757: A type without linkage shall not be used as the type of a
2776 variable or function with linkage, unless
2777 o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
2778 o the variable or function is not used (3.2 [basic.def.odr]) or is
2779 defined in the same translation unit.
2781 Since non-extern "C" decls need to be defined in the same
2782 translation unit, we can make the type internal. */
2783 constrain_visibility (decl
, VISIBILITY_ANON
, false);
2785 /* If visibility changed and DECL already has DECL_RTL, ensure
2786 symbol flags are updated. */
2787 if ((DECL_VISIBILITY (decl
) != orig_visibility
2788 || DECL_VISIBILITY_SPECIFIED (decl
) != orig_visibility_specified
)
2789 && ((VAR_P (decl
) && TREE_STATIC (decl
))
2790 || TREE_CODE (decl
) == FUNCTION_DECL
)
2791 && DECL_RTL_SET_P (decl
))
2792 make_decl_rtl (decl
);
2795 /* By default, static data members and function members receive
2796 the visibility of their containing class. */
2799 determine_visibility_from_class (tree decl
, tree class_type
)
2801 if (DECL_VISIBILITY_SPECIFIED (decl
))
2804 if (determine_hidden_inline (decl
))
2805 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2808 /* Default to the class visibility. */
2809 DECL_VISIBILITY (decl
) = CLASSTYPE_VISIBILITY (class_type
);
2810 DECL_VISIBILITY_SPECIFIED (decl
)
2811 = CLASSTYPE_VISIBILITY_SPECIFIED (class_type
);
2814 /* Give the target a chance to override the visibility associated
2817 && TREE_PUBLIC (decl
)
2818 && (DECL_TINFO_P (decl
) || DECL_VTABLE_OR_VTT_P (decl
))
2819 && !DECL_REALLY_EXTERN (decl
)
2820 && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type
))
2821 targetm
.cxx
.determine_class_data_visibility (decl
);
2824 /* Returns true iff DECL is an inline that should get hidden visibility
2825 because of -fvisibility-inlines-hidden. */
2828 determine_hidden_inline (tree decl
)
2830 return (visibility_options
.inlines_hidden
2831 /* Don't do this for inline templates; specializations might not be
2832 inline, and we don't want them to inherit the hidden
2833 visibility. We'll set it here for all inline instantiations. */
2834 && !processing_template_decl
2835 && TREE_CODE (decl
) == FUNCTION_DECL
2836 && DECL_DECLARED_INLINE_P (decl
)
2837 && (! DECL_LANG_SPECIFIC (decl
)
2838 || ! DECL_EXPLICIT_INSTANTIATION (decl
)));
2841 /* Constrain the visibility of a class TYPE based on the visibility of its
2842 field types. Warn if any fields require lesser visibility. */
2845 constrain_class_visibility (tree type
)
2851 int vis
= type_visibility (type
);
2853 if (vis
== VISIBILITY_ANON
2854 || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type
)))
2857 /* Don't warn about visibility if the class has explicit visibility. */
2858 if (CLASSTYPE_VISIBILITY_SPECIFIED (type
))
2859 vis
= VISIBILITY_INTERNAL
;
2861 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
2862 if (TREE_CODE (t
) == FIELD_DECL
&& TREE_TYPE (t
) != error_mark_node
2863 && !DECL_ARTIFICIAL (t
))
2865 tree ftype
= strip_pointer_or_array_types (TREE_TYPE (t
));
2866 int subvis
= type_visibility (ftype
);
2868 if (subvis
== VISIBILITY_ANON
)
2870 if (!in_main_input_context())
2872 tree nlt
= no_linkage_check (ftype
, /*relaxed_p=*/false);
2875 if (same_type_p (TREE_TYPE (t
), nlt
))
2876 warning (OPT_Wsubobject_linkage
, "\
2877 %qT has a field %qD whose type has no linkage",
2880 warning (OPT_Wsubobject_linkage
, "\
2881 %qT has a field %qD whose type depends on the type %qT which has no linkage",
2885 warning (OPT_Wsubobject_linkage
, "\
2886 %qT has a field %qD whose type uses the anonymous namespace",
2890 else if (MAYBE_CLASS_TYPE_P (ftype
)
2891 && vis
< VISIBILITY_HIDDEN
2892 && subvis
>= VISIBILITY_HIDDEN
)
2893 warning (OPT_Wattributes
, "\
2894 %qT declared with greater visibility than the type of its field %qD",
2898 binfo
= TYPE_BINFO (type
);
2899 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, t
); ++i
)
2901 int subvis
= type_visibility (TREE_TYPE (t
));
2903 if (subvis
== VISIBILITY_ANON
)
2905 if (!in_main_input_context())
2907 tree nlt
= no_linkage_check (TREE_TYPE (t
), /*relaxed_p=*/false);
2910 if (same_type_p (TREE_TYPE (t
), nlt
))
2911 warning (OPT_Wsubobject_linkage
, "\
2912 %qT has a base %qT whose type has no linkage",
2913 type
, TREE_TYPE (t
));
2915 warning (OPT_Wsubobject_linkage
, "\
2916 %qT has a base %qT whose type depends on the type %qT which has no linkage",
2917 type
, TREE_TYPE (t
), nlt
);
2920 warning (OPT_Wsubobject_linkage
, "\
2921 %qT has a base %qT whose type uses the anonymous namespace",
2922 type
, TREE_TYPE (t
));
2925 else if (vis
< VISIBILITY_HIDDEN
2926 && subvis
>= VISIBILITY_HIDDEN
)
2927 warning (OPT_Wattributes
, "\
2928 %qT declared with greater visibility than its base %qT",
2929 type
, TREE_TYPE (t
));
2933 /* Functions for adjusting the visibility of a tagged type and its nested
2934 types and declarations when it gets a name for linkage purposes from a
2936 // FIXME: It is now a DR for such a class type to contain anything
2937 // other than C. So at minium most of this can probably be deleted.
2939 /* First reset the visibility of all the types. */
2942 reset_type_linkage_1 (tree type
)
2944 set_linkage_according_to_type (type
, TYPE_MAIN_DECL (type
));
2945 if (CLASS_TYPE_P (type
))
2946 for (tree member
= TYPE_FIELDS (type
); member
; member
= DECL_CHAIN (member
))
2947 if (DECL_IMPLICIT_TYPEDEF_P (member
))
2948 reset_type_linkage_1 (TREE_TYPE (member
));
2951 /* Then reset the visibility of any static data members or member
2952 functions that use those types. */
2955 reset_decl_linkage (tree decl
)
2957 if (TREE_PUBLIC (decl
))
2959 if (DECL_CLONED_FUNCTION_P (decl
))
2961 TREE_PUBLIC (decl
) = true;
2962 DECL_INTERFACE_KNOWN (decl
) = false;
2963 determine_visibility (decl
);
2964 tentative_decl_linkage (decl
);
2968 reset_type_linkage (tree type
)
2970 reset_type_linkage_1 (type
);
2971 if (CLASS_TYPE_P (type
))
2973 if (tree vt
= CLASSTYPE_VTABLES (type
))
2975 tree name
= mangle_vtbl_for_type (type
);
2976 DECL_NAME (vt
) = name
;
2977 SET_DECL_ASSEMBLER_NAME (vt
, name
);
2978 reset_decl_linkage (vt
);
2980 if (!ANON_AGGR_TYPE_P (type
))
2981 if (tree ti
= CLASSTYPE_TYPEINFO_VAR (type
))
2983 tree name
= mangle_typeinfo_for_type (type
);
2984 DECL_NAME (ti
) = name
;
2985 SET_DECL_ASSEMBLER_NAME (ti
, name
);
2986 TREE_TYPE (name
) = type
;
2987 reset_decl_linkage (ti
);
2989 for (tree m
= TYPE_FIELDS (type
); m
; m
= DECL_CHAIN (m
))
2991 tree mem
= STRIP_TEMPLATE (m
);
2992 if (TREE_CODE (mem
) == VAR_DECL
|| TREE_CODE (mem
) == FUNCTION_DECL
)
2993 reset_decl_linkage (mem
);
2994 else if (DECL_IMPLICIT_TYPEDEF_P (mem
))
2995 reset_type_linkage (TREE_TYPE (mem
));
3000 /* Set up our initial idea of what the linkage of DECL should be. */
3003 tentative_decl_linkage (tree decl
)
3005 if (DECL_INTERFACE_KNOWN (decl
))
3006 /* We've already made a decision as to how this function will
3008 else if (vague_linkage_p (decl
))
3010 if (TREE_CODE (decl
) == FUNCTION_DECL
3011 && decl_defined_p (decl
))
3013 DECL_EXTERNAL (decl
) = 1;
3014 DECL_NOT_REALLY_EXTERN (decl
) = 1;
3015 note_vague_linkage_fn (decl
);
3016 /* A non-template inline function with external linkage will
3017 always be COMDAT. As we must eventually determine the
3018 linkage of all functions, and as that causes writes to
3019 the data mapped in from the PCH file, it's advantageous
3020 to mark the functions at this point. */
3021 if (DECL_DECLARED_INLINE_P (decl
)
3022 && (!DECL_IMPLICIT_INSTANTIATION (decl
)
3023 || DECL_DEFAULTED_FN (decl
)))
3025 /* This function must have external linkage, as
3026 otherwise DECL_INTERFACE_KNOWN would have been
3028 gcc_assert (TREE_PUBLIC (decl
));
3029 comdat_linkage (decl
);
3030 DECL_INTERFACE_KNOWN (decl
) = 1;
3033 else if (VAR_P (decl
))
3034 maybe_commonize_var (decl
);
3038 /* DECL is a FUNCTION_DECL or VAR_DECL. If the object file linkage
3039 for DECL has not already been determined, do so now by setting
3040 DECL_EXTERNAL, DECL_COMDAT and other related flags. Until this
3041 function is called entities with vague linkage whose definitions
3042 are available must have TREE_PUBLIC set.
3044 If this function decides to place DECL in COMDAT, it will set
3045 appropriate flags -- but will not clear DECL_EXTERNAL. It is up to
3046 the caller to decide whether or not to clear DECL_EXTERNAL. Some
3047 callers defer that decision until it is clear that DECL is actually
3051 import_export_decl (tree decl
)
3055 tree class_type
= NULL_TREE
;
3057 if (DECL_INTERFACE_KNOWN (decl
))
3060 /* We cannot determine what linkage to give to an entity with vague
3061 linkage until the end of the file. For example, a virtual table
3062 for a class will be defined if and only if the key method is
3063 defined in this translation unit. */
3064 gcc_assert (at_eof
);
3065 /* Object file linkage for explicit instantiations is handled in
3066 mark_decl_instantiated. For static variables in functions with
3067 vague linkage, maybe_commonize_var is used.
3069 Therefore, the only declarations that should be provided to this
3070 function are those with external linkage that are:
3072 * implicit instantiations of function templates
3076 * implicit instantiations of static data members of class
3083 Furthermore, all entities that reach this point must have a
3084 definition available in this translation unit.
3086 The following assertions check these conditions. */
3087 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
3088 /* Any code that creates entities with TREE_PUBLIC cleared should
3089 also set DECL_INTERFACE_KNOWN. */
3090 gcc_assert (TREE_PUBLIC (decl
));
3091 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3092 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl
)
3093 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
)
3094 || DECL_DECLARED_INLINE_P (decl
));
3096 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl
)
3097 || DECL_VTABLE_OR_VTT_P (decl
)
3098 || DECL_TINFO_P (decl
));
3099 /* Check that a definition of DECL is available in this translation
3101 gcc_assert (!DECL_REALLY_EXTERN (decl
));
3103 /* Assume that DECL will not have COMDAT linkage. */
3105 /* Assume that DECL will not be imported into this translation
3109 if (VAR_P (decl
) && DECL_VTABLE_OR_VTT_P (decl
))
3111 class_type
= DECL_CONTEXT (decl
);
3112 import_export_class (class_type
);
3113 if (CLASSTYPE_INTERFACE_KNOWN (class_type
)
3114 && CLASSTYPE_INTERFACE_ONLY (class_type
))
3116 else if ((!flag_weak
|| TARGET_WEAK_NOT_IN_ARCHIVE_TOC
)
3117 && !CLASSTYPE_USE_TEMPLATE (class_type
)
3118 && CLASSTYPE_KEY_METHOD (class_type
)
3119 && !DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type
)))
3120 /* The ABI requires that all virtual tables be emitted with
3121 COMDAT linkage. However, on systems where COMDAT symbols
3122 don't show up in the table of contents for a static
3123 archive, or on systems without weak symbols (where we
3124 approximate COMDAT linkage by using internal linkage), the
3125 linker will report errors about undefined symbols because
3126 it will not see the virtual table definition. Therefore,
3127 in the case that we know that the virtual table will be
3128 emitted in only one translation unit, we make the virtual
3129 table an ordinary definition with external linkage. */
3130 DECL_EXTERNAL (decl
) = 0;
3131 else if (CLASSTYPE_INTERFACE_KNOWN (class_type
))
3133 /* CLASS_TYPE is being exported from this translation unit,
3134 so DECL should be defined here. */
3135 if (!flag_weak
&& CLASSTYPE_EXPLICIT_INSTANTIATION (class_type
))
3136 /* If a class is declared in a header with the "extern
3137 template" extension, then it will not be instantiated,
3138 even in translation units that would normally require
3139 it. Often such classes are explicitly instantiated in
3140 one translation unit. Therefore, the explicit
3141 instantiation must be made visible to other translation
3143 DECL_EXTERNAL (decl
) = 0;
3146 /* The generic C++ ABI says that class data is always
3147 COMDAT, even if there is a key function. Some
3148 variants (e.g., the ARM EABI) says that class data
3149 only has COMDAT linkage if the class data might be
3150 emitted in more than one translation unit. When the
3151 key method can be inline and is inline, we still have
3152 to arrange for comdat even though
3153 class_data_always_comdat is false. */
3154 if (!CLASSTYPE_KEY_METHOD (class_type
)
3155 || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type
))
3156 || targetm
.cxx
.class_data_always_comdat ())
3158 /* The ABI requires COMDAT linkage. Normally, we
3159 only emit COMDAT things when they are needed;
3160 make sure that we realize that this entity is
3167 else if (!flag_implicit_templates
3168 && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type
))
3173 else if (VAR_P (decl
) && DECL_TINFO_P (decl
))
3175 tree type
= TREE_TYPE (DECL_NAME (decl
));
3176 if (CLASS_TYPE_P (type
))
3179 import_export_class (type
);
3180 if (CLASSTYPE_INTERFACE_KNOWN (type
)
3181 && TYPE_POLYMORPHIC_P (type
)
3182 && CLASSTYPE_INTERFACE_ONLY (type
)
3183 /* If -fno-rtti was specified, then we cannot be sure
3184 that RTTI information will be emitted with the
3185 virtual table of the class, so we must emit it
3186 wherever it is used. */
3191 if (CLASSTYPE_INTERFACE_KNOWN (type
)
3192 && !CLASSTYPE_INTERFACE_ONLY (type
))
3194 comdat_p
= (targetm
.cxx
.class_data_always_comdat ()
3195 || (CLASSTYPE_KEY_METHOD (type
)
3196 && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type
))));
3201 DECL_EXTERNAL (decl
) = 0;
3211 else if (DECL_TEMPLOID_INSTANTIATION (decl
))
3213 /* DECL is an implicit instantiation of a function or static
3215 if (flag_implicit_templates
3216 || (flag_implicit_inline_templates
3217 && TREE_CODE (decl
) == FUNCTION_DECL
3218 && DECL_DECLARED_INLINE_P (decl
)))
3221 /* If we are not implicitly generating templates, then mark
3222 this entity as undefined in this translation unit. */
3225 else if (DECL_FUNCTION_MEMBER_P (decl
))
3227 if (!DECL_DECLARED_INLINE_P (decl
))
3229 tree ctype
= DECL_CONTEXT (decl
);
3230 import_export_class (ctype
);
3231 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
3233 DECL_NOT_REALLY_EXTERN (decl
)
3234 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
3235 || (DECL_DECLARED_INLINE_P (decl
)
3236 && ! flag_implement_inlines
3237 && !DECL_VINDEX (decl
)));
3239 if (!DECL_NOT_REALLY_EXTERN (decl
))
3240 DECL_EXTERNAL (decl
) = 1;
3242 /* Always make artificials weak. */
3243 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
3246 maybe_make_one_only (decl
);
3257 /* If we are importing DECL into this translation unit, mark is
3258 an undefined here. */
3259 DECL_EXTERNAL (decl
) = 1;
3260 DECL_NOT_REALLY_EXTERN (decl
) = 0;
3264 /* If we decided to put DECL in COMDAT, mark it accordingly at
3266 comdat_linkage (decl
);
3269 DECL_INTERFACE_KNOWN (decl
) = 1;
3272 /* Return an expression that performs the destruction of DECL, which
3273 must be a VAR_DECL whose type has a non-trivial destructor, or is
3274 an array whose (innermost) elements have a non-trivial destructor. */
3277 build_cleanup (tree decl
)
3279 tree clean
= cxx_maybe_build_cleanup (decl
, tf_warning_or_error
);
3280 gcc_assert (clean
!= NULL_TREE
);
3284 /* GUARD is a helper variable for DECL; make them have the same linkage and
3288 copy_linkage (tree guard
, tree decl
)
3290 TREE_PUBLIC (guard
) = TREE_PUBLIC (decl
);
3291 TREE_STATIC (guard
) = TREE_STATIC (decl
);
3292 DECL_COMMON (guard
) = DECL_COMMON (decl
);
3293 DECL_COMDAT (guard
) = DECL_COMDAT (decl
);
3294 if (TREE_STATIC (guard
))
3296 CP_DECL_THREAD_LOCAL_P (guard
) = CP_DECL_THREAD_LOCAL_P (decl
);
3297 set_decl_tls_model (guard
, DECL_TLS_MODEL (decl
));
3298 if (DECL_ONE_ONLY (decl
))
3299 make_decl_one_only (guard
, cxx_comdat_group (guard
));
3300 if (TREE_PUBLIC (decl
))
3301 DECL_WEAK (guard
) = DECL_WEAK (decl
);
3302 /* Also check vague_linkage_p, as DECL_WEAK and DECL_ONE_ONLY might not
3303 be set until import_export_decl at EOF. */
3304 if (vague_linkage_p (decl
))
3305 comdat_linkage (guard
);
3306 DECL_VISIBILITY (guard
) = DECL_VISIBILITY (decl
);
3307 DECL_VISIBILITY_SPECIFIED (guard
) = DECL_VISIBILITY_SPECIFIED (decl
);
3311 /* Returns the initialization guard variable for the variable DECL,
3312 which has static storage duration. */
3315 get_guard (tree decl
)
3317 tree sname
= mangle_guard_variable (decl
);
3318 tree guard
= get_global_binding (sname
);
3323 /* We use a type that is big enough to contain a mutex as well
3324 as an integer counter. */
3325 guard_type
= targetm
.cxx
.guard_type ();
3326 guard
= build_decl (DECL_SOURCE_LOCATION (decl
),
3327 VAR_DECL
, sname
, guard_type
);
3329 /* The guard should have the same linkage as what it guards. */
3330 copy_linkage (guard
, decl
);
3332 DECL_ARTIFICIAL (guard
) = 1;
3333 DECL_IGNORED_P (guard
) = 1;
3334 TREE_USED (guard
) = 1;
3335 pushdecl_top_level_and_finish (guard
, NULL_TREE
);
3340 /* Returns true if accessing the GUARD atomic is expensive,
3341 i.e. involves a call to __sync_synchronize or similar.
3342 In this case let __cxa_guard_acquire handle the atomics. */
3345 is_atomic_expensive_p (machine_mode mode
)
3347 if (!flag_inline_atomics
)
3350 if (!can_compare_and_swap_p (mode
, false) || !can_atomic_load_p (mode
))
3356 /* Return an atomic load of src with the appropriate memory model. */
3359 build_atomic_load_type (tree src
, HOST_WIDE_INT model
, tree type
)
3361 tree ptr_type
= build_pointer_type (type
);
3362 tree mem_model
= build_int_cst (integer_type_node
, model
);
3367 size
= tree_to_uhwi (TYPE_SIZE_UNIT (type
));
3369 fncode
= BUILT_IN_ATOMIC_LOAD_N
+ exact_log2 (size
) + 1;
3370 t
= builtin_decl_implicit ((enum built_in_function
) fncode
);
3372 addr
= build1 (ADDR_EXPR
, ptr_type
, src
);
3373 val
= build_call_expr (t
, 2, addr
, mem_model
);
3377 /* Return those bits of the GUARD variable that should be set when the
3378 guarded entity is actually initialized. */
3381 get_guard_bits (tree guard
)
3383 if (!targetm
.cxx
.guard_mask_bit ())
3385 /* We only set the first byte of the guard, in order to leave room
3386 for a mutex in the high-order bits. */
3387 guard
= build1 (ADDR_EXPR
,
3388 build_pointer_type (TREE_TYPE (guard
)),
3390 guard
= build1 (NOP_EXPR
,
3391 build_pointer_type (char_type_node
),
3393 guard
= build1 (INDIRECT_REF
, char_type_node
, guard
);
3399 /* Return an expression which determines whether or not the GUARD
3400 variable has already been initialized. */
3403 get_guard_cond (tree guard
, bool thread_safe
)
3408 guard
= get_guard_bits (guard
);
3411 tree type
= targetm
.cxx
.guard_mask_bit ()
3412 ? TREE_TYPE (guard
) : char_type_node
;
3414 if (is_atomic_expensive_p (TYPE_MODE (type
)))
3415 guard
= integer_zero_node
;
3417 guard
= build_atomic_load_type (guard
, MEMMODEL_ACQUIRE
, type
);
3420 /* Mask off all but the low bit. */
3421 if (targetm
.cxx
.guard_mask_bit ())
3423 guard_value
= integer_one_node
;
3424 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
3425 guard_value
= fold_convert (TREE_TYPE (guard
), guard_value
);
3426 guard
= cp_build_binary_op (input_location
,
3427 BIT_AND_EXPR
, guard
, guard_value
,
3428 tf_warning_or_error
);
3431 guard_value
= integer_zero_node
;
3432 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
3433 guard_value
= fold_convert (TREE_TYPE (guard
), guard_value
);
3434 return cp_build_binary_op (input_location
,
3435 EQ_EXPR
, guard
, guard_value
,
3436 tf_warning_or_error
);
3439 /* Return an expression which sets the GUARD variable, indicating that
3440 the variable being guarded has been initialized. */
3443 set_guard (tree guard
)
3447 /* Set the GUARD to one. */
3448 guard
= get_guard_bits (guard
);
3449 guard_init
= integer_one_node
;
3450 if (!same_type_p (TREE_TYPE (guard_init
), TREE_TYPE (guard
)))
3451 guard_init
= fold_convert (TREE_TYPE (guard
), guard_init
);
3452 return cp_build_modify_expr (input_location
, guard
, NOP_EXPR
, guard_init
,
3453 tf_warning_or_error
);
3456 /* Returns true iff we can tell that VAR does not have a dynamic
3460 var_defined_without_dynamic_init (tree var
)
3462 /* constinit vars are guaranteed to not have dynamic initializer,
3463 but still registering the destructor counts as dynamic initialization. */
3464 if (DECL_DECLARED_CONSTINIT_P (var
)
3465 && COMPLETE_TYPE_P (TREE_TYPE (var
))
3466 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var
)))
3468 /* If it's defined in another TU, we can't tell. */
3469 if (DECL_EXTERNAL (var
))
3471 /* If it has a non-trivial destructor, registering the destructor
3472 counts as dynamic initialization. */
3473 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var
)))
3475 /* If it's in this TU, its initializer has been processed, unless
3476 it's a case of self-initialization, then DECL_INITIALIZED_P is
3477 false while the initializer is handled by finish_id_expression. */
3478 if (!DECL_INITIALIZED_P (var
))
3480 /* If it has no initializer or a constant one, it's not dynamic. */
3481 return (!DECL_NONTRIVIALLY_INITIALIZED_P (var
)
3482 || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var
));
3485 /* Returns true iff VAR is a variable that needs uses to be
3486 wrapped for possible dynamic initialization. */
3489 var_needs_tls_wrapper (tree var
)
3491 return (!error_operand_p (var
)
3492 && CP_DECL_THREAD_LOCAL_P (var
)
3493 && !DECL_GNU_TLS_P (var
)
3494 && !DECL_FUNCTION_SCOPE_P (var
)
3495 && !var_defined_without_dynamic_init (var
));
3498 /* Get the FUNCTION_DECL for the shared TLS init function for this
3499 translation unit. */
3502 get_local_tls_init_fn (location_t loc
)
3504 tree sname
= get_identifier ("__tls_init");
3505 tree fn
= get_global_binding (sname
);
3508 fn
= build_lang_decl_loc (loc
, FUNCTION_DECL
, sname
,
3509 build_function_type (void_type_node
,
3511 SET_DECL_LANGUAGE (fn
, lang_c
);
3512 TREE_PUBLIC (fn
) = false;
3513 DECL_ARTIFICIAL (fn
) = true;
3515 set_global_binding (fn
);
3520 /* Get a FUNCTION_DECL for the init function for the thread_local
3521 variable VAR. The init function will be an alias to the function
3522 that initializes all the non-local TLS variables in the translation
3523 unit. The init function is only used by the wrapper function. */
3526 get_tls_init_fn (tree var
)
3528 /* Only C++11 TLS vars need this init fn. */
3529 if (!var_needs_tls_wrapper (var
))
3532 /* If -fno-extern-tls-init, assume that we don't need to call
3533 a tls init function for a variable defined in another TU. */
3534 if (!flag_extern_tls_init
&& DECL_EXTERNAL (var
))
3537 /* If the variable is internal, or if we can't generate aliases,
3538 call the local init function directly. */
3539 if (!TREE_PUBLIC (var
) || !TARGET_SUPPORTS_ALIASES
)
3540 return get_local_tls_init_fn (DECL_SOURCE_LOCATION (var
));
3542 tree sname
= mangle_tls_init_fn (var
);
3543 tree fn
= get_global_binding (sname
);
3546 fn
= build_lang_decl (FUNCTION_DECL
, sname
,
3547 build_function_type (void_type_node
,
3549 SET_DECL_LANGUAGE (fn
, lang_c
);
3550 TREE_PUBLIC (fn
) = TREE_PUBLIC (var
);
3551 DECL_ARTIFICIAL (fn
) = true;
3552 DECL_COMDAT (fn
) = DECL_COMDAT (var
);
3553 DECL_EXTERNAL (fn
) = DECL_EXTERNAL (var
);
3554 if (DECL_ONE_ONLY (var
))
3555 make_decl_one_only (fn
, cxx_comdat_group (fn
));
3556 if (TREE_PUBLIC (var
))
3558 tree obtype
= strip_array_types (non_reference (TREE_TYPE (var
)));
3559 /* If the variable is defined somewhere else and might have static
3560 initialization, make the init function a weak reference. */
3561 if ((!TYPE_NEEDS_CONSTRUCTING (obtype
)
3562 || TYPE_HAS_CONSTEXPR_CTOR (obtype
)
3563 || TYPE_HAS_TRIVIAL_DFLT (obtype
))
3564 && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype
)
3565 && DECL_EXTERNAL (var
))
3568 DECL_WEAK (fn
) = DECL_WEAK (var
);
3570 DECL_VISIBILITY (fn
) = DECL_VISIBILITY (var
);
3571 DECL_VISIBILITY_SPECIFIED (fn
) = DECL_VISIBILITY_SPECIFIED (var
);
3572 DECL_DLLIMPORT_P (fn
) = DECL_DLLIMPORT_P (var
);
3573 DECL_IGNORED_P (fn
) = 1;
3576 DECL_BEFRIENDING_CLASSES (fn
) = var
;
3578 set_global_binding (fn
);
3583 /* Get a FUNCTION_DECL for the init wrapper function for the thread_local
3584 variable VAR. The wrapper function calls the init function (if any) for
3585 VAR and then returns a reference to VAR. The wrapper function is used
3586 in place of VAR everywhere VAR is mentioned. */
3589 get_tls_wrapper_fn (tree var
)
3591 /* Only C++11 TLS vars need this wrapper fn. */
3592 if (!var_needs_tls_wrapper (var
))
3595 tree sname
= mangle_tls_wrapper_fn (var
);
3596 tree fn
= get_global_binding (sname
);
3599 /* A named rvalue reference is an lvalue, so the wrapper should
3600 always return an lvalue reference. */
3601 tree type
= non_reference (TREE_TYPE (var
));
3602 type
= build_reference_type (type
);
3603 tree fntype
= build_function_type (type
, void_list_node
);
3605 fn
= build_lang_decl_loc (DECL_SOURCE_LOCATION (var
),
3606 FUNCTION_DECL
, sname
, fntype
);
3607 SET_DECL_LANGUAGE (fn
, lang_c
);
3608 TREE_PUBLIC (fn
) = TREE_PUBLIC (var
);
3609 DECL_ARTIFICIAL (fn
) = true;
3610 DECL_IGNORED_P (fn
) = 1;
3611 /* The wrapper is inline and emitted everywhere var is used. */
3612 DECL_DECLARED_INLINE_P (fn
) = true;
3613 if (TREE_PUBLIC (var
))
3615 comdat_linkage (fn
);
3616 #ifdef HAVE_GAS_HIDDEN
3617 /* Make the wrapper bind locally; there's no reason to share
3618 the wrapper between multiple shared objects. */
3619 DECL_VISIBILITY (fn
) = VISIBILITY_INTERNAL
;
3620 DECL_VISIBILITY_SPECIFIED (fn
) = true;
3623 if (!TREE_PUBLIC (fn
))
3624 DECL_INTERFACE_KNOWN (fn
) = true;
3626 note_vague_linkage_fn (fn
);
3629 /* We want CSE to commonize calls to the wrapper, but marking it as
3630 pure is unsafe since it has side-effects. I guess we need a new
3631 ECF flag even weaker than ECF_PURE. FIXME! */
3632 DECL_PURE_P (fn
) = true;
3635 DECL_BEFRIENDING_CLASSES (fn
) = var
;
3637 set_global_binding (fn
);
3642 /* If EXPR is a thread_local variable that should be wrapped by init
3643 wrapper function, return a call to that function, otherwise return
3647 maybe_get_tls_wrapper_call (tree expr
)
3650 && !processing_template_decl
3651 && !cp_unevaluated_operand
3652 && CP_DECL_THREAD_LOCAL_P (expr
))
3653 if (tree wrap
= get_tls_wrapper_fn (expr
))
3654 return build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3658 /* At EOF, generate the definition for the TLS wrapper function FN:
3661 if (init_fn) init_fn();
3666 generate_tls_wrapper (tree fn
)
3668 tree var
= DECL_BEFRIENDING_CLASSES (fn
);
3670 start_preparsed_function (fn
, NULL_TREE
, SF_DEFAULT
| SF_PRE_PARSED
);
3671 tree body
= begin_function_body ();
3672 /* Only call the init fn if there might be one. */
3673 if (tree init_fn
= get_tls_init_fn (var
))
3675 tree if_stmt
= NULL_TREE
;
3676 /* If init_fn is a weakref, make sure it exists before calling. */
3677 if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn
)))
3679 if_stmt
= begin_if_stmt ();
3680 tree addr
= cp_build_addr_expr (init_fn
, tf_warning_or_error
);
3681 tree cond
= cp_build_binary_op (DECL_SOURCE_LOCATION (var
),
3682 NE_EXPR
, addr
, nullptr_node
,
3683 tf_warning_or_error
);
3684 finish_if_stmt_cond (cond
, if_stmt
);
3686 finish_expr_stmt (build_cxx_call
3687 (init_fn
, 0, NULL
, tf_warning_or_error
));
3690 finish_then_clause (if_stmt
);
3691 finish_if_stmt (if_stmt
);
3695 /* If there's no initialization, the wrapper is a constant function. */
3696 TREE_READONLY (fn
) = true;
3697 finish_return_stmt (convert_from_reference (var
));
3698 finish_function_body (body
);
3699 expand_or_defer_fn (finish_function (/*inline_p=*/false));
3702 /* Start the process of running a particular set of global constructors
3703 or destructors. Subroutine of do_[cd]tors. Also called from
3704 vtv_start_verification_constructor_init_function. */
3707 start_objects (int method_type
, int initp
)
3709 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
3710 int module_init
= 0;
3712 if (initp
== DEFAULT_INIT_PRIORITY
&& method_type
== 'I')
3713 module_init
= module_initializer_kind ();
3715 tree name
= NULL_TREE
;
3716 if (module_init
> 0)
3717 name
= mangle_module_global_init (0);
3722 unsigned len
= sprintf (type
, "sub_%c", method_type
);
3723 if (initp
!= DEFAULT_INIT_PRIORITY
)
3729 type
[len
++] = joiner
;
3730 sprintf (type
+ len
, "%.5u", initp
);
3732 name
= get_file_function_name (type
);
3735 tree fntype
= build_function_type (void_type_node
, void_list_node
);
3736 tree fndecl
= build_lang_decl (FUNCTION_DECL
, name
, fntype
);
3737 DECL_CONTEXT (fndecl
) = FROB_CONTEXT (global_namespace
);
3738 if (module_init
> 0)
3740 SET_DECL_ASSEMBLER_NAME (fndecl
, name
);
3741 TREE_PUBLIC (fndecl
) = true;
3742 determine_visibility (fndecl
);
3745 TREE_PUBLIC (fndecl
) = 0;
3746 start_preparsed_function (fndecl
, /*attrs=*/NULL_TREE
, SF_PRE_PARSED
);
3748 /* Mark as artificial because it's not explicitly in the user's
3750 DECL_ARTIFICIAL (current_function_decl
) = 1;
3752 /* Mark this declaration as used to avoid spurious warnings. */
3753 TREE_USED (current_function_decl
) = 1;
3755 /* Mark this function as a global constructor or destructor. */
3756 if (method_type
== 'I')
3757 DECL_GLOBAL_CTOR_P (current_function_decl
) = 1;
3759 DECL_GLOBAL_DTOR_P (current_function_decl
) = 1;
3761 tree body
= begin_compound_stmt (BCS_FN_BODY
);
3763 if (module_init
> 0)
3765 // 'static bool __in_chrg = false;
3766 // if (__inchrg) return;
3768 tree var
= build_lang_decl (VAR_DECL
, in_charge_identifier
,
3770 DECL_CONTEXT (var
) = fndecl
;
3771 DECL_ARTIFICIAL (var
) = true;
3772 TREE_STATIC (var
) = true;
3774 cp_finish_decl (var
, NULL_TREE
, false, NULL_TREE
, 0);
3776 tree if_stmt
= begin_if_stmt ();
3777 finish_if_stmt_cond (var
, if_stmt
);
3778 finish_return_stmt (NULL_TREE
);
3779 finish_then_clause (if_stmt
);
3780 finish_if_stmt (if_stmt
);
3782 tree assign
= build2 (MODIFY_EXPR
, boolean_type_node
,
3783 var
, boolean_true_node
);
3784 TREE_SIDE_EFFECTS (assign
) = true;
3785 finish_expr_stmt (assign
);
3789 module_add_import_initializers ();
3794 /* Finish the process of running a particular set of global constructors
3795 or destructors. Subroutine of do_[cd]tors. */
3798 finish_objects (int method_type
, int initp
, tree body
)
3801 finish_compound_stmt (body
);
3802 tree fn
= finish_function (/*inline_p=*/false);
3804 if (method_type
== 'I')
3806 DECL_STATIC_CONSTRUCTOR (fn
) = 1;
3807 decl_init_priority_insert (fn
, initp
);
3811 DECL_STATIC_DESTRUCTOR (fn
) = 1;
3812 decl_fini_priority_insert (fn
, initp
);
3815 expand_or_defer_fn (fn
);
3818 /* The names of the parameters to the function created to handle
3819 initializations and destructions for objects with static storage
3821 #define INITIALIZE_P_IDENTIFIER "__initialize_p"
3822 #define PRIORITY_IDENTIFIER "__priority"
3824 /* The name of the function we create to handle initializations and
3825 destructions for objects with static storage duration. */
3826 #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
3828 /* The declaration for the __INITIALIZE_P argument. */
3829 static GTY(()) tree initialize_p_decl
;
3831 /* The declaration for the __PRIORITY argument. */
3832 static GTY(()) tree priority_decl
;
3834 /* The declaration for the static storage duration function. */
3835 static GTY(()) tree ssdf_decl
;
3837 /* All the static storage duration functions created in this
3838 translation unit. */
3839 static GTY(()) vec
<tree
, va_gc
> *ssdf_decls
;
3841 /* A map from priority levels to information about that priority
3842 level. There may be many such levels, so efficient lookup is
3844 static splay_tree priority_info_map
;
3846 /* Begins the generation of the function that will handle all
3847 initialization and destruction of objects with static storage
3848 duration. The function generated takes two parameters of type
3849 `int': __INITIALIZE_P and __PRIORITY. If __INITIALIZE_P is
3850 nonzero, it performs initializations. Otherwise, it performs
3851 destructions. It only performs those initializations or
3852 destructions with the indicated __PRIORITY. The generated function
3855 It is assumed that this function will only be called once per
3856 translation unit. */
3859 start_static_storage_duration_function (unsigned count
)
3863 char id
[sizeof (SSDF_IDENTIFIER
) + 1 /* '\0' */ + 32];
3865 /* Create the identifier for this function. It will be of the form
3866 SSDF_IDENTIFIER_<number>. */
3867 sprintf (id
, "%s_%u", SSDF_IDENTIFIER
, count
);
3869 type
= build_function_type_list (void_type_node
,
3870 integer_type_node
, integer_type_node
,
3873 /* Create the FUNCTION_DECL itself. */
3874 ssdf_decl
= build_lang_decl (FUNCTION_DECL
,
3875 get_identifier (id
),
3877 TREE_PUBLIC (ssdf_decl
) = 0;
3878 DECL_ARTIFICIAL (ssdf_decl
) = 1;
3880 /* Put this function in the list of functions to be called from the
3881 static constructors and destructors. */
3884 vec_alloc (ssdf_decls
, 32);
3886 /* Take this opportunity to initialize the map from priority
3887 numbers to information about that priority level. */
3888 priority_info_map
= splay_tree_new (splay_tree_compare_ints
,
3889 /*delete_key_fn=*/0,
3890 /*delete_value_fn=*/
3891 splay_tree_delete_pointers
);
3893 /* We always need to generate functions for the
3894 DEFAULT_INIT_PRIORITY so enter it now. That way when we walk
3895 priorities later, we'll be sure to find the
3896 DEFAULT_INIT_PRIORITY. */
3897 get_priority_info (DEFAULT_INIT_PRIORITY
);
3900 vec_safe_push (ssdf_decls
, ssdf_decl
);
3902 /* Create the argument list. */
3903 initialize_p_decl
= cp_build_parm_decl
3904 (ssdf_decl
, get_identifier (INITIALIZE_P_IDENTIFIER
), integer_type_node
);
3905 TREE_USED (initialize_p_decl
) = 1;
3906 priority_decl
= cp_build_parm_decl
3907 (ssdf_decl
, get_identifier (PRIORITY_IDENTIFIER
), integer_type_node
);
3908 TREE_USED (priority_decl
) = 1;
3910 DECL_CHAIN (initialize_p_decl
) = priority_decl
;
3911 DECL_ARGUMENTS (ssdf_decl
) = initialize_p_decl
;
3913 /* Put the function in the global scope. */
3914 pushdecl (ssdf_decl
);
3916 /* Start the function itself. This is equivalent to declaring the
3919 static void __ssdf (int __initialize_p, init __priority_p);
3921 It is static because we only need to call this function from the
3922 various constructor and destructor functions for this module. */
3923 start_preparsed_function (ssdf_decl
,
3924 /*attrs=*/NULL_TREE
,
3927 /* Set up the scope of the outermost block in the function. */
3928 body
= begin_compound_stmt (BCS_FN_BODY
);
3933 /* Finish the generation of the function which performs initialization
3934 and destruction of objects with static storage duration. After
3935 this point, no more such objects can be created. */
3938 finish_static_storage_duration_function (tree body
)
3940 /* Close out the function. */
3941 finish_compound_stmt (body
);
3942 expand_or_defer_fn (finish_function (/*inline_p=*/false));
3945 /* Return the information about the indicated PRIORITY level. If no
3946 code to handle this level has yet been generated, generate the
3947 appropriate prologue. */
3949 static priority_info
3950 get_priority_info (int priority
)
3955 n
= splay_tree_lookup (priority_info_map
,
3956 (splay_tree_key
) priority
);
3959 /* Create a new priority information structure, and insert it
3961 pi
= XNEW (struct priority_info_s
);
3962 pi
->initializations_p
= 0;
3963 pi
->destructions_p
= 0;
3964 splay_tree_insert (priority_info_map
,
3965 (splay_tree_key
) priority
,
3966 (splay_tree_value
) pi
);
3969 pi
= (priority_info
) n
->value
;
3974 /* The effective initialization priority of a DECL. */
3976 #define DECL_EFFECTIVE_INIT_PRIORITY(decl) \
3977 ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
3978 ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
3980 /* Whether a DECL needs a guard to protect it against multiple
3983 #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl) \
3984 || DECL_ONE_ONLY (decl) \
3985 || DECL_WEAK (decl)))
3987 /* Called from one_static_initialization_or_destruction(),
3989 Walks the initializer list of a global variable and looks for
3990 temporary variables (DECL_NAME() == NULL and DECL_ARTIFICIAL != 0)
3991 and that have their DECL_CONTEXT() == NULL.
3992 For each such temporary variable, set their DECL_CONTEXT() to
3993 the current function. This is necessary because otherwise
3994 some optimizers (enabled by -O2 -fprofile-arcs) might crash
3995 when trying to refer to a temporary variable that does not have
3996 it's DECL_CONTECT() properly set. */
3998 fix_temporary_vars_context_r (tree
*node
,
4002 gcc_assert (current_function_decl
);
4004 if (TREE_CODE (*node
) == BIND_EXPR
)
4008 for (var
= BIND_EXPR_VARS (*node
); var
; var
= DECL_CHAIN (var
))
4011 && DECL_ARTIFICIAL (var
)
4012 && !DECL_CONTEXT (var
))
4013 DECL_CONTEXT (var
) = current_function_decl
;
4019 /* Set up to handle the initialization or destruction of DECL. If
4020 INITP is nonzero, we are initializing the variable. Otherwise, we
4021 are destroying it. */
4024 one_static_initialization_or_destruction (tree decl
, tree init
, bool initp
)
4026 tree guard_if_stmt
= NULL_TREE
;
4029 /* If we are supposed to destruct and there's a trivial destructor,
4030 nothing has to be done. */
4032 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
4035 /* Trick the compiler into thinking we are at the file and line
4036 where DECL was declared so that error-messages make sense, and so
4037 that the debugger will show somewhat sensible file and line
4039 input_location
= DECL_SOURCE_LOCATION (decl
);
4041 /* Make sure temporary variables in the initialiser all have
4042 their DECL_CONTEXT() set to a value different from NULL_TREE.
4043 This can happen when global variables initializers are built.
4044 In that case, the DECL_CONTEXT() of the global variables _AND_ of all
4045 the temporary variables that might have been generated in the
4046 accompanying initializers is NULL_TREE, meaning the variables have been
4047 declared in the global namespace.
4048 What we want to do here is to fix that and make sure the DECL_CONTEXT()
4049 of the temporaries are set to the current function decl. */
4050 cp_walk_tree_without_duplicates (&init
,
4051 fix_temporary_vars_context_r
,
4058 Access control for implicit calls to the constructors,
4059 the conversion functions, or the destructor called to
4060 create and destroy a static data member is performed as
4061 if these calls appeared in the scope of the member's
4064 we pretend we are in a static member function of the class of
4065 which the DECL is a member. */
4066 if (member_p (decl
))
4068 DECL_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
4069 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
4072 /* Assume we don't need a guard. */
4074 /* We need a guard if this is an object with external linkage that
4075 might be initialized in more than one place. (For example, a
4076 static data member of a template, when the data member requires
4078 if (NEEDS_GUARD_P (decl
))
4082 guard
= get_guard (decl
);
4084 /* When using __cxa_atexit, we just check the GUARD as we would
4085 for a local static. */
4086 if (flag_use_cxa_atexit
)
4088 /* When using __cxa_atexit, we never try to destroy
4089 anything from a static destructor. */
4091 guard_cond
= get_guard_cond (guard
, false);
4093 /* If we don't have __cxa_atexit, then we will be running
4094 destructors from .fini sections, or their equivalents. So,
4095 we need to know how many times we've tried to initialize this
4096 object. We do initializations only if the GUARD is zero,
4097 i.e., if we are the first to initialize the variable. We do
4098 destructions only if the GUARD is one, i.e., if we are the
4099 last to destroy the variable. */
4102 = cp_build_binary_op (input_location
,
4104 cp_build_unary_op (PREINCREMENT_EXPR
,
4107 tf_warning_or_error
),
4109 tf_warning_or_error
);
4112 = cp_build_binary_op (input_location
,
4114 cp_build_unary_op (PREDECREMENT_EXPR
,
4117 tf_warning_or_error
),
4119 tf_warning_or_error
);
4121 guard_if_stmt
= begin_if_stmt ();
4122 finish_if_stmt_cond (guard_cond
, guard_if_stmt
);
4126 /* If we're using __cxa_atexit, we have not already set the GUARD,
4127 so we must do so now. */
4128 if (guard
&& initp
&& flag_use_cxa_atexit
)
4129 finish_expr_stmt (set_guard (guard
));
4131 /* Perform the initialization or destruction. */
4136 finish_expr_stmt (init
);
4137 if (sanitize_flags_p (SANITIZE_ADDRESS
, decl
))
4139 varpool_node
*vnode
= varpool_node::get (decl
);
4141 vnode
->dynamically_initialized
= 1;
4145 /* If we're using __cxa_atexit, register a function that calls the
4146 destructor for the object. */
4147 if (flag_use_cxa_atexit
)
4148 finish_expr_stmt (register_dtor_fn (decl
));
4151 finish_expr_stmt (build_cleanup (decl
));
4153 /* Finish the guard if-stmt, if necessary. */
4156 finish_then_clause (guard_if_stmt
);
4157 finish_if_stmt (guard_if_stmt
);
4160 /* Now that we're done with DECL we don't need to pretend to be a
4161 member of its class any longer. */
4162 DECL_CONTEXT (current_function_decl
) = NULL_TREE
;
4163 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
4166 /* Generate code to do the initialization or destruction of the decls in VARS,
4167 a TREE_LIST of VAR_DECL with static storage duration.
4168 Whether initialization or destruction is performed is specified by INITP. */
4171 do_static_initialization_or_destruction (tree vars
, bool initp
)
4173 tree node
, init_if_stmt
, cond
;
4175 /* Build the outer if-stmt to check for initialization or destruction. */
4176 init_if_stmt
= begin_if_stmt ();
4177 cond
= initp
? integer_one_node
: integer_zero_node
;
4178 cond
= cp_build_binary_op (input_location
,
4182 tf_warning_or_error
);
4183 finish_if_stmt_cond (cond
, init_if_stmt
);
4185 /* To make sure dynamic construction doesn't access globals from other
4186 compilation units where they might not be yet constructed, for
4187 -fsanitize=address insert __asan_before_dynamic_init call that
4188 prevents access to either all global variables that need construction
4189 in other compilation units, or at least those that haven't been
4190 initialized yet. Variables that need dynamic construction in
4191 the current compilation unit are kept accessible. */
4192 if (initp
&& (flag_sanitize
& SANITIZE_ADDRESS
))
4193 finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/false));
4197 tree decl
= TREE_VALUE (node
);
4198 tree priority_if_stmt
;
4202 /* If we don't need a destructor, there's nothing to do. Avoid
4203 creating a possibly empty if-stmt. */
4204 if (!initp
&& TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
4206 node
= TREE_CHAIN (node
);
4210 /* Remember that we had an initialization or finalization at this
4212 priority
= DECL_EFFECTIVE_INIT_PRIORITY (decl
);
4213 pi
= get_priority_info (priority
);
4215 pi
->initializations_p
= 1;
4217 pi
->destructions_p
= 1;
4219 /* Conditionalize this initialization on being in the right priority
4220 and being initializing/finalizing appropriately. */
4221 priority_if_stmt
= begin_if_stmt ();
4222 cond
= cp_build_binary_op (input_location
,
4225 build_int_cst (NULL_TREE
, priority
),
4226 tf_warning_or_error
);
4227 finish_if_stmt_cond (cond
, priority_if_stmt
);
4229 /* Process initializers with same priority. */
4231 && DECL_EFFECTIVE_INIT_PRIORITY (TREE_VALUE (node
)) == priority
;
4232 node
= TREE_CHAIN (node
))
4233 /* Do one initialization or destruction. */
4234 one_static_initialization_or_destruction (TREE_VALUE (node
),
4235 TREE_PURPOSE (node
), initp
);
4237 /* Finish up the priority if-stmt body. */
4238 finish_then_clause (priority_if_stmt
);
4239 finish_if_stmt (priority_if_stmt
);
4243 /* Revert what __asan_before_dynamic_init did by calling
4244 __asan_after_dynamic_init. */
4245 if (initp
&& (flag_sanitize
& SANITIZE_ADDRESS
))
4246 finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/true));
4248 /* Finish up the init/destruct if-stmt body. */
4249 finish_then_clause (init_if_stmt
);
4250 finish_if_stmt (init_if_stmt
);
4253 /* VARS is a list of variables with static storage duration which may
4254 need initialization and/or finalization. Remove those variables
4255 that don't really need to be initialized or finalized, and return
4256 the resulting list. The order in which the variables appear in
4257 VARS is in reverse order of the order in which they should actually
4258 be initialized. The list we return is in the unreversed order;
4259 i.e., the first variable should be initialized first. */
4262 prune_vars_needing_no_initialization (tree
*vars
)
4265 tree result
= NULL_TREE
;
4270 tree decl
= TREE_VALUE (t
);
4271 tree init
= TREE_PURPOSE (t
);
4273 /* Deal gracefully with error. */
4274 if (error_operand_p (decl
))
4276 var
= &TREE_CHAIN (t
);
4280 /* The only things that can be initialized are variables. */
4281 gcc_assert (VAR_P (decl
));
4283 /* If this object is not defined, we don't need to do anything
4285 if (DECL_EXTERNAL (decl
))
4287 var
= &TREE_CHAIN (t
);
4291 /* Also, if the initializer already contains errors, we can bail
4293 if (init
&& TREE_CODE (init
) == TREE_LIST
4294 && value_member (error_mark_node
, init
))
4296 var
= &TREE_CHAIN (t
);
4300 /* This variable is going to need initialization and/or
4301 finalization, so we add it to the list. */
4302 *var
= TREE_CHAIN (t
);
4303 TREE_CHAIN (t
) = result
;
4310 /* Make sure we have told the back end about all the variables in
4314 write_out_vars (tree vars
)
4318 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
4320 tree var
= TREE_VALUE (v
);
4321 if (!var_finalized_p (var
))
4323 import_export_decl (var
);
4324 rest_of_decl_compilation (var
, 1, 1);
4329 /* Generate a static constructor (if CONSTRUCTOR_P) or destructor
4330 (otherwise) that will initialize all global objects with static
4331 storage duration having the indicated PRIORITY. */
4334 generate_ctor_or_dtor_function (bool constructor_p
, int priority
,
4337 input_location
= *locus
;
4339 /* We use `I' to indicate initialization and `D' to indicate
4341 char function_key
= constructor_p
? 'I' : 'D';
4343 /* We emit the function lazily, to avoid generating empty
4344 global constructors and destructors. */
4345 tree body
= NULL_TREE
;
4347 if (constructor_p
&& priority
== DEFAULT_INIT_PRIORITY
)
4349 bool objc
= c_dialect_objc () && objc_static_init_needed_p ();
4351 /* We may have module initialization to emit and/or insert
4352 before other intializations. */
4353 if (module_initializer_kind () || objc
)
4354 body
= start_objects (function_key
, priority
);
4356 /* For Objective-C++, we may need to initialize metadata found
4357 in this module. This must be done _before_ any other static
4360 objc_generate_static_init_call (NULL_TREE
);
4363 /* Call the static storage duration function with appropriate
4367 FOR_EACH_VEC_SAFE_ELT (ssdf_decls
, i
, fndecl
)
4369 /* Calls to pure or const functions will expand to nothing. */
4370 if (! (flags_from_decl_or_type (fndecl
) & (ECF_CONST
| ECF_PURE
)))
4373 body
= start_objects (function_key
, priority
);
4375 tree call
= cp_build_function_call_nary (fndecl
, tf_warning_or_error
,
4376 build_int_cst (NULL_TREE
,
4378 build_int_cst (NULL_TREE
,
4381 finish_expr_stmt (call
);
4385 /* Close out the function. */
4387 finish_objects (function_key
, priority
, body
);
4390 /* Generate constructor and destructor functions for the priority
4394 generate_ctor_and_dtor_functions_for_priority (splay_tree_node n
, void * data
)
4396 location_t
*locus
= (location_t
*) data
;
4397 int priority
= (int) n
->key
;
4398 priority_info pi
= (priority_info
) n
->value
;
4400 /* Generate the functions themselves, but only if they are really
4402 if (pi
->initializations_p
)
4403 generate_ctor_or_dtor_function (/*constructor_p=*/true, priority
, locus
);
4404 if (pi
->destructions_p
)
4405 generate_ctor_or_dtor_function (/*constructor_p=*/false, priority
, locus
);
4407 /* Keep iterating. */
4411 /* Return C++ property of T, based on given operation OP. */
4414 cpp_check (tree t
, cpp_operation op
)
4418 case HAS_DEPENDENT_TEMPLATE_ARGS
:
4420 tree ti
= CLASSTYPE_TEMPLATE_INFO (t
);
4423 ++processing_template_decl
;
4424 const bool dep
= any_dependent_template_arguments_p (TI_ARGS (ti
));
4425 --processing_template_decl
;
4429 return DECL_PURE_VIRTUAL_P (t
);
4430 case IS_ASSIGNMENT_OPERATOR
:
4431 return DECL_ASSIGNMENT_OPERATOR_P (t
);
4432 case IS_CONSTRUCTOR
:
4433 return DECL_CONSTRUCTOR_P (t
);
4435 return DECL_DESTRUCTOR_P (t
);
4436 case IS_COPY_CONSTRUCTOR
:
4437 return DECL_COPY_CONSTRUCTOR_P (t
);
4438 case IS_MOVE_CONSTRUCTOR
:
4439 return DECL_MOVE_CONSTRUCTOR_P (t
);
4441 return TREE_CODE (t
) == TEMPLATE_DECL
;
4443 return trivial_type_p (t
);
4449 /* Collect source file references recursively, starting from NAMESPC. */
4452 collect_source_refs (tree namespc
)
4454 /* Iterate over names in this name space. */
4455 for (tree t
= NAMESPACE_LEVEL (namespc
)->names
; t
; t
= TREE_CHAIN (t
))
4456 if (DECL_IS_UNDECLARED_BUILTIN (t
))
4458 else if (TREE_CODE (t
) == NAMESPACE_DECL
&& !DECL_NAMESPACE_ALIAS (t
))
4459 collect_source_refs (t
);
4461 collect_source_ref (DECL_SOURCE_FILE (t
));
4464 /* Collect decls relevant to SOURCE_FILE from all namespaces recursively,
4465 starting from NAMESPC. */
4468 collect_ada_namespace (tree namespc
, const char *source_file
)
4470 tree decl
= NAMESPACE_LEVEL (namespc
)->names
;
4472 /* Collect decls from this namespace. This will skip
4473 NAMESPACE_DECLs (both aliases and regular, it cannot tell). */
4474 collect_ada_nodes (decl
, source_file
);
4476 /* Now scan for namespace children, and dump them. */
4477 for (; decl
; decl
= TREE_CHAIN (decl
))
4478 if (TREE_CODE (decl
) == NAMESPACE_DECL
&& !DECL_NAMESPACE_ALIAS (decl
))
4479 collect_ada_namespace (decl
, source_file
);
4482 /* Returns true iff there is a definition available for variable or
4486 decl_defined_p (tree decl
)
4488 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4489 return (DECL_INITIAL (decl
) != NULL_TREE
4490 /* A pending instantiation of a friend temploid is defined. */
4491 || (DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
)
4492 && DECL_INITIAL (DECL_TEMPLATE_RESULT
4493 (DECL_TI_TEMPLATE (decl
)))));
4496 gcc_assert (VAR_P (decl
));
4497 return !DECL_EXTERNAL (decl
);
4501 /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
4505 An integral constant-expression can only involve ... const
4506 variables of integral or enumeration types initialized with
4507 constant expressions ...
4509 C++0x also allows constexpr variables and temporaries initialized
4510 with constant expressions. We handle the former here, but the latter
4511 are just folded away in cxx_eval_constant_expression.
4513 The standard does not require that the expression be non-volatile.
4514 G++ implements the proposed correction in DR 457. */
4517 decl_constant_var_p (tree decl
)
4519 if (!decl_maybe_constant_var_p (decl
))
4522 /* We don't know if a template static data member is initialized with
4523 a constant expression until we instantiate its initializer. Even
4524 in the case of a constexpr variable, we can't treat it as a
4525 constant until its initializer is complete in case it's used in
4526 its own initializer. */
4527 maybe_instantiate_decl (decl
);
4528 return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
);
4531 /* Returns true if DECL could be a symbolic constant variable, depending on
4535 decl_maybe_constant_var_p (tree decl
)
4537 tree type
= TREE_TYPE (decl
);
4540 if (DECL_DECLARED_CONSTEXPR_P (decl
) && !TREE_THIS_VOLATILE (decl
))
4542 if (DECL_HAS_VALUE_EXPR_P (decl
))
4543 /* A proxy isn't constant. */
4545 if (TYPE_REF_P (type
))
4546 /* References can be constant. */;
4547 else if (CP_TYPE_CONST_NON_VOLATILE_P (type
)
4548 && INTEGRAL_OR_ENUMERATION_TYPE_P (type
))
4549 /* And const integers. */;
4553 if (DECL_INITIAL (decl
)
4554 && !DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
))
4555 /* We know the initializer, and it isn't constant. */
4561 /* Complain that DECL uses a type with no linkage. In C++98 mode this is
4562 called from grokfndecl and grokvardecl; in all modes it is called from
4563 cp_write_global_declarations. */
4566 no_linkage_error (tree decl
)
4568 if (cxx_dialect
>= cxx11
4569 && (decl_defined_p (decl
)
4570 /* Treat templates which limit_bad_template_recursion decided
4571 not to instantiate as if they were defined. */
4572 || (errorcount
+ sorrycount
> 0
4573 && DECL_LANG_SPECIFIC (decl
)
4574 && DECL_TEMPLATE_INFO (decl
)
4575 && warning_suppressed_p (decl
/* What warning? */))))
4576 /* In C++11 it's ok if the decl is defined. */
4579 if (DECL_LANG_SPECIFIC (decl
) && DECL_MODULE_IMPORT_P (decl
))
4580 /* An imported decl is ok. */
4583 tree t
= no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/false);
4585 /* The type that got us on no_linkage_decls must have gotten a name for
4586 linkage purposes. */;
4587 else if (CLASS_TYPE_P (t
) && TYPE_BEING_DEFINED (t
))
4588 // FIXME: This is now invalid, as a DR to c++98
4589 /* The type might end up having a typedef name for linkage purposes. */
4590 vec_safe_push (no_linkage_decls
, decl
);
4591 else if (TYPE_UNNAMED_P (t
))
4594 auto_diagnostic_group grp
;
4595 if (cxx_dialect
>= cxx11
)
4596 d
= permerror (DECL_SOURCE_LOCATION (decl
), "%q#D, declared using "
4597 "unnamed type, is used but never defined", decl
);
4598 else if (DECL_EXTERN_C_P (decl
))
4599 /* Allow this; it's pretty common in C. */;
4600 else if (VAR_P (decl
))
4601 /* DRs 132, 319 and 389 seem to indicate types with
4602 no linkage can only be used to declare extern "C"
4603 entities. Since it's not always an error in the
4604 ISO C++ 90 Standard, we only issue a warning. */
4605 d
= warning_at (DECL_SOURCE_LOCATION (decl
), 0, "unnamed type "
4606 "with no linkage used to declare variable %q#D with "
4609 d
= permerror (DECL_SOURCE_LOCATION (decl
), "unnamed type with no "
4610 "linkage used to declare function %q#D with linkage",
4612 if (d
&& is_typedef_decl (TYPE_NAME (t
)))
4613 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "%q#D does not refer "
4614 "to the unqualified type, so it is not used for linkage",
4617 else if (cxx_dialect
>= cxx11
)
4619 if (VAR_P (decl
) || !DECL_PURE_VIRTUAL_P (decl
))
4620 permerror (DECL_SOURCE_LOCATION (decl
),
4621 "%q#D, declared using local type "
4622 "%qT, is used but never defined", decl
, t
);
4624 else if (VAR_P (decl
))
4625 warning_at (DECL_SOURCE_LOCATION (decl
), 0, "type %qT with no linkage "
4626 "used to declare variable %q#D with linkage", t
, decl
);
4628 permerror (DECL_SOURCE_LOCATION (decl
), "type %qT with no linkage used "
4629 "to declare function %q#D with linkage", t
, decl
);
4632 /* Collect declarations from all namespaces relevant to SOURCE_FILE. */
4635 collect_all_refs (const char *source_file
)
4637 collect_ada_namespace (global_namespace
, source_file
);
4640 /* Clear DECL_EXTERNAL for NODE. */
4643 clear_decl_external (struct cgraph_node
*node
, void * /*data*/)
4645 DECL_EXTERNAL (node
->decl
) = 0;
4649 /* Build up the function to run dynamic initializers for thread_local
4650 variables in this translation unit and alias the init functions for the
4651 individual variables to it. */
4654 handle_tls_init (void)
4656 tree vars
= prune_vars_needing_no_initialization (&tls_aggregates
);
4657 if (vars
== NULL_TREE
)
4660 location_t loc
= DECL_SOURCE_LOCATION (TREE_VALUE (vars
));
4662 write_out_vars (vars
);
4664 tree guard
= build_decl (loc
, VAR_DECL
, get_identifier ("__tls_guard"),
4666 TREE_PUBLIC (guard
) = false;
4667 TREE_STATIC (guard
) = true;
4668 DECL_ARTIFICIAL (guard
) = true;
4669 DECL_IGNORED_P (guard
) = true;
4670 TREE_USED (guard
) = true;
4671 CP_DECL_THREAD_LOCAL_P (guard
) = true;
4672 set_decl_tls_model (guard
, decl_default_tls_model (guard
));
4673 pushdecl_top_level_and_finish (guard
, NULL_TREE
);
4675 tree fn
= get_local_tls_init_fn (loc
);
4676 start_preparsed_function (fn
, NULL_TREE
, SF_PRE_PARSED
);
4677 tree body
= begin_function_body ();
4678 tree if_stmt
= begin_if_stmt ();
4679 tree cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, guard
, false,
4680 tf_warning_or_error
);
4681 finish_if_stmt_cond (cond
, if_stmt
);
4682 finish_expr_stmt (cp_build_modify_expr (loc
, guard
, NOP_EXPR
,
4684 tf_warning_or_error
));
4685 for (; vars
; vars
= TREE_CHAIN (vars
))
4687 tree var
= TREE_VALUE (vars
);
4688 tree init
= TREE_PURPOSE (vars
);
4689 one_static_initialization_or_destruction (var
, init
, true);
4691 /* Output init aliases even with -fno-extern-tls-init. */
4692 if (TARGET_SUPPORTS_ALIASES
&& TREE_PUBLIC (var
))
4694 tree single_init_fn
= get_tls_init_fn (var
);
4695 if (single_init_fn
== NULL_TREE
)
4698 = cgraph_node::get_create (fn
)->create_same_body_alias
4699 (single_init_fn
, fn
);
4700 gcc_assert (alias
!= NULL
);
4704 finish_then_clause (if_stmt
);
4705 finish_if_stmt (if_stmt
);
4706 finish_function_body (body
);
4707 expand_or_defer_fn (finish_function (/*inline_p=*/false));
4710 /* We're at the end of compilation, so generate any mangling aliases that
4711 we've been saving up, if DECL is going to be output and ID2 isn't
4712 already taken by another declaration. */
4715 generate_mangling_alias (tree decl
, tree id2
)
4717 struct cgraph_node
*n
= NULL
;
4719 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4721 n
= cgraph_node::get (decl
);
4723 /* Don't create an alias to an unreferenced function. */
4728 = mangled_decls
->find_slot_with_hash (id2
, IDENTIFIER_HASH_VALUE (id2
),
4731 /* If there's a declaration already using this mangled name,
4732 don't create a compatibility alias that conflicts. */
4736 tree alias
= make_alias_for (decl
, id2
);
4739 DECL_IGNORED_P (alias
) = 1;
4740 TREE_PUBLIC (alias
) = TREE_PUBLIC (decl
);
4741 DECL_VISIBILITY (alias
) = DECL_VISIBILITY (decl
);
4742 if (vague_linkage_p (decl
))
4743 DECL_WEAK (alias
) = 1;
4746 n
->create_same_body_alias (alias
, decl
);
4748 varpool_node::create_extra_name_alias (alias
, decl
);
4751 /* Note that we might want to emit an alias with the symbol ID2 for DECL at
4752 the end of translation, for compatibility across bugs in the mangling
4756 note_mangling_alias (tree decl
, tree id2
)
4758 if (TARGET_SUPPORTS_ALIASES
)
4760 if (!defer_mangling_aliases
)
4761 generate_mangling_alias (decl
, id2
);
4764 vec_safe_push (mangling_aliases
, decl
);
4765 vec_safe_push (mangling_aliases
, id2
);
4770 /* Emit all mangling aliases that were deferred up to this point. */
4773 generate_mangling_aliases ()
4775 while (!vec_safe_is_empty (mangling_aliases
))
4777 tree id2
= mangling_aliases
->pop();
4778 tree decl
= mangling_aliases
->pop();
4779 generate_mangling_alias (decl
, id2
);
4781 defer_mangling_aliases
= false;
4784 /* Record a mangling of DECL, whose DECL_ASSEMBLER_NAME has just been
4785 set. NEED_WARNING is true if we must warn about collisions. We do
4786 this to spot changes in mangling that may require compatibility
4790 record_mangling (tree decl
, bool need_warning
)
4793 mangled_decls
= hash_table
<mangled_decl_hash
>::create_ggc (499);
4795 gcc_checking_assert (DECL_ASSEMBLER_NAME_SET_P (decl
));
4796 tree id
= DECL_ASSEMBLER_NAME_RAW (decl
);
4798 = mangled_decls
->find_slot_with_hash (id
, IDENTIFIER_HASH_VALUE (id
),
4801 /* If this is already an alias, remove the alias, because the real
4802 decl takes precedence. */
4803 if (*slot
&& DECL_ARTIFICIAL (*slot
) && DECL_IGNORED_P (*slot
))
4804 if (symtab_node
*n
= symtab_node::get (*slot
))
4805 if (n
->cpp_implicit_alias
)
4813 else if (need_warning
)
4815 error_at (DECL_SOURCE_LOCATION (decl
),
4816 "mangling of %q#D as %qE conflicts with a previous mangle",
4818 inform (DECL_SOURCE_LOCATION (*slot
),
4819 "previous mangling %q#D", *slot
);
4820 inform (DECL_SOURCE_LOCATION (decl
),
4821 "a later %<-fabi-version=%> (or =0)"
4822 " avoids this error with a change in mangling");
4827 /* The mangled name of DECL is being forcibly changed to NAME. Remove
4828 any existing knowledge of DECL's mangled name meaning DECL. */
4831 overwrite_mangling (tree decl
, tree name
)
4833 if (tree id
= DECL_ASSEMBLER_NAME_RAW (decl
))
4834 if ((TREE_CODE (decl
) == VAR_DECL
4835 || TREE_CODE (decl
) == FUNCTION_DECL
)
4838 = mangled_decls
->find_slot_with_hash (id
, IDENTIFIER_HASH_VALUE (id
),
4842 mangled_decls
->clear_slot (slot
);
4844 /* If this is an alias, remove it from the symbol table. */
4845 if (DECL_ARTIFICIAL (decl
) && DECL_IGNORED_P (decl
))
4846 if (symtab_node
*n
= symtab_node::get (decl
))
4847 if (n
->cpp_implicit_alias
)
4851 DECL_ASSEMBLER_NAME_RAW (decl
) = name
;
4854 /* The entire file is now complete. If requested, dump everything
4861 if (FILE *stream
= dump_begin (raw_dump_id
, &flags
))
4863 dump_node (global_namespace
, flags
& ~TDF_SLIM
, stream
);
4864 dump_end (raw_dump_id
, stream
);
4868 static location_t locus_at_end_of_parsing
;
4870 /* Check the deallocation functions for CODE to see if we want to warn that
4871 only one was defined. */
4874 maybe_warn_sized_delete (enum tree_code code
)
4876 tree sized
= NULL_TREE
;
4877 tree unsized
= NULL_TREE
;
4879 for (ovl_iterator
iter (get_global_binding (ovl_op_identifier (false, code
)));
4883 /* We're only interested in usual deallocation functions. */
4884 if (!usual_deallocation_fn_p (fn
))
4886 if (FUNCTION_ARG_CHAIN (fn
) == void_list_node
)
4891 if (DECL_INITIAL (unsized
) && !DECL_INITIAL (sized
))
4892 warning_at (DECL_SOURCE_LOCATION (unsized
), OPT_Wsized_deallocation
,
4893 "the program should also define %qD", sized
);
4894 else if (!DECL_INITIAL (unsized
) && DECL_INITIAL (sized
))
4895 warning_at (DECL_SOURCE_LOCATION (sized
), OPT_Wsized_deallocation
,
4896 "the program should also define %qD", unsized
);
4899 /* Check the global deallocation functions to see if we want to warn about
4900 defining unsized without sized (or vice versa). */
4903 maybe_warn_sized_delete ()
4905 if (!flag_sized_deallocation
|| !warn_sized_deallocation
)
4907 maybe_warn_sized_delete (DELETE_EXPR
);
4908 maybe_warn_sized_delete (VEC_DELETE_EXPR
);
4911 /* Earlier we left PTRMEM_CST in variable initializers alone so that we could
4912 look them up when evaluating non-type template parameters. Now we need to
4913 lower them to something the back end can understand. */
4919 FOR_EACH_VARIABLE (node
)
4921 tree d
= node
->decl
;
4922 if (tree init
= DECL_INITIAL (d
))
4923 DECL_INITIAL (d
) = cplus_expand_constant (init
);
4927 /* This routine is called at the end of compilation.
4928 Its job is to create all the code needed to initialize and
4929 destroy the global aggregates. We do the destruction
4930 first, since that way we only need to reverse the decls once. */
4933 c_parse_final_cleanups (void)
4938 locus_at_end_of_parsing
= input_location
;
4941 /* Bad parse errors. Just forget about it. */
4942 if (! global_bindings_p () || current_class_type
4943 || !vec_safe_is_empty (decl_namespace_list
))
4946 /* This is the point to write out a PCH if we're doing that.
4947 In that case we do not want to do anything else. */
4950 /* Mangle all symbols at PCH creation time. */
4952 FOR_EACH_SYMBOL (node
)
4953 if (! is_a
<varpool_node
*> (node
)
4954 || ! DECL_HARD_REGISTER (node
->decl
))
4955 DECL_ASSEMBLER_NAME (node
->decl
);
4956 c_common_write_pch ();
4958 /* Ensure even the callers don't try to finalize the CU. */
4959 flag_syntax_only
= 1;
4963 timevar_stop (TV_PHASE_PARSING
);
4964 timevar_start (TV_PHASE_DEFERRED
);
4966 symtab
->process_same_body_aliases ();
4968 /* Handle -fdump-ada-spec[-slim] */
4969 if (flag_dump_ada_spec
|| flag_dump_ada_spec_slim
)
4971 collect_source_ref (main_input_filename
);
4972 if (!flag_dump_ada_spec_slim
)
4973 collect_source_refs (global_namespace
);
4975 dump_ada_specs (collect_all_refs
, cpp_check
);
4978 /* FIXME - huh? was input_line -= 1;*/
4980 /* We now have to write out all the stuff we put off writing out.
4983 o Template specializations that we have not yet instantiated,
4984 but which are needed.
4985 o Initialization and destruction for non-local objects with
4986 static storage duration. (Local objects with static storage
4987 duration are initialized when their scope is first entered,
4988 and are cleaned up via atexit.)
4989 o Virtual function tables.
4991 All of these may cause others to be needed. For example,
4992 instantiating one function may cause another to be needed, and
4993 generating the initializer for an object may cause templates to be
4994 instantiated, etc., etc. */
4996 emit_support_tinfos ();
4998 /* Track vtables we want to emit that refer to consteval functions. */
4999 auto_vec
<tree
> consteval_vtables
;
5002 unsigned ssdf_count
= 0;
5003 for (bool reconsider
= true; reconsider
; retries
++)
5007 /* If there are templates that we've put off instantiating, do
5009 instantiate_pending_templates (retries
);
5012 if (header_module_p ())
5013 /* A header modules initializations are handled in its
5017 /* Write out virtual tables as required. Writing out the
5018 virtual table for a template class may cause the
5019 instantiation of members of that class. If we write out
5020 vtables then we remove the class from our list so we don't
5021 have to look at it again. */
5023 for (i
= keyed_classes
->length ();
5024 keyed_classes
->iterate (--i
, &t
);)
5025 if (maybe_emit_vtables (t
, consteval_vtables
))
5028 keyed_classes
->unordered_remove (i
);
5030 /* The input_location may have been changed during marking of
5032 input_location
= locus_at_end_of_parsing
;
5034 /* Write out needed type info variables. We have to be careful
5035 looping through unemitted decls, because emit_tinfo_decl may
5036 cause other variables to be needed. New elements will be
5037 appended, and we remove from the vector those that actually
5039 for (i
= unemitted_tinfo_decls
->length ();
5040 unemitted_tinfo_decls
->iterate (--i
, &t
);)
5041 if (emit_tinfo_decl (t
))
5044 unemitted_tinfo_decls
->unordered_remove (i
);
5047 /* The list of objects with static storage duration is built up
5048 in reverse order. We clear STATIC_AGGREGATES so that any new
5049 aggregates added during the initialization of these will be
5050 initialized in the correct order when we next come around the
5052 if (tree vars
= prune_vars_needing_no_initialization (&static_aggregates
))
5055 /* Add initializer information from VARS into
5056 DYNAMIC_INITIALIZERS. */
5057 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
5058 hash_map_safe_put
<hm_ggc
> (dynamic_initializers
,
5059 TREE_VALUE (t
), TREE_PURPOSE (t
));
5061 /* We need to start a new initialization function each time
5062 through the loop. That's because we need to know which
5063 vtables have been referenced, and TREE_SYMBOL_REFERENCED
5064 isn't computed until a function is finished, and written
5065 out. That's a deficiency in the back end. When this is
5066 fixed, these initialization functions could all become
5067 inline, with resulting performance improvements. */
5070 /* Make sure the back end knows about all the variables. */
5071 write_out_vars (vars
);
5073 /* Set the line and file, so that it is obviously not from
5075 input_location
= locus_at_end_of_parsing
;
5076 ssdf_body
= start_static_storage_duration_function (ssdf_count
);
5078 /* First generate code to do all the initializations. */
5080 do_static_initialization_or_destruction (vars
, /*initp=*/true);
5082 /* Then, generate code to do all the destructions. Do these
5083 in reverse order so that the most recently constructed
5084 variable is the first destroyed. If we're using
5085 __cxa_atexit, then we don't need to do this; functions
5086 were registered at initialization time to destroy the
5088 if (!flag_use_cxa_atexit
&& vars
)
5090 vars
= nreverse (vars
);
5091 do_static_initialization_or_destruction (vars
, /*initp=*/false);
5096 /* Finish up the static storage duration function for this
5098 input_location
= locus_at_end_of_parsing
;
5099 finish_static_storage_duration_function (ssdf_body
);
5101 /* All those initializations and finalizations might cause
5102 us to need more inline functions, more template
5103 instantiations, etc. */
5108 /* Now do the same for thread_local variables. */
5111 /* Go through the set of inline functions whose bodies have not
5112 been emitted yet. If out-of-line copies of these functions
5113 are required, emit them. */
5114 FOR_EACH_VEC_SAFE_ELT (deferred_fns
, i
, decl
)
5116 /* Does it need synthesizing? */
5117 if (DECL_DEFAULTED_FN (decl
) && ! DECL_INITIAL (decl
)
5118 && (! DECL_REALLY_EXTERN (decl
) || possibly_inlined_p (decl
)))
5120 /* Even though we're already at the top-level, we push
5121 there again. That way, when we pop back a few lines
5122 hence, all of our state is restored. Otherwise,
5123 finish_function doesn't clean things up, and we end
5124 up with CURRENT_FUNCTION_DECL set. */
5125 push_to_top_level ();
5126 /* The decl's location will mark where it was first
5127 needed. Save that so synthesize method can indicate
5128 where it was needed from, in case of error */
5129 input_location
= DECL_SOURCE_LOCATION (decl
);
5130 synthesize_method (decl
);
5131 pop_from_top_level ();
5135 if (!DECL_INITIAL (decl
) && decl_tls_wrapper_p (decl
))
5136 generate_tls_wrapper (decl
);
5138 if (!DECL_SAVED_TREE (decl
))
5141 cgraph_node
*node
= cgraph_node::get_create (decl
);
5143 /* We lie to the back end, pretending that some functions
5144 are not defined when they really are. This keeps these
5145 functions from being put out unnecessarily. But, we must
5146 stop lying when the functions are referenced, or if they
5147 are not comdat since they need to be put out now. If
5148 DECL_INTERFACE_KNOWN, then we have already set
5149 DECL_EXTERNAL appropriately, so there's no need to check
5150 again, and we do not want to clear DECL_EXTERNAL if a
5151 previous call to import_export_decl set it.
5153 This is done in a separate for cycle, because if some
5154 deferred function is contained in another deferred
5155 function later in deferred_fns varray,
5156 rest_of_compilation would skip this function and we
5157 really cannot expand the same function twice. */
5158 import_export_decl (decl
);
5159 if (DECL_NOT_REALLY_EXTERN (decl
)
5160 && DECL_INITIAL (decl
)
5161 && decl_needed_p (decl
))
5163 if (node
->cpp_implicit_alias
)
5164 node
= node
->get_alias_target ();
5166 node
->call_for_symbol_thunks_and_aliases (clear_decl_external
,
5168 /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
5169 group, we need to mark all symbols in the same comdat group
5171 if (node
->same_comdat_group
)
5172 for (cgraph_node
*next
5173 = dyn_cast
<cgraph_node
*> (node
->same_comdat_group
);
5175 next
= dyn_cast
<cgraph_node
*> (next
->same_comdat_group
))
5176 next
->call_for_symbol_thunks_and_aliases (clear_decl_external
,
5180 /* If we're going to need to write this function out, and
5181 there's already a body for it, create RTL for it now.
5182 (There might be no body if this is a method we haven't
5183 gotten around to synthesizing yet.) */
5184 if (!DECL_EXTERNAL (decl
)
5185 && decl_needed_p (decl
)
5186 && !TREE_ASM_WRITTEN (decl
)
5187 && !node
->definition
)
5189 /* We will output the function; no longer consider it in this
5191 DECL_DEFER_OUTPUT (decl
) = 0;
5192 /* Generate RTL for this function now that we know we
5194 expand_or_defer_fn (decl
);
5199 if (wrapup_namespace_globals ())
5202 /* Static data members are just like namespace-scope globals. */
5203 FOR_EACH_VEC_SAFE_ELT (pending_statics
, i
, decl
)
5205 if (var_finalized_p (decl
) || DECL_REALLY_EXTERN (decl
)
5206 /* Don't write it out if we haven't seen a definition. */
5207 || DECL_IN_AGGR_P (decl
))
5209 import_export_decl (decl
);
5210 /* If this static data member is needed, provide it to the
5212 if (DECL_NOT_REALLY_EXTERN (decl
) && decl_needed_p (decl
))
5213 DECL_EXTERNAL (decl
) = 0;
5216 if (vec_safe_length (pending_statics
) != 0
5217 && wrapup_global_declarations (pending_statics
->address (),
5218 pending_statics
->length ()))
5222 finish_module_processing (parse_in
);
5226 generate_mangling_aliases ();
5228 /* All used inline functions must have a definition at this point. */
5229 FOR_EACH_VEC_SAFE_ELT (deferred_fns
, i
, decl
)
5231 if (/* Check online inline functions that were actually used. */
5232 DECL_ODR_USED (decl
) && DECL_DECLARED_INLINE_P (decl
)
5233 /* If the definition actually was available here, then the
5234 fact that the function was not defined merely represents
5235 that for some reason (use of a template repository,
5236 #pragma interface, etc.) we decided not to emit the
5238 && !DECL_INITIAL (decl
)
5239 /* A defaulted fn in a header module can be synthesized on
5240 demand later. (In non-header modules we should have
5241 synthesized it above.) */
5242 && !(DECL_DEFAULTED_FN (decl
) && header_module_p ())
5243 /* Don't complain if the template was defined. */
5244 && !(DECL_TEMPLATE_INSTANTIATION (decl
)
5245 && DECL_INITIAL (DECL_TEMPLATE_RESULT
5246 (template_for_substitution (decl
))))
5247 && warning_at (DECL_SOURCE_LOCATION (decl
), 0,
5248 "inline function %qD used but never defined", decl
))
5249 /* Avoid a duplicate warning from check_global_declaration. */
5250 suppress_warning (decl
, OPT_Wunused
);
5253 /* So must decls that use a type with no linkage. */
5254 FOR_EACH_VEC_SAFE_ELT (no_linkage_decls
, i
, decl
)
5255 no_linkage_error (decl
);
5257 maybe_warn_sized_delete ();
5259 /* Then, do the Objective-C stuff. This is where all the
5260 Objective-C module stuff gets generated (symtab,
5261 class/protocol/selector lists etc). This must be done after C++
5262 templates, destructors etc. so that selectors used in C++
5263 templates are properly allocated. */
5264 if (c_dialect_objc ())
5265 objc_write_global_declarations ();
5267 /* We give C linkage to static constructors and destructors. */
5268 push_lang_context (lang_name_c
);
5270 /* Generate initialization and destruction functions for all
5271 priorities for which they are required. */
5272 if (priority_info_map
)
5273 splay_tree_foreach (priority_info_map
,
5274 generate_ctor_and_dtor_functions_for_priority
,
5275 /*data=*/&locus_at_end_of_parsing
);
5276 else if ((c_dialect_objc () && objc_static_init_needed_p ())
5277 || module_initializer_kind ())
5278 generate_ctor_or_dtor_function (/*constructor_p=*/true,
5279 DEFAULT_INIT_PRIORITY
,
5280 &locus_at_end_of_parsing
);
5282 /* We're done with the splay-tree now. */
5283 if (priority_info_map
)
5284 splay_tree_delete (priority_info_map
);
5288 /* Generate any missing aliases. */
5289 maybe_apply_pending_pragma_weaks ();
5291 /* We're done with static constructors, so we can go back to "C++"
5293 pop_lang_context ();
5295 if (flag_vtable_verify
)
5297 vtv_recover_class_info ();
5298 vtv_compute_class_hierarchy_transitive_closure ();
5299 vtv_build_vtable_verify_fndecl ();
5302 perform_deferred_noexcept_checks ();
5305 cp_tree_c_finish_parsing ();
5306 clear_consteval_vfns (consteval_vtables
);
5308 /* The entire file is now complete. If requested, dump everything
5312 if (flag_detailed_statistics
)
5314 dump_tree_statistics ();
5315 dump_time_statistics ();
5318 timevar_stop (TV_PHASE_DEFERRED
);
5319 timevar_start (TV_PHASE_PARSING
);
5321 /* Indicate that we're done with front end processing. */
5325 /* Perform any post compilation-proper cleanups for the C++ front-end.
5326 This should really go away. No front-end should need to do
5327 anything past the compilation process. */
5330 cxx_post_compilation_parsing_cleanups (void)
5332 timevar_start (TV_PHASE_LATE_PARSING_CLEANUPS
);
5334 if (flag_vtable_verify
)
5336 /* Generate the special constructor initialization function that
5337 calls __VLTRegisterPairs, and give it a very high
5338 initialization priority. This must be done after
5339 finalize_compilation_unit so that we have accurate
5340 information about which vtable will actually be emitted. */
5341 vtv_generate_init_routine ();
5344 input_location
= locus_at_end_of_parsing
;
5347 validate_conversion_obstack ();
5349 timevar_stop (TV_PHASE_LATE_PARSING_CLEANUPS
);
5352 /* FN is an OFFSET_REF, DOTSTAR_EXPR or MEMBER_REF indicating the
5353 function to call in parse-tree form; it has not yet been
5354 semantically analyzed. ARGS are the arguments to the function.
5355 They have already been semantically analyzed. This may change
5359 build_offset_ref_call_from_tree (tree fn
, vec
<tree
, va_gc
> **args
,
5360 tsubst_flags_t complain
)
5363 vec
<tree
, va_gc
> *orig_args
= NULL
;
5368 object
= TREE_OPERAND (fn
, 0);
5370 if (processing_template_decl
)
5372 gcc_assert (TREE_CODE (fn
) == DOTSTAR_EXPR
5373 || TREE_CODE (fn
) == MEMBER_REF
);
5374 if (type_dependent_expression_p (fn
)
5375 || any_type_dependent_arguments_p (*args
))
5376 return build_min_nt_call_vec (fn
, *args
);
5378 orig_args
= make_tree_vector_copy (*args
);
5380 /* Transform the arguments and add the implicit "this"
5381 parameter. That must be done before the FN is transformed
5382 because we depend on the form of FN. */
5383 make_args_non_dependent (*args
);
5384 object
= build_non_dependent_expr (object
);
5385 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
5387 if (TREE_CODE (fn
) == DOTSTAR_EXPR
)
5388 object
= cp_build_addr_expr (object
, complain
);
5389 vec_safe_insert (*args
, 0, object
);
5391 /* Now that the arguments are done, transform FN. */
5392 fn
= build_non_dependent_expr (fn
);
5395 /* A qualified name corresponding to a bound pointer-to-member is
5396 represented as an OFFSET_REF:
5398 struct B { void g(); };
5400 void B::g() { (this->*p)(); } */
5401 if (TREE_CODE (fn
) == OFFSET_REF
)
5403 tree object_addr
= cp_build_addr_expr (object
, complain
);
5404 fn
= TREE_OPERAND (fn
, 1);
5405 fn
= get_member_function_from_ptrfunc (&object_addr
, fn
,
5407 vec_safe_insert (*args
, 0, object_addr
);
5410 if (CLASS_TYPE_P (TREE_TYPE (fn
)))
5411 expr
= build_op_call (fn
, args
, complain
);
5413 expr
= cp_build_function_call_vec (fn
, args
, complain
);
5414 if (processing_template_decl
&& expr
!= error_mark_node
)
5415 expr
= build_min_non_dep_call_vec (expr
, orig_fn
, orig_args
);
5417 if (orig_args
!= NULL
)
5418 release_tree_vector (orig_args
);
5425 check_default_args (tree x
)
5427 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
5428 bool saw_def
= false;
5429 bool noted_first_def
= false;
5430 int idx_of_first_default_arg
= 0;
5431 location_t loc_of_first_default_arg
= UNKNOWN_LOCATION
;
5432 int i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
5433 tree fndecl
= STRIP_TEMPLATE (x
);
5434 auto_diagnostic_group d
;
5435 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
5437 if (TREE_PURPOSE (arg
))
5442 idx_of_first_default_arg
= i
;
5443 location_t loc
= get_fndecl_argument_location (fndecl
, i
);
5444 if (loc
!= DECL_SOURCE_LOCATION (x
))
5445 loc_of_first_default_arg
= loc
;
5448 else if (saw_def
&& !PACK_EXPANSION_P (TREE_VALUE (arg
)))
5450 error_at (get_fndecl_argument_location (fndecl
, i
),
5451 "default argument missing for parameter %P of %q#D", i
, x
);
5452 if (loc_of_first_default_arg
!= UNKNOWN_LOCATION
5453 && !noted_first_def
)
5455 inform (loc_of_first_default_arg
,
5456 "...following parameter %P which has a default argument",
5457 idx_of_first_default_arg
);
5458 noted_first_def
= true;
5460 TREE_PURPOSE (arg
) = error_mark_node
;
5465 /* Return true if function DECL can be inlined. This is used to force
5466 instantiation of methods that might be interesting for inlining. */
5468 possibly_inlined_p (tree decl
)
5470 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
5471 if (DECL_UNINLINABLE (decl
))
5474 return DECL_DECLARED_INLINE_P (decl
);
5475 /* When optimizing, we might inline everything when flatten
5476 attribute or heuristics inlining for size or autoinlining
5481 /* Normally, we can wait until instantiation-time to synthesize DECL.
5482 However, if DECL is a static data member initialized with a constant
5483 or a constexpr function, we need it right now because a reference to
5484 such a data member or a call to such function is not value-dependent.
5485 For a function that uses auto in the return type, we need to instantiate
5486 it to find out its type. For OpenMP user defined reductions, we need
5487 them instantiated for reduction clauses which inline them by hand
5491 maybe_instantiate_decl (tree decl
)
5493 if (DECL_LANG_SPECIFIC (decl
)
5494 && DECL_TEMPLATE_INFO (decl
)
5495 && (decl_maybe_constant_var_p (decl
)
5496 || (TREE_CODE (decl
) == FUNCTION_DECL
5497 && DECL_OMP_DECLARE_REDUCTION_P (decl
))
5498 || undeduced_auto_decl (decl
))
5499 && !DECL_DECLARED_CONCEPT_P (decl
)
5500 && !uses_template_parms (DECL_TI_ARGS (decl
)))
5502 /* Instantiating a function will result in garbage collection. We
5503 must treat this situation as if we were within the body of a
5504 function so as to avoid collecting live data only referenced from
5505 the stack (such as overload resolution candidates). */
5507 instantiate_decl (decl
, /*defer_ok=*/false,
5508 /*expl_inst_class_mem_p=*/false);
5513 /* Error if the DECL is unavailable (unless this is currently suppressed).
5514 Maybe warn if DECL is deprecated, subject to COMPLAIN. Returns true if
5515 an error or warning was emitted. */
5518 cp_handle_deprecated_or_unavailable (tree decl
, tsubst_flags_t complain
)
5523 if ((complain
& tf_error
)
5524 && deprecated_state
!= UNAVAILABLE_DEPRECATED_SUPPRESS
)
5526 if (TREE_UNAVAILABLE (decl
))
5528 error_unavailable_use (decl
, NULL_TREE
);
5533 /* Perhaps this is an unavailable typedef. */
5536 && TREE_UNAVAILABLE (TYPE_NAME (decl
)))
5538 decl
= TYPE_NAME (decl
);
5539 /* Don't error within members of a unavailable type. */
5541 && currently_open_class (decl
))
5544 error_unavailable_use (decl
, NULL_TREE
);
5548 /* Carry on to consider deprecatedness. */
5551 if (!(complain
& tf_warning
)
5552 || deprecated_state
== DEPRECATED_SUPPRESS
5553 || deprecated_state
== UNAVAILABLE_DEPRECATED_SUPPRESS
)
5556 if (!TREE_DEPRECATED (decl
))
5558 /* Perhaps this is a deprecated typedef. */
5559 if (TYPE_P (decl
) && TYPE_NAME (decl
))
5560 decl
= TYPE_NAME (decl
);
5562 if (!TREE_DEPRECATED (decl
))
5566 /* Don't warn within members of a deprecated type. */
5568 && currently_open_class (decl
))
5571 bool warned
= false;
5572 if (cxx_dialect
>= cxx11
5574 && DECL_ARTIFICIAL (decl
)
5575 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
5576 && copy_fn_p (decl
))
5578 /* Don't warn if the flag was disabled around the class definition
5580 if (warning_enabled_at (DECL_SOURCE_LOCATION (decl
),
5581 OPT_Wdeprecated_copy
))
5583 auto_diagnostic_group d
;
5584 tree ctx
= DECL_CONTEXT (decl
);
5585 tree other
= classtype_has_depr_implicit_copy (ctx
);
5586 int opt
= (DECL_DESTRUCTOR_P (other
)
5587 ? OPT_Wdeprecated_copy_dtor
5588 : OPT_Wdeprecated_copy
);
5589 warned
= warning (opt
, "implicitly-declared %qD is deprecated",
5592 inform (DECL_SOURCE_LOCATION (other
),
5593 "because %qT has user-provided %qD",
5598 warned
= warn_deprecated_use (decl
, NULL_TREE
);
5603 /* Like above, but takes into account outer scopes. */
5606 cp_warn_deprecated_use_scopes (tree scope
)
5609 && scope
!= error_mark_node
5610 && scope
!= global_namespace
)
5612 if ((TREE_CODE (scope
) == NAMESPACE_DECL
|| OVERLOAD_TYPE_P (scope
))
5613 && cp_handle_deprecated_or_unavailable (scope
))
5616 scope
= CP_TYPE_CONTEXT (scope
);
5618 scope
= CP_DECL_CONTEXT (scope
);
5622 /* True if DECL or its enclosing scope have unbound template parameters. */
5625 decl_dependent_p (tree decl
)
5627 if (DECL_FUNCTION_SCOPE_P (decl
)
5628 || TREE_CODE (decl
) == CONST_DECL
5629 || TREE_CODE (decl
) == USING_DECL
5630 || TREE_CODE (decl
) == FIELD_DECL
)
5631 decl
= CP_DECL_CONTEXT (decl
);
5632 if (tree tinfo
= get_template_info (decl
))
5633 if (any_dependent_template_arguments_p (TI_ARGS (tinfo
)))
5635 if (LAMBDA_FUNCTION_P (decl
)
5636 && dependent_type_p (DECL_CONTEXT (decl
)))
5641 /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
5642 If DECL is a specialization or implicitly declared class member,
5643 generate the actual definition. Return false if something goes
5644 wrong, true otherwise. */
5647 mark_used (tree decl
, tsubst_flags_t complain
)
5649 /* If we're just testing conversions or resolving overloads, we
5650 don't want any permanent effects like forcing functions to be
5651 output or instantiating templates. */
5652 if ((complain
& tf_conv
))
5655 /* If DECL is a BASELINK for a single function, then treat it just
5656 like the DECL for the function. Otherwise, if the BASELINK is
5657 for an overloaded function, we don't know which function was
5658 actually used until after overload resolution. */
5659 if (BASELINK_P (decl
))
5661 decl
= BASELINK_FUNCTIONS (decl
);
5662 if (really_overloaded_fn (decl
))
5664 decl
= OVL_FIRST (decl
);
5670 /* Set TREE_USED for the benefit of -Wunused. */
5671 TREE_USED (decl
) = true;
5673 /* And for structured bindings also the underlying decl. */
5674 if (DECL_DECOMPOSITION_P (decl
) && DECL_DECOMP_BASE (decl
))
5675 TREE_USED (DECL_DECOMP_BASE (decl
)) = true;
5677 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
5680 if (DECL_CLONED_FUNCTION_P (decl
))
5681 TREE_USED (DECL_CLONED_FUNCTION (decl
)) = 1;
5683 /* Mark enumeration types as used. */
5684 if (TREE_CODE (decl
) == CONST_DECL
)
5685 used_types_insert (DECL_CONTEXT (decl
));
5687 if (TREE_CODE (decl
) == FUNCTION_DECL
5688 && !maybe_instantiate_noexcept (decl
, complain
))
5691 if (TREE_CODE (decl
) == FUNCTION_DECL
5692 && DECL_DELETED_FN (decl
))
5694 if (DECL_ARTIFICIAL (decl
)
5695 && DECL_CONV_FN_P (decl
)
5696 && LAMBDA_TYPE_P (DECL_CONTEXT (decl
)))
5697 /* We mark a lambda conversion op as deleted if we can't
5698 generate it properly; see maybe_add_lambda_conv_op. */
5699 sorry ("converting lambda that uses %<...%> to function pointer");
5700 else if (complain
& tf_error
)
5702 error ("use of deleted function %qD", decl
);
5703 if (!maybe_explain_implicit_delete (decl
))
5704 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
5709 if (VAR_OR_FUNCTION_DECL_P (decl
) && DECL_LOCAL_DECL_P (decl
))
5711 if (!DECL_LANG_SPECIFIC (decl
))
5712 /* An unresolved dependent local extern. */
5715 DECL_ODR_USED (decl
) = 1;
5716 auto alias
= DECL_LOCAL_DECL_ALIAS (decl
);
5717 if (!alias
|| alias
== error_mark_node
)
5720 /* Process the underlying decl. */
5722 TREE_USED (decl
) = true;
5725 cp_handle_deprecated_or_unavailable (decl
, complain
);
5727 /* We can only check DECL_ODR_USED on variables or functions with
5728 DECL_LANG_SPECIFIC set, and these are also the only decls that we
5729 might need special handling for. */
5730 if (!VAR_OR_FUNCTION_DECL_P (decl
)
5731 || DECL_LANG_SPECIFIC (decl
) == NULL
5732 || DECL_THUNK_P (decl
))
5734 if (!decl_dependent_p (decl
)
5735 && !require_deduced_type (decl
, complain
))
5740 /* We only want to do this processing once. We don't need to keep trying
5741 to instantiate inline templates, because unit-at-a-time will make sure
5742 we get them compiled before functions that want to inline them. */
5743 if (DECL_ODR_USED (decl
))
5746 if (flag_concepts
&& TREE_CODE (decl
) == FUNCTION_DECL
5747 && !constraints_satisfied_p (decl
))
5749 if (complain
& tf_error
)
5751 auto_diagnostic_group d
;
5752 error ("use of function %qD with unsatisfied constraints",
5754 location_t loc
= DECL_SOURCE_LOCATION (decl
);
5755 inform (loc
, "declared here");
5756 diagnose_constraints (loc
, decl
, NULL_TREE
);
5761 /* Normally, we can wait until instantiation-time to synthesize DECL.
5762 However, if DECL is a static data member initialized with a constant
5763 or a constexpr function, we need it right now because a reference to
5764 such a data member or a call to such function is not value-dependent.
5765 For a function that uses auto in the return type, we need to instantiate
5766 it to find out its type. For OpenMP user defined reductions, we need
5767 them instantiated for reduction clauses which inline them by hand
5769 maybe_instantiate_decl (decl
);
5771 if (processing_template_decl
|| in_template_function ())
5774 /* Check this too in case we're within instantiate_non_dependent_expr. */
5775 if (DECL_TEMPLATE_INFO (decl
)
5776 && uses_template_parms (DECL_TI_ARGS (decl
)))
5779 if (!require_deduced_type (decl
, complain
))
5782 if (builtin_pack_fn_p (decl
))
5784 error ("use of built-in parameter pack %qD outside of a template",
5789 /* If we don't need a value, then we don't need to synthesize DECL. */
5790 if (cp_unevaluated_operand
|| in_discarded_stmt
)
5793 DECL_ODR_USED (decl
) = 1;
5794 if (DECL_CLONED_FUNCTION_P (decl
))
5795 DECL_ODR_USED (DECL_CLONED_FUNCTION (decl
)) = 1;
5797 /* DR 757: A type without linkage shall not be used as the type of a
5798 variable or function with linkage, unless
5799 o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
5800 o the variable or function is not used (3.2 [basic.def.odr]) or is
5801 defined in the same translation unit. */
5802 if (cxx_dialect
> cxx98
5803 && decl_linkage (decl
) != lk_none
5804 && !DECL_EXTERN_C_P (decl
)
5805 && !DECL_ARTIFICIAL (decl
)
5806 && !decl_defined_p (decl
)
5807 && no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/false))
5808 vec_safe_push (no_linkage_decls
, decl
);
5810 if (TREE_CODE (decl
) == FUNCTION_DECL
5811 && DECL_DECLARED_INLINE_P (decl
)
5812 && !DECL_INITIAL (decl
)
5813 && !DECL_ARTIFICIAL (decl
)
5814 && !DECL_PURE_VIRTUAL_P (decl
))
5815 /* Remember it, so we can check it was defined. */
5816 note_vague_linkage_fn (decl
);
5818 /* Is it a synthesized method that needs to be synthesized? */
5819 if (TREE_CODE (decl
) == FUNCTION_DECL
5820 && DECL_DEFAULTED_FN (decl
)
5821 /* A function defaulted outside the class is synthesized either by
5822 cp_finish_decl or instantiate_decl. */
5823 && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl
)
5824 && ! DECL_INITIAL (decl
))
5826 /* Defer virtual destructors so that thunks get the right
5828 if (DECL_VIRTUAL_P (decl
) && !at_eof
)
5830 note_vague_linkage_fn (decl
);
5834 /* Remember the current location for a function we will end up
5835 synthesizing. Then we can inform the user where it was
5836 required in the case of error. */
5837 if (decl_remember_implicit_trigger_p (decl
))
5838 DECL_SOURCE_LOCATION (decl
) = input_location
;
5840 /* Synthesizing an implicitly defined member function will result in
5841 garbage collection. We must treat this situation as if we were
5842 within the body of a function so as to avoid collecting live data
5843 on the stack (such as overload resolution candidates).
5845 We could just let c_parse_final_cleanups handle synthesizing
5846 this function by adding it to deferred_fns, but doing
5847 it at the use site produces better error messages. */
5849 synthesize_method (decl
);
5851 /* If this is a synthesized method we don't need to
5852 do the instantiation test below. */
5854 else if (VAR_OR_FUNCTION_DECL_P (decl
)
5855 && DECL_TEMPLATE_INFO (decl
)
5856 && !DECL_DECLARED_CONCEPT_P (decl
)
5857 && (!DECL_EXPLICIT_INSTANTIATION (decl
)
5858 || always_instantiate_p (decl
)))
5859 /* If this is a function or variable that is an instance of some
5860 template, we now know that we will need to actually do the
5861 instantiation. We check that DECL is not an explicit
5862 instantiation because that is not checked in instantiate_decl.
5864 We put off instantiating functions in order to improve compile
5865 times. Maintaining a stack of active functions is expensive,
5866 and the inliner knows to instantiate any functions it might
5867 need. Therefore, we always try to defer instantiation. */
5870 instantiate_decl (decl
, /*defer_ok=*/true,
5871 /*expl_inst_class_mem_p=*/false);
5879 mark_used (tree decl
)
5881 return mark_used (decl
, tf_warning_or_error
);
5885 vtv_start_verification_constructor_init_function (void)
5887 return start_objects ('I', MAX_RESERVED_INIT_PRIORITY
- 1);
5891 vtv_finish_verification_constructor_init_function (tree function_body
)
5895 finish_compound_stmt (function_body
);
5896 fn
= finish_function (/*inline_p=*/false);
5897 DECL_STATIC_CONSTRUCTOR (fn
) = 1;
5898 decl_init_priority_insert (fn
, MAX_RESERVED_INIT_PRIORITY
- 1);
5903 #include "gt-cp-decl2.h"