1 /* Process declarations and variables for C++ compiler.
2 Copyright (C) 1988-2015 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"
36 #include "stringpool.h"
39 #include "stor-layout.h"
48 #include "c-family/c-common.h"
49 #include "c-family/c-objc.h"
50 #include "hard-reg-set.h"
53 #include "tree-inline.h"
54 #include "c-family/c-pragma.h"
57 #include "splay-tree.h"
58 #include "langhooks.h"
59 #include "c-family/c-ada-spec.h"
62 extern cpp_reader
*parse_in
;
64 /* This structure contains information about the initializations
65 and/or destructions required for a particular priority level. */
66 typedef struct priority_info_s
{
67 /* Nonzero if there have been any initializations at this priority
68 throughout the translation unit. */
69 int initializations_p
;
70 /* Nonzero if there have been any destructions at this priority
71 throughout the translation unit. */
75 static void mark_vtable_entries (tree
);
76 static bool maybe_emit_vtables (tree
);
77 static bool acceptable_java_type (tree
);
78 static tree
start_objects (int, int);
79 static void finish_objects (int, int, tree
);
80 static tree
start_static_storage_duration_function (unsigned);
81 static void finish_static_storage_duration_function (tree
);
82 static priority_info
get_priority_info (int);
83 static void do_static_initialization_or_destruction (tree
, bool);
84 static void one_static_initialization_or_destruction (tree
, tree
, bool);
85 static void generate_ctor_or_dtor_function (bool, int, location_t
*);
86 static int generate_ctor_and_dtor_functions_for_priority (splay_tree_node
,
88 static tree
prune_vars_needing_no_initialization (tree
*);
89 static void write_out_vars (tree
);
90 static void import_export_class (tree
);
91 static tree
get_guard_bits (tree
);
92 static void determine_visibility_from_class (tree
, tree
);
93 static bool determine_hidden_inline (tree
);
94 static bool decl_defined_p (tree
);
96 /* A list of static class variables. This is needed, because a
97 static class variable can be declared inside the class without
98 an initializer, and then initialized, statically, outside the class. */
99 static GTY(()) vec
<tree
, va_gc
> *pending_statics
;
101 /* A list of functions which were declared inline, but which we
102 may need to emit outline anyway. */
103 static GTY(()) vec
<tree
, va_gc
> *deferred_fns
;
105 /* A list of decls that use types with no linkage, which we need to make
107 static GTY(()) vec
<tree
, va_gc
> *no_linkage_decls
;
109 /* A vector of alternating decls and identifiers, where the latter
110 is to be an alias for the former if the former is defined. */
111 static GTY(()) vec
<tree
, va_gc
> *mangling_aliases
;
113 /* Nonzero if we're done parsing and into end-of-file activities. */
118 /* Return a member function type (a METHOD_TYPE), given FNTYPE (a
119 FUNCTION_TYPE), CTYPE (class type), and QUALS (the cv-qualifiers
120 that apply to the function). */
123 build_memfn_type (tree fntype
, tree ctype
, cp_cv_quals quals
,
124 cp_ref_qualifier rqual
)
129 bool late_return_type_p
;
131 if (fntype
== error_mark_node
|| ctype
== error_mark_node
)
132 return error_mark_node
;
134 gcc_assert (TREE_CODE (fntype
) == FUNCTION_TYPE
135 || TREE_CODE (fntype
) == METHOD_TYPE
);
137 type_quals
= quals
& ~TYPE_QUAL_RESTRICT
;
138 ctype
= cp_build_qualified_type (ctype
, type_quals
);
139 raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
140 attrs
= TYPE_ATTRIBUTES (fntype
);
141 late_return_type_p
= TYPE_HAS_LATE_RETURN_TYPE (fntype
);
142 fntype
= build_method_type_directly (ctype
, TREE_TYPE (fntype
),
143 (TREE_CODE (fntype
) == METHOD_TYPE
144 ? TREE_CHAIN (TYPE_ARG_TYPES (fntype
))
145 : TYPE_ARG_TYPES (fntype
)));
147 fntype
= cp_build_type_attribute_variant (fntype
, attrs
);
149 fntype
= build_ref_qualified_type (fntype
, rqual
);
151 fntype
= build_exception_variant (fntype
, raises
);
152 if (late_return_type_p
)
153 TYPE_HAS_LATE_RETURN_TYPE (fntype
) = 1;
158 /* Return a variant of FNTYPE, a FUNCTION_TYPE or METHOD_TYPE, with its
159 return type changed to NEW_RET. */
162 change_return_type (tree new_ret
, tree fntype
)
165 tree args
= TYPE_ARG_TYPES (fntype
);
166 tree raises
= TYPE_RAISES_EXCEPTIONS (fntype
);
167 tree attrs
= TYPE_ATTRIBUTES (fntype
);
168 bool late_return_type_p
= TYPE_HAS_LATE_RETURN_TYPE (fntype
);
170 if (new_ret
== error_mark_node
)
173 if (same_type_p (new_ret
, TREE_TYPE (fntype
)))
176 if (TREE_CODE (fntype
) == FUNCTION_TYPE
)
178 newtype
= build_function_type (new_ret
, args
);
179 newtype
= apply_memfn_quals (newtype
,
180 type_memfn_quals (fntype
),
181 type_memfn_rqual (fntype
));
184 newtype
= build_method_type_directly
185 (class_of_this_parm (fntype
), new_ret
, TREE_CHAIN (args
));
186 if (FUNCTION_REF_QUALIFIED (fntype
))
187 newtype
= build_ref_qualified_type (newtype
, type_memfn_rqual (fntype
));
189 newtype
= build_exception_variant (newtype
, raises
);
191 newtype
= cp_build_type_attribute_variant (newtype
, attrs
);
192 if (late_return_type_p
)
193 TYPE_HAS_LATE_RETURN_TYPE (newtype
) = 1;
198 /* Build a PARM_DECL with NAME and TYPE, and set DECL_ARG_TYPE
202 cp_build_parm_decl (tree name
, tree type
)
204 tree parm
= build_decl (input_location
,
205 PARM_DECL
, name
, type
);
206 /* DECL_ARG_TYPE is only used by the back end and the back end never
208 if (!processing_template_decl
)
209 DECL_ARG_TYPE (parm
) = type_passed_as (type
);
214 /* Returns a PARM_DECL for a parameter of the indicated TYPE, with the
218 build_artificial_parm (tree name
, tree type
)
220 tree parm
= cp_build_parm_decl (name
, type
);
221 DECL_ARTIFICIAL (parm
) = 1;
222 /* All our artificial parms are implicitly `const'; they cannot be
224 TREE_READONLY (parm
) = 1;
228 /* Constructors for types with virtual baseclasses need an "in-charge" flag
229 saying whether this constructor is responsible for initialization of
230 virtual baseclasses or not. All destructors also need this "in-charge"
231 flag, which additionally determines whether or not the destructor should
232 free the memory for the object.
234 This function adds the "in-charge" flag to member function FN if
235 appropriate. It is called from grokclassfn and tsubst.
236 FN must be either a constructor or destructor.
238 The in-charge flag follows the 'this' parameter, and is followed by the
239 VTT parm (if any), then the user-written parms. */
242 maybe_retrofit_in_chrg (tree fn
)
244 tree basetype
, arg_types
, parms
, parm
, fntype
;
246 /* If we've already add the in-charge parameter don't do it again. */
247 if (DECL_HAS_IN_CHARGE_PARM_P (fn
))
250 /* When processing templates we can't know, in general, whether or
251 not we're going to have virtual baseclasses. */
252 if (processing_template_decl
)
255 /* We don't need an in-charge parameter for constructors that don't
256 have virtual bases. */
257 if (DECL_CONSTRUCTOR_P (fn
)
258 && !CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn
)))
261 arg_types
= TYPE_ARG_TYPES (TREE_TYPE (fn
));
262 basetype
= TREE_TYPE (TREE_VALUE (arg_types
));
263 arg_types
= TREE_CHAIN (arg_types
);
265 parms
= DECL_CHAIN (DECL_ARGUMENTS (fn
));
267 /* If this is a subobject constructor or destructor, our caller will
268 pass us a pointer to our VTT. */
269 if (CLASSTYPE_VBASECLASSES (DECL_CONTEXT (fn
)))
271 parm
= build_artificial_parm (vtt_parm_identifier
, vtt_parm_type
);
273 /* First add it to DECL_ARGUMENTS between 'this' and the real args... */
274 DECL_CHAIN (parm
) = parms
;
277 /* ...and then to TYPE_ARG_TYPES. */
278 arg_types
= hash_tree_chain (vtt_parm_type
, arg_types
);
280 DECL_HAS_VTT_PARM_P (fn
) = 1;
283 /* Then add the in-charge parm (before the VTT parm). */
284 parm
= build_artificial_parm (in_charge_identifier
, integer_type_node
);
285 DECL_CHAIN (parm
) = parms
;
287 arg_types
= hash_tree_chain (integer_type_node
, arg_types
);
289 /* Insert our new parameter(s) into the list. */
290 DECL_CHAIN (DECL_ARGUMENTS (fn
)) = parms
;
292 /* And rebuild the function type. */
293 fntype
= build_method_type_directly (basetype
, TREE_TYPE (TREE_TYPE (fn
)),
295 if (TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)))
296 fntype
= build_exception_variant (fntype
,
297 TYPE_RAISES_EXCEPTIONS (TREE_TYPE (fn
)));
298 if (TYPE_ATTRIBUTES (TREE_TYPE (fn
)))
299 fntype
= (cp_build_type_attribute_variant
300 (fntype
, TYPE_ATTRIBUTES (TREE_TYPE (fn
))));
301 TREE_TYPE (fn
) = fntype
;
303 /* Now we've got the in-charge parameter. */
304 DECL_HAS_IN_CHARGE_PARM_P (fn
) = 1;
307 /* Classes overload their constituent function names automatically.
308 When a function name is declared in a record structure,
309 its name is changed to it overloaded name. Since names for
310 constructors and destructors can conflict, we place a leading
313 CNAME is the name of the class we are grokking for.
315 FUNCTION is a FUNCTION_DECL. It was created by `grokdeclarator'.
317 FLAGS contains bits saying what's special about today's
318 arguments. DTOR_FLAG == DESTRUCTOR.
320 If FUNCTION is a destructor, then we must add the `auto-delete' field
321 as a second parameter. There is some hair associated with the fact
322 that we must "declare" this variable in the manner consistent with the
323 way the rest of the arguments were declared.
325 QUALS are the qualifiers for the this pointer. */
328 grokclassfn (tree ctype
, tree function
, enum overload_flags flags
)
330 tree fn_name
= DECL_NAME (function
);
332 /* Even within an `extern "C"' block, members get C++ linkage. See
333 [dcl.link] for details. */
334 SET_DECL_LANGUAGE (function
, lang_cplusplus
);
336 if (fn_name
== NULL_TREE
)
338 error ("name missing for member function");
339 fn_name
= get_identifier ("<anonymous>");
340 DECL_NAME (function
) = fn_name
;
343 DECL_CONTEXT (function
) = ctype
;
345 if (flags
== DTOR_FLAG
)
346 DECL_DESTRUCTOR_P (function
) = 1;
348 if (flags
== DTOR_FLAG
|| DECL_CONSTRUCTOR_P (function
))
349 maybe_retrofit_in_chrg (function
);
352 /* Create an ARRAY_REF, checking for the user doing things backwards
353 along the way. DECLTYPE_P is for N3276, as in the parser. */
356 grok_array_decl (location_t loc
, tree array_expr
, tree index_exp
,
361 tree orig_array_expr
= array_expr
;
362 tree orig_index_exp
= index_exp
;
364 if (error_operand_p (array_expr
) || error_operand_p (index_exp
))
365 return error_mark_node
;
367 if (processing_template_decl
)
369 if (type_dependent_expression_p (array_expr
)
370 || type_dependent_expression_p (index_exp
))
371 return build_min_nt_loc (loc
, ARRAY_REF
, array_expr
, index_exp
,
372 NULL_TREE
, NULL_TREE
);
373 array_expr
= build_non_dependent_expr (array_expr
);
374 index_exp
= build_non_dependent_expr (index_exp
);
377 type
= TREE_TYPE (array_expr
);
379 type
= non_reference (type
);
381 /* If they have an `operator[]', use that. */
382 if (MAYBE_CLASS_TYPE_P (type
) || MAYBE_CLASS_TYPE_P (TREE_TYPE (index_exp
)))
384 tsubst_flags_t complain
= tf_warning_or_error
;
386 complain
|= tf_decltype
;
387 expr
= build_new_op (loc
, ARRAY_REF
, LOOKUP_NORMAL
, array_expr
,
388 index_exp
, NULL_TREE
, /*overload=*/NULL
, complain
);
394 /* Otherwise, create an ARRAY_REF for a pointer or array type.
395 It is a little-known fact that, if `a' is an array and `i' is
396 an int, you can write `i[a]', which means the same thing as
398 if (TREE_CODE (type
) == ARRAY_TYPE
|| TREE_CODE (type
) == VECTOR_TYPE
)
401 p1
= build_expr_type_conversion (WANT_POINTER
, array_expr
, false);
403 if (TREE_CODE (TREE_TYPE (index_exp
)) == ARRAY_TYPE
)
406 p2
= build_expr_type_conversion (WANT_POINTER
, index_exp
, false);
408 i1
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, array_expr
,
410 i2
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, index_exp
,
413 if ((p1
&& i2
) && (i1
&& p2
))
414 error ("ambiguous conversion for array subscript");
417 array_expr
= p1
, index_exp
= i2
;
419 array_expr
= p2
, index_exp
= i1
;
422 error ("invalid types %<%T[%T]%> for array subscript",
423 type
, TREE_TYPE (index_exp
));
424 return error_mark_node
;
427 if (array_expr
== error_mark_node
|| index_exp
== error_mark_node
)
428 error ("ambiguous conversion for array subscript");
430 expr
= build_array_ref (input_location
, array_expr
, index_exp
);
432 if (processing_template_decl
&& expr
!= error_mark_node
)
433 return build_min_non_dep (ARRAY_REF
, expr
, orig_array_expr
, orig_index_exp
,
434 NULL_TREE
, NULL_TREE
);
438 /* Given the cast expression EXP, checking out its validity. Either return
439 an error_mark_node if there was an unavoidable error, return a cast to
440 void for trying to delete a pointer w/ the value 0, or return the
441 call to delete. If DOING_VEC is true, we handle things differently
442 for doing an array delete.
443 Implements ARM $5.3.4. This is called from the parser. */
446 delete_sanity (tree exp
, tree size
, bool doing_vec
, int use_global_delete
,
447 tsubst_flags_t complain
)
451 if (exp
== error_mark_node
)
454 if (processing_template_decl
)
456 t
= build_min (DELETE_EXPR
, void_type_node
, exp
, size
);
457 DELETE_EXPR_USE_GLOBAL (t
) = use_global_delete
;
458 DELETE_EXPR_USE_VEC (t
) = doing_vec
;
459 TREE_SIDE_EFFECTS (t
) = 1;
463 /* An array can't have been allocated by new, so complain. */
464 if (TREE_CODE (TREE_TYPE (exp
)) == ARRAY_TYPE
)
465 warning (0, "deleting array %q#E", exp
);
467 t
= build_expr_type_conversion (WANT_POINTER
, exp
, true);
469 if (t
== NULL_TREE
|| t
== error_mark_node
)
471 error ("type %q#T argument given to %<delete%>, expected pointer",
473 return error_mark_node
;
476 type
= TREE_TYPE (t
);
478 /* As of Valley Forge, you can delete a pointer to const. */
480 /* You can't delete functions. */
481 if (TREE_CODE (TREE_TYPE (type
)) == FUNCTION_TYPE
)
483 error ("cannot delete a function. Only pointer-to-objects are "
484 "valid arguments to %<delete%>");
485 return error_mark_node
;
488 /* Deleting ptr to void is undefined behavior [expr.delete/3]. */
489 if (VOID_TYPE_P (TREE_TYPE (type
)))
491 warning (OPT_Wdelete_incomplete
, "deleting %qT is undefined", type
);
495 /* Deleting a pointer with the value zero is valid and has no effect. */
496 if (integer_zerop (t
))
497 return build1 (NOP_EXPR
, void_type_node
, t
);
500 return build_vec_delete (t
, /*maxindex=*/NULL_TREE
,
501 sfk_deleting_destructor
,
502 use_global_delete
, complain
);
504 return build_delete (type
, t
, sfk_deleting_destructor
,
505 LOOKUP_NORMAL
, use_global_delete
,
509 /* Report an error if the indicated template declaration is not the
510 sort of thing that should be a member template. */
513 check_member_template (tree tmpl
)
517 gcc_assert (TREE_CODE (tmpl
) == TEMPLATE_DECL
);
518 decl
= DECL_TEMPLATE_RESULT (tmpl
);
520 if (TREE_CODE (decl
) == FUNCTION_DECL
521 || DECL_ALIAS_TEMPLATE_P (tmpl
)
522 || (TREE_CODE (decl
) == TYPE_DECL
523 && MAYBE_CLASS_TYPE_P (TREE_TYPE (decl
))))
525 /* The parser rejects template declarations in local classes
526 (with the exception of generic lambdas). */
527 gcc_assert (!current_function_decl
|| LAMBDA_FUNCTION_P (decl
));
528 /* The parser rejects any use of virtual in a function template. */
529 gcc_assert (!(TREE_CODE (decl
) == FUNCTION_DECL
530 && DECL_VIRTUAL_P (decl
)));
532 /* The debug-information generating code doesn't know what to do
533 with member templates. */
534 DECL_IGNORED_P (tmpl
) = 1;
536 else if (variable_template_p (tmpl
))
539 error ("template declaration of %q#D", decl
);
542 /* Return true iff TYPE is a valid Java parameter or return type. */
545 acceptable_java_type (tree type
)
547 if (type
== error_mark_node
)
550 if (VOID_TYPE_P (type
) || TYPE_FOR_JAVA (type
))
552 if (TYPE_PTR_P (type
) || TREE_CODE (type
) == REFERENCE_TYPE
)
554 type
= TREE_TYPE (type
);
555 if (TREE_CODE (type
) == RECORD_TYPE
)
558 if (! TYPE_FOR_JAVA (type
))
560 if (! CLASSTYPE_TEMPLATE_INFO (type
))
562 args
= CLASSTYPE_TI_ARGS (type
);
563 i
= TREE_VEC_LENGTH (args
);
566 type
= TREE_VEC_ELT (args
, i
);
567 if (TYPE_PTR_P (type
))
568 type
= TREE_TYPE (type
);
569 if (! TYPE_FOR_JAVA (type
))
578 /* For a METHOD in a Java class CTYPE, return true if
579 the parameter and return types are valid Java types.
580 Otherwise, print appropriate error messages, and return false. */
583 check_java_method (tree method
)
586 tree arg_types
= TYPE_ARG_TYPES (TREE_TYPE (method
));
587 tree ret_type
= TREE_TYPE (TREE_TYPE (method
));
589 if (!acceptable_java_type (ret_type
))
591 error ("Java method %qD has non-Java return type %qT",
596 arg_types
= TREE_CHAIN (arg_types
);
597 if (DECL_HAS_IN_CHARGE_PARM_P (method
))
598 arg_types
= TREE_CHAIN (arg_types
);
599 if (DECL_HAS_VTT_PARM_P (method
))
600 arg_types
= TREE_CHAIN (arg_types
);
602 for (; arg_types
!= NULL_TREE
; arg_types
= TREE_CHAIN (arg_types
))
604 tree type
= TREE_VALUE (arg_types
);
605 if (!acceptable_java_type (type
))
607 if (type
!= error_mark_node
)
608 error ("Java method %qD has non-Java parameter type %qT",
616 /* Sanity check: report error if this function FUNCTION is not
617 really a member of the class (CTYPE) it is supposed to belong to.
618 TEMPLATE_PARMS is used to specify the template parameters of a member
619 template passed as FUNCTION_DECL. If the member template is passed as a
620 TEMPLATE_DECL, it can be NULL since the parameters can be extracted
621 from the declaration. If the function is not a function template, it
623 It returns the original declaration for the function, NULL_TREE if
624 no declaration was found, error_mark_node if an error was emitted. */
627 check_classfn (tree ctype
, tree function
, tree template_parms
)
633 if (DECL_USE_TEMPLATE (function
)
634 && !(TREE_CODE (function
) == TEMPLATE_DECL
635 && DECL_TEMPLATE_SPECIALIZATION (function
))
636 && DECL_MEMBER_TEMPLATE_P (DECL_TI_TEMPLATE (function
)))
637 /* Since this is a specialization of a member template,
638 we're not going to find the declaration in the class.
641 struct S { template <typename T> void f(T); };
642 template <> void S::f(int);
644 we're not going to find `S::f(int)', but there's no
645 reason we should, either. We let our callers know we didn't
646 find the method, but we don't complain. */
649 /* Basic sanity check: for a template function, the template parameters
650 either were not passed, or they are the same of DECL_TEMPLATE_PARMS. */
651 if (TREE_CODE (function
) == TEMPLATE_DECL
)
654 && !comp_template_parms (template_parms
,
655 DECL_TEMPLATE_PARMS (function
)))
657 error ("template parameter lists provided don%'t match the "
658 "template parameters of %qD", function
);
659 return error_mark_node
;
661 template_parms
= DECL_TEMPLATE_PARMS (function
);
664 /* OK, is this a definition of a member template? */
665 is_template
= (template_parms
!= NULL_TREE
);
669 A destructor shall not be a member template. */
670 if (DECL_DESTRUCTOR_P (function
) && is_template
)
672 error ("destructor %qD declared as member template", function
);
673 return error_mark_node
;
676 /* We must enter the scope here, because conversion operators are
677 named by target type, and type equivalence relies on typenames
678 resolving within the scope of CTYPE. */
679 pushed_scope
= push_scope (ctype
);
680 ix
= class_method_index_for_fn (complete_type (ctype
), function
);
683 vec
<tree
, va_gc
> *methods
= CLASSTYPE_METHOD_VEC (ctype
);
684 tree fndecls
, fndecl
= 0;
686 const char *format
= NULL
;
688 for (fndecls
= (*methods
)[ix
];
689 fndecls
; fndecls
= OVL_NEXT (fndecls
))
693 fndecl
= OVL_CURRENT (fndecls
);
694 p1
= TYPE_ARG_TYPES (TREE_TYPE (function
));
695 p2
= TYPE_ARG_TYPES (TREE_TYPE (fndecl
));
697 /* We cannot simply call decls_match because this doesn't
698 work for static member functions that are pretending to
699 be methods, and because the name may have been changed by
702 /* Get rid of the this parameter on functions that become
704 if (DECL_STATIC_FUNCTION_P (fndecl
)
705 && TREE_CODE (TREE_TYPE (function
)) == METHOD_TYPE
)
706 p1
= TREE_CHAIN (p1
);
708 /* A member template definition only matches a member template
710 if (is_template
!= (TREE_CODE (fndecl
) == TEMPLATE_DECL
))
713 /* ref-qualifier or absence of same must match. */
714 if (type_memfn_rqual (TREE_TYPE (function
))
715 != type_memfn_rqual (TREE_TYPE (fndecl
)))
718 /* While finding a match, same types and params are not enough
719 if the function is versioned. Also check version ("target")
721 if (same_type_p (TREE_TYPE (TREE_TYPE (function
)),
722 TREE_TYPE (TREE_TYPE (fndecl
)))
723 && compparms (p1
, p2
)
724 && !targetm
.target_option
.function_versions (function
, fndecl
)
726 || comp_template_parms (template_parms
,
727 DECL_TEMPLATE_PARMS (fndecl
)))
728 && (DECL_TEMPLATE_SPECIALIZATION (function
)
729 == DECL_TEMPLATE_SPECIALIZATION (fndecl
))
730 && (!DECL_TEMPLATE_SPECIALIZATION (function
)
731 || (DECL_TI_TEMPLATE (function
)
732 == DECL_TI_TEMPLATE (fndecl
))))
738 pop_scope (pushed_scope
);
739 return OVL_CURRENT (fndecls
);
742 error_at (DECL_SOURCE_LOCATION (function
),
743 "prototype for %q#D does not match any in class %qT",
745 is_conv_op
= DECL_CONV_FN_P (fndecl
);
748 ix
= CLASSTYPE_FIRST_CONVERSION_SLOT
;
749 fndecls
= (*methods
)[ix
];
752 fndecl
= OVL_CURRENT (fndecls
);
753 fndecls
= OVL_NEXT (fndecls
);
755 if (!fndecls
&& is_conv_op
)
757 if (methods
->length () > (size_t) ++ix
)
759 fndecls
= (*methods
)[ix
];
760 if (!DECL_CONV_FN_P (OVL_CURRENT (fndecls
)))
772 format
= N_("candidates are: %+#D");
774 format
= N_("candidate is: %+#D");
775 error (format
, fndecl
);
778 else if (!COMPLETE_TYPE_P (ctype
))
779 cxx_incomplete_type_error (function
, ctype
);
781 error ("no %q#D member function declared in class %qT",
785 pop_scope (pushed_scope
);
786 return error_mark_node
;
789 /* DECL is a function with vague linkage. Remember it so that at the
790 end of the translation unit we can decide whether or not to emit
794 note_vague_linkage_fn (tree decl
)
796 DECL_DEFER_OUTPUT (decl
) = 1;
797 vec_safe_push (deferred_fns
, decl
);
800 /* As above, but for variable template instantiations. */
803 note_variable_template_instantiation (tree decl
)
805 vec_safe_push (pending_statics
, decl
);
808 /* We have just processed the DECL, which is a static data member.
809 The other parameters are as for cp_finish_decl. */
812 finish_static_data_member_decl (tree decl
,
813 tree init
, bool init_const_expr_p
,
817 DECL_CONTEXT (decl
) = current_class_type
;
819 /* We cannot call pushdecl here, because that would fill in the
820 TREE_CHAIN of our decl. Instead, we modify cp_finish_decl to do
821 the right thing, namely, to put this decl out straight away. */
823 if (! processing_template_decl
)
824 vec_safe_push (pending_statics
, decl
);
826 if (LOCAL_CLASS_P (current_class_type
)
827 /* We already complained about the template definition. */
828 && !DECL_TEMPLATE_INSTANTIATION (decl
))
829 permerror (input_location
, "local class %q#T shall not have static data member %q#D",
830 current_class_type
, decl
);
832 for (tree t
= current_class_type
; TYPE_P (t
);
833 t
= CP_TYPE_CONTEXT (t
))
834 if (TYPE_ANONYMOUS_P (t
))
836 if (permerror (DECL_SOURCE_LOCATION (decl
),
837 "static data member %qD in unnamed class", decl
))
838 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)),
839 "unnamed class defined here");
843 DECL_IN_AGGR_P (decl
) = 1;
845 if (TREE_CODE (TREE_TYPE (decl
)) == ARRAY_TYPE
846 && TYPE_DOMAIN (TREE_TYPE (decl
)) == NULL_TREE
)
847 SET_VAR_HAD_UNKNOWN_BOUND (decl
);
849 cp_finish_decl (decl
, init
, init_const_expr_p
, asmspec_tree
, flags
);
852 /* DECLARATOR and DECLSPECS correspond to a class member. The other
853 parameters are as for cp_finish_decl. Return the DECL for the
854 class member declared. */
857 grokfield (const cp_declarator
*declarator
,
858 cp_decl_specifier_seq
*declspecs
,
859 tree init
, bool init_const_expr_p
,
864 const char *asmspec
= 0;
869 && TREE_CODE (init
) == TREE_LIST
870 && TREE_VALUE (init
) == error_mark_node
871 && TREE_CHAIN (init
) == NULL_TREE
)
874 value
= grokdeclarator (declarator
, declspecs
, FIELD
, init
!= 0, &attrlist
);
875 if (! value
|| value
== error_mark_node
)
876 /* friend or constructor went bad. */
877 return error_mark_node
;
878 if (TREE_TYPE (value
) == error_mark_node
)
881 if (TREE_CODE (value
) == TYPE_DECL
&& init
)
883 error ("typedef %qD is initialized (use decltype instead)", value
);
887 /* Pass friendly classes back. */
888 if (value
== void_type_node
)
892 name
= DECL_NAME (value
);
894 if (name
!= NULL_TREE
)
896 if (TREE_CODE (name
) == TEMPLATE_ID_EXPR
)
898 error ("explicit template argument list not allowed");
899 return error_mark_node
;
902 if (IDENTIFIER_POINTER (name
)[0] == '_'
903 && ! strcmp (IDENTIFIER_POINTER (name
), "_vptr"))
904 error ("member %qD conflicts with virtual function table field name",
908 /* Stash away type declarations. */
909 if (TREE_CODE (value
) == TYPE_DECL
)
911 DECL_NONLOCAL (value
) = 1;
912 DECL_CONTEXT (value
) = current_class_type
;
918 /* If this is a typedef that names the class for linkage purposes
919 (7.1.3p8), apply any attributes directly to the type. */
920 if (OVERLOAD_TYPE_P (TREE_TYPE (value
))
921 && value
== TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value
))))
922 attrflags
= ATTR_FLAG_TYPE_IN_PLACE
;
924 cplus_decl_attributes (&value
, attrlist
, attrflags
);
927 if (decl_spec_seq_has_spec_p (declspecs
, ds_typedef
)
928 && TREE_TYPE (value
) != error_mark_node
929 && TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value
))) != value
)
930 set_underlying_type (value
);
932 /* It's important that push_template_decl below follows
933 set_underlying_type above so that the created template
934 carries the properly set type of VALUE. */
935 if (processing_template_decl
)
936 value
= push_template_decl (value
);
938 record_locally_defined_typedef (value
);
942 int friendp
= decl_spec_seq_has_spec_p (declspecs
, ds_friend
);
944 if (!friendp
&& DECL_IN_AGGR_P (value
))
946 error ("%qD is already defined in %qT", value
, DECL_CONTEXT (value
));
947 return void_type_node
;
950 if (asmspec_tree
&& asmspec_tree
!= error_mark_node
)
951 asmspec
= TREE_STRING_POINTER (asmspec_tree
);
955 if (TREE_CODE (value
) == FUNCTION_DECL
)
957 if (init
== ridpointers
[(int)RID_DELETE
])
959 DECL_DELETED_FN (value
) = 1;
960 DECL_DECLARED_INLINE_P (value
) = 1;
961 DECL_INITIAL (value
) = error_mark_node
;
963 else if (init
== ridpointers
[(int)RID_DEFAULT
])
965 if (defaultable_fn_check (value
))
967 DECL_DEFAULTED_FN (value
) = 1;
968 DECL_INITIALIZED_IN_CLASS_P (value
) = 1;
969 DECL_DECLARED_INLINE_P (value
) = 1;
972 else if (TREE_CODE (init
) == DEFAULT_ARG
)
973 error ("invalid initializer for member function %qD", value
);
974 else if (TREE_CODE (TREE_TYPE (value
)) == METHOD_TYPE
)
976 if (integer_zerop (init
))
977 DECL_PURE_VIRTUAL_P (value
) = 1;
978 else if (error_operand_p (init
))
979 ; /* An error has already been reported. */
981 error ("invalid initializer for member function %qD",
986 gcc_assert (TREE_CODE (TREE_TYPE (value
)) == FUNCTION_TYPE
);
988 error ("initializer specified for friend function %qD",
991 error ("initializer specified for static member function %qD",
995 else if (TREE_CODE (value
) == FIELD_DECL
)
996 /* C++11 NSDMI, keep going. */;
997 else if (!VAR_P (value
))
1001 /* Pass friend decls back. */
1002 if ((TREE_CODE (value
) == FUNCTION_DECL
1003 || TREE_CODE (value
) == TEMPLATE_DECL
)
1004 && DECL_CONTEXT (value
) != current_class_type
)
1007 /* Need to set this before push_template_decl. */
1008 if (TREE_CODE (value
) == VAR_DECL
)
1009 DECL_CONTEXT (value
) = current_class_type
;
1011 if (processing_template_decl
&& VAR_OR_FUNCTION_DECL_P (value
))
1013 value
= push_template_decl (value
);
1014 if (error_operand_p (value
))
1015 return error_mark_node
;
1019 cplus_decl_attributes (&value
, attrlist
, 0);
1021 if (init
&& DIRECT_LIST_INIT_P (init
))
1022 flags
= LOOKUP_NORMAL
;
1024 flags
= LOOKUP_IMPLICIT
;
1026 switch (TREE_CODE (value
))
1029 finish_static_data_member_decl (value
, init
, init_const_expr_p
,
1030 asmspec_tree
, flags
);
1035 error ("%<asm%> specifiers are not permitted on non-static data members");
1036 if (DECL_INITIAL (value
) == error_mark_node
)
1037 init
= error_mark_node
;
1038 cp_finish_decl (value
, init
, /*init_const_expr_p=*/false,
1040 DECL_IN_AGGR_P (value
) = 1;
1045 set_user_assembler_name (value
, asmspec
);
1047 cp_finish_decl (value
,
1049 /*init_const_expr_p=*/false,
1050 asmspec_tree
, flags
);
1052 /* Pass friends back this way. */
1053 if (DECL_FRIEND_P (value
))
1054 return void_type_node
;
1056 DECL_IN_AGGR_P (value
) = 1;
1065 /* Like `grokfield', but for bitfields.
1066 WIDTH is non-NULL for bit fields only, and is an INTEGER_CST node. */
1069 grokbitfield (const cp_declarator
*declarator
,
1070 cp_decl_specifier_seq
*declspecs
, tree width
,
1073 tree value
= grokdeclarator (declarator
, declspecs
, BITFIELD
, 0, &attrlist
);
1075 if (value
== error_mark_node
)
1076 return NULL_TREE
; /* friends went bad. */
1077 if (TREE_TYPE (value
) == error_mark_node
)
1080 /* Pass friendly classes back. */
1081 if (VOID_TYPE_P (value
))
1082 return void_type_node
;
1084 if (!INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (value
))
1085 && (POINTER_TYPE_P (value
)
1086 || !dependent_type_p (TREE_TYPE (value
))))
1088 error ("bit-field %qD with non-integral type", value
);
1089 return error_mark_node
;
1092 if (TREE_CODE (value
) == TYPE_DECL
)
1094 error ("cannot declare %qD to be a bit-field type", value
);
1098 /* Usually, finish_struct_1 catches bitfields with invalid types.
1099 But, in the case of bitfields with function type, we confuse
1100 ourselves into thinking they are member functions, so we must
1102 if (TREE_CODE (value
) == FUNCTION_DECL
)
1104 error ("cannot declare bit-field %qD with function type",
1109 if (DECL_IN_AGGR_P (value
))
1111 error ("%qD is already defined in the class %qT", value
,
1112 DECL_CONTEXT (value
));
1113 return void_type_node
;
1116 if (TREE_STATIC (value
))
1118 error ("static member %qD cannot be a bit-field", value
);
1121 cp_finish_decl (value
, NULL_TREE
, false, NULL_TREE
, 0);
1123 if (width
!= error_mark_node
)
1125 /* The width must be an integer type. */
1126 if (!type_dependent_expression_p (width
)
1127 && !INTEGRAL_OR_UNSCOPED_ENUMERATION_TYPE_P (TREE_TYPE (width
)))
1128 error ("width of bit-field %qD has non-integral type %qT", value
,
1130 DECL_INITIAL (value
) = width
;
1131 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 /* Attribute unused is applied directly, as it appertains to
1164 if (is_attribute_p ("unused", name
))
1167 /* #pragma omp declare simd attribute needs to be always deferred. */
1169 && is_attribute_p ("omp declare simd", name
))
1172 /* An attribute pack is clearly dependent. */
1173 if (args
&& PACK_EXPANSION_P (args
))
1176 /* If any of the arguments are dependent expressions, we can't evaluate
1177 the attribute until instantiation time. */
1178 for (arg
= args
; arg
; arg
= TREE_CHAIN (arg
))
1180 tree t
= TREE_VALUE (arg
);
1182 /* If the first attribute argument is an identifier, only consider
1183 second and following arguments. Attributes like mode, format,
1184 cleanup and several target specific attributes aren't late
1185 just because they have an IDENTIFIER_NODE as first argument. */
1186 if (arg
== args
&& identifier_p (t
))
1189 if (value_dependent_expression_p (t
)
1190 || type_dependent_expression_p (t
))
1194 if (TREE_CODE (decl
) == TYPE_DECL
1196 || spec
->type_required
)
1198 tree type
= TYPE_P (decl
) ? decl
: TREE_TYPE (decl
);
1200 /* We can't apply any attributes to a completely unknown type until
1201 instantiation time. */
1202 enum tree_code code
= TREE_CODE (type
);
1203 if (code
== TEMPLATE_TYPE_PARM
1204 || code
== BOUND_TEMPLATE_TEMPLATE_PARM
1205 || code
== TYPENAME_TYPE
)
1207 /* Also defer most attributes on dependent types. This is not
1208 necessary in all cases, but is the better default. */
1209 else if (dependent_type_p (type
)
1210 /* But some attributes specifically apply to templates. */
1211 && !is_attribute_p ("abi_tag", name
)
1212 && !is_attribute_p ("deprecated", name
)
1213 && !is_attribute_p ("visibility", name
))
1222 /* ATTR_P is a list of attributes. Remove any attributes which need to be
1223 applied at instantiation time and return them. If IS_DEPENDENT is true,
1224 the declaration itself is dependent, so all attributes should be applied
1225 at instantiation time. */
1228 splice_template_attributes (tree
*attr_p
, tree decl
)
1231 tree late_attrs
= NULL_TREE
;
1232 tree
*q
= &late_attrs
;
1239 if (is_late_template_attribute (*p
, decl
))
1241 ATTR_IS_DEPENDENT (*p
) = 1;
1243 *p
= TREE_CHAIN (*p
);
1244 q
= &TREE_CHAIN (*q
);
1248 p
= &TREE_CHAIN (*p
);
1254 /* Remove any late attributes from the list in ATTR_P and attach them to
1258 save_template_attributes (tree
*attr_p
, tree
*decl_p
)
1262 if (attr_p
&& *attr_p
== error_mark_node
)
1265 tree late_attrs
= splice_template_attributes (attr_p
, *decl_p
);
1269 if (DECL_P (*decl_p
))
1270 q
= &DECL_ATTRIBUTES (*decl_p
);
1272 q
= &TYPE_ATTRIBUTES (*decl_p
);
1274 tree old_attrs
= *q
;
1276 /* Merge the late attributes at the beginning with the attribute
1278 late_attrs
= merge_attributes (late_attrs
, *q
);
1281 if (!DECL_P (*decl_p
) && *decl_p
== TYPE_MAIN_VARIANT (*decl_p
))
1283 /* We've added new attributes directly to the main variant, so
1284 now we need to update all of the other variants to include
1285 these new attributes. */
1287 for (variant
= TYPE_NEXT_VARIANT (*decl_p
); variant
;
1288 variant
= TYPE_NEXT_VARIANT (variant
))
1290 gcc_assert (TYPE_ATTRIBUTES (variant
) == old_attrs
);
1291 TYPE_ATTRIBUTES (variant
) = TYPE_ATTRIBUTES (*decl_p
);
1296 /* Return true iff ATTRS are acceptable attributes to be applied in-place
1297 to a typedef which gives a previously anonymous class or enum a name for
1298 linkage purposes. */
1301 attributes_naming_typedef_ok (tree attrs
)
1303 for (; attrs
; attrs
= TREE_CHAIN (attrs
))
1305 tree name
= get_attribute_name (attrs
);
1306 if (is_attribute_p ("vector_size", name
))
1312 /* Like reconstruct_complex_type, but handle also template trees. */
1315 cp_reconstruct_complex_type (tree type
, tree bottom
)
1318 bool late_return_type_p
= false;
1320 if (TYPE_PTR_P (type
))
1322 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1323 outer
= build_pointer_type_for_mode (inner
, TYPE_MODE (type
),
1324 TYPE_REF_CAN_ALIAS_ALL (type
));
1326 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
1328 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1329 outer
= build_reference_type_for_mode (inner
, TYPE_MODE (type
),
1330 TYPE_REF_CAN_ALIAS_ALL (type
));
1332 else if (TREE_CODE (type
) == ARRAY_TYPE
)
1334 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1335 outer
= build_cplus_array_type (inner
, TYPE_DOMAIN (type
));
1336 /* Don't call cp_build_qualified_type on ARRAY_TYPEs, the
1337 element type qualification will be handled by the recursive
1338 cp_reconstruct_complex_type call and cp_build_qualified_type
1339 for ARRAY_TYPEs changes the element type. */
1342 else if (TREE_CODE (type
) == FUNCTION_TYPE
)
1344 late_return_type_p
= TYPE_HAS_LATE_RETURN_TYPE (type
);
1345 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1346 outer
= build_function_type (inner
, TYPE_ARG_TYPES (type
));
1347 outer
= apply_memfn_quals (outer
,
1348 type_memfn_quals (type
),
1349 type_memfn_rqual (type
));
1351 else if (TREE_CODE (type
) == METHOD_TYPE
)
1353 late_return_type_p
= TYPE_HAS_LATE_RETURN_TYPE (type
);
1354 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1355 /* The build_method_type_directly() routine prepends 'this' to argument list,
1356 so we must compensate by getting rid of it. */
1358 = build_method_type_directly
1359 (class_of_this_parm (type
), inner
,
1360 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
1362 else if (TREE_CODE (type
) == OFFSET_TYPE
)
1364 inner
= cp_reconstruct_complex_type (TREE_TYPE (type
), bottom
);
1365 outer
= build_offset_type (TYPE_OFFSET_BASETYPE (type
), inner
);
1370 if (TYPE_ATTRIBUTES (type
))
1371 outer
= cp_build_type_attribute_variant (outer
, TYPE_ATTRIBUTES (type
));
1372 outer
= cp_build_qualified_type (outer
, cp_type_quals (type
));
1374 if (late_return_type_p
)
1375 TYPE_HAS_LATE_RETURN_TYPE (outer
) = 1;
1380 /* Replaces any constexpr expression that may be into the attributes
1381 arguments with their reduced value. */
1384 cp_check_const_attributes (tree attributes
)
1386 if (attributes
== error_mark_node
)
1390 for (attr
= attributes
; attr
; attr
= TREE_CHAIN (attr
))
1393 for (arg
= TREE_VALUE (attr
); arg
; arg
= TREE_CHAIN (arg
))
1395 tree expr
= TREE_VALUE (arg
);
1397 TREE_VALUE (arg
) = maybe_constant_value (expr
);
1402 /* Return true if TYPE is an OpenMP mappable type. */
1404 cp_omp_mappable_type (tree type
)
1406 /* Mappable type has to be complete. */
1407 if (type
== error_mark_node
|| !COMPLETE_TYPE_P (type
))
1409 /* Arrays have mappable type if the elements have mappable type. */
1410 while (TREE_CODE (type
) == ARRAY_TYPE
)
1411 type
= TREE_TYPE (type
);
1412 /* A mappable type cannot contain virtual members. */
1413 if (CLASS_TYPE_P (type
) && CLASSTYPE_VTABLES (type
))
1415 /* All data members must be non-static. */
1416 if (CLASS_TYPE_P (type
))
1419 for (field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
1420 if (TREE_CODE (field
) == VAR_DECL
)
1422 /* All fields must have mappable types. */
1423 else if (TREE_CODE (field
) == FIELD_DECL
1424 && !cp_omp_mappable_type (TREE_TYPE (field
)))
1430 /* Like decl_attributes, but handle C++ complexity. */
1433 cplus_decl_attributes (tree
*decl
, tree attributes
, int flags
)
1435 if (*decl
== NULL_TREE
|| *decl
== void_type_node
1436 || *decl
== error_mark_node
)
1439 /* Add implicit "omp declare target" attribute if requested. */
1440 if (scope_chain
->omp_declare_target_attribute
1441 && ((TREE_CODE (*decl
) == VAR_DECL
1442 && (TREE_STATIC (*decl
) || DECL_EXTERNAL (*decl
)))
1443 || TREE_CODE (*decl
) == FUNCTION_DECL
))
1445 if (TREE_CODE (*decl
) == VAR_DECL
1446 && DECL_CLASS_SCOPE_P (*decl
))
1447 error ("%q+D static data member inside of declare target directive",
1449 else if (TREE_CODE (*decl
) == VAR_DECL
1450 && (DECL_FUNCTION_SCOPE_P (*decl
)
1451 || (current_function_decl
&& !DECL_EXTERNAL (*decl
))))
1452 error ("%q+D in block scope inside of declare target directive",
1454 else if (!processing_template_decl
1455 && TREE_CODE (*decl
) == VAR_DECL
1456 && !cp_omp_mappable_type (TREE_TYPE (*decl
)))
1457 error ("%q+D in declare target directive does not have mappable type",
1460 attributes
= tree_cons (get_identifier ("omp declare target"),
1461 NULL_TREE
, attributes
);
1464 if (processing_template_decl
)
1466 if (check_for_bare_parameter_packs (attributes
))
1469 save_template_attributes (&attributes
, decl
);
1472 cp_check_const_attributes (attributes
);
1474 if (TREE_CODE (*decl
) == TEMPLATE_DECL
)
1475 decl
= &DECL_TEMPLATE_RESULT (*decl
);
1477 if (TREE_TYPE (*decl
) && TYPE_PTRMEMFUNC_P (TREE_TYPE (*decl
)))
1480 = decl_attributes (decl
, attributes
, flags
| ATTR_FLAG_FUNCTION_NEXT
);
1481 decl_attributes (&TYPE_PTRMEMFUNC_FN_TYPE_RAW (TREE_TYPE (*decl
)),
1485 decl_attributes (decl
, attributes
, flags
);
1487 if (TREE_CODE (*decl
) == TYPE_DECL
)
1488 SET_IDENTIFIER_TYPE_VALUE (DECL_NAME (*decl
), TREE_TYPE (*decl
));
1490 /* Propagate deprecation out to the template. */
1491 if (TREE_DEPRECATED (*decl
))
1492 if (tree ti
= get_template_info (*decl
))
1494 tree tmpl
= TI_TEMPLATE (ti
);
1495 tree pattern
= (TYPE_P (*decl
) ? TREE_TYPE (tmpl
)
1496 : DECL_TEMPLATE_RESULT (tmpl
));
1497 if (*decl
== pattern
)
1498 TREE_DEPRECATED (tmpl
) = true;
1502 /* Walks through the namespace- or function-scope anonymous union
1503 OBJECT, with the indicated TYPE, building appropriate VAR_DECLs.
1504 Returns one of the fields for use in the mangled name. */
1507 build_anon_union_vars (tree type
, tree object
)
1509 tree main_decl
= NULL_TREE
;
1512 /* Rather than write the code to handle the non-union case,
1513 just give an error. */
1514 if (TREE_CODE (type
) != UNION_TYPE
)
1516 error ("anonymous struct not inside named type");
1517 return error_mark_node
;
1520 for (field
= TYPE_FIELDS (type
);
1522 field
= DECL_CHAIN (field
))
1527 if (DECL_ARTIFICIAL (field
))
1529 if (TREE_CODE (field
) != FIELD_DECL
)
1531 permerror (input_location
, "%q+#D invalid; an anonymous union can only "
1532 "have non-static data members", field
);
1536 if (TREE_PRIVATE (field
))
1537 permerror (input_location
, "private member %q+#D in anonymous union", field
);
1538 else if (TREE_PROTECTED (field
))
1539 permerror (input_location
, "protected member %q+#D in anonymous union", field
);
1541 if (processing_template_decl
)
1542 ref
= build_min_nt_loc (UNKNOWN_LOCATION
, COMPONENT_REF
, object
,
1543 DECL_NAME (field
), NULL_TREE
);
1545 ref
= build_class_member_access_expr (object
, field
, NULL_TREE
,
1546 false, tf_warning_or_error
);
1548 if (DECL_NAME (field
))
1552 decl
= build_decl (input_location
,
1553 VAR_DECL
, DECL_NAME (field
), TREE_TYPE (field
));
1554 DECL_ANON_UNION_VAR_P (decl
) = 1;
1555 DECL_ARTIFICIAL (decl
) = 1;
1557 base
= get_base_address (object
);
1558 TREE_PUBLIC (decl
) = TREE_PUBLIC (base
);
1559 TREE_STATIC (decl
) = TREE_STATIC (base
);
1560 DECL_EXTERNAL (decl
) = DECL_EXTERNAL (base
);
1562 SET_DECL_VALUE_EXPR (decl
, ref
);
1563 DECL_HAS_VALUE_EXPR_P (decl
) = 1;
1565 decl
= pushdecl (decl
);
1567 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
1568 decl
= build_anon_union_vars (TREE_TYPE (field
), ref
);
1572 if (main_decl
== NULL_TREE
)
1579 /* Finish off the processing of a UNION_TYPE structure. If the union is an
1580 anonymous union, then all members must be laid out together. PUBLIC_P
1581 is nonzero if this union is not declared static. */
1584 finish_anon_union (tree anon_union_decl
)
1590 if (anon_union_decl
== error_mark_node
)
1593 type
= TREE_TYPE (anon_union_decl
);
1594 public_p
= TREE_PUBLIC (anon_union_decl
);
1596 /* The VAR_DECL's context is the same as the TYPE's context. */
1597 DECL_CONTEXT (anon_union_decl
) = DECL_CONTEXT (TYPE_NAME (type
));
1599 if (TYPE_FIELDS (type
) == NULL_TREE
)
1604 error ("namespace-scope anonymous aggregates must be static");
1608 main_decl
= build_anon_union_vars (type
, anon_union_decl
);
1609 if (main_decl
== error_mark_node
)
1611 if (main_decl
== NULL_TREE
)
1613 warning (0, "anonymous union with no members");
1617 if (!processing_template_decl
)
1619 /* Use main_decl to set the mangled name. */
1620 DECL_NAME (anon_union_decl
) = DECL_NAME (main_decl
);
1621 maybe_commonize_var (anon_union_decl
);
1622 if (TREE_STATIC (anon_union_decl
) || DECL_EXTERNAL (anon_union_decl
))
1623 mangle_decl (anon_union_decl
);
1624 DECL_NAME (anon_union_decl
) = NULL_TREE
;
1627 pushdecl (anon_union_decl
);
1628 cp_finish_decl (anon_union_decl
, NULL_TREE
, false, NULL_TREE
, 0);
1631 /* Auxiliary functions to make type signatures for
1632 `operator new' and `operator delete' correspond to
1633 what compiler will be expecting. */
1636 coerce_new_type (tree type
)
1639 tree args
= TYPE_ARG_TYPES (type
);
1641 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
1643 if (!same_type_p (TREE_TYPE (type
), ptr_type_node
))
1646 error ("%<operator new%> must return type %qT", ptr_type_node
);
1649 if (args
&& args
!= void_list_node
)
1651 if (TREE_PURPOSE (args
))
1653 /* [basic.stc.dynamic.allocation]
1655 The first parameter shall not have an associated default
1657 error ("the first parameter of %<operator new%> cannot "
1658 "have a default argument");
1659 /* Throw away the default argument. */
1660 TREE_PURPOSE (args
) = NULL_TREE
;
1663 if (!same_type_p (TREE_VALUE (args
), size_type_node
))
1666 args
= TREE_CHAIN (args
);
1673 permerror (input_location
, "%<operator new%> takes type %<size_t%> (%qT) "
1674 "as first parameter", size_type_node
);
1679 args
= tree_cons (NULL_TREE
, size_type_node
, args
);
1682 type
= build_exception_variant
1683 (build_function_type (ptr_type_node
, args
),
1684 TYPE_RAISES_EXCEPTIONS (type
));
1692 coerce_delete_type (tree type
)
1695 tree args
= TYPE_ARG_TYPES (type
);
1697 gcc_assert (TREE_CODE (type
) == FUNCTION_TYPE
);
1699 if (!same_type_p (TREE_TYPE (type
), void_type_node
))
1702 error ("%<operator delete%> must return type %qT", void_type_node
);
1705 if (!args
|| args
== void_list_node
1706 || !same_type_p (TREE_VALUE (args
), ptr_type_node
))
1709 if (args
&& args
!= void_list_node
)
1710 args
= TREE_CHAIN (args
);
1711 error ("%<operator delete%> takes type %qT as first parameter",
1717 args
= tree_cons (NULL_TREE
, ptr_type_node
, args
);
1720 type
= build_exception_variant
1721 (build_function_type (void_type_node
, args
),
1722 TYPE_RAISES_EXCEPTIONS (type
));
1730 /* DECL is a VAR_DECL for a vtable: walk through the entries in the vtable
1731 and mark them as needed. */
1734 mark_vtable_entries (tree decl
)
1737 unsigned HOST_WIDE_INT idx
;
1739 FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (DECL_INITIAL (decl
)),
1744 STRIP_NOPS (fnaddr
);
1746 if (TREE_CODE (fnaddr
) != ADDR_EXPR
1747 && TREE_CODE (fnaddr
) != FDESC_EXPR
)
1748 /* This entry is an offset: a virtual base class offset, a
1749 virtual call offset, an RTTI offset, etc. */
1752 fn
= TREE_OPERAND (fnaddr
, 0);
1753 TREE_ADDRESSABLE (fn
) = 1;
1754 /* When we don't have vcall offsets, we output thunks whenever
1755 we output the vtables that contain them. With vcall offsets,
1756 we know all the thunks we'll need when we emit a virtual
1757 function, so we emit the thunks there instead. */
1758 if (DECL_THUNK_P (fn
))
1759 use_thunk (fn
, /*emit_p=*/0);
1764 /* Set DECL up to have the closest approximation of "initialized common"
1765 linkage available. */
1768 comdat_linkage (tree decl
)
1771 make_decl_one_only (decl
, cxx_comdat_group (decl
));
1772 else if (TREE_CODE (decl
) == FUNCTION_DECL
1773 || (VAR_P (decl
) && DECL_ARTIFICIAL (decl
)))
1774 /* We can just emit function and compiler-generated variables
1775 statically; having multiple copies is (for the most part) only
1778 There are two correctness issues, however: the address of a
1779 template instantiation with external linkage should be the
1780 same, independent of what translation unit asks for the
1781 address, and this will not hold when we emit multiple copies of
1782 the function. However, there's little else we can do.
1784 Also, by default, the typeinfo implementation assumes that
1785 there will be only one copy of the string used as the name for
1786 each type. Therefore, if weak symbols are unavailable, the
1787 run-time library should perform a more conservative check; it
1788 should perform a string comparison, rather than an address
1790 TREE_PUBLIC (decl
) = 0;
1793 /* Static data member template instantiations, however, cannot
1794 have multiple copies. */
1795 if (DECL_INITIAL (decl
) == 0
1796 || DECL_INITIAL (decl
) == error_mark_node
)
1797 DECL_COMMON (decl
) = 1;
1798 else if (EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl
)))
1800 DECL_COMMON (decl
) = 1;
1801 DECL_INITIAL (decl
) = error_mark_node
;
1803 else if (!DECL_EXPLICIT_INSTANTIATION (decl
))
1805 /* We can't do anything useful; leave vars for explicit
1807 DECL_EXTERNAL (decl
) = 1;
1808 DECL_NOT_REALLY_EXTERN (decl
) = 0;
1812 DECL_COMDAT (decl
) = 1;
1815 /* For win32 we also want to put explicit instantiations in
1816 linkonce sections, so that they will be merged with implicit
1817 instantiations; otherwise we get duplicate symbol errors.
1818 For Darwin we do not want explicit instantiations to be
1822 maybe_make_one_only (tree decl
)
1824 /* We used to say that this was not necessary on targets that support weak
1825 symbols, because the implicit instantiations will defer to the explicit
1826 one. However, that's not actually the case in SVR4; a strong definition
1827 after a weak one is an error. Also, not making explicit
1828 instantiations one_only means that we can end up with two copies of
1829 some template instantiations. */
1833 /* We can't set DECL_COMDAT on functions, or cp_finish_file will think
1834 we can get away with not emitting them if they aren't used. We need
1835 to for variables so that cp_finish_decl will update their linkage,
1836 because their DECL_INITIAL may not have been set properly yet. */
1838 if (!TARGET_WEAK_NOT_IN_ARCHIVE_TOC
1839 || (! DECL_EXPLICIT_INSTANTIATION (decl
)
1840 && ! DECL_TEMPLATE_SPECIALIZATION (decl
)))
1842 make_decl_one_only (decl
, cxx_comdat_group (decl
));
1846 varpool_node
*node
= varpool_node::get_create (decl
);
1847 DECL_COMDAT (decl
) = 1;
1848 /* Mark it needed so we don't forget to emit it. */
1849 node
->forced_by_abi
= true;
1850 TREE_USED (decl
) = 1;
1855 /* Returns true iff DECL, a FUNCTION_DECL or VAR_DECL, has vague linkage.
1856 This predicate will give the right answer during parsing of the
1857 function, which other tests may not. */
1860 vague_linkage_p (tree decl
)
1862 if (!TREE_PUBLIC (decl
))
1864 gcc_checking_assert (!DECL_COMDAT (decl
));
1867 /* Unfortunately, import_export_decl has not always been called
1868 before the function is processed, so we cannot simply check
1870 if (DECL_COMDAT (decl
)
1871 || (TREE_CODE (decl
) == FUNCTION_DECL
1872 && DECL_DECLARED_INLINE_P (decl
))
1873 || (DECL_LANG_SPECIFIC (decl
)
1874 && DECL_TEMPLATE_INSTANTIATION (decl
)))
1876 else if (DECL_FUNCTION_SCOPE_P (decl
))
1877 /* A local static in an inline effectively has vague linkage. */
1878 return (TREE_STATIC (decl
)
1879 && vague_linkage_p (DECL_CONTEXT (decl
)));
1884 /* Determine whether or not we want to specifically import or export CTYPE,
1885 using various heuristics. */
1888 import_export_class (tree ctype
)
1890 /* -1 for imported, 1 for exported. */
1891 int import_export
= 0;
1893 /* It only makes sense to call this function at EOF. The reason is
1894 that this function looks at whether or not the first non-inline
1895 non-abstract virtual member function has been defined in this
1896 translation unit. But, we can't possibly know that until we've
1897 seen the entire translation unit. */
1898 gcc_assert (at_eof
);
1900 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
1903 /* If MULTIPLE_SYMBOL_SPACES is set and we saw a #pragma interface,
1904 we will have CLASSTYPE_INTERFACE_ONLY set but not
1905 CLASSTYPE_INTERFACE_KNOWN. In that case, we don't want to use this
1906 heuristic because someone will supply a #pragma implementation
1907 elsewhere, and deducing it here would produce a conflict. */
1908 if (CLASSTYPE_INTERFACE_ONLY (ctype
))
1911 if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (ctype
)))
1913 else if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (ctype
)))
1915 else if (CLASSTYPE_IMPLICIT_INSTANTIATION (ctype
)
1916 && !flag_implicit_templates
)
1917 /* For a template class, without -fimplicit-templates, check the
1918 repository. If the virtual table is assigned to this
1919 translation unit, then export the class; otherwise, import
1921 import_export
= repo_export_class_p (ctype
) ? 1 : -1;
1922 else if (TYPE_POLYMORPHIC_P (ctype
))
1924 /* The ABI specifies that the virtual table and associated
1925 information are emitted with the key method, if any. */
1926 tree method
= CLASSTYPE_KEY_METHOD (ctype
);
1927 /* If weak symbol support is not available, then we must be
1928 careful not to emit the vtable when the key function is
1929 inline. An inline function can be defined in multiple
1930 translation units. If we were to emit the vtable in each
1931 translation unit containing a definition, we would get
1932 multiple definition errors at link-time. */
1933 if (method
&& (flag_weak
|| ! DECL_DECLARED_INLINE_P (method
)))
1934 import_export
= (DECL_REALLY_EXTERN (method
) ? -1 : 1);
1937 /* When MULTIPLE_SYMBOL_SPACES is set, we cannot count on seeing
1938 a definition anywhere else. */
1939 if (MULTIPLE_SYMBOL_SPACES
&& import_export
== -1)
1942 /* Allow back ends the chance to overrule the decision. */
1943 if (targetm
.cxx
.import_export_class
)
1944 import_export
= targetm
.cxx
.import_export_class (ctype
, import_export
);
1948 SET_CLASSTYPE_INTERFACE_KNOWN (ctype
);
1949 CLASSTYPE_INTERFACE_ONLY (ctype
) = (import_export
< 0);
1953 /* Return true if VAR has already been provided to the back end; in that
1954 case VAR should not be modified further by the front end. */
1956 var_finalized_p (tree var
)
1958 return varpool_node::get_create (var
)->definition
;
1961 /* DECL is a VAR_DECL or FUNCTION_DECL which, for whatever reason,
1962 must be emitted in this translation unit. Mark it as such. */
1965 mark_needed (tree decl
)
1967 TREE_USED (decl
) = 1;
1968 if (TREE_CODE (decl
) == FUNCTION_DECL
)
1970 /* Extern inline functions don't become needed when referenced.
1971 If we know a method will be emitted in other TU and no new
1972 functions can be marked reachable, just use the external
1974 struct cgraph_node
*node
= cgraph_node::get_create (decl
);
1975 node
->forced_by_abi
= true;
1977 /* #pragma interface and -frepo code can call mark_needed for
1978 maybe-in-charge 'tors; mark the clones as well. */
1980 FOR_EACH_CLONE (clone
, decl
)
1981 mark_needed (clone
);
1983 else if (TREE_CODE (decl
) == VAR_DECL
)
1985 varpool_node
*node
= varpool_node::get_create (decl
);
1986 /* C++ frontend use mark_decl_references to force COMDAT variables
1987 to be output that might appear dead otherwise. */
1988 node
->forced_by_abi
= true;
1992 /* DECL is either a FUNCTION_DECL or a VAR_DECL. This function
1993 returns true if a definition of this entity should be provided in
1994 this object file. Callers use this function to determine whether
1995 or not to let the back end know that a definition of DECL is
1996 available in this translation unit. */
1999 decl_needed_p (tree decl
)
2001 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
2002 /* This function should only be called at the end of the translation
2003 unit. We cannot be sure of whether or not something will be
2004 COMDAT until that point. */
2005 gcc_assert (at_eof
);
2007 /* All entities with external linkage that are not COMDAT/EXTERN should be
2008 emitted; they may be referred to from other object files. */
2009 if (TREE_PUBLIC (decl
) && !DECL_COMDAT (decl
) && !DECL_REALLY_EXTERN (decl
))
2011 /* Functions marked "dllexport" must be emitted so that they are
2012 visible to other DLLs. */
2013 if (flag_keep_inline_dllexport
2014 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl
)))
2017 /* When not optimizing, do not bother to produce definitions for extern
2019 if (DECL_REALLY_EXTERN (decl
)
2020 && ((TREE_CODE (decl
) != FUNCTION_DECL
2022 || (TREE_CODE (decl
) == FUNCTION_DECL
2023 && !opt_for_fn (decl
, optimize
)))
2024 && !lookup_attribute ("always_inline", decl
))
2027 /* If this entity was used, let the back end see it; it will decide
2028 whether or not to emit it into the object file. */
2029 if (TREE_USED (decl
))
2031 /* Virtual functions might be needed for devirtualization. */
2032 if (flag_devirtualize
2033 && TREE_CODE (decl
) == FUNCTION_DECL
2034 && DECL_VIRTUAL_P (decl
))
2036 /* Otherwise, DECL does not need to be emitted -- yet. A subsequent
2037 reference to DECL might cause it to be emitted later. */
2041 /* If necessary, write out the vtables for the dynamic class CTYPE.
2042 Returns true if any vtables were emitted. */
2045 maybe_emit_vtables (tree ctype
)
2050 varpool_node
*current
= NULL
, *last
= NULL
;
2052 /* If the vtables for this class have already been emitted there is
2053 nothing more to do. */
2054 primary_vtbl
= CLASSTYPE_VTABLES (ctype
);
2055 if (var_finalized_p (primary_vtbl
))
2057 /* Ignore dummy vtables made by get_vtable_decl. */
2058 if (TREE_TYPE (primary_vtbl
) == void_type_node
)
2061 /* On some targets, we cannot determine the key method until the end
2062 of the translation unit -- which is when this function is
2064 if (!targetm
.cxx
.key_method_may_be_inline ())
2065 determine_key_method (ctype
);
2067 /* See if any of the vtables are needed. */
2068 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= DECL_CHAIN (vtbl
))
2070 import_export_decl (vtbl
);
2071 if (DECL_NOT_REALLY_EXTERN (vtbl
) && decl_needed_p (vtbl
))
2076 /* If the references to this class' vtables are optimized away,
2077 still emit the appropriate debugging information. See
2079 if (DECL_COMDAT (primary_vtbl
)
2080 && CLASSTYPE_DEBUG_REQUESTED (ctype
))
2081 note_debug_info_needed (ctype
);
2085 /* The ABI requires that we emit all of the vtables if we emit any
2087 for (vtbl
= CLASSTYPE_VTABLES (ctype
); vtbl
; vtbl
= DECL_CHAIN (vtbl
))
2089 /* Mark entities references from the virtual table as used. */
2090 mark_vtable_entries (vtbl
);
2092 if (TREE_TYPE (DECL_INITIAL (vtbl
)) == 0)
2094 vec
<tree
, va_gc
> *cleanups
= NULL
;
2095 tree expr
= store_init_value (vtbl
, DECL_INITIAL (vtbl
), &cleanups
,
2098 /* It had better be all done at compile-time. */
2099 gcc_assert (!expr
&& !cleanups
);
2103 DECL_EXTERNAL (vtbl
) = 0;
2104 rest_of_decl_compilation (vtbl
, 1, 1);
2106 /* Because we're only doing syntax-checking, we'll never end up
2107 actually marking the variable as written. */
2108 if (flag_syntax_only
)
2109 TREE_ASM_WRITTEN (vtbl
) = 1;
2110 else if (DECL_ONE_ONLY (vtbl
))
2112 current
= varpool_node::get_create (vtbl
);
2114 current
->add_to_same_comdat_group (last
);
2119 /* Since we're writing out the vtable here, also write the debug
2121 note_debug_info_needed (ctype
);
2126 /* A special return value from type_visibility meaning internal
2129 enum { VISIBILITY_ANON
= VISIBILITY_INTERNAL
+1 };
2131 /* walk_tree helper function for type_visibility. */
2134 min_vis_r (tree
*tp
, int *walk_subtrees
, void *data
)
2136 int *vis_p
= (int *)data
;
2141 else if (OVERLOAD_TYPE_P (*tp
)
2142 && !TREE_PUBLIC (TYPE_MAIN_DECL (*tp
)))
2144 *vis_p
= VISIBILITY_ANON
;
2147 else if (CLASS_TYPE_P (*tp
)
2148 && CLASSTYPE_VISIBILITY (*tp
) > *vis_p
)
2149 *vis_p
= CLASSTYPE_VISIBILITY (*tp
);
2153 /* Returns the visibility of TYPE, which is the minimum visibility of its
2157 type_visibility (tree type
)
2159 int vis
= VISIBILITY_DEFAULT
;
2160 cp_walk_tree_without_duplicates (&type
, min_vis_r
, &vis
);
2164 /* Limit the visibility of DECL to VISIBILITY, if not explicitly
2165 specified (or if VISIBILITY is static). If TMPL is true, this
2166 constraint is for a template argument, and takes precedence
2167 over explicitly-specified visibility on the template. */
2170 constrain_visibility (tree decl
, int visibility
, bool tmpl
)
2172 if (visibility
== VISIBILITY_ANON
)
2174 /* extern "C" declarations aren't affected by the anonymous
2176 if (!DECL_EXTERN_C_P (decl
))
2178 TREE_PUBLIC (decl
) = 0;
2179 DECL_WEAK (decl
) = 0;
2180 DECL_COMMON (decl
) = 0;
2181 DECL_COMDAT (decl
) = false;
2182 if (TREE_CODE (decl
) == FUNCTION_DECL
2183 || TREE_CODE (decl
) == VAR_DECL
)
2185 struct symtab_node
*snode
= symtab_node::get (decl
);
2188 snode
->set_comdat_group (NULL
);
2190 DECL_INTERFACE_KNOWN (decl
) = 1;
2191 if (DECL_LANG_SPECIFIC (decl
))
2192 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2195 else if (visibility
> DECL_VISIBILITY (decl
)
2196 && (tmpl
|| !DECL_VISIBILITY_SPECIFIED (decl
)))
2198 DECL_VISIBILITY (decl
) = (enum symbol_visibility
) visibility
;
2199 /* This visibility was not specified. */
2200 DECL_VISIBILITY_SPECIFIED (decl
) = false;
2204 /* Constrain the visibility of DECL based on the visibility of its template
2208 constrain_visibility_for_template (tree decl
, tree targs
)
2210 /* If this is a template instantiation, check the innermost
2211 template args for visibility constraints. The outer template
2212 args are covered by the class check. */
2213 tree args
= INNERMOST_TEMPLATE_ARGS (targs
);
2215 for (i
= TREE_VEC_LENGTH (args
); i
> 0; --i
)
2219 tree arg
= TREE_VEC_ELT (args
, i
-1);
2221 vis
= type_visibility (arg
);
2224 if (REFERENCE_REF_P (arg
))
2225 arg
= TREE_OPERAND (arg
, 0);
2226 if (TREE_TYPE (arg
))
2228 if (TREE_CODE (arg
) == ADDR_EXPR
)
2229 arg
= TREE_OPERAND (arg
, 0);
2230 if (VAR_OR_FUNCTION_DECL_P (arg
))
2232 if (! TREE_PUBLIC (arg
))
2233 vis
= VISIBILITY_ANON
;
2235 vis
= DECL_VISIBILITY (arg
);
2239 constrain_visibility (decl
, vis
, true);
2243 /* Like c_determine_visibility, but with additional C++-specific
2246 Function-scope entities can rely on the function's visibility because
2247 it is set in start_preparsed_function.
2249 Class-scope entities cannot rely on the class's visibility until the end
2250 of the enclosing class definition.
2252 Note that because namespaces have multiple independent definitions,
2253 namespace visibility is handled elsewhere using the #pragma visibility
2254 machinery rather than by decorating the namespace declaration.
2256 The goal is for constraints from the type to give a diagnostic, and
2257 other constraints to be applied silently. */
2260 determine_visibility (tree decl
)
2262 tree class_type
= NULL_TREE
;
2264 bool orig_visibility_specified
;
2265 enum symbol_visibility orig_visibility
;
2267 /* Remember that all decls get VISIBILITY_DEFAULT when built. */
2269 /* Only relevant for names with external linkage. */
2270 if (!TREE_PUBLIC (decl
))
2273 /* Cloned constructors and destructors get the same visibility as
2274 the underlying function. That should be set up in
2275 maybe_clone_body. */
2276 gcc_assert (!DECL_CLONED_FUNCTION_P (decl
));
2278 orig_visibility_specified
= DECL_VISIBILITY_SPECIFIED (decl
);
2279 orig_visibility
= DECL_VISIBILITY (decl
);
2281 if (TREE_CODE (decl
) == TYPE_DECL
)
2283 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
2284 use_template
= CLASSTYPE_USE_TEMPLATE (TREE_TYPE (decl
));
2285 else if (TYPE_TEMPLATE_INFO (TREE_TYPE (decl
)))
2290 else if (DECL_LANG_SPECIFIC (decl
))
2291 use_template
= DECL_USE_TEMPLATE (decl
);
2295 /* If DECL is a member of a class, visibility specifiers on the
2296 class can influence the visibility of the DECL. */
2297 if (DECL_CLASS_SCOPE_P (decl
))
2298 class_type
= DECL_CONTEXT (decl
);
2301 /* Not a class member. */
2303 /* Virtual tables have DECL_CONTEXT set to their associated class,
2304 so they are automatically handled above. */
2305 gcc_assert (!VAR_P (decl
)
2306 || !DECL_VTABLE_OR_VTT_P (decl
));
2308 if (DECL_FUNCTION_SCOPE_P (decl
) && ! DECL_VISIBILITY_SPECIFIED (decl
))
2310 /* Local statics and classes get the visibility of their
2311 containing function by default, except that
2312 -fvisibility-inlines-hidden doesn't affect them. */
2313 tree fn
= DECL_CONTEXT (decl
);
2314 if (DECL_VISIBILITY_SPECIFIED (fn
))
2316 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (fn
);
2317 DECL_VISIBILITY_SPECIFIED (decl
) =
2318 DECL_VISIBILITY_SPECIFIED (fn
);
2322 if (DECL_CLASS_SCOPE_P (fn
))
2323 determine_visibility_from_class (decl
, DECL_CONTEXT (fn
));
2324 else if (determine_hidden_inline (fn
))
2326 DECL_VISIBILITY (decl
) = default_visibility
;
2327 DECL_VISIBILITY_SPECIFIED (decl
) =
2328 visibility_options
.inpragma
;
2332 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (fn
);
2333 DECL_VISIBILITY_SPECIFIED (decl
) =
2334 DECL_VISIBILITY_SPECIFIED (fn
);
2338 /* Local classes in templates have CLASSTYPE_USE_TEMPLATE set,
2339 but have no TEMPLATE_INFO, so don't try to check it. */
2342 else if (VAR_P (decl
) && DECL_TINFO_P (decl
)
2343 && flag_visibility_ms_compat
)
2345 /* Under -fvisibility-ms-compat, types are visible by default,
2346 even though their contents aren't. */
2347 tree underlying_type
= TREE_TYPE (DECL_NAME (decl
));
2348 int underlying_vis
= type_visibility (underlying_type
);
2349 if (underlying_vis
== VISIBILITY_ANON
2350 || (CLASS_TYPE_P (underlying_type
)
2351 && CLASSTYPE_VISIBILITY_SPECIFIED (underlying_type
)))
2352 constrain_visibility (decl
, underlying_vis
, false);
2354 DECL_VISIBILITY (decl
) = VISIBILITY_DEFAULT
;
2356 else if (VAR_P (decl
) && DECL_TINFO_P (decl
))
2358 /* tinfo visibility is based on the type it's for. */
2359 constrain_visibility
2360 (decl
, type_visibility (TREE_TYPE (DECL_NAME (decl
))), false);
2362 /* Give the target a chance to override the visibility associated
2364 if (TREE_PUBLIC (decl
)
2365 && !DECL_REALLY_EXTERN (decl
)
2366 && CLASS_TYPE_P (TREE_TYPE (DECL_NAME (decl
)))
2367 && !CLASSTYPE_VISIBILITY_SPECIFIED (TREE_TYPE (DECL_NAME (decl
))))
2368 targetm
.cxx
.determine_class_data_visibility (decl
);
2370 else if (use_template
)
2371 /* Template instantiations and specializations get visibility based
2372 on their template unless they override it with an attribute. */;
2373 else if (! DECL_VISIBILITY_SPECIFIED (decl
))
2375 if (determine_hidden_inline (decl
))
2376 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2379 /* Set default visibility to whatever the user supplied with
2380 #pragma GCC visibility or a namespace visibility attribute. */
2381 DECL_VISIBILITY (decl
) = default_visibility
;
2382 DECL_VISIBILITY_SPECIFIED (decl
) = visibility_options
.inpragma
;
2389 /* If the specialization doesn't specify visibility, use the
2390 visibility from the template. */
2391 tree tinfo
= get_template_info (decl
);
2392 tree args
= TI_ARGS (tinfo
);
2393 tree attribs
= (TREE_CODE (decl
) == TYPE_DECL
2394 ? TYPE_ATTRIBUTES (TREE_TYPE (decl
))
2395 : DECL_ATTRIBUTES (decl
));
2397 if (args
!= error_mark_node
)
2399 tree pattern
= DECL_TEMPLATE_RESULT (TI_TEMPLATE (tinfo
));
2401 if (!DECL_VISIBILITY_SPECIFIED (decl
))
2403 if (!DECL_VISIBILITY_SPECIFIED (pattern
)
2404 && determine_hidden_inline (decl
))
2405 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2408 DECL_VISIBILITY (decl
) = DECL_VISIBILITY (pattern
);
2409 DECL_VISIBILITY_SPECIFIED (decl
)
2410 = DECL_VISIBILITY_SPECIFIED (pattern
);
2415 /* Template argument visibility outweighs #pragma or namespace
2416 visibility, but not an explicit attribute. */
2417 && !lookup_attribute ("visibility", attribs
))
2419 int depth
= TMPL_ARGS_DEPTH (args
);
2420 if (DECL_VISIBILITY_SPECIFIED (decl
))
2422 /* A class template member with explicit visibility
2423 overrides the class visibility, so we need to apply
2424 all the levels of template args directly. */
2426 for (i
= 1; i
<= depth
; ++i
)
2428 tree lev
= TMPL_ARGS_LEVEL (args
, i
);
2429 constrain_visibility_for_template (decl
, lev
);
2432 else if (PRIMARY_TEMPLATE_P (TI_TEMPLATE (tinfo
)))
2433 /* Limit visibility based on its template arguments. */
2434 constrain_visibility_for_template (decl
, args
);
2440 determine_visibility_from_class (decl
, class_type
);
2442 if (decl_anon_ns_mem_p (decl
))
2443 /* Names in an anonymous namespace get internal linkage.
2444 This might change once we implement export. */
2445 constrain_visibility (decl
, VISIBILITY_ANON
, false);
2446 else if (TREE_CODE (decl
) != TYPE_DECL
)
2448 /* Propagate anonymity from type to decl. */
2449 int tvis
= type_visibility (TREE_TYPE (decl
));
2450 if (tvis
== VISIBILITY_ANON
2451 || ! DECL_VISIBILITY_SPECIFIED (decl
))
2452 constrain_visibility (decl
, tvis
, false);
2454 else if (no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/true))
2455 /* DR 757: A type without linkage shall not be used as the type of a
2456 variable or function with linkage, unless
2457 o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
2458 o the variable or function is not used (3.2 [basic.def.odr]) or is
2459 defined in the same translation unit.
2461 Since non-extern "C" decls need to be defined in the same
2462 translation unit, we can make the type internal. */
2463 constrain_visibility (decl
, VISIBILITY_ANON
, false);
2465 /* If visibility changed and DECL already has DECL_RTL, ensure
2466 symbol flags are updated. */
2467 if ((DECL_VISIBILITY (decl
) != orig_visibility
2468 || DECL_VISIBILITY_SPECIFIED (decl
) != orig_visibility_specified
)
2469 && ((VAR_P (decl
) && TREE_STATIC (decl
))
2470 || TREE_CODE (decl
) == FUNCTION_DECL
)
2471 && DECL_RTL_SET_P (decl
))
2472 make_decl_rtl (decl
);
2475 /* By default, static data members and function members receive
2476 the visibility of their containing class. */
2479 determine_visibility_from_class (tree decl
, tree class_type
)
2481 if (DECL_VISIBILITY_SPECIFIED (decl
))
2484 if (determine_hidden_inline (decl
))
2485 DECL_VISIBILITY (decl
) = VISIBILITY_HIDDEN
;
2488 /* Default to the class visibility. */
2489 DECL_VISIBILITY (decl
) = CLASSTYPE_VISIBILITY (class_type
);
2490 DECL_VISIBILITY_SPECIFIED (decl
)
2491 = CLASSTYPE_VISIBILITY_SPECIFIED (class_type
);
2494 /* Give the target a chance to override the visibility associated
2497 && (DECL_TINFO_P (decl
)
2498 || (DECL_VTABLE_OR_VTT_P (decl
)
2499 /* Construction virtual tables are not exported because
2500 they cannot be referred to from other object files;
2501 their name is not standardized by the ABI. */
2502 && !DECL_CONSTRUCTION_VTABLE_P (decl
)))
2503 && TREE_PUBLIC (decl
)
2504 && !DECL_REALLY_EXTERN (decl
)
2505 && !CLASSTYPE_VISIBILITY_SPECIFIED (class_type
))
2506 targetm
.cxx
.determine_class_data_visibility (decl
);
2509 /* Returns true iff DECL is an inline that should get hidden visibility
2510 because of -fvisibility-inlines-hidden. */
2513 determine_hidden_inline (tree decl
)
2515 return (visibility_options
.inlines_hidden
2516 /* Don't do this for inline templates; specializations might not be
2517 inline, and we don't want them to inherit the hidden
2518 visibility. We'll set it here for all inline instantiations. */
2519 && !processing_template_decl
2520 && TREE_CODE (decl
) == FUNCTION_DECL
2521 && DECL_DECLARED_INLINE_P (decl
)
2522 && (! DECL_LANG_SPECIFIC (decl
)
2523 || ! DECL_EXPLICIT_INSTANTIATION (decl
)));
2526 /* Constrain the visibility of a class TYPE based on the visibility of its
2527 field types. Warn if any fields require lesser visibility. */
2530 constrain_class_visibility (tree type
)
2536 int vis
= type_visibility (type
);
2538 if (vis
== VISIBILITY_ANON
2539 || DECL_IN_SYSTEM_HEADER (TYPE_MAIN_DECL (type
)))
2542 /* Don't warn about visibility if the class has explicit visibility. */
2543 if (CLASSTYPE_VISIBILITY_SPECIFIED (type
))
2544 vis
= VISIBILITY_INTERNAL
;
2546 for (t
= TYPE_FIELDS (type
); t
; t
= DECL_CHAIN (t
))
2547 if (TREE_CODE (t
) == FIELD_DECL
&& TREE_TYPE (t
) != error_mark_node
)
2549 tree ftype
= strip_pointer_or_array_types (TREE_TYPE (t
));
2550 int subvis
= type_visibility (ftype
);
2552 if (subvis
== VISIBILITY_ANON
)
2554 if (!in_main_input_context ())
2556 %qT has a field %qD whose type uses the anonymous namespace",
2559 else if (MAYBE_CLASS_TYPE_P (ftype
)
2560 && vis
< VISIBILITY_HIDDEN
2561 && subvis
>= VISIBILITY_HIDDEN
)
2562 warning (OPT_Wattributes
, "\
2563 %qT declared with greater visibility than the type of its field %qD",
2567 binfo
= TYPE_BINFO (type
);
2568 for (i
= 0; BINFO_BASE_ITERATE (binfo
, i
, t
); ++i
)
2570 int subvis
= type_visibility (TREE_TYPE (t
));
2572 if (subvis
== VISIBILITY_ANON
)
2574 if (!in_main_input_context())
2576 %qT has a base %qT whose type uses the anonymous namespace",
2577 type
, TREE_TYPE (t
));
2579 else if (vis
< VISIBILITY_HIDDEN
2580 && subvis
>= VISIBILITY_HIDDEN
)
2581 warning (OPT_Wattributes
, "\
2582 %qT declared with greater visibility than its base %qT",
2583 type
, TREE_TYPE (t
));
2587 /* Functions for adjusting the visibility of a tagged type and its nested
2588 types and declarations when it gets a name for linkage purposes from a
2591 static void bt_reset_linkage_1 (binding_entry
, void *);
2592 static void bt_reset_linkage_2 (binding_entry
, void *);
2594 /* First reset the visibility of all the types. */
2597 reset_type_linkage_1 (tree type
)
2599 set_linkage_according_to_type (type
, TYPE_MAIN_DECL (type
));
2600 if (CLASS_TYPE_P (type
))
2601 binding_table_foreach (CLASSTYPE_NESTED_UTDS (type
),
2602 bt_reset_linkage_1
, NULL
);
2605 bt_reset_linkage_1 (binding_entry b
, void */
*data*/
)
2607 reset_type_linkage_1 (b
->type
);
2610 /* Then reset the visibility of any static data members or member
2611 functions that use those types. */
2614 reset_decl_linkage (tree decl
)
2616 if (TREE_PUBLIC (decl
))
2618 if (DECL_CLONED_FUNCTION_P (decl
))
2620 TREE_PUBLIC (decl
) = true;
2621 DECL_INTERFACE_KNOWN (decl
) = false;
2622 determine_visibility (decl
);
2623 tentative_decl_linkage (decl
);
2626 reset_type_linkage_2 (tree type
)
2628 if (CLASS_TYPE_P (type
))
2630 if (tree vt
= CLASSTYPE_VTABLES (type
))
2632 tree name
= mangle_vtbl_for_type (type
);
2633 DECL_NAME (vt
) = name
;
2634 SET_DECL_ASSEMBLER_NAME (vt
, name
);
2635 reset_decl_linkage (vt
);
2637 if (tree ti
= CLASSTYPE_TYPEINFO_VAR (type
))
2639 tree name
= mangle_typeinfo_for_type (type
);
2640 DECL_NAME (ti
) = name
;
2641 SET_DECL_ASSEMBLER_NAME (ti
, name
);
2642 TREE_TYPE (name
) = type
;
2643 reset_decl_linkage (ti
);
2645 for (tree m
= TYPE_FIELDS (type
); m
; m
= DECL_CHAIN (m
))
2646 if (TREE_CODE (m
) == VAR_DECL
)
2647 reset_decl_linkage (m
);
2648 for (tree m
= TYPE_METHODS (type
); m
; m
= DECL_CHAIN (m
))
2650 reset_decl_linkage (m
);
2651 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (m
))
2652 /* Also update its name, for cxx_dwarf_name. */
2653 DECL_NAME (m
) = TYPE_IDENTIFIER (type
);
2655 binding_table_foreach (CLASSTYPE_NESTED_UTDS (type
),
2656 bt_reset_linkage_2
, NULL
);
2660 bt_reset_linkage_2 (binding_entry b
, void */
*data*/
)
2662 reset_type_linkage_2 (b
->type
);
2665 reset_type_linkage (tree type
)
2667 reset_type_linkage_1 (type
);
2668 reset_type_linkage_2 (type
);
2671 /* Set up our initial idea of what the linkage of DECL should be. */
2674 tentative_decl_linkage (tree decl
)
2676 if (DECL_INTERFACE_KNOWN (decl
))
2677 /* We've already made a decision as to how this function will
2679 else if (vague_linkage_p (decl
))
2681 if (TREE_CODE (decl
) == FUNCTION_DECL
2682 && decl_defined_p (decl
))
2684 DECL_EXTERNAL (decl
) = 1;
2685 DECL_NOT_REALLY_EXTERN (decl
) = 1;
2686 note_vague_linkage_fn (decl
);
2687 /* A non-template inline function with external linkage will
2688 always be COMDAT. As we must eventually determine the
2689 linkage of all functions, and as that causes writes to
2690 the data mapped in from the PCH file, it's advantageous
2691 to mark the functions at this point. */
2692 if (DECL_DECLARED_INLINE_P (decl
)
2693 && (!DECL_IMPLICIT_INSTANTIATION (decl
)
2694 || DECL_DEFAULTED_FN (decl
)))
2696 /* This function must have external linkage, as
2697 otherwise DECL_INTERFACE_KNOWN would have been
2699 gcc_assert (TREE_PUBLIC (decl
));
2700 comdat_linkage (decl
);
2701 DECL_INTERFACE_KNOWN (decl
) = 1;
2704 else if (TREE_CODE (decl
) == VAR_DECL
)
2705 maybe_commonize_var (decl
);
2709 /* DECL is a FUNCTION_DECL or VAR_DECL. If the object file linkage
2710 for DECL has not already been determined, do so now by setting
2711 DECL_EXTERNAL, DECL_COMDAT and other related flags. Until this
2712 function is called entities with vague linkage whose definitions
2713 are available must have TREE_PUBLIC set.
2715 If this function decides to place DECL in COMDAT, it will set
2716 appropriate flags -- but will not clear DECL_EXTERNAL. It is up to
2717 the caller to decide whether or not to clear DECL_EXTERNAL. Some
2718 callers defer that decision until it is clear that DECL is actually
2722 import_export_decl (tree decl
)
2727 tree class_type
= NULL_TREE
;
2729 if (DECL_INTERFACE_KNOWN (decl
))
2732 /* We cannot determine what linkage to give to an entity with vague
2733 linkage until the end of the file. For example, a virtual table
2734 for a class will be defined if and only if the key method is
2735 defined in this translation unit. As a further example, consider
2736 that when compiling a translation unit that uses PCH file with
2737 "-frepo" it would be incorrect to make decisions about what
2738 entities to emit when building the PCH; those decisions must be
2739 delayed until the repository information has been processed. */
2740 gcc_assert (at_eof
);
2741 /* Object file linkage for explicit instantiations is handled in
2742 mark_decl_instantiated. For static variables in functions with
2743 vague linkage, maybe_commonize_var is used.
2745 Therefore, the only declarations that should be provided to this
2746 function are those with external linkage that are:
2748 * implicit instantiations of function templates
2752 * implicit instantiations of static data members of class
2759 Furthermore, all entities that reach this point must have a
2760 definition available in this translation unit.
2762 The following assertions check these conditions. */
2763 gcc_assert (VAR_OR_FUNCTION_DECL_P (decl
));
2764 /* Any code that creates entities with TREE_PUBLIC cleared should
2765 also set DECL_INTERFACE_KNOWN. */
2766 gcc_assert (TREE_PUBLIC (decl
));
2767 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2768 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl
)
2769 || DECL_FRIEND_PSEUDO_TEMPLATE_INSTANTIATION (decl
)
2770 || DECL_DECLARED_INLINE_P (decl
));
2772 gcc_assert (DECL_IMPLICIT_INSTANTIATION (decl
)
2773 || DECL_VTABLE_OR_VTT_P (decl
)
2774 || DECL_TINFO_P (decl
));
2775 /* Check that a definition of DECL is available in this translation
2777 gcc_assert (!DECL_REALLY_EXTERN (decl
));
2779 /* Assume that DECL will not have COMDAT linkage. */
2781 /* Assume that DECL will not be imported into this translation
2785 /* See if the repository tells us whether or not to emit DECL in
2786 this translation unit. */
2787 emit_p
= repo_emit_p (decl
);
2790 else if (emit_p
== 1)
2792 /* The repository indicates that this entity should be defined
2793 here. Make sure the back end honors that request. */
2795 /* Output the definition as an ordinary strong definition. */
2796 DECL_EXTERNAL (decl
) = 0;
2797 DECL_INTERFACE_KNOWN (decl
) = 1;
2802 /* We have already decided what to do with this DECL; there is no
2803 need to check anything further. */
2805 else if (VAR_P (decl
) && DECL_VTABLE_OR_VTT_P (decl
))
2807 class_type
= DECL_CONTEXT (decl
);
2808 import_export_class (class_type
);
2809 if (TYPE_FOR_JAVA (class_type
))
2811 else if (CLASSTYPE_INTERFACE_KNOWN (class_type
)
2812 && CLASSTYPE_INTERFACE_ONLY (class_type
))
2814 else if ((!flag_weak
|| TARGET_WEAK_NOT_IN_ARCHIVE_TOC
)
2815 && !CLASSTYPE_USE_TEMPLATE (class_type
)
2816 && CLASSTYPE_KEY_METHOD (class_type
)
2817 && !DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type
)))
2818 /* The ABI requires that all virtual tables be emitted with
2819 COMDAT linkage. However, on systems where COMDAT symbols
2820 don't show up in the table of contents for a static
2821 archive, or on systems without weak symbols (where we
2822 approximate COMDAT linkage by using internal linkage), the
2823 linker will report errors about undefined symbols because
2824 it will not see the virtual table definition. Therefore,
2825 in the case that we know that the virtual table will be
2826 emitted in only one translation unit, we make the virtual
2827 table an ordinary definition with external linkage. */
2828 DECL_EXTERNAL (decl
) = 0;
2829 else if (CLASSTYPE_INTERFACE_KNOWN (class_type
))
2831 /* CLASS_TYPE is being exported from this translation unit,
2832 so DECL should be defined here. */
2833 if (!flag_weak
&& CLASSTYPE_EXPLICIT_INSTANTIATION (class_type
))
2834 /* If a class is declared in a header with the "extern
2835 template" extension, then it will not be instantiated,
2836 even in translation units that would normally require
2837 it. Often such classes are explicitly instantiated in
2838 one translation unit. Therefore, the explicit
2839 instantiation must be made visible to other translation
2841 DECL_EXTERNAL (decl
) = 0;
2844 /* The generic C++ ABI says that class data is always
2845 COMDAT, even if there is a key function. Some
2846 variants (e.g., the ARM EABI) says that class data
2847 only has COMDAT linkage if the class data might be
2848 emitted in more than one translation unit. When the
2849 key method can be inline and is inline, we still have
2850 to arrange for comdat even though
2851 class_data_always_comdat is false. */
2852 if (!CLASSTYPE_KEY_METHOD (class_type
)
2853 || DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (class_type
))
2854 || targetm
.cxx
.class_data_always_comdat ())
2856 /* The ABI requires COMDAT linkage. Normally, we
2857 only emit COMDAT things when they are needed;
2858 make sure that we realize that this entity is
2865 else if (!flag_implicit_templates
2866 && CLASSTYPE_IMPLICIT_INSTANTIATION (class_type
))
2871 else if (VAR_P (decl
) && DECL_TINFO_P (decl
))
2873 tree type
= TREE_TYPE (DECL_NAME (decl
));
2874 if (CLASS_TYPE_P (type
))
2877 import_export_class (type
);
2878 if (CLASSTYPE_INTERFACE_KNOWN (type
)
2879 && TYPE_POLYMORPHIC_P (type
)
2880 && CLASSTYPE_INTERFACE_ONLY (type
)
2881 /* If -fno-rtti was specified, then we cannot be sure
2882 that RTTI information will be emitted with the
2883 virtual table of the class, so we must emit it
2884 wherever it is used. */
2889 if (CLASSTYPE_INTERFACE_KNOWN (type
)
2890 && !CLASSTYPE_INTERFACE_ONLY (type
))
2892 comdat_p
= (targetm
.cxx
.class_data_always_comdat ()
2893 || (CLASSTYPE_KEY_METHOD (type
)
2894 && DECL_DECLARED_INLINE_P (CLASSTYPE_KEY_METHOD (type
))));
2899 DECL_EXTERNAL (decl
) = 0;
2909 else if (DECL_TEMPLOID_INSTANTIATION (decl
))
2911 /* DECL is an implicit instantiation of a function or static
2913 if ((flag_implicit_templates
2914 && !flag_use_repository
)
2915 || (flag_implicit_inline_templates
2916 && TREE_CODE (decl
) == FUNCTION_DECL
2917 && DECL_DECLARED_INLINE_P (decl
)))
2920 /* If we are not implicitly generating templates, then mark
2921 this entity as undefined in this translation unit. */
2924 else if (DECL_FUNCTION_MEMBER_P (decl
))
2926 if (!DECL_DECLARED_INLINE_P (decl
))
2928 tree ctype
= DECL_CONTEXT (decl
);
2929 import_export_class (ctype
);
2930 if (CLASSTYPE_INTERFACE_KNOWN (ctype
))
2932 DECL_NOT_REALLY_EXTERN (decl
)
2933 = ! (CLASSTYPE_INTERFACE_ONLY (ctype
)
2934 || (DECL_DECLARED_INLINE_P (decl
)
2935 && ! flag_implement_inlines
2936 && !DECL_VINDEX (decl
)));
2938 if (!DECL_NOT_REALLY_EXTERN (decl
))
2939 DECL_EXTERNAL (decl
) = 1;
2941 /* Always make artificials weak. */
2942 if (DECL_ARTIFICIAL (decl
) && flag_weak
)
2945 maybe_make_one_only (decl
);
2956 /* If we are importing DECL into this translation unit, mark is
2957 an undefined here. */
2958 DECL_EXTERNAL (decl
) = 1;
2959 DECL_NOT_REALLY_EXTERN (decl
) = 0;
2963 /* If we decided to put DECL in COMDAT, mark it accordingly at
2965 comdat_linkage (decl
);
2968 DECL_INTERFACE_KNOWN (decl
) = 1;
2971 /* Return an expression that performs the destruction of DECL, which
2972 must be a VAR_DECL whose type has a non-trivial destructor, or is
2973 an array whose (innermost) elements have a non-trivial destructor. */
2976 build_cleanup (tree decl
)
2978 tree clean
= cxx_maybe_build_cleanup (decl
, tf_warning_or_error
);
2979 gcc_assert (clean
!= NULL_TREE
);
2983 /* Returns the initialization guard variable for the variable DECL,
2984 which has static storage duration. */
2987 get_guard (tree decl
)
2992 sname
= mangle_guard_variable (decl
);
2993 guard
= IDENTIFIER_GLOBAL_VALUE (sname
);
2998 /* We use a type that is big enough to contain a mutex as well
2999 as an integer counter. */
3000 guard_type
= targetm
.cxx
.guard_type ();
3001 guard
= build_decl (DECL_SOURCE_LOCATION (decl
),
3002 VAR_DECL
, sname
, guard_type
);
3004 /* The guard should have the same linkage as what it guards. */
3005 TREE_PUBLIC (guard
) = TREE_PUBLIC (decl
);
3006 TREE_STATIC (guard
) = TREE_STATIC (decl
);
3007 DECL_COMMON (guard
) = DECL_COMMON (decl
);
3008 DECL_COMDAT (guard
) = DECL_COMDAT (decl
);
3009 set_decl_tls_model (guard
, DECL_TLS_MODEL (decl
));
3010 if (DECL_ONE_ONLY (decl
))
3011 make_decl_one_only (guard
, cxx_comdat_group (guard
));
3012 if (TREE_PUBLIC (decl
))
3013 DECL_WEAK (guard
) = DECL_WEAK (decl
);
3014 DECL_VISIBILITY (guard
) = DECL_VISIBILITY (decl
);
3015 DECL_VISIBILITY_SPECIFIED (guard
) = DECL_VISIBILITY_SPECIFIED (decl
);
3017 DECL_ARTIFICIAL (guard
) = 1;
3018 DECL_IGNORED_P (guard
) = 1;
3019 TREE_USED (guard
) = 1;
3020 pushdecl_top_level_and_finish (guard
, NULL_TREE
);
3025 /* Return an atomic load of src with the appropriate memory model. */
3028 build_atomic_load_byte (tree src
, HOST_WIDE_INT model
)
3030 tree ptr_type
= build_pointer_type (char_type_node
);
3031 tree mem_model
= build_int_cst (integer_type_node
, model
);
3036 size
= tree_to_uhwi (TYPE_SIZE_UNIT (char_type_node
));
3038 fncode
= BUILT_IN_ATOMIC_LOAD_N
+ exact_log2 (size
) + 1;
3039 t
= builtin_decl_implicit ((enum built_in_function
) fncode
);
3041 addr
= build1 (ADDR_EXPR
, ptr_type
, src
);
3042 val
= build_call_expr (t
, 2, addr
, mem_model
);
3046 /* Return those bits of the GUARD variable that should be set when the
3047 guarded entity is actually initialized. */
3050 get_guard_bits (tree guard
)
3052 if (!targetm
.cxx
.guard_mask_bit ())
3054 /* We only set the first byte of the guard, in order to leave room
3055 for a mutex in the high-order bits. */
3056 guard
= build1 (ADDR_EXPR
,
3057 build_pointer_type (TREE_TYPE (guard
)),
3059 guard
= build1 (NOP_EXPR
,
3060 build_pointer_type (char_type_node
),
3062 guard
= build1 (INDIRECT_REF
, char_type_node
, guard
);
3068 /* Return an expression which determines whether or not the GUARD
3069 variable has already been initialized. */
3072 get_guard_cond (tree guard
, bool thread_safe
)
3077 guard
= get_guard_bits (guard
);
3079 guard
= build_atomic_load_byte (guard
, MEMMODEL_ACQUIRE
);
3081 /* Mask off all but the low bit. */
3082 if (targetm
.cxx
.guard_mask_bit ())
3084 guard_value
= integer_one_node
;
3085 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
3086 guard_value
= convert (TREE_TYPE (guard
), guard_value
);
3087 guard
= cp_build_binary_op (input_location
,
3088 BIT_AND_EXPR
, guard
, guard_value
,
3089 tf_warning_or_error
);
3092 guard_value
= integer_zero_node
;
3093 if (!same_type_p (TREE_TYPE (guard_value
), TREE_TYPE (guard
)))
3094 guard_value
= convert (TREE_TYPE (guard
), guard_value
);
3095 return cp_build_binary_op (input_location
,
3096 EQ_EXPR
, guard
, guard_value
,
3097 tf_warning_or_error
);
3100 /* Return an expression which sets the GUARD variable, indicating that
3101 the variable being guarded has been initialized. */
3104 set_guard (tree guard
)
3108 /* Set the GUARD to one. */
3109 guard
= get_guard_bits (guard
);
3110 guard_init
= integer_one_node
;
3111 if (!same_type_p (TREE_TYPE (guard_init
), TREE_TYPE (guard
)))
3112 guard_init
= convert (TREE_TYPE (guard
), guard_init
);
3113 return cp_build_modify_expr (guard
, NOP_EXPR
, guard_init
,
3114 tf_warning_or_error
);
3117 /* Returns true iff we can tell that VAR does not have a dynamic
3121 var_defined_without_dynamic_init (tree var
)
3123 /* If it's defined in another TU, we can't tell. */
3124 if (DECL_EXTERNAL (var
))
3126 /* If it has a non-trivial destructor, registering the destructor
3127 counts as dynamic initialization. */
3128 if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TREE_TYPE (var
)))
3130 /* If it's in this TU, its initializer has been processed, unless
3131 it's a case of self-initialization, then DECL_INITIALIZED_P is
3132 false while the initializer is handled by finish_id_expression. */
3133 if (!DECL_INITIALIZED_P (var
))
3135 /* If it has no initializer or a constant one, it's not dynamic. */
3136 return (!DECL_NONTRIVIALLY_INITIALIZED_P (var
)
3137 || DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (var
));
3140 /* Returns true iff VAR is a variable that needs uses to be
3141 wrapped for possible dynamic initialization. */
3144 var_needs_tls_wrapper (tree var
)
3146 return (!error_operand_p (var
)
3147 && DECL_THREAD_LOCAL_P (var
)
3148 && !DECL_GNU_TLS_P (var
)
3149 && !DECL_FUNCTION_SCOPE_P (var
)
3150 && !var_defined_without_dynamic_init (var
));
3153 /* Get the FUNCTION_DECL for the shared TLS init function for this
3154 translation unit. */
3157 get_local_tls_init_fn (void)
3159 tree sname
= get_identifier ("__tls_init");
3160 tree fn
= IDENTIFIER_GLOBAL_VALUE (sname
);
3163 fn
= build_lang_decl (FUNCTION_DECL
, sname
,
3164 build_function_type (void_type_node
,
3166 SET_DECL_LANGUAGE (fn
, lang_c
);
3167 TREE_PUBLIC (fn
) = false;
3168 DECL_ARTIFICIAL (fn
) = true;
3170 SET_IDENTIFIER_GLOBAL_VALUE (sname
, fn
);
3175 /* Get a FUNCTION_DECL for the init function for the thread_local
3176 variable VAR. The init function will be an alias to the function
3177 that initializes all the non-local TLS variables in the translation
3178 unit. The init function is only used by the wrapper function. */
3181 get_tls_init_fn (tree var
)
3183 /* Only C++11 TLS vars need this init fn. */
3184 if (!var_needs_tls_wrapper (var
))
3187 /* If -fno-extern-tls-init, assume that we don't need to call
3188 a tls init function for a variable defined in another TU. */
3189 if (!flag_extern_tls_init
&& DECL_EXTERNAL (var
))
3192 #ifdef ASM_OUTPUT_DEF
3193 /* If the variable is internal, or if we can't generate aliases,
3194 call the local init function directly. */
3195 if (!TREE_PUBLIC (var
))
3197 return get_local_tls_init_fn ();
3199 tree sname
= mangle_tls_init_fn (var
);
3200 tree fn
= IDENTIFIER_GLOBAL_VALUE (sname
);
3203 fn
= build_lang_decl (FUNCTION_DECL
, sname
,
3204 build_function_type (void_type_node
,
3206 SET_DECL_LANGUAGE (fn
, lang_c
);
3207 TREE_PUBLIC (fn
) = TREE_PUBLIC (var
);
3208 DECL_ARTIFICIAL (fn
) = true;
3209 DECL_COMDAT (fn
) = DECL_COMDAT (var
);
3210 DECL_EXTERNAL (fn
) = DECL_EXTERNAL (var
);
3211 if (DECL_ONE_ONLY (var
))
3212 make_decl_one_only (fn
, cxx_comdat_group (fn
));
3213 if (TREE_PUBLIC (var
))
3215 tree obtype
= strip_array_types (non_reference (TREE_TYPE (var
)));
3216 /* If the variable is defined somewhere else and might have static
3217 initialization, make the init function a weak reference. */
3218 if ((!TYPE_NEEDS_CONSTRUCTING (obtype
)
3219 || TYPE_HAS_CONSTEXPR_CTOR (obtype
))
3220 && TYPE_HAS_TRIVIAL_DESTRUCTOR (obtype
)
3221 && DECL_EXTERNAL (var
))
3224 DECL_WEAK (fn
) = DECL_WEAK (var
);
3226 DECL_VISIBILITY (fn
) = DECL_VISIBILITY (var
);
3227 DECL_VISIBILITY_SPECIFIED (fn
) = DECL_VISIBILITY_SPECIFIED (var
);
3228 DECL_DLLIMPORT_P (fn
) = DECL_DLLIMPORT_P (var
);
3229 DECL_IGNORED_P (fn
) = 1;
3232 DECL_BEFRIENDING_CLASSES (fn
) = var
;
3234 SET_IDENTIFIER_GLOBAL_VALUE (sname
, fn
);
3239 /* Get a FUNCTION_DECL for the init wrapper function for the thread_local
3240 variable VAR. The wrapper function calls the init function (if any) for
3241 VAR and then returns a reference to VAR. The wrapper function is used
3242 in place of VAR everywhere VAR is mentioned. */
3245 get_tls_wrapper_fn (tree var
)
3247 /* Only C++11 TLS vars need this wrapper fn. */
3248 if (!var_needs_tls_wrapper (var
))
3251 tree sname
= mangle_tls_wrapper_fn (var
);
3252 tree fn
= IDENTIFIER_GLOBAL_VALUE (sname
);
3255 /* A named rvalue reference is an lvalue, so the wrapper should
3256 always return an lvalue reference. */
3257 tree type
= non_reference (TREE_TYPE (var
));
3258 type
= build_reference_type (type
);
3259 tree fntype
= build_function_type (type
, void_list_node
);
3260 fn
= build_lang_decl (FUNCTION_DECL
, sname
, fntype
);
3261 SET_DECL_LANGUAGE (fn
, lang_c
);
3262 TREE_PUBLIC (fn
) = TREE_PUBLIC (var
);
3263 DECL_ARTIFICIAL (fn
) = true;
3264 DECL_IGNORED_P (fn
) = 1;
3265 /* The wrapper is inline and emitted everywhere var is used. */
3266 DECL_DECLARED_INLINE_P (fn
) = true;
3267 if (TREE_PUBLIC (var
))
3269 comdat_linkage (fn
);
3270 #ifdef HAVE_GAS_HIDDEN
3271 /* Make the wrapper bind locally; there's no reason to share
3272 the wrapper between multiple shared objects. */
3273 DECL_VISIBILITY (fn
) = VISIBILITY_INTERNAL
;
3274 DECL_VISIBILITY_SPECIFIED (fn
) = true;
3277 if (!TREE_PUBLIC (fn
))
3278 DECL_INTERFACE_KNOWN (fn
) = true;
3280 note_vague_linkage_fn (fn
);
3283 /* We want CSE to commonize calls to the wrapper, but marking it as
3284 pure is unsafe since it has side-effects. I guess we need a new
3285 ECF flag even weaker than ECF_PURE. FIXME! */
3286 DECL_PURE_P (fn
) = true;
3289 DECL_BEFRIENDING_CLASSES (fn
) = var
;
3291 SET_IDENTIFIER_GLOBAL_VALUE (sname
, fn
);
3296 /* At EOF, generate the definition for the TLS wrapper function FN:
3299 if (init_fn) init_fn();
3304 generate_tls_wrapper (tree fn
)
3306 tree var
= DECL_BEFRIENDING_CLASSES (fn
);
3308 start_preparsed_function (fn
, NULL_TREE
, SF_DEFAULT
| SF_PRE_PARSED
);
3309 tree body
= begin_function_body ();
3310 /* Only call the init fn if there might be one. */
3311 if (tree init_fn
= get_tls_init_fn (var
))
3313 tree if_stmt
= NULL_TREE
;
3314 /* If init_fn is a weakref, make sure it exists before calling. */
3315 if (lookup_attribute ("weak", DECL_ATTRIBUTES (init_fn
)))
3317 if_stmt
= begin_if_stmt ();
3318 tree addr
= cp_build_addr_expr (init_fn
, tf_warning_or_error
);
3319 tree cond
= cp_build_binary_op (DECL_SOURCE_LOCATION (var
),
3320 NE_EXPR
, addr
, nullptr_node
,
3321 tf_warning_or_error
);
3322 finish_if_stmt_cond (cond
, if_stmt
);
3324 finish_expr_stmt (build_cxx_call
3325 (init_fn
, 0, NULL
, tf_warning_or_error
));
3328 finish_then_clause (if_stmt
);
3329 finish_if_stmt (if_stmt
);
3333 /* If there's no initialization, the wrapper is a constant function. */
3334 TREE_READONLY (fn
) = true;
3335 finish_return_stmt (convert_from_reference (var
));
3336 finish_function_body (body
);
3337 expand_or_defer_fn (finish_function (0));
3340 /* Start the process of running a particular set of global constructors
3341 or destructors. Subroutine of do_[cd]tors. Also called from
3342 vtv_start_verification_constructor_init_function. */
3345 start_objects (int method_type
, int initp
)
3351 /* Make ctor or dtor function. METHOD_TYPE may be 'I' or 'D'. */
3353 if (initp
!= DEFAULT_INIT_PRIORITY
)
3363 sprintf (type
, "sub_%c%c%.5u", method_type
, joiner
, initp
);
3366 sprintf (type
, "sub_%c", method_type
);
3368 fndecl
= build_lang_decl (FUNCTION_DECL
,
3369 get_file_function_name (type
),
3370 build_function_type_list (void_type_node
,
3372 start_preparsed_function (fndecl
, /*attrs=*/NULL_TREE
, SF_PRE_PARSED
);
3374 TREE_PUBLIC (current_function_decl
) = 0;
3376 /* Mark as artificial because it's not explicitly in the user's
3378 DECL_ARTIFICIAL (current_function_decl
) = 1;
3380 /* Mark this declaration as used to avoid spurious warnings. */
3381 TREE_USED (current_function_decl
) = 1;
3383 /* Mark this function as a global constructor or destructor. */
3384 if (method_type
== 'I')
3385 DECL_GLOBAL_CTOR_P (current_function_decl
) = 1;
3387 DECL_GLOBAL_DTOR_P (current_function_decl
) = 1;
3389 body
= begin_compound_stmt (BCS_FN_BODY
);
3394 /* Finish the process of running a particular set of global constructors
3395 or destructors. Subroutine of do_[cd]tors. */
3398 finish_objects (int method_type
, int initp
, tree body
)
3403 finish_compound_stmt (body
);
3404 fn
= finish_function (0);
3406 if (method_type
== 'I')
3408 DECL_STATIC_CONSTRUCTOR (fn
) = 1;
3409 decl_init_priority_insert (fn
, initp
);
3413 DECL_STATIC_DESTRUCTOR (fn
) = 1;
3414 decl_fini_priority_insert (fn
, initp
);
3417 expand_or_defer_fn (fn
);
3420 /* The names of the parameters to the function created to handle
3421 initializations and destructions for objects with static storage
3423 #define INITIALIZE_P_IDENTIFIER "__initialize_p"
3424 #define PRIORITY_IDENTIFIER "__priority"
3426 /* The name of the function we create to handle initializations and
3427 destructions for objects with static storage duration. */
3428 #define SSDF_IDENTIFIER "__static_initialization_and_destruction"
3430 /* The declaration for the __INITIALIZE_P argument. */
3431 static GTY(()) tree initialize_p_decl
;
3433 /* The declaration for the __PRIORITY argument. */
3434 static GTY(()) tree priority_decl
;
3436 /* The declaration for the static storage duration function. */
3437 static GTY(()) tree ssdf_decl
;
3439 /* All the static storage duration functions created in this
3440 translation unit. */
3441 static GTY(()) vec
<tree
, va_gc
> *ssdf_decls
;
3443 /* A map from priority levels to information about that priority
3444 level. There may be many such levels, so efficient lookup is
3446 static splay_tree priority_info_map
;
3448 /* Begins the generation of the function that will handle all
3449 initialization and destruction of objects with static storage
3450 duration. The function generated takes two parameters of type
3451 `int': __INITIALIZE_P and __PRIORITY. If __INITIALIZE_P is
3452 nonzero, it performs initializations. Otherwise, it performs
3453 destructions. It only performs those initializations or
3454 destructions with the indicated __PRIORITY. The generated function
3457 It is assumed that this function will only be called once per
3458 translation unit. */
3461 start_static_storage_duration_function (unsigned count
)
3465 char id
[sizeof (SSDF_IDENTIFIER
) + 1 /* '\0' */ + 32];
3467 /* Create the identifier for this function. It will be of the form
3468 SSDF_IDENTIFIER_<number>. */
3469 sprintf (id
, "%s_%u", SSDF_IDENTIFIER
, count
);
3471 type
= build_function_type_list (void_type_node
,
3472 integer_type_node
, integer_type_node
,
3475 /* Create the FUNCTION_DECL itself. */
3476 ssdf_decl
= build_lang_decl (FUNCTION_DECL
,
3477 get_identifier (id
),
3479 TREE_PUBLIC (ssdf_decl
) = 0;
3480 DECL_ARTIFICIAL (ssdf_decl
) = 1;
3482 /* Put this function in the list of functions to be called from the
3483 static constructors and destructors. */
3486 vec_alloc (ssdf_decls
, 32);
3488 /* Take this opportunity to initialize the map from priority
3489 numbers to information about that priority level. */
3490 priority_info_map
= splay_tree_new (splay_tree_compare_ints
,
3491 /*delete_key_fn=*/0,
3492 /*delete_value_fn=*/
3493 (splay_tree_delete_value_fn
) &free
);
3495 /* We always need to generate functions for the
3496 DEFAULT_INIT_PRIORITY so enter it now. That way when we walk
3497 priorities later, we'll be sure to find the
3498 DEFAULT_INIT_PRIORITY. */
3499 get_priority_info (DEFAULT_INIT_PRIORITY
);
3502 vec_safe_push (ssdf_decls
, ssdf_decl
);
3504 /* Create the argument list. */
3505 initialize_p_decl
= cp_build_parm_decl
3506 (get_identifier (INITIALIZE_P_IDENTIFIER
), integer_type_node
);
3507 DECL_CONTEXT (initialize_p_decl
) = ssdf_decl
;
3508 TREE_USED (initialize_p_decl
) = 1;
3509 priority_decl
= cp_build_parm_decl
3510 (get_identifier (PRIORITY_IDENTIFIER
), integer_type_node
);
3511 DECL_CONTEXT (priority_decl
) = ssdf_decl
;
3512 TREE_USED (priority_decl
) = 1;
3514 DECL_CHAIN (initialize_p_decl
) = priority_decl
;
3515 DECL_ARGUMENTS (ssdf_decl
) = initialize_p_decl
;
3517 /* Put the function in the global scope. */
3518 pushdecl (ssdf_decl
);
3520 /* Start the function itself. This is equivalent to declaring the
3523 static void __ssdf (int __initialize_p, init __priority_p);
3525 It is static because we only need to call this function from the
3526 various constructor and destructor functions for this module. */
3527 start_preparsed_function (ssdf_decl
,
3528 /*attrs=*/NULL_TREE
,
3531 /* Set up the scope of the outermost block in the function. */
3532 body
= begin_compound_stmt (BCS_FN_BODY
);
3537 /* Finish the generation of the function which performs initialization
3538 and destruction of objects with static storage duration. After
3539 this point, no more such objects can be created. */
3542 finish_static_storage_duration_function (tree body
)
3544 /* Close out the function. */
3545 finish_compound_stmt (body
);
3546 expand_or_defer_fn (finish_function (0));
3549 /* Return the information about the indicated PRIORITY level. If no
3550 code to handle this level has yet been generated, generate the
3551 appropriate prologue. */
3553 static priority_info
3554 get_priority_info (int priority
)
3559 n
= splay_tree_lookup (priority_info_map
,
3560 (splay_tree_key
) priority
);
3563 /* Create a new priority information structure, and insert it
3565 pi
= XNEW (struct priority_info_s
);
3566 pi
->initializations_p
= 0;
3567 pi
->destructions_p
= 0;
3568 splay_tree_insert (priority_info_map
,
3569 (splay_tree_key
) priority
,
3570 (splay_tree_value
) pi
);
3573 pi
= (priority_info
) n
->value
;
3578 /* The effective initialization priority of a DECL. */
3580 #define DECL_EFFECTIVE_INIT_PRIORITY(decl) \
3581 ((!DECL_HAS_INIT_PRIORITY_P (decl) || DECL_INIT_PRIORITY (decl) == 0) \
3582 ? DEFAULT_INIT_PRIORITY : DECL_INIT_PRIORITY (decl))
3584 /* Whether a DECL needs a guard to protect it against multiple
3587 #define NEEDS_GUARD_P(decl) (TREE_PUBLIC (decl) && (DECL_COMMON (decl) \
3588 || DECL_ONE_ONLY (decl) \
3589 || DECL_WEAK (decl)))
3591 /* Called from one_static_initialization_or_destruction(),
3593 Walks the initializer list of a global variable and looks for
3594 temporary variables (DECL_NAME() == NULL and DECL_ARTIFICIAL != 0)
3595 and that have their DECL_CONTEXT() == NULL.
3596 For each such temporary variable, set their DECL_CONTEXT() to
3597 the current function. This is necessary because otherwise
3598 some optimizers (enabled by -O2 -fprofile-arcs) might crash
3599 when trying to refer to a temporary variable that does not have
3600 it's DECL_CONTECT() properly set. */
3602 fix_temporary_vars_context_r (tree
*node
,
3606 gcc_assert (current_function_decl
);
3608 if (TREE_CODE (*node
) == BIND_EXPR
)
3612 for (var
= BIND_EXPR_VARS (*node
); var
; var
= DECL_CHAIN (var
))
3615 && DECL_ARTIFICIAL (var
)
3616 && !DECL_CONTEXT (var
))
3617 DECL_CONTEXT (var
) = current_function_decl
;
3623 /* Set up to handle the initialization or destruction of DECL. If
3624 INITP is nonzero, we are initializing the variable. Otherwise, we
3625 are destroying it. */
3628 one_static_initialization_or_destruction (tree decl
, tree init
, bool initp
)
3630 tree guard_if_stmt
= NULL_TREE
;
3633 /* If we are supposed to destruct and there's a trivial destructor,
3634 nothing has to be done. */
3636 && TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
3639 /* Trick the compiler into thinking we are at the file and line
3640 where DECL was declared so that error-messages make sense, and so
3641 that the debugger will show somewhat sensible file and line
3643 input_location
= DECL_SOURCE_LOCATION (decl
);
3645 /* Make sure temporary variables in the initialiser all have
3646 their DECL_CONTEXT() set to a value different from NULL_TREE.
3647 This can happen when global variables initialisers are built.
3648 In that case, the DECL_CONTEXT() of the global variables _AND_ of all
3649 the temporary variables that might have been generated in the
3650 accompagning initialisers is NULL_TREE, meaning the variables have been
3651 declared in the global namespace.
3652 What we want to do here is to fix that and make sure the DECL_CONTEXT()
3653 of the temporaries are set to the current function decl. */
3654 cp_walk_tree_without_duplicates (&init
,
3655 fix_temporary_vars_context_r
,
3662 Access control for implicit calls to the constructors,
3663 the conversion functions, or the destructor called to
3664 create and destroy a static data member is performed as
3665 if these calls appeared in the scope of the member's
3668 we pretend we are in a static member function of the class of
3669 which the DECL is a member. */
3670 if (member_p (decl
))
3672 DECL_CONTEXT (current_function_decl
) = DECL_CONTEXT (decl
);
3673 DECL_STATIC_FUNCTION_P (current_function_decl
) = 1;
3676 /* Assume we don't need a guard. */
3678 /* We need a guard if this is an object with external linkage that
3679 might be initialized in more than one place. (For example, a
3680 static data member of a template, when the data member requires
3682 if (NEEDS_GUARD_P (decl
))
3686 guard
= get_guard (decl
);
3688 /* When using __cxa_atexit, we just check the GUARD as we would
3689 for a local static. */
3690 if (flag_use_cxa_atexit
)
3692 /* When using __cxa_atexit, we never try to destroy
3693 anything from a static destructor. */
3695 guard_cond
= get_guard_cond (guard
, false);
3697 /* If we don't have __cxa_atexit, then we will be running
3698 destructors from .fini sections, or their equivalents. So,
3699 we need to know how many times we've tried to initialize this
3700 object. We do initializations only if the GUARD is zero,
3701 i.e., if we are the first to initialize the variable. We do
3702 destructions only if the GUARD is one, i.e., if we are the
3703 last to destroy the variable. */
3706 = cp_build_binary_op (input_location
,
3708 cp_build_unary_op (PREINCREMENT_EXPR
,
3711 tf_warning_or_error
),
3713 tf_warning_or_error
);
3716 = cp_build_binary_op (input_location
,
3718 cp_build_unary_op (PREDECREMENT_EXPR
,
3721 tf_warning_or_error
),
3723 tf_warning_or_error
);
3725 guard_if_stmt
= begin_if_stmt ();
3726 finish_if_stmt_cond (guard_cond
, guard_if_stmt
);
3730 /* If we're using __cxa_atexit, we have not already set the GUARD,
3731 so we must do so now. */
3732 if (guard
&& initp
&& flag_use_cxa_atexit
)
3733 finish_expr_stmt (set_guard (guard
));
3735 /* Perform the initialization or destruction. */
3740 finish_expr_stmt (init
);
3741 if (flag_sanitize
& SANITIZE_ADDRESS
)
3743 varpool_node
*vnode
= varpool_node::get (decl
);
3745 vnode
->dynamically_initialized
= 1;
3749 /* If we're using __cxa_atexit, register a function that calls the
3750 destructor for the object. */
3751 if (flag_use_cxa_atexit
)
3752 finish_expr_stmt (register_dtor_fn (decl
));
3755 finish_expr_stmt (build_cleanup (decl
));
3757 /* Finish the guard if-stmt, if necessary. */
3760 finish_then_clause (guard_if_stmt
);
3761 finish_if_stmt (guard_if_stmt
);
3764 /* Now that we're done with DECL we don't need to pretend to be a
3765 member of its class any longer. */
3766 DECL_CONTEXT (current_function_decl
) = NULL_TREE
;
3767 DECL_STATIC_FUNCTION_P (current_function_decl
) = 0;
3770 /* Generate code to do the initialization or destruction of the decls in VARS,
3771 a TREE_LIST of VAR_DECL with static storage duration.
3772 Whether initialization or destruction is performed is specified by INITP. */
3775 do_static_initialization_or_destruction (tree vars
, bool initp
)
3777 tree node
, init_if_stmt
, cond
;
3779 /* Build the outer if-stmt to check for initialization or destruction. */
3780 init_if_stmt
= begin_if_stmt ();
3781 cond
= initp
? integer_one_node
: integer_zero_node
;
3782 cond
= cp_build_binary_op (input_location
,
3786 tf_warning_or_error
);
3787 finish_if_stmt_cond (cond
, init_if_stmt
);
3789 /* To make sure dynamic construction doesn't access globals from other
3790 compilation units where they might not be yet constructed, for
3791 -fsanitize=address insert __asan_before_dynamic_init call that
3792 prevents access to either all global variables that need construction
3793 in other compilation units, or at least those that haven't been
3794 initialized yet. Variables that need dynamic construction in
3795 the current compilation unit are kept accessible. */
3796 if (flag_sanitize
& SANITIZE_ADDRESS
)
3797 finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/false));
3801 tree decl
= TREE_VALUE (node
);
3802 tree priority_if_stmt
;
3806 /* If we don't need a destructor, there's nothing to do. Avoid
3807 creating a possibly empty if-stmt. */
3808 if (!initp
&& TYPE_HAS_TRIVIAL_DESTRUCTOR (TREE_TYPE (decl
)))
3810 node
= TREE_CHAIN (node
);
3814 /* Remember that we had an initialization or finalization at this
3816 priority
= DECL_EFFECTIVE_INIT_PRIORITY (decl
);
3817 pi
= get_priority_info (priority
);
3819 pi
->initializations_p
= 1;
3821 pi
->destructions_p
= 1;
3823 /* Conditionalize this initialization on being in the right priority
3824 and being initializing/finalizing appropriately. */
3825 priority_if_stmt
= begin_if_stmt ();
3826 cond
= cp_build_binary_op (input_location
,
3829 build_int_cst (NULL_TREE
, priority
),
3830 tf_warning_or_error
);
3831 finish_if_stmt_cond (cond
, priority_if_stmt
);
3833 /* Process initializers with same priority. */
3835 && DECL_EFFECTIVE_INIT_PRIORITY (TREE_VALUE (node
)) == priority
;
3836 node
= TREE_CHAIN (node
))
3837 /* Do one initialization or destruction. */
3838 one_static_initialization_or_destruction (TREE_VALUE (node
),
3839 TREE_PURPOSE (node
), initp
);
3841 /* Finish up the priority if-stmt body. */
3842 finish_then_clause (priority_if_stmt
);
3843 finish_if_stmt (priority_if_stmt
);
3847 /* Revert what __asan_before_dynamic_init did by calling
3848 __asan_after_dynamic_init. */
3849 if (flag_sanitize
& SANITIZE_ADDRESS
)
3850 finish_expr_stmt (asan_dynamic_init_call (/*after_p=*/true));
3852 /* Finish up the init/destruct if-stmt body. */
3853 finish_then_clause (init_if_stmt
);
3854 finish_if_stmt (init_if_stmt
);
3857 /* VARS is a list of variables with static storage duration which may
3858 need initialization and/or finalization. Remove those variables
3859 that don't really need to be initialized or finalized, and return
3860 the resulting list. The order in which the variables appear in
3861 VARS is in reverse order of the order in which they should actually
3862 be initialized. The list we return is in the unreversed order;
3863 i.e., the first variable should be initialized first. */
3866 prune_vars_needing_no_initialization (tree
*vars
)
3869 tree result
= NULL_TREE
;
3874 tree decl
= TREE_VALUE (t
);
3875 tree init
= TREE_PURPOSE (t
);
3877 /* Deal gracefully with error. */
3878 if (decl
== error_mark_node
)
3880 var
= &TREE_CHAIN (t
);
3884 /* The only things that can be initialized are variables. */
3885 gcc_assert (VAR_P (decl
));
3887 /* If this object is not defined, we don't need to do anything
3889 if (DECL_EXTERNAL (decl
))
3891 var
= &TREE_CHAIN (t
);
3895 /* Also, if the initializer already contains errors, we can bail
3897 if (init
&& TREE_CODE (init
) == TREE_LIST
3898 && value_member (error_mark_node
, init
))
3900 var
= &TREE_CHAIN (t
);
3904 /* This variable is going to need initialization and/or
3905 finalization, so we add it to the list. */
3906 *var
= TREE_CHAIN (t
);
3907 TREE_CHAIN (t
) = result
;
3914 /* Make sure we have told the back end about all the variables in
3918 write_out_vars (tree vars
)
3922 for (v
= vars
; v
; v
= TREE_CHAIN (v
))
3924 tree var
= TREE_VALUE (v
);
3925 if (!var_finalized_p (var
))
3927 import_export_decl (var
);
3928 rest_of_decl_compilation (var
, 1, 1);
3933 /* Generate a static constructor (if CONSTRUCTOR_P) or destructor
3934 (otherwise) that will initialize all global objects with static
3935 storage duration having the indicated PRIORITY. */
3938 generate_ctor_or_dtor_function (bool constructor_p
, int priority
,
3946 input_location
= *locus
;
3948 /* Was: locus->line++; */
3950 /* We use `I' to indicate initialization and `D' to indicate
3952 function_key
= constructor_p
? 'I' : 'D';
3954 /* We emit the function lazily, to avoid generating empty
3955 global constructors and destructors. */
3958 /* For Objective-C++, we may need to initialize metadata found in this module.
3959 This must be done _before_ any other static initializations. */
3960 if (c_dialect_objc () && (priority
== DEFAULT_INIT_PRIORITY
)
3961 && constructor_p
&& objc_static_init_needed_p ())
3963 body
= start_objects (function_key
, priority
);
3964 objc_generate_static_init_call (NULL_TREE
);
3967 /* Call the static storage duration function with appropriate
3969 FOR_EACH_VEC_SAFE_ELT (ssdf_decls
, i
, fndecl
)
3971 /* Calls to pure or const functions will expand to nothing. */
3972 if (! (flags_from_decl_or_type (fndecl
) & (ECF_CONST
| ECF_PURE
)))
3977 body
= start_objects (function_key
, priority
);
3979 call
= cp_build_function_call_nary (fndecl
, tf_warning_or_error
,
3980 build_int_cst (NULL_TREE
,
3982 build_int_cst (NULL_TREE
,
3985 finish_expr_stmt (call
);
3989 /* Close out the function. */
3991 finish_objects (function_key
, priority
, body
);
3994 /* Generate constructor and destructor functions for the priority
3998 generate_ctor_and_dtor_functions_for_priority (splay_tree_node n
, void * data
)
4000 location_t
*locus
= (location_t
*) data
;
4001 int priority
= (int) n
->key
;
4002 priority_info pi
= (priority_info
) n
->value
;
4004 /* Generate the functions themselves, but only if they are really
4006 if (pi
->initializations_p
)
4007 generate_ctor_or_dtor_function (/*constructor_p=*/true, priority
, locus
);
4008 if (pi
->destructions_p
)
4009 generate_ctor_or_dtor_function (/*constructor_p=*/false, priority
, locus
);
4011 /* Keep iterating. */
4015 /* Java requires that we be able to reference a local address for a
4016 method, and not be confused by PLT entries. If supported, create a
4017 hidden alias for all such methods. */
4020 build_java_method_aliases (void)
4022 #ifndef HAVE_GAS_HIDDEN
4026 struct cgraph_node
*node
;
4027 FOR_EACH_FUNCTION (node
)
4029 tree fndecl
= node
->decl
;
4031 if (DECL_CLASS_SCOPE_P (fndecl
)
4032 && TYPE_FOR_JAVA (DECL_CONTEXT (fndecl
))
4033 && TARGET_USE_LOCAL_THUNK_ALIAS_P (fndecl
))
4035 /* Mangle the name in a predictable way; we need to reference
4036 this from a java compiled object file. */
4037 tree oid
= DECL_ASSEMBLER_NAME (fndecl
);
4038 const char *oname
= IDENTIFIER_POINTER (oid
);
4039 gcc_assert (oname
[0] == '_' && oname
[1] == 'Z');
4040 char *nname
= ACONCAT (("_ZGA", oname
+ 2, NULL
));
4042 tree alias
= make_alias_for (fndecl
, get_identifier (nname
));
4043 TREE_PUBLIC (alias
) = 1;
4044 DECL_VISIBILITY (alias
) = VISIBILITY_HIDDEN
;
4046 cgraph_node::create_same_body_alias (alias
, fndecl
);
4051 /* Return C++ property of T, based on given operation OP. */
4054 cpp_check (tree t
, cpp_operation op
)
4058 case HAS_DEPENDENT_TEMPLATE_ARGS
:
4060 tree ti
= CLASSTYPE_TEMPLATE_INFO (t
);
4063 ++processing_template_decl
;
4064 const bool dep
= any_dependent_template_arguments_p (TI_ARGS (ti
));
4065 --processing_template_decl
;
4069 return DECL_PURE_VIRTUAL_P (t
);
4070 case IS_CONSTRUCTOR
:
4071 return DECL_CONSTRUCTOR_P (t
);
4073 return DECL_DESTRUCTOR_P (t
);
4074 case IS_COPY_CONSTRUCTOR
:
4075 return DECL_COPY_CONSTRUCTOR_P (t
);
4077 return TREE_CODE (t
) == TEMPLATE_DECL
;
4079 return trivial_type_p (t
);
4085 /* Collect source file references recursively, starting from NAMESPC. */
4088 collect_source_refs (tree namespc
)
4095 /* Iterate over names in this name space. */
4096 for (t
= NAMESPACE_LEVEL (namespc
)->names
; t
; t
= TREE_CHAIN (t
))
4097 if (!DECL_IS_BUILTIN (t
) )
4098 collect_source_ref (DECL_SOURCE_FILE (t
));
4100 /* Dump siblings, if any */
4101 collect_source_refs (TREE_CHAIN (namespc
));
4103 /* Dump children, if any */
4104 collect_source_refs (NAMESPACE_LEVEL (namespc
)->namespaces
);
4107 /* Collect decls relevant to SOURCE_FILE from all namespaces recursively,
4108 starting from NAMESPC. */
4111 collect_ada_namespace (tree namespc
, const char *source_file
)
4116 /* Collect decls from this namespace */
4117 collect_ada_nodes (NAMESPACE_LEVEL (namespc
)->names
, source_file
);
4119 /* Collect siblings, if any */
4120 collect_ada_namespace (TREE_CHAIN (namespc
), source_file
);
4122 /* Collect children, if any */
4123 collect_ada_namespace (NAMESPACE_LEVEL (namespc
)->namespaces
, source_file
);
4126 /* Returns true iff there is a definition available for variable or
4130 decl_defined_p (tree decl
)
4132 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4133 return (DECL_INITIAL (decl
) != NULL_TREE
);
4136 gcc_assert (VAR_P (decl
));
4137 return !DECL_EXTERNAL (decl
);
4141 /* Nonzero for a VAR_DECL whose value can be used in a constant expression.
4145 An integral constant-expression can only involve ... const
4146 variables of integral or enumeration types initialized with
4147 constant expressions ...
4149 C++0x also allows constexpr variables and temporaries initialized
4150 with constant expressions. We handle the former here, but the latter
4151 are just folded away in cxx_eval_constant_expression.
4153 The standard does not require that the expression be non-volatile.
4154 G++ implements the proposed correction in DR 457. */
4157 decl_constant_var_p (tree decl
)
4159 if (!decl_maybe_constant_var_p (decl
))
4162 /* We don't know if a template static data member is initialized with
4163 a constant expression until we instantiate its initializer. Even
4164 in the case of a constexpr variable, we can't treat it as a
4165 constant until its initializer is complete in case it's used in
4166 its own initializer. */
4168 return DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
);
4171 /* Returns true if DECL could be a symbolic constant variable, depending on
4175 decl_maybe_constant_var_p (tree decl
)
4177 tree type
= TREE_TYPE (decl
);
4180 if (DECL_DECLARED_CONSTEXPR_P (decl
))
4182 return (CP_TYPE_CONST_NON_VOLATILE_P (type
)
4183 && INTEGRAL_OR_ENUMERATION_TYPE_P (type
));
4186 /* Complain that DECL uses a type with no linkage. In C++98 mode this is
4187 called from grokfndecl and grokvardecl; in all modes it is called from
4188 cp_write_global_declarations. */
4191 no_linkage_error (tree decl
)
4193 if (cxx_dialect
>= cxx11
&& decl_defined_p (decl
))
4194 /* In C++11 it's ok if the decl is defined. */
4196 tree t
= no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/false);
4198 /* The type that got us on no_linkage_decls must have gotten a name for
4199 linkage purposes. */;
4200 else if (CLASS_TYPE_P (t
) && TYPE_BEING_DEFINED (t
))
4201 /* The type might end up having a typedef name for linkage purposes. */
4202 vec_safe_push (no_linkage_decls
, decl
);
4203 else if (TYPE_ANONYMOUS_P (t
))
4206 if (cxx_dialect
>= cxx11
)
4207 d
= permerror (DECL_SOURCE_LOCATION (decl
), "%q#D, declared using "
4208 "anonymous type, is used but never defined", decl
);
4209 else if (DECL_EXTERN_C_P (decl
))
4210 /* Allow this; it's pretty common in C. */;
4211 else if (TREE_CODE (decl
) == VAR_DECL
)
4212 /* DRs 132, 319 and 389 seem to indicate types with
4213 no linkage can only be used to declare extern "C"
4214 entities. Since it's not always an error in the
4215 ISO C++ 90 Standard, we only issue a warning. */
4216 d
= warning_at (DECL_SOURCE_LOCATION (decl
), 0, "anonymous type "
4217 "with no linkage used to declare variable %q#D with "
4220 d
= permerror (DECL_SOURCE_LOCATION (decl
), "anonymous type with no "
4221 "linkage used to declare function %q#D with linkage",
4223 if (d
&& is_typedef_decl (TYPE_NAME (t
)))
4224 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "%q#D does not refer "
4225 "to the unqualified type, so it is not used for linkage",
4228 else if (cxx_dialect
>= cxx11
)
4230 if (TREE_CODE (decl
) == VAR_DECL
|| !DECL_PURE_VIRTUAL_P (decl
))
4231 permerror (DECL_SOURCE_LOCATION (decl
),
4232 "%q#D, declared using local type "
4233 "%qT, is used but never defined", decl
, t
);
4235 else if (TREE_CODE (decl
) == VAR_DECL
)
4236 warning_at (DECL_SOURCE_LOCATION (decl
), 0, "type %qT with no linkage "
4237 "used to declare variable %q#D with linkage", t
, decl
);
4239 permerror (DECL_SOURCE_LOCATION (decl
), "type %qT with no linkage used "
4240 "to declare function %q#D with linkage", t
, decl
);
4243 /* Collect declarations from all namespaces relevant to SOURCE_FILE. */
4246 collect_all_refs (const char *source_file
)
4248 collect_ada_namespace (global_namespace
, source_file
);
4251 /* Clear DECL_EXTERNAL for NODE. */
4254 clear_decl_external (struct cgraph_node
*node
, void * /*data*/)
4256 DECL_EXTERNAL (node
->decl
) = 0;
4260 /* Build up the function to run dynamic initializers for thread_local
4261 variables in this translation unit and alias the init functions for the
4262 individual variables to it. */
4265 handle_tls_init (void)
4267 tree vars
= prune_vars_needing_no_initialization (&tls_aggregates
);
4268 if (vars
== NULL_TREE
)
4271 location_t loc
= DECL_SOURCE_LOCATION (TREE_VALUE (vars
));
4273 write_out_vars (vars
);
4275 tree guard
= build_decl (loc
, VAR_DECL
, get_identifier ("__tls_guard"),
4277 TREE_PUBLIC (guard
) = false;
4278 TREE_STATIC (guard
) = true;
4279 DECL_ARTIFICIAL (guard
) = true;
4280 DECL_IGNORED_P (guard
) = true;
4281 TREE_USED (guard
) = true;
4282 set_decl_tls_model (guard
, decl_default_tls_model (guard
));
4283 pushdecl_top_level_and_finish (guard
, NULL_TREE
);
4285 tree fn
= get_local_tls_init_fn ();
4286 start_preparsed_function (fn
, NULL_TREE
, SF_PRE_PARSED
);
4287 tree body
= begin_function_body ();
4288 tree if_stmt
= begin_if_stmt ();
4289 tree cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, guard
, false,
4290 tf_warning_or_error
);
4291 finish_if_stmt_cond (cond
, if_stmt
);
4292 finish_expr_stmt (cp_build_modify_expr (guard
, NOP_EXPR
, boolean_true_node
,
4293 tf_warning_or_error
));
4294 for (; vars
; vars
= TREE_CHAIN (vars
))
4296 tree var
= TREE_VALUE (vars
);
4297 tree init
= TREE_PURPOSE (vars
);
4298 one_static_initialization_or_destruction (var
, init
, true);
4300 #ifdef ASM_OUTPUT_DEF
4301 /* Output init aliases even with -fno-extern-tls-init. */
4302 if (TREE_PUBLIC (var
))
4304 tree single_init_fn
= get_tls_init_fn (var
);
4305 if (single_init_fn
== NULL_TREE
)
4308 = cgraph_node::get_create (fn
)->create_same_body_alias
4309 (single_init_fn
, fn
);
4310 gcc_assert (alias
!= NULL
);
4315 finish_then_clause (if_stmt
);
4316 finish_if_stmt (if_stmt
);
4317 finish_function_body (body
);
4318 expand_or_defer_fn (finish_function (0));
4321 /* We're at the end of compilation, so generate any mangling aliases that
4322 we've been saving up, if DECL is going to be output and ID2 isn't
4323 already taken by another declaration. */
4326 generate_mangling_alias (tree decl
, tree id2
)
4328 /* If there's a declaration already using this mangled name,
4329 don't create a compatibility alias that conflicts. */
4330 if (IDENTIFIER_GLOBAL_VALUE (id2
))
4333 struct cgraph_node
*n
= NULL
;
4334 if (TREE_CODE (decl
) == FUNCTION_DECL
4335 && !(n
= cgraph_node::get (decl
)))
4336 /* Don't create an alias to an unreferenced function. */
4339 tree alias
= make_alias_for (decl
, id2
);
4340 SET_IDENTIFIER_GLOBAL_VALUE (id2
, alias
);
4341 DECL_IGNORED_P (alias
) = 1;
4342 TREE_PUBLIC (alias
) = TREE_PUBLIC (decl
);
4343 DECL_VISIBILITY (alias
) = DECL_VISIBILITY (decl
);
4344 if (vague_linkage_p (decl
))
4345 DECL_WEAK (alias
) = 1;
4346 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4347 n
->create_same_body_alias (alias
, decl
);
4349 varpool_node::create_extra_name_alias (alias
, decl
);
4352 /* Note that we might want to emit an alias with the symbol ID2 for DECL at
4353 the end of translation, for compatibility across bugs in the mangling
4357 note_mangling_alias (tree decl ATTRIBUTE_UNUSED
, tree id2 ATTRIBUTE_UNUSED
)
4359 #ifdef ASM_OUTPUT_DEF
4361 generate_mangling_alias (decl
, id2
);
4364 vec_safe_push (mangling_aliases
, decl
);
4365 vec_safe_push (mangling_aliases
, id2
);
4371 generate_mangling_aliases ()
4373 while (!vec_safe_is_empty (mangling_aliases
))
4375 tree id2
= mangling_aliases
->pop();
4376 tree decl
= mangling_aliases
->pop();
4377 generate_mangling_alias (decl
, id2
);
4381 /* The entire file is now complete. If requested, dump everything
4388 FILE *stream
= dump_begin (TDI_tu
, &flags
);
4392 dump_node (global_namespace
, flags
& ~TDF_SLIM
, stream
);
4393 dump_end (TDI_tu
, stream
);
4397 static location_t locus_at_end_of_parsing
;
4399 /* Check the deallocation functions for CODE to see if we want to warn that
4400 only one was defined. */
4403 maybe_warn_sized_delete (enum tree_code code
)
4405 tree sized
= NULL_TREE
;
4406 tree unsized
= NULL_TREE
;
4408 for (tree ovl
= IDENTIFIER_GLOBAL_VALUE (ansi_opname (code
));
4409 ovl
; ovl
= OVL_NEXT (ovl
))
4411 tree fn
= OVL_CURRENT (ovl
);
4412 /* We're only interested in usual deallocation functions. */
4413 if (!non_placement_deallocation_fn_p (fn
))
4415 if (FUNCTION_ARG_CHAIN (fn
) == void_list_node
)
4420 if (DECL_INITIAL (unsized
) && !DECL_INITIAL (sized
))
4421 warning_at (DECL_SOURCE_LOCATION (unsized
), OPT_Wsized_deallocation
,
4422 "the program should also define %qD", sized
);
4423 else if (!DECL_INITIAL (unsized
) && DECL_INITIAL (sized
))
4424 warning_at (DECL_SOURCE_LOCATION (sized
), OPT_Wsized_deallocation
,
4425 "the program should also define %qD", unsized
);
4428 /* Check the global deallocation functions to see if we want to warn about
4429 defining unsized without sized (or vice versa). */
4432 maybe_warn_sized_delete ()
4434 if (!flag_sized_deallocation
|| !warn_sized_deallocation
)
4436 maybe_warn_sized_delete (DELETE_EXPR
);
4437 maybe_warn_sized_delete (VEC_DELETE_EXPR
);
4440 /* This routine is called at the end of compilation.
4441 Its job is to create all the code needed to initialize and
4442 destroy the global aggregates. We do the destruction
4443 first, since that way we only need to reverse the decls once. */
4446 c_parse_final_cleanups (void)
4451 unsigned ssdf_count
= 0;
4455 locus_at_end_of_parsing
= input_location
;
4458 /* Bad parse errors. Just forget about it. */
4459 if (! global_bindings_p () || current_class_type
4460 || !vec_safe_is_empty (decl_namespace_list
))
4463 /* This is the point to write out a PCH if we're doing that.
4464 In that case we do not want to do anything else. */
4467 c_common_write_pch ();
4472 timevar_stop (TV_PHASE_PARSING
);
4473 timevar_start (TV_PHASE_DEFERRED
);
4475 symtab
->process_same_body_aliases ();
4477 /* Handle -fdump-ada-spec[-slim] */
4478 if (flag_dump_ada_spec
|| flag_dump_ada_spec_slim
)
4480 if (flag_dump_ada_spec_slim
)
4481 collect_source_ref (main_input_filename
);
4483 collect_source_refs (global_namespace
);
4485 dump_ada_specs (collect_all_refs
, cpp_check
);
4488 /* FIXME - huh? was input_line -= 1;*/
4490 /* We now have to write out all the stuff we put off writing out.
4493 o Template specializations that we have not yet instantiated,
4494 but which are needed.
4495 o Initialization and destruction for non-local objects with
4496 static storage duration. (Local objects with static storage
4497 duration are initialized when their scope is first entered,
4498 and are cleaned up via atexit.)
4499 o Virtual function tables.
4501 All of these may cause others to be needed. For example,
4502 instantiating one function may cause another to be needed, and
4503 generating the initializer for an object may cause templates to be
4504 instantiated, etc., etc. */
4506 emit_support_tinfos ();
4515 /* If there are templates that we've put off instantiating, do
4517 instantiate_pending_templates (retries
);
4520 /* Write out virtual tables as required. Note that writing out
4521 the virtual table for a template class may cause the
4522 instantiation of members of that class. If we write out
4523 vtables then we remove the class from our list so we don't
4524 have to look at it again. */
4526 while (keyed_classes
!= NULL_TREE
4527 && maybe_emit_vtables (TREE_VALUE (keyed_classes
)))
4530 keyed_classes
= TREE_CHAIN (keyed_classes
);
4536 tree next
= TREE_CHAIN (t
);
4540 if (maybe_emit_vtables (TREE_VALUE (next
)))
4543 TREE_CHAIN (t
) = TREE_CHAIN (next
);
4548 next
= TREE_CHAIN (t
);
4552 /* Write out needed type info variables. We have to be careful
4553 looping through unemitted decls, because emit_tinfo_decl may
4554 cause other variables to be needed. New elements will be
4555 appended, and we remove from the vector those that actually
4557 for (i
= unemitted_tinfo_decls
->length ();
4558 unemitted_tinfo_decls
->iterate (--i
, &t
);)
4559 if (emit_tinfo_decl (t
))
4562 unemitted_tinfo_decls
->unordered_remove (i
);
4565 /* The list of objects with static storage duration is built up
4566 in reverse order. We clear STATIC_AGGREGATES so that any new
4567 aggregates added during the initialization of these will be
4568 initialized in the correct order when we next come around the
4570 vars
= prune_vars_needing_no_initialization (&static_aggregates
);
4574 /* We need to start a new initialization function each time
4575 through the loop. That's because we need to know which
4576 vtables have been referenced, and TREE_SYMBOL_REFERENCED
4577 isn't computed until a function is finished, and written
4578 out. That's a deficiency in the back end. When this is
4579 fixed, these initialization functions could all become
4580 inline, with resulting performance improvements. */
4583 /* Set the line and file, so that it is obviously not from
4585 input_location
= locus_at_end_of_parsing
;
4586 ssdf_body
= start_static_storage_duration_function (ssdf_count
);
4588 /* Make sure the back end knows about all the variables. */
4589 write_out_vars (vars
);
4591 /* First generate code to do all the initializations. */
4593 do_static_initialization_or_destruction (vars
, /*initp=*/true);
4595 /* Then, generate code to do all the destructions. Do these
4596 in reverse order so that the most recently constructed
4597 variable is the first destroyed. If we're using
4598 __cxa_atexit, then we don't need to do this; functions
4599 were registered at initialization time to destroy the
4601 if (!flag_use_cxa_atexit
&& vars
)
4603 vars
= nreverse (vars
);
4604 do_static_initialization_or_destruction (vars
, /*initp=*/false);
4609 /* Finish up the static storage duration function for this
4611 input_location
= locus_at_end_of_parsing
;
4612 finish_static_storage_duration_function (ssdf_body
);
4614 /* All those initializations and finalizations might cause
4615 us to need more inline functions, more template
4616 instantiations, etc. */
4619 /* ??? was: locus_at_end_of_parsing.line++; */
4622 /* Now do the same for thread_local variables. */
4625 /* Go through the set of inline functions whose bodies have not
4626 been emitted yet. If out-of-line copies of these functions
4627 are required, emit them. */
4628 FOR_EACH_VEC_SAFE_ELT (deferred_fns
, i
, decl
)
4630 /* Does it need synthesizing? */
4631 if (DECL_DEFAULTED_FN (decl
) && ! DECL_INITIAL (decl
)
4632 && (! DECL_REALLY_EXTERN (decl
) || possibly_inlined_p (decl
)))
4634 /* Even though we're already at the top-level, we push
4635 there again. That way, when we pop back a few lines
4636 hence, all of our state is restored. Otherwise,
4637 finish_function doesn't clean things up, and we end
4638 up with CURRENT_FUNCTION_DECL set. */
4639 push_to_top_level ();
4640 /* The decl's location will mark where it was first
4641 needed. Save that so synthesize method can indicate
4642 where it was needed from, in case of error */
4643 input_location
= DECL_SOURCE_LOCATION (decl
);
4644 synthesize_method (decl
);
4645 pop_from_top_level ();
4649 if (!DECL_INITIAL (decl
) && decl_tls_wrapper_p (decl
))
4650 generate_tls_wrapper (decl
);
4652 if (!DECL_SAVED_TREE (decl
))
4655 /* We lie to the back end, pretending that some functions
4656 are not defined when they really are. This keeps these
4657 functions from being put out unnecessarily. But, we must
4658 stop lying when the functions are referenced, or if they
4659 are not comdat since they need to be put out now. If
4660 DECL_INTERFACE_KNOWN, then we have already set
4661 DECL_EXTERNAL appropriately, so there's no need to check
4662 again, and we do not want to clear DECL_EXTERNAL if a
4663 previous call to import_export_decl set it.
4665 This is done in a separate for cycle, because if some
4666 deferred function is contained in another deferred
4667 function later in deferred_fns varray,
4668 rest_of_compilation would skip this function and we
4669 really cannot expand the same function twice. */
4670 import_export_decl (decl
);
4671 if (DECL_NOT_REALLY_EXTERN (decl
)
4672 && DECL_INITIAL (decl
)
4673 && decl_needed_p (decl
))
4675 struct cgraph_node
*node
, *next
;
4677 node
= cgraph_node::get (decl
);
4678 if (node
->cpp_implicit_alias
)
4679 node
= node
->get_alias_target ();
4681 node
->call_for_symbol_thunks_and_aliases (clear_decl_external
,
4683 /* If we mark !DECL_EXTERNAL one of the symbols in some comdat
4684 group, we need to mark all symbols in the same comdat group
4686 if (node
->same_comdat_group
)
4687 for (next
= dyn_cast
<cgraph_node
*> (node
->same_comdat_group
);
4689 next
= dyn_cast
<cgraph_node
*> (next
->same_comdat_group
))
4690 next
->call_for_symbol_thunks_and_aliases (clear_decl_external
,
4694 /* If we're going to need to write this function out, and
4695 there's already a body for it, create RTL for it now.
4696 (There might be no body if this is a method we haven't
4697 gotten around to synthesizing yet.) */
4698 if (!DECL_EXTERNAL (decl
)
4699 && decl_needed_p (decl
)
4700 && !TREE_ASM_WRITTEN (decl
)
4701 && !cgraph_node::get (decl
)->definition
)
4703 /* We will output the function; no longer consider it in this
4705 DECL_DEFER_OUTPUT (decl
) = 0;
4706 /* Generate RTL for this function now that we know we
4708 expand_or_defer_fn (decl
);
4709 /* If we're compiling -fsyntax-only pretend that this
4710 function has been written out so that we don't try to
4712 if (flag_syntax_only
)
4713 TREE_ASM_WRITTEN (decl
) = 1;
4718 if (walk_namespaces (wrapup_globals_for_namespace
, /*data=*/0))
4721 /* Static data members are just like namespace-scope globals. */
4722 FOR_EACH_VEC_SAFE_ELT (pending_statics
, i
, decl
)
4724 if (var_finalized_p (decl
) || DECL_REALLY_EXTERN (decl
)
4725 /* Don't write it out if we haven't seen a definition. */
4726 || DECL_IN_AGGR_P (decl
))
4728 import_export_decl (decl
);
4729 /* If this static data member is needed, provide it to the
4731 if (DECL_NOT_REALLY_EXTERN (decl
) && decl_needed_p (decl
))
4732 DECL_EXTERNAL (decl
) = 0;
4734 if (vec_safe_length (pending_statics
) != 0
4735 && wrapup_global_declarations (pending_statics
->address (),
4736 pending_statics
->length ()))
4743 generate_mangling_aliases ();
4745 /* All used inline functions must have a definition at this point. */
4746 FOR_EACH_VEC_SAFE_ELT (deferred_fns
, i
, decl
)
4748 if (/* Check online inline functions that were actually used. */
4749 DECL_ODR_USED (decl
) && DECL_DECLARED_INLINE_P (decl
)
4750 /* If the definition actually was available here, then the
4751 fact that the function was not defined merely represents
4752 that for some reason (use of a template repository,
4753 #pragma interface, etc.) we decided not to emit the
4755 && !DECL_INITIAL (decl
)
4756 /* Don't complain if the template was defined. */
4757 && !(DECL_TEMPLATE_INSTANTIATION (decl
)
4758 && DECL_INITIAL (DECL_TEMPLATE_RESULT
4759 (template_for_substitution (decl
)))))
4761 warning (0, "inline function %q+D used but never defined", decl
);
4762 /* Avoid a duplicate warning from check_global_declaration. */
4763 TREE_NO_WARNING (decl
) = 1;
4767 /* So must decls that use a type with no linkage. */
4768 FOR_EACH_VEC_SAFE_ELT (no_linkage_decls
, i
, decl
)
4769 no_linkage_error (decl
);
4771 maybe_warn_sized_delete ();
4773 /* Then, do the Objective-C stuff. This is where all the
4774 Objective-C module stuff gets generated (symtab,
4775 class/protocol/selector lists etc). This must be done after C++
4776 templates, destructors etc. so that selectors used in C++
4777 templates are properly allocated. */
4778 if (c_dialect_objc ())
4779 objc_write_global_declarations ();
4781 /* We give C linkage to static constructors and destructors. */
4782 push_lang_context (lang_name_c
);
4784 /* Generate initialization and destruction functions for all
4785 priorities for which they are required. */
4786 if (priority_info_map
)
4787 splay_tree_foreach (priority_info_map
,
4788 generate_ctor_and_dtor_functions_for_priority
,
4789 /*data=*/&locus_at_end_of_parsing
);
4790 else if (c_dialect_objc () && objc_static_init_needed_p ())
4791 /* If this is obj-c++ and we need a static init, call
4792 generate_ctor_or_dtor_function. */
4793 generate_ctor_or_dtor_function (/*constructor_p=*/true,
4794 DEFAULT_INIT_PRIORITY
,
4795 &locus_at_end_of_parsing
);
4797 /* We're done with the splay-tree now. */
4798 if (priority_info_map
)
4799 splay_tree_delete (priority_info_map
);
4801 /* Generate any missing aliases. */
4802 maybe_apply_pending_pragma_weaks ();
4804 /* We're done with static constructors, so we can go back to "C++"
4806 pop_lang_context ();
4808 /* Generate Java hidden aliases. */
4809 build_java_method_aliases ();
4811 if (flag_vtable_verify
)
4813 vtv_recover_class_info ();
4814 vtv_compute_class_hierarchy_transitive_closure ();
4815 vtv_build_vtable_verify_fndecl ();
4818 perform_deferred_noexcept_checks ();
4822 /* The entire file is now complete. If requested, dump everything
4826 if (flag_detailed_statistics
)
4828 dump_tree_statistics ();
4829 dump_time_statistics ();
4832 timevar_stop (TV_PHASE_DEFERRED
);
4833 timevar_start (TV_PHASE_PARSING
);
4836 /* Perform any post compilation-proper cleanups for the C++ front-end.
4837 This should really go away. No front-end should need to do
4838 anything past the compilation process. */
4841 cxx_post_compilation_parsing_cleanups (void)
4843 timevar_start (TV_PHASE_LATE_PARSING_CLEANUPS
);
4845 if (flag_vtable_verify
)
4847 /* Generate the special constructor initialization function that
4848 calls __VLTRegisterPairs, and give it a very high
4849 initialization priority. This must be done after
4850 finalize_compilation_unit so that we have accurate
4851 information about which vtable will actually be emitted. */
4852 vtv_generate_init_routine ();
4855 input_location
= locus_at_end_of_parsing
;
4857 #ifdef ENABLE_CHECKING
4858 validate_conversion_obstack ();
4859 #endif /* ENABLE_CHECKING */
4861 timevar_stop (TV_PHASE_LATE_PARSING_CLEANUPS
);
4864 /* FN is an OFFSET_REF, DOTSTAR_EXPR or MEMBER_REF indicating the
4865 function to call in parse-tree form; it has not yet been
4866 semantically analyzed. ARGS are the arguments to the function.
4867 They have already been semantically analyzed. This may change
4871 build_offset_ref_call_from_tree (tree fn
, vec
<tree
, va_gc
> **args
,
4872 tsubst_flags_t complain
)
4875 vec
<tree
, va_gc
> *orig_args
= NULL
;
4880 object
= TREE_OPERAND (fn
, 0);
4882 if (processing_template_decl
)
4884 gcc_assert (TREE_CODE (fn
) == DOTSTAR_EXPR
4885 || TREE_CODE (fn
) == MEMBER_REF
);
4886 if (type_dependent_expression_p (fn
)
4887 || any_type_dependent_arguments_p (*args
))
4888 return build_nt_call_vec (fn
, *args
);
4890 orig_args
= make_tree_vector_copy (*args
);
4892 /* Transform the arguments and add the implicit "this"
4893 parameter. That must be done before the FN is transformed
4894 because we depend on the form of FN. */
4895 make_args_non_dependent (*args
);
4896 object
= build_non_dependent_expr (object
);
4897 if (TREE_CODE (TREE_TYPE (fn
)) == METHOD_TYPE
)
4899 if (TREE_CODE (fn
) == DOTSTAR_EXPR
)
4900 object
= cp_build_addr_expr (object
, complain
);
4901 vec_safe_insert (*args
, 0, object
);
4903 /* Now that the arguments are done, transform FN. */
4904 fn
= build_non_dependent_expr (fn
);
4907 /* A qualified name corresponding to a bound pointer-to-member is
4908 represented as an OFFSET_REF:
4910 struct B { void g(); };
4912 void B::g() { (this->*p)(); } */
4913 if (TREE_CODE (fn
) == OFFSET_REF
)
4915 tree object_addr
= cp_build_addr_expr (object
, complain
);
4916 fn
= TREE_OPERAND (fn
, 1);
4917 fn
= get_member_function_from_ptrfunc (&object_addr
, fn
,
4919 vec_safe_insert (*args
, 0, object_addr
);
4922 if (CLASS_TYPE_P (TREE_TYPE (fn
)))
4923 expr
= build_op_call (fn
, args
, complain
);
4925 expr
= cp_build_function_call_vec (fn
, args
, complain
);
4926 if (processing_template_decl
&& expr
!= error_mark_node
)
4927 expr
= build_min_non_dep_call_vec (expr
, orig_fn
, orig_args
);
4929 if (orig_args
!= NULL
)
4930 release_tree_vector (orig_args
);
4937 check_default_args (tree x
)
4939 tree arg
= TYPE_ARG_TYPES (TREE_TYPE (x
));
4940 bool saw_def
= false;
4941 int i
= 0 - (TREE_CODE (TREE_TYPE (x
)) == METHOD_TYPE
);
4942 for (; arg
&& arg
!= void_list_node
; arg
= TREE_CHAIN (arg
), ++i
)
4944 if (TREE_PURPOSE (arg
))
4946 else if (saw_def
&& !PACK_EXPANSION_P (TREE_VALUE (arg
)))
4948 error ("default argument missing for parameter %P of %q+#D", i
, x
);
4949 TREE_PURPOSE (arg
) = error_mark_node
;
4954 /* Return true if function DECL can be inlined. This is used to force
4955 instantiation of methods that might be interesting for inlining. */
4957 possibly_inlined_p (tree decl
)
4959 gcc_assert (TREE_CODE (decl
) == FUNCTION_DECL
);
4960 if (DECL_UNINLINABLE (decl
))
4962 if (!optimize
|| pragma_java_exceptions
)
4963 return DECL_DECLARED_INLINE_P (decl
);
4964 /* When optimizing, we might inline everything when flatten
4965 attribute or heuristics inlining for size or autoinlining
4970 /* Mark DECL (either a _DECL or a BASELINK) as "used" in the program.
4971 If DECL is a specialization or implicitly declared class member,
4972 generate the actual definition. Return false if something goes
4973 wrong, true otherwise. */
4976 mark_used (tree decl
, tsubst_flags_t complain
)
4978 /* If DECL is a BASELINK for a single function, then treat it just
4979 like the DECL for the function. Otherwise, if the BASELINK is
4980 for an overloaded function, we don't know which function was
4981 actually used until after overload resolution. */
4982 if (BASELINK_P (decl
))
4984 decl
= BASELINK_FUNCTIONS (decl
);
4985 if (really_overloaded_fn (decl
))
4987 decl
= OVL_CURRENT (decl
);
4990 /* Set TREE_USED for the benefit of -Wunused. */
4991 TREE_USED (decl
) = 1;
4992 if (DECL_CLONED_FUNCTION_P (decl
))
4993 TREE_USED (DECL_CLONED_FUNCTION (decl
)) = 1;
4995 /* Mark enumeration types as used. */
4996 if (TREE_CODE (decl
) == CONST_DECL
)
4997 used_types_insert (DECL_CONTEXT (decl
));
4999 if (TREE_CODE (decl
) == FUNCTION_DECL
)
5000 maybe_instantiate_noexcept (decl
);
5002 if (TREE_CODE (decl
) == FUNCTION_DECL
5003 && DECL_DELETED_FN (decl
))
5005 if (DECL_ARTIFICIAL (decl
))
5007 if (DECL_OVERLOADED_OPERATOR_P (decl
) == TYPE_EXPR
5008 && LAMBDA_TYPE_P (DECL_CONTEXT (decl
)))
5010 /* We mark a lambda conversion op as deleted if we can't
5011 generate it properly; see maybe_add_lambda_conv_op. */
5012 sorry ("converting lambda which uses %<...%> to "
5013 "function pointer");
5017 if (complain
& tf_error
)
5019 error ("use of deleted function %qD", decl
);
5020 if (!maybe_explain_implicit_delete (decl
))
5021 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
5026 if (TREE_DEPRECATED (decl
) && (complain
& tf_warning
)
5027 && deprecated_state
!= DEPRECATED_SUPPRESS
)
5028 warn_deprecated_use (decl
, NULL_TREE
);
5030 /* We can only check DECL_ODR_USED on variables or functions with
5031 DECL_LANG_SPECIFIC set, and these are also the only decls that we
5032 might need special handling for. */
5033 if (!VAR_OR_FUNCTION_DECL_P (decl
)
5034 || DECL_LANG_SPECIFIC (decl
) == NULL
5035 || DECL_THUNK_P (decl
))
5037 if (!processing_template_decl
&& type_uses_auto (TREE_TYPE (decl
)))
5039 if (complain
& tf_error
)
5040 error ("use of %qD before deduction of %<auto%>", decl
);
5046 /* We only want to do this processing once. We don't need to keep trying
5047 to instantiate inline templates, because unit-at-a-time will make sure
5048 we get them compiled before functions that want to inline them. */
5049 if (DECL_ODR_USED (decl
))
5052 /* If within finish_function, defer the rest until that function
5053 finishes, otherwise it might recurse. */
5054 if (defer_mark_used_calls
)
5056 vec_safe_push (deferred_mark_used_calls
, decl
);
5060 /* Normally, we can wait until instantiation-time to synthesize DECL.
5061 However, if DECL is a static data member initialized with a constant
5062 or a constexpr function, we need it right now because a reference to
5063 such a data member or a call to such function is not value-dependent.
5064 For a function that uses auto in the return type, we need to instantiate
5065 it to find out its type. For OpenMP user defined reductions, we need
5066 them instantiated for reduction clauses which inline them by hand
5068 if (DECL_LANG_SPECIFIC (decl
)
5069 && DECL_TEMPLATE_INFO (decl
)
5070 && (decl_maybe_constant_var_p (decl
)
5071 || (TREE_CODE (decl
) == FUNCTION_DECL
5072 && DECL_OMP_DECLARE_REDUCTION_P (decl
))
5073 || undeduced_auto_decl (decl
))
5074 && !uses_template_parms (DECL_TI_ARGS (decl
)))
5076 /* Instantiating a function will result in garbage collection. We
5077 must treat this situation as if we were within the body of a
5078 function so as to avoid collecting live data only referenced from
5079 the stack (such as overload resolution candidates). */
5081 instantiate_decl (decl
, /*defer_ok=*/false,
5082 /*expl_inst_class_mem_p=*/false);
5086 if (processing_template_decl
|| in_template_function ())
5089 /* Check this too in case we're within instantiate_non_dependent_expr. */
5090 if (DECL_TEMPLATE_INFO (decl
)
5091 && uses_template_parms (DECL_TI_ARGS (decl
)))
5094 if (undeduced_auto_decl (decl
))
5096 if (complain
& tf_error
)
5097 error ("use of %qD before deduction of %<auto%>", decl
);
5101 /* If we don't need a value, then we don't need to synthesize DECL. */
5102 if (cp_unevaluated_operand
!= 0)
5105 DECL_ODR_USED (decl
) = 1;
5106 if (DECL_CLONED_FUNCTION_P (decl
))
5107 DECL_ODR_USED (DECL_CLONED_FUNCTION (decl
)) = 1;
5109 /* DR 757: A type without linkage shall not be used as the type of a
5110 variable or function with linkage, unless
5111 o the variable or function has extern "C" linkage (7.5 [dcl.link]), or
5112 o the variable or function is not used (3.2 [basic.def.odr]) or is
5113 defined in the same translation unit. */
5114 if (cxx_dialect
> cxx98
5115 && decl_linkage (decl
) != lk_none
5116 && !DECL_EXTERN_C_P (decl
)
5117 && !DECL_ARTIFICIAL (decl
)
5118 && !decl_defined_p (decl
)
5119 && no_linkage_check (TREE_TYPE (decl
), /*relaxed_p=*/false))
5121 if (is_local_extern (decl
))
5122 /* There's no way to define a local extern, and adding it to
5123 the vector interferes with GC, so give an error now. */
5124 no_linkage_error (decl
);
5126 vec_safe_push (no_linkage_decls
, decl
);
5129 if (TREE_CODE (decl
) == FUNCTION_DECL
&& DECL_DECLARED_INLINE_P (decl
)
5130 && !DECL_INITIAL (decl
) && !DECL_ARTIFICIAL (decl
))
5131 /* Remember it, so we can check it was defined. */
5132 note_vague_linkage_fn (decl
);
5134 /* Is it a synthesized method that needs to be synthesized? */
5135 if (TREE_CODE (decl
) == FUNCTION_DECL
5136 && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl
)
5137 && DECL_DEFAULTED_FN (decl
)
5138 /* A function defaulted outside the class is synthesized either by
5139 cp_finish_decl or instantiate_decl. */
5140 && !DECL_DEFAULTED_OUTSIDE_CLASS_P (decl
)
5141 && ! DECL_INITIAL (decl
))
5143 /* Defer virtual destructors so that thunks get the right
5145 if (DECL_VIRTUAL_P (decl
) && !at_eof
)
5147 note_vague_linkage_fn (decl
);
5151 /* Remember the current location for a function we will end up
5152 synthesizing. Then we can inform the user where it was
5153 required in the case of error. */
5154 DECL_SOURCE_LOCATION (decl
) = input_location
;
5156 /* Synthesizing an implicitly defined member function will result in
5157 garbage collection. We must treat this situation as if we were
5158 within the body of a function so as to avoid collecting live data
5159 on the stack (such as overload resolution candidates).
5161 We could just let cp_write_global_declarations handle synthesizing
5162 this function by adding it to deferred_fns, but doing
5163 it at the use site produces better error messages. */
5165 synthesize_method (decl
);
5167 /* If this is a synthesized method we don't need to
5168 do the instantiation test below. */
5170 else if (VAR_OR_FUNCTION_DECL_P (decl
)
5171 && DECL_TEMPLATE_INFO (decl
)
5172 && (!DECL_EXPLICIT_INSTANTIATION (decl
)
5173 || always_instantiate_p (decl
)))
5174 /* If this is a function or variable that is an instance of some
5175 template, we now know that we will need to actually do the
5176 instantiation. We check that DECL is not an explicit
5177 instantiation because that is not checked in instantiate_decl.
5179 We put off instantiating functions in order to improve compile
5180 times. Maintaining a stack of active functions is expensive,
5181 and the inliner knows to instantiate any functions it might
5182 need. Therefore, we always try to defer instantiation. */
5185 instantiate_decl (decl
, /*defer_ok=*/true,
5186 /*expl_inst_class_mem_p=*/false);
5194 mark_used (tree decl
)
5196 return mark_used (decl
, tf_warning_or_error
);
5200 vtv_start_verification_constructor_init_function (void)
5202 return start_objects ('I', MAX_RESERVED_INIT_PRIORITY
- 1);
5206 vtv_finish_verification_constructor_init_function (tree function_body
)
5210 finish_compound_stmt (function_body
);
5211 fn
= finish_function (0);
5212 DECL_STATIC_CONSTRUCTOR (fn
) = 1;
5213 decl_init_priority_insert (fn
, MAX_RESERVED_INIT_PRIORITY
- 1);
5218 #include "gt-cp-decl2.h"