1 /* RunTime Type Identification
2 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
3 Free Software Foundation, Inc.
4 Mostly written by Jason Merrill (jason@cygnus.com).
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2, or (at your option)
13 GCC is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING. If not, write to
20 the Free Software Foundation, 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
26 #include "coretypes.h"
35 /* C++ returns type information to the user in struct type_info
36 objects. We also use type information to implement dynamic_cast and
37 exception handlers. Type information for a particular type is
38 indicated with an ABI defined structure derived from type_info.
39 This would all be very straight forward, but for the fact that the
40 runtime library provides the definitions of the type_info structure
41 and the ABI defined derived classes. We cannot build declarations
42 of them directly in the compiler, but we need to layout objects of
43 their type. Somewhere we have to lie.
45 We define layout compatible POD-structs with compiler-defined names
46 and generate the appropriate initializations for them (complete
47 with explicit mention of their vtable). When we have to provide a
48 type_info to the user we reinterpret_cast the internal compiler
49 type to type_info. A well formed program can only explicitly refer
50 to the type_infos of complete types (& cv void). However, we chain
51 pointer type_infos to the pointed-to-type, and that can be
52 incomplete. We only need the addresses of such incomplete
53 type_info objects for static initialization.
55 The type information VAR_DECL of a type is held on the
56 IDENTIFIER_GLOBAL_VALUE of the type's mangled name. That VAR_DECL
57 will be the internal type. It will usually have the correct
58 internal type reflecting the kind of type it represents (pointer,
59 array, function, class, inherited class, etc). When the type it
60 represents is incomplete, it will have the internal type
61 corresponding to type_info. That will only happen at the end of
62 translation, when we are emitting the type info objects. */
64 /* Accessors for the type_info objects. We need to remember several things
65 about each of the type_info types. The global tree nodes such as
66 bltn_desc_type_node are TREE_LISTs, and these macros are used to access
67 the required information. */
68 /* The RECORD_TYPE of a type_info derived class. */
69 #define TINFO_PSEUDO_TYPE(NODE) TREE_TYPE (NODE)
70 /* The VAR_DECL of the vtable for the type_info derived class.
71 This is only filled in at the end of the translation. */
72 #define TINFO_VTABLE_DECL(NODE) TREE_VALUE (NODE)
73 /* The IDENTIFIER_NODE naming the real class. */
74 #define TINFO_REAL_NAME(NODE) TREE_PURPOSE (NODE)
76 static tree build_headof
PARAMS((tree
));
77 static tree ifnonnull
PARAMS((tree
, tree
));
78 static tree tinfo_name
PARAMS((tree
));
79 static tree build_dynamic_cast_1
PARAMS((tree
, tree
));
80 static tree throw_bad_cast
PARAMS((void));
81 static tree throw_bad_typeid
PARAMS((void));
82 static tree get_tinfo_decl_dynamic
PARAMS((tree
));
83 static tree get_tinfo_ptr
PARAMS((tree
));
84 static bool typeid_ok_p
PARAMS((void));
85 static int qualifier_flags
PARAMS((tree
));
86 static bool target_incomplete_p (tree
);
87 static tree tinfo_base_init
PARAMS((tree
, tree
));
88 static tree generic_initializer
PARAMS((tree
, tree
));
89 static tree
ptr_initializer (tree
, tree
, bool *);
90 static tree
ptm_initializer (tree
, tree
, bool *);
91 static tree dfs_class_hint_mark
PARAMS ((tree
, void *));
92 static tree dfs_class_hint_unmark
PARAMS ((tree
, void *));
93 static int class_hint_flags
PARAMS((tree
));
94 static tree class_initializer
PARAMS((tree
, tree
, tree
));
95 static tree create_pseudo_type_info
PARAMS((const char *, int, ...));
96 static tree get_pseudo_ti_init
PARAMS ((tree
, tree
, bool *));
97 static tree get_pseudo_ti_desc
PARAMS((tree
));
98 static void create_tinfo_types
PARAMS((void));
99 static bool typeinfo_in_lib_p (tree
);
101 static int doing_runtime
= 0;
104 /* Declare language defined type_info type and a pointer to const
105 type_info. This is incomplete here, and will be completed when
106 the user #includes <typeinfo>. There are language defined
107 restrictions on what can be done until that is included. Create
108 the internal versions of the ABI types. */
111 init_rtti_processing (void)
113 tree const_type_info_type
;
115 push_namespace (std_identifier
);
117 = xref_tag (class_type
, get_identifier ("type_info"),
118 /*attributes=*/NULL_TREE
, 1);
120 const_type_info_type
= build_qualified_type (type_info_type_node
,
122 type_info_ptr_type
= build_pointer_type (const_type_info_type
);
123 type_info_ref_type
= build_reference_type (const_type_info_type
);
125 create_tinfo_types ();
128 /* Given the expression EXP of type `class *', return the head of the
129 object pointed to by EXP with type cv void*, if the class has any
130 virtual functions (TYPE_POLYMORPHIC_P), else just return the
134 build_headof (tree exp
)
136 tree type
= TREE_TYPE (exp
);
140 my_friendly_assert (TREE_CODE (type
) == POINTER_TYPE
, 20000112);
141 type
= TREE_TYPE (type
);
143 if (!TYPE_POLYMORPHIC_P (type
))
146 /* We use this a couple of times below, protect it. */
147 exp
= save_expr (exp
);
149 /* The offset-to-top field is at index -2 from the vptr. */
150 index
= build_int_2 (-2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE
, -1);
152 offset
= build_vtbl_ref (build_indirect_ref (exp
, NULL
), index
);
154 type
= build_qualified_type (ptr_type_node
,
155 cp_type_quals (TREE_TYPE (exp
)));
156 return build (PLUS_EXPR
, type
, exp
,
157 cp_convert (ptrdiff_type_node
, offset
));
160 /* Get a bad_cast node for the program to throw...
162 See libstdc++/exception.cc for __throw_bad_cast */
165 throw_bad_cast (void)
167 tree fn
= get_identifier ("__cxa_bad_cast");
168 if (IDENTIFIER_GLOBAL_VALUE (fn
))
169 fn
= IDENTIFIER_GLOBAL_VALUE (fn
);
171 fn
= push_throw_library_fn (fn
, build_function_type (ptr_type_node
,
174 return build_call (fn
, NULL_TREE
);
177 /* Return an expression for "__cxa_bad_typeid()". The expression
178 returned is an lvalue of type "const std::type_info". */
181 throw_bad_typeid (void)
183 tree fn
= get_identifier ("__cxa_bad_typeid");
184 if (IDENTIFIER_GLOBAL_VALUE (fn
))
185 fn
= IDENTIFIER_GLOBAL_VALUE (fn
);
188 tree t
= build_qualified_type (type_info_type_node
, TYPE_QUAL_CONST
);
189 t
= build_function_type (build_reference_type (t
), void_list_node
);
190 fn
= push_throw_library_fn (fn
, t
);
193 return convert_from_reference (build_call (fn
, NULL_TREE
));
196 /* Return an lvalue expression whose type is "const std::type_info"
197 and whose value indicates the type of the expression EXP. If EXP
198 is a reference to a polymorphic class, return the dynamic type;
199 otherwise return the static type of the expression. */
202 get_tinfo_decl_dynamic (tree exp
)
207 if (exp
== error_mark_node
)
208 return error_mark_node
;
210 type
= TREE_TYPE (exp
);
212 /* peel back references, so they match. */
213 if (TREE_CODE (type
) == REFERENCE_TYPE
)
214 type
= TREE_TYPE (type
);
216 /* Peel off cv qualifiers. */
217 type
= TYPE_MAIN_VARIANT (type
);
219 if (!VOID_TYPE_P (type
))
220 type
= complete_type_or_else (type
, exp
);
223 return error_mark_node
;
225 /* If exp is a reference to polymorphic type, get the real type_info. */
226 if (TYPE_POLYMORPHIC_P (type
) && ! resolves_to_fixed_type_p (exp
, 0))
228 /* build reference to type_info from vtable. */
231 /* The RTTI information is at index -1. */
232 index
= build_int_2 (-1 * TARGET_VTABLE_DATA_ENTRY_DISTANCE
, -1);
233 t
= build_vtbl_ref (exp
, index
);
234 TREE_TYPE (t
) = type_info_ptr_type
;
237 /* Otherwise return the type_info for the static type of the expr. */
238 t
= get_tinfo_ptr (TYPE_MAIN_VARIANT (type
));
240 return build_indirect_ref (t
, NULL
);
248 error ("cannot use typeid with -fno-rtti");
252 if (!COMPLETE_TYPE_P (type_info_type_node
))
254 error ("must #include <typeinfo> before using typeid");
261 /* Return an expression for "typeid(EXP)". The expression returned is
262 an lvalue of type "const std::type_info". */
265 build_typeid (tree exp
)
267 tree cond
= NULL_TREE
;
270 if (exp
== error_mark_node
|| !typeid_ok_p ())
271 return error_mark_node
;
273 if (processing_template_decl
)
274 return build_min (TYPEID_EXPR
, type_info_ref_type
, exp
);
276 if (TREE_CODE (exp
) == INDIRECT_REF
277 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp
, 0))) == POINTER_TYPE
278 && TYPE_POLYMORPHIC_P (TREE_TYPE (exp
))
279 && ! resolves_to_fixed_type_p (exp
, &nonnull
)
282 exp
= stabilize_reference (exp
);
283 cond
= cp_convert (boolean_type_node
, TREE_OPERAND (exp
, 0));
286 exp
= get_tinfo_decl_dynamic (exp
);
288 if (exp
== error_mark_node
)
289 return error_mark_node
;
293 tree bad
= throw_bad_typeid ();
295 exp
= build (COND_EXPR
, TREE_TYPE (exp
), cond
, exp
, bad
);
301 /* Generate the NTBS name of a type. */
303 tinfo_name (tree type
)
308 name
= mangle_type_string (type
);
309 name_string
= fix_string_type (build_string (strlen (name
) + 1, name
));
313 /* Return a VAR_DECL for the internal ABI defined type_info object for
314 TYPE. You must arrange that the decl is mark_used, if actually use
315 it --- decls in vtables are only used if the vtable is output. */
318 get_tinfo_decl (tree type
)
323 if (COMPLETE_TYPE_P (type
)
324 && TREE_CODE (TYPE_SIZE (type
)) != INTEGER_CST
)
326 error ("cannot create type information for type `%T' because its size is variable",
328 return error_mark_node
;
331 if (TREE_CODE (type
) == OFFSET_TYPE
)
332 type
= TREE_TYPE (type
);
333 if (TREE_CODE (type
) == METHOD_TYPE
)
334 type
= build_function_type (TREE_TYPE (type
),
335 TREE_CHAIN (TYPE_ARG_TYPES (type
)));
337 /* For a class type, the variable is cached in the type node
339 if (CLASS_TYPE_P (type
))
341 d
= CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type
));
346 name
= mangle_typeinfo_for_type (type
);
348 d
= IDENTIFIER_GLOBAL_VALUE (name
);
351 tree var_desc
= get_pseudo_ti_desc (type
);
353 d
= build_lang_decl (VAR_DECL
, name
, TINFO_PSEUDO_TYPE (var_desc
));
355 DECL_ARTIFICIAL (d
) = 1;
356 TREE_READONLY (d
) = 1;
358 DECL_EXTERNAL (d
) = 1;
359 SET_DECL_ASSEMBLER_NAME (d
, name
);
361 cp_finish_decl (d
, NULL_TREE
, NULL_TREE
, 0);
363 pushdecl_top_level (d
);
365 if (CLASS_TYPE_P (type
))
366 CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type
)) = d
;
368 /* Remember the type it is for. */
369 TREE_TYPE (name
) = type
;
375 /* Return a pointer to a type_info object describing TYPE, suitably
376 cast to the language defined type. */
379 get_tinfo_ptr (tree type
)
381 tree exp
= get_tinfo_decl (type
);
383 /* Convert to type_info type. */
384 exp
= build_unary_op (ADDR_EXPR
, exp
, 0);
385 exp
= ocp_convert (type_info_ptr_type
, exp
, CONV_REINTERPRET
, 0);
390 /* Return the type_info object for TYPE. */
393 get_typeid (tree type
)
395 if (type
== error_mark_node
|| !typeid_ok_p ())
396 return error_mark_node
;
398 if (processing_template_decl
)
399 return build_min (TYPEID_EXPR
, type_info_ref_type
, type
);
401 /* If the type of the type-id is a reference type, the result of the
402 typeid expression refers to a type_info object representing the
404 if (TREE_CODE (type
) == REFERENCE_TYPE
)
405 type
= TREE_TYPE (type
);
407 /* The top-level cv-qualifiers of the lvalue expression or the type-id
408 that is the operand of typeid are always ignored. */
409 type
= TYPE_MAIN_VARIANT (type
);
411 if (!VOID_TYPE_P (type
))
412 type
= complete_type_or_else (type
, NULL_TREE
);
415 return error_mark_node
;
417 return build_indirect_ref (get_tinfo_ptr (type
), NULL
);
420 /* Check whether TEST is null before returning RESULT. If TEST is used in
421 RESULT, it must have previously had a save_expr applied to it. */
424 ifnonnull (tree test
, tree result
)
426 return build (COND_EXPR
, TREE_TYPE (result
),
427 build (EQ_EXPR
, boolean_type_node
, test
, integer_zero_node
),
428 cp_convert (TREE_TYPE (result
), integer_zero_node
),
432 /* Execute a dynamic cast, as described in section 5.2.6 of the 9/93 working
436 build_dynamic_cast_1 (tree type
, tree expr
)
438 enum tree_code tc
= TREE_CODE (type
);
439 tree exprtype
= TREE_TYPE (expr
);
441 tree old_expr
= expr
;
442 const char *errstr
= NULL
;
444 /* T shall be a pointer or reference to a complete class type, or
445 `pointer to cv void''. */
449 if (TREE_CODE (TREE_TYPE (type
)) == VOID_TYPE
)
452 if (! IS_AGGR_TYPE (TREE_TYPE (type
)))
454 errstr
= "target is not pointer or reference to class";
457 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type
))))
459 errstr
= "target is not pointer or reference to complete type";
465 errstr
= "target is not pointer or reference";
469 if (TREE_CODE (expr
) == OFFSET_REF
)
471 expr
= resolve_offset_ref (expr
);
472 exprtype
= TREE_TYPE (expr
);
475 if (tc
== POINTER_TYPE
)
476 expr
= convert_from_reference (expr
);
477 else if (TREE_CODE (exprtype
) != REFERENCE_TYPE
)
479 /* Apply trivial conversion T -> T& for dereferenced ptrs. */
480 exprtype
= build_reference_type (exprtype
);
481 expr
= convert_to_reference (exprtype
, expr
, CONV_IMPLICIT
,
482 LOOKUP_NORMAL
, NULL_TREE
);
485 exprtype
= TREE_TYPE (expr
);
487 if (tc
== POINTER_TYPE
)
489 /* If T is a pointer type, v shall be an rvalue of a pointer to
490 complete class type, and the result is an rvalue of type T. */
492 if (TREE_CODE (exprtype
) != POINTER_TYPE
)
494 errstr
= "source is not a pointer";
497 if (! IS_AGGR_TYPE (TREE_TYPE (exprtype
)))
499 errstr
= "source is not a pointer to class";
502 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (exprtype
))))
504 errstr
= "source is a pointer to incomplete type";
510 /* T is a reference type, v shall be an lvalue of a complete class
511 type, and the result is an lvalue of the type referred to by T. */
513 if (! IS_AGGR_TYPE (TREE_TYPE (exprtype
)))
515 errstr
= "source is not of class type";
518 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (exprtype
))))
520 errstr
= "source is of incomplete class type";
526 /* The dynamic_cast operator shall not cast away constness. */
527 if (!at_least_as_qualified_p (TREE_TYPE (type
),
528 TREE_TYPE (exprtype
)))
530 errstr
= "conversion casts away constness";
534 /* If *type is an unambiguous accessible base class of *exprtype,
535 convert statically. */
539 binfo
= lookup_base (TREE_TYPE (exprtype
), TREE_TYPE (type
),
540 ba_not_special
, NULL
);
544 expr
= build_base_path (PLUS_EXPR
, convert_from_reference (expr
),
546 if (TREE_CODE (exprtype
) == POINTER_TYPE
)
547 expr
= non_lvalue (expr
);
552 /* Otherwise *exprtype must be a polymorphic class (have a vtbl). */
553 if (TYPE_POLYMORPHIC_P (TREE_TYPE (exprtype
)))
556 /* if TYPE is `void *', return pointer to complete object. */
557 if (tc
== POINTER_TYPE
&& VOID_TYPE_P (TREE_TYPE (type
)))
559 /* if b is an object, dynamic_cast<void *>(&b) == (void *)&b. */
560 if (TREE_CODE (expr
) == ADDR_EXPR
561 && TREE_CODE (TREE_OPERAND (expr
, 0)) == VAR_DECL
562 && TREE_CODE (TREE_TYPE (TREE_OPERAND (expr
, 0))) == RECORD_TYPE
)
563 return build1 (NOP_EXPR
, type
, expr
);
565 /* Since expr is used twice below, save it. */
566 expr
= save_expr (expr
);
568 expr1
= build_headof (expr
);
569 if (TREE_TYPE (expr1
) != type
)
570 expr1
= build1 (NOP_EXPR
, type
, expr1
);
571 return ifnonnull (expr
, expr1
);
576 tree result
, td2
, td3
, elems
;
577 tree static_type
, target_type
, boff
;
579 /* If we got here, we can't convert statically. Therefore,
580 dynamic_cast<D&>(b) (b an object) cannot succeed. */
581 if (tc
== REFERENCE_TYPE
)
583 if (TREE_CODE (old_expr
) == VAR_DECL
584 && TREE_CODE (TREE_TYPE (old_expr
)) == RECORD_TYPE
)
586 tree expr
= throw_bad_cast ();
587 warning ("dynamic_cast of `%#D' to `%#T' can never succeed",
589 /* Bash it to the expected type. */
590 TREE_TYPE (expr
) = type
;
594 /* Ditto for dynamic_cast<D*>(&b). */
595 else if (TREE_CODE (expr
) == ADDR_EXPR
)
597 tree op
= TREE_OPERAND (expr
, 0);
598 if (TREE_CODE (op
) == VAR_DECL
599 && TREE_CODE (TREE_TYPE (op
)) == RECORD_TYPE
)
601 warning ("dynamic_cast of `%#D' to `%#T' can never succeed",
603 retval
= build_int_2 (0, 0);
604 TREE_TYPE (retval
) = type
;
609 target_type
= TYPE_MAIN_VARIANT (TREE_TYPE (type
));
610 static_type
= TYPE_MAIN_VARIANT (TREE_TYPE (exprtype
));
611 td2
= build_unary_op (ADDR_EXPR
, get_tinfo_decl (target_type
), 0);
612 td3
= build_unary_op (ADDR_EXPR
, get_tinfo_decl (static_type
), 0);
614 /* Determine how T and V are related. */
615 boff
= get_dynamic_cast_base_type (static_type
, target_type
);
617 /* Since expr is used twice below, save it. */
618 expr
= save_expr (expr
);
621 if (tc
== REFERENCE_TYPE
)
622 expr1
= build_unary_op (ADDR_EXPR
, expr1
, 0);
625 (NULL_TREE
, expr1
, tree_cons
626 (NULL_TREE
, td3
, tree_cons
627 (NULL_TREE
, td2
, tree_cons
628 (NULL_TREE
, boff
, NULL_TREE
))));
630 dcast_fn
= dynamic_cast_node
;
638 push_nested_namespace (ns
);
639 tinfo_ptr
= xref_tag (class_type
,
640 get_identifier ("__class_type_info"),
641 /*attributes=*/NULL_TREE
,
644 tinfo_ptr
= build_pointer_type
645 (build_qualified_type
646 (tinfo_ptr
, TYPE_QUAL_CONST
));
647 name
= "__dynamic_cast";
649 (NULL_TREE
, const_ptr_type_node
, tree_cons
650 (NULL_TREE
, tinfo_ptr
, tree_cons
651 (NULL_TREE
, tinfo_ptr
, tree_cons
652 (NULL_TREE
, ptrdiff_type_node
, void_list_node
))));
653 tmp
= build_function_type (ptr_type_node
, tmp
);
654 dcast_fn
= build_library_fn_ptr (name
, tmp
);
655 pop_nested_namespace (ns
);
656 dynamic_cast_node
= dcast_fn
;
658 result
= build_call (dcast_fn
, elems
);
660 if (tc
== REFERENCE_TYPE
)
662 tree bad
= throw_bad_cast ();
664 result
= save_expr (result
);
665 return build (COND_EXPR
, type
, result
, result
, bad
);
668 /* Now back to the type we want from a void*. */
669 result
= cp_convert (type
, result
);
670 return ifnonnull (expr
, result
);
674 errstr
= "source type is not polymorphic";
677 error ("cannot dynamic_cast `%E' (of type `%#T') to type `%#T' (%s)",
678 expr
, exprtype
, type
, errstr
);
679 return error_mark_node
;
683 build_dynamic_cast (tree type
, tree expr
)
685 if (type
== error_mark_node
|| expr
== error_mark_node
)
686 return error_mark_node
;
688 if (processing_template_decl
)
689 return build_min (DYNAMIC_CAST_EXPR
, type
, expr
);
691 return convert_from_reference (build_dynamic_cast_1 (type
, expr
));
694 /* Return the runtime bit mask encoding the qualifiers of TYPE. */
697 qualifier_flags (tree type
)
700 int quals
= cp_type_quals (type
);
702 if (quals
& TYPE_QUAL_CONST
)
704 if (quals
& TYPE_QUAL_VOLATILE
)
706 if (quals
& TYPE_QUAL_RESTRICT
)
711 /* Return true, if the pointer chain TYPE ends at an incomplete type, or
712 contains a pointer to member of an incomplete class. */
715 target_incomplete_p (tree type
)
717 while (TREE_CODE (type
) == POINTER_TYPE
)
718 if (TYPE_PTRMEM_P (type
))
720 if (!COMPLETE_TYPE_P (TYPE_PTRMEM_CLASS_TYPE (type
)))
722 type
= TYPE_PTRMEM_POINTED_TO_TYPE (type
);
725 type
= TREE_TYPE (type
);
726 if (!COMPLETE_OR_VOID_TYPE_P (type
))
732 /* Return a CONSTRUCTOR for the common part of the type_info objects. This
733 is the vtable pointer and NTBS name. The NTBS name is emitted as a
734 comdat const char array, so it becomes a unique key for the type. Generate
735 and emit that VAR_DECL here. (We can't always emit the type_info itself
736 as comdat, because of pointers to incomplete.) */
739 tinfo_base_init (tree desc
, tree target
)
741 tree init
= NULL_TREE
;
748 /* Generate the NTBS array variable. */
749 tree name_type
= build_cplus_array_type
750 (build_qualified_type (char_type_node
, TYPE_QUAL_CONST
),
752 tree name_string
= tinfo_name (target
);
754 name_name
= mangle_typeinfo_string_for_type (target
);
755 name_decl
= build_lang_decl (VAR_DECL
, name_name
, name_type
);
757 DECL_ARTIFICIAL (name_decl
) = 1;
758 TREE_READONLY (name_decl
) = 1;
759 TREE_STATIC (name_decl
) = 1;
760 DECL_EXTERNAL (name_decl
) = 0;
761 TREE_PUBLIC (name_decl
) = 1;
762 comdat_linkage (name_decl
);
763 /* External name of the string containing the type's name has a
765 SET_DECL_ASSEMBLER_NAME (name_decl
,
766 mangle_typeinfo_string_for_type (target
));
767 DECL_INITIAL (name_decl
) = name_string
;
768 cp_finish_decl (name_decl
, name_string
, NULL_TREE
, 0);
769 pushdecl_top_level (name_decl
);
772 vtable_ptr
= TINFO_VTABLE_DECL (desc
);
777 push_nested_namespace (abi_node
);
778 real_type
= xref_tag (class_type
, TINFO_REAL_NAME (desc
),
779 /*attributes=*/NULL_TREE
, 1);
780 pop_nested_namespace (abi_node
);
782 if (!COMPLETE_TYPE_P (real_type
))
784 /* We never saw a definition of this type, so we need to
785 tell the compiler that this is an exported class, as
786 indeed all of the __*_type_info classes are. */
787 SET_CLASSTYPE_INTERFACE_KNOWN (real_type
);
788 CLASSTYPE_INTERFACE_ONLY (real_type
) = 1;
791 vtable_ptr
= get_vtable_decl (real_type
, /*complete=*/1);
792 vtable_ptr
= build_unary_op (ADDR_EXPR
, vtable_ptr
, 0);
794 /* We need to point into the middle of the vtable. */
796 (PLUS_EXPR
, TREE_TYPE (vtable_ptr
), vtable_ptr
,
797 size_binop (MULT_EXPR
,
798 size_int (2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE
),
799 TYPE_SIZE_UNIT (vtable_entry_type
)));
800 TREE_CONSTANT (vtable_ptr
) = 1;
802 TINFO_VTABLE_DECL (desc
) = vtable_ptr
;
805 init
= tree_cons (NULL_TREE
, vtable_ptr
, init
);
807 init
= tree_cons (NULL_TREE
, decay_conversion (name_decl
), init
);
809 init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, nreverse (init
));
810 TREE_HAS_CONSTRUCTOR (init
) = TREE_CONSTANT (init
) = TREE_STATIC (init
) = 1;
811 init
= tree_cons (NULL_TREE
, init
, NULL_TREE
);
816 /* Return the CONSTRUCTOR expr for a type_info of TYPE. DESC provides the
817 information about the particular type_info derivation, which adds no
818 additional fields to the type_info base. */
821 generic_initializer (tree desc
, tree target
)
823 tree init
= tinfo_base_init (desc
, target
);
825 init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, init
);
826 TREE_HAS_CONSTRUCTOR (init
) = TREE_CONSTANT (init
) = TREE_STATIC (init
) = 1;
830 /* Return the CONSTRUCTOR expr for a type_info of pointer TYPE.
831 DESC provides information about the particular type_info derivation,
832 which adds target type and qualifier flags members to the type_info base. */
835 ptr_initializer (tree desc
, tree target
, bool *non_public_ptr
)
837 tree init
= tinfo_base_init (desc
, target
);
838 tree to
= TREE_TYPE (target
);
839 int flags
= qualifier_flags (to
);
840 bool incomplete
= target_incomplete_p (to
);
845 *non_public_ptr
= true;
847 init
= tree_cons (NULL_TREE
, build_int_2 (flags
, 0), init
);
848 init
= tree_cons (NULL_TREE
,
849 get_tinfo_ptr (TYPE_MAIN_VARIANT (to
)),
852 init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, nreverse (init
));
853 TREE_HAS_CONSTRUCTOR (init
) = TREE_CONSTANT (init
) = TREE_STATIC (init
) = 1;
857 /* Return the CONSTRUCTOR expr for a type_info of pointer to member data TYPE.
858 DESC provides information about the particular type_info derivation,
859 which adds class, target type and qualifier flags members to the type_info
863 ptm_initializer (tree desc
, tree target
, bool *non_public_ptr
)
865 tree init
= tinfo_base_init (desc
, target
);
866 tree to
= TYPE_PTRMEM_POINTED_TO_TYPE (target
);
867 tree klass
= TYPE_PTRMEM_CLASS_TYPE (target
);
868 int flags
= qualifier_flags (to
);
869 bool incomplete
= target_incomplete_p (to
);
874 *non_public_ptr
= true;
876 if (!COMPLETE_TYPE_P (klass
))
879 *non_public_ptr
= true;
881 init
= tree_cons (NULL_TREE
, build_int_2 (flags
, 0), init
);
882 init
= tree_cons (NULL_TREE
,
883 get_tinfo_ptr (TYPE_MAIN_VARIANT (to
)),
885 init
= tree_cons (NULL_TREE
,
886 get_tinfo_ptr (klass
),
889 init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, nreverse (init
));
890 TREE_HAS_CONSTRUCTOR (init
) = TREE_CONSTANT (init
) = TREE_STATIC (init
) = 1;
894 /* Check base BINFO to set hint flags in *DATA, which is really an int.
895 We use CLASSTYPE_MARKED to tag types we've found as non-virtual bases and
896 CLASSTYPE_MARKED2 to tag those which are virtual bases. Remember it is
897 possible for a type to be both a virtual and non-virtual base. */
900 dfs_class_hint_mark (tree binfo
, void *data
)
902 tree basetype
= BINFO_TYPE (binfo
);
903 int *hint
= (int *) data
;
905 if (TREE_VIA_VIRTUAL (binfo
))
907 if (CLASSTYPE_MARKED (basetype
))
909 if (CLASSTYPE_MARKED2 (basetype
))
911 SET_CLASSTYPE_MARKED2 (basetype
);
915 if (CLASSTYPE_MARKED (basetype
) || CLASSTYPE_MARKED2 (basetype
))
917 SET_CLASSTYPE_MARKED (basetype
);
922 /* Clear the base's dfs marks, after searching for duplicate bases. */
925 dfs_class_hint_unmark (tree binfo
, void *data ATTRIBUTE_UNUSED
)
927 tree basetype
= BINFO_TYPE (binfo
);
929 CLEAR_CLASSTYPE_MARKED (basetype
);
930 CLEAR_CLASSTYPE_MARKED2 (basetype
);
934 /* Determine the hint flags describing the features of a class's hierarchy. */
937 class_hint_flags (tree type
)
941 dfs_walk (TYPE_BINFO (type
), dfs_class_hint_mark
, NULL
, &hint_flags
);
942 dfs_walk (TYPE_BINFO (type
), dfs_class_hint_unmark
, NULL
, NULL
);
947 /* Return the CONSTRUCTOR expr for a type_info of class TYPE.
948 DESC provides information about the particular __class_type_info derivation,
949 which adds hint flags and TRAIL initializers to the type_info base. */
952 class_initializer (tree desc
, tree target
, tree trail
)
954 tree init
= tinfo_base_init (desc
, target
);
956 TREE_CHAIN (init
) = trail
;
957 init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, init
);
958 TREE_HAS_CONSTRUCTOR (init
) = TREE_CONSTANT (init
) = TREE_STATIC (init
) = 1;
962 /* Returns true if the typeinfo for type should be placed in
963 the runtime library. */
966 typeinfo_in_lib_p (tree type
)
968 /* The typeinfo objects for `T*' and `const T*' are in the runtime
969 library for simple types T. */
970 if (TREE_CODE (type
) == POINTER_TYPE
971 && (cp_type_quals (TREE_TYPE (type
)) == TYPE_QUAL_CONST
972 || cp_type_quals (TREE_TYPE (type
)) == TYPE_UNQUALIFIED
))
973 type
= TREE_TYPE (type
);
975 switch (TREE_CODE (type
))
989 /* Generate the initializer for the type info describing
990 TYPE. VAR_DESC is a . NON_PUBLIC_P is set nonzero, if the VAR_DECL
991 should not be exported from this object file. This should only be
992 called at the end of translation, when we know that no further
993 types will be completed. */
996 get_pseudo_ti_init (tree type
, tree var_desc
, bool *non_public_p
)
998 my_friendly_assert (at_eof
, 20021120);
999 switch (TREE_CODE (type
))
1002 if (TYPE_PTRMEM_P (type
))
1003 return ptm_initializer (var_desc
, type
, non_public_p
);
1005 return ptr_initializer (var_desc
, type
, non_public_p
);
1008 return generic_initializer (var_desc
, type
);
1011 return generic_initializer (var_desc
, type
);
1014 return generic_initializer (var_desc
, type
);
1018 if (TYPE_PTRMEMFUNC_P (type
))
1019 return ptm_initializer (var_desc
, type
, non_public_p
);
1020 else if (var_desc
== class_desc_type_node
)
1022 if (!COMPLETE_TYPE_P (type
))
1023 /* Emit a non-public class_type_info. */
1024 *non_public_p
= true;
1025 return class_initializer (var_desc
, type
, NULL_TREE
);
1027 else if (var_desc
== si_class_desc_type_node
)
1029 tree base_binfos
= BINFO_BASETYPES (TYPE_BINFO (type
));
1030 tree base_binfo
= TREE_VEC_ELT (base_binfos
, 0);
1031 tree tinfo
= get_tinfo_ptr (BINFO_TYPE (base_binfo
));
1032 tree base_inits
= tree_cons (NULL_TREE
, tinfo
, NULL_TREE
);
1034 return class_initializer (var_desc
, type
, base_inits
);
1038 int hint
= class_hint_flags (type
);
1039 tree binfo
= TYPE_BINFO (type
);
1040 int nbases
= BINFO_N_BASETYPES (binfo
);
1041 tree base_binfos
= BINFO_BASETYPES (binfo
);
1042 tree base_accesses
= BINFO_BASEACCESSES (binfo
);
1043 tree base_inits
= NULL_TREE
;
1046 /* Generate the base information initializer. */
1047 for (ix
= nbases
; ix
--;)
1049 tree base_binfo
= TREE_VEC_ELT (base_binfos
, ix
);
1050 tree base_init
= NULL_TREE
;
1055 if (TREE_VEC_ELT (base_accesses
, ix
) == access_public_node
)
1057 tinfo
= get_tinfo_ptr (BINFO_TYPE (base_binfo
));
1058 if (TREE_VIA_VIRTUAL (base_binfo
))
1060 /* We store the vtable offset at which the virtual
1061 base offset can be found. */
1062 offset
= BINFO_VPTR_FIELD (base_binfo
);
1063 offset
= convert (sizetype
, offset
);
1067 offset
= BINFO_OFFSET (base_binfo
);
1069 /* combine offset and flags into one field */
1070 offset
= cp_build_binary_op (LSHIFT_EXPR
, offset
,
1071 build_int_2 (8, 0));
1072 offset
= cp_build_binary_op (BIT_IOR_EXPR
, offset
,
1073 build_int_2 (flags
, 0));
1074 base_init
= tree_cons (NULL_TREE
, offset
, base_init
);
1075 base_init
= tree_cons (NULL_TREE
, tinfo
, base_init
);
1076 base_init
= build (CONSTRUCTOR
, NULL_TREE
, NULL_TREE
, base_init
);
1077 TREE_HAS_CONSTRUCTOR (base_init
) = 1;
1078 base_inits
= tree_cons (NULL_TREE
, base_init
, base_inits
);
1080 base_inits
= build (CONSTRUCTOR
,
1081 NULL_TREE
, NULL_TREE
, base_inits
);
1082 TREE_HAS_CONSTRUCTOR (base_inits
) = 1;
1083 base_inits
= tree_cons (NULL_TREE
, base_inits
, NULL_TREE
);
1084 /* Prepend the number of bases. */
1085 base_inits
= tree_cons (NULL_TREE
,
1086 build_int_2 (nbases
, 0), base_inits
);
1087 /* Prepend the hint flags. */
1088 base_inits
= tree_cons (NULL_TREE
,
1089 build_int_2 (hint
, 0), base_inits
);
1091 return class_initializer (var_desc
, type
, base_inits
);
1096 return generic_initializer (var_desc
, type
);
1100 /* Generate the RECORD_TYPE containing the data layout of a type_info
1101 derivative as used by the runtime. This layout must be consistent with
1102 that defined in the runtime support. Also generate the VAR_DECL for the
1103 type's vtable. We explicitly manage the vtable member, and name it for
1104 real type as used in the runtime. The RECORD type has a different name,
1105 to avoid collisions. Return a TREE_LIST who's TINFO_PSEUDO_TYPE
1106 is the generated type and TINFO_VTABLE_NAME is the name of the
1107 vtable. We have to delay generating the VAR_DECL of the vtable
1108 until the end of the translation, when we'll have seen the library
1109 definition, if there was one.
1111 REAL_NAME is the runtime's name of the type. Trailing arguments are
1112 additional FIELD_DECL's for the structure. The final argument must be
1116 create_pseudo_type_info (const char *real_name
, int ident
, ...)
1124 VA_OPEN (ap
, ident
);
1125 VA_FIXEDARG (ap
, const char *, real_name
);
1126 VA_FIXEDARG (ap
, int, ident
);
1128 /* Generate the pseudo type name. */
1129 pseudo_name
= (char *)alloca (strlen (real_name
) + 30);
1130 strcpy (pseudo_name
, real_name
);
1131 strcat (pseudo_name
, "_pseudo");
1133 sprintf (pseudo_name
+ strlen (pseudo_name
), "%d", ident
);
1135 /* First field is the pseudo type_info base class. */
1136 fields
= build_decl (FIELD_DECL
, NULL_TREE
, ti_desc_type_node
);
1138 /* Now add the derived fields. */
1139 while ((field_decl
= va_arg (ap
, tree
)))
1141 TREE_CHAIN (field_decl
) = fields
;
1142 fields
= field_decl
;
1145 /* Create the pseudo type. */
1146 pseudo_type
= make_aggr_type (RECORD_TYPE
);
1147 finish_builtin_struct (pseudo_type
, pseudo_name
, fields
, NULL_TREE
);
1148 CLASSTYPE_AS_BASE (pseudo_type
) = pseudo_type
;
1150 result
= tree_cons (NULL_TREE
, NULL_TREE
, NULL_TREE
);
1151 TINFO_REAL_NAME (result
) = get_identifier (real_name
);
1152 TINFO_PSEUDO_TYPE (result
) =
1153 cp_build_qualified_type (pseudo_type
, TYPE_QUAL_CONST
);
1159 /* Return a pseudo type info type node used to describe TYPE. TYPE
1160 must be a complete type (or cv void), except at the end of the
1161 translation unit. */
1164 get_pseudo_ti_desc (tree type
)
1166 switch (TREE_CODE (type
))
1169 return TYPE_PTRMEM_P (type
) ? ptm_desc_type_node
: ptr_desc_type_node
;
1171 return enum_desc_type_node
;
1173 return func_desc_type_node
;
1175 return ary_desc_type_node
;
1178 if (TYPE_PTRMEMFUNC_P (type
))
1179 return ptm_desc_type_node
;
1180 else if (!COMPLETE_TYPE_P (type
))
1183 cxx_incomplete_type_error (NULL_TREE
, type
);
1184 return class_desc_type_node
;
1186 else if (!CLASSTYPE_N_BASECLASSES (type
))
1187 return class_desc_type_node
;
1190 tree binfo
= TYPE_BINFO (type
);
1191 tree base_binfos
= BINFO_BASETYPES (binfo
);
1192 tree base_accesses
= BINFO_BASEACCESSES (binfo
);
1193 tree base_binfo
= TREE_VEC_ELT (base_binfos
, 0);
1194 int num_bases
= TREE_VEC_LENGTH (base_binfos
);
1197 && TREE_VEC_ELT (base_accesses
, 0) == access_public_node
1198 && !TREE_VIA_VIRTUAL (base_binfo
)
1199 && integer_zerop (BINFO_OFFSET (base_binfo
)))
1200 /* single non-virtual public. */
1201 return si_class_desc_type_node
;
1205 tree array_domain
, base_array
;
1207 if (TREE_VEC_LENGTH (vmi_class_desc_type_node
) <= num_bases
)
1210 tree extend
= make_tree_vec (num_bases
+ 5);
1212 for (ix
= TREE_VEC_LENGTH (vmi_class_desc_type_node
); ix
--;)
1213 TREE_VEC_ELT (extend
, ix
)
1214 = TREE_VEC_ELT (vmi_class_desc_type_node
, ix
);
1215 vmi_class_desc_type_node
= extend
;
1217 var_desc
= TREE_VEC_ELT (vmi_class_desc_type_node
, num_bases
);
1221 /* Create the array of __base_class_type_info entries.
1222 G++ 3.2 allocated an array that had one too many
1223 entries, and then filled that extra entries with
1225 if (abi_version_at_least (2))
1226 array_domain
= build_index_type (size_int (num_bases
- 1));
1228 array_domain
= build_index_type (size_int (num_bases
));
1230 build_array_type (base_desc_type_node
, array_domain
);
1232 push_nested_namespace (abi_node
);
1233 var_desc
= create_pseudo_type_info
1234 ("__vmi_class_type_info", num_bases
,
1235 build_decl (FIELD_DECL
, NULL_TREE
, integer_type_node
),
1236 build_decl (FIELD_DECL
, NULL_TREE
, integer_type_node
),
1237 build_decl (FIELD_DECL
, NULL_TREE
, base_array
),
1239 pop_nested_namespace (abi_node
);
1241 TREE_VEC_ELT (vmi_class_desc_type_node
, num_bases
) = var_desc
;
1246 return bltn_desc_type_node
;
1250 /* Make sure the required builtin types exist for generating the type_info
1251 varable definitions. */
1254 create_tinfo_types (void)
1256 my_friendly_assert (!ti_desc_type_node
, 20020609);
1258 push_nested_namespace (abi_node
);
1260 /* Create the internal type_info structure. This is used as a base for
1261 the other structures. */
1265 ti_desc_type_node
= make_aggr_type (RECORD_TYPE
);
1266 field
= build_decl (FIELD_DECL
, NULL_TREE
, const_ptr_type_node
);
1269 field
= build_decl (FIELD_DECL
, NULL_TREE
, const_string_type_node
);
1270 TREE_CHAIN (field
) = fields
;
1273 finish_builtin_struct (ti_desc_type_node
, "__type_info_pseudo",
1275 TYPE_HAS_CONSTRUCTOR (ti_desc_type_node
) = 1;
1278 /* Fundamental type_info */
1279 bltn_desc_type_node
= create_pseudo_type_info
1280 ("__fundamental_type_info", 0,
1283 /* Array, function and enum type_info. No additional fields. */
1284 ary_desc_type_node
= create_pseudo_type_info
1285 ("__array_type_info", 0,
1287 func_desc_type_node
= create_pseudo_type_info
1288 ("__function_type_info", 0,
1290 enum_desc_type_node
= create_pseudo_type_info
1291 ("__enum_type_info", 0,
1294 /* Class type_info. Add a flags field. */
1295 class_desc_type_node
= create_pseudo_type_info
1296 ("__class_type_info", 0,
1299 /* Single public non-virtual base class. Add pointer to base class.
1300 This is really a descendant of __class_type_info. */
1301 si_class_desc_type_node
= create_pseudo_type_info
1302 ("__si_class_type_info", 0,
1303 build_decl (FIELD_DECL
, NULL_TREE
, type_info_ptr_type
),
1306 /* Base class internal helper. Pointer to base type, offset to base,
1311 field
= build_decl (FIELD_DECL
, NULL_TREE
, type_info_ptr_type
);
1314 field
= build_decl (FIELD_DECL
, NULL_TREE
, integer_types
[itk_long
]);
1315 TREE_CHAIN (field
) = fields
;
1318 base_desc_type_node
= make_aggr_type (RECORD_TYPE
);
1319 finish_builtin_struct (base_desc_type_node
, "__base_class_type_info_pseudo",
1321 TYPE_HAS_CONSTRUCTOR (base_desc_type_node
) = 1;
1324 /* General hierarchy is created as necessary in this vector. */
1325 vmi_class_desc_type_node
= make_tree_vec (10);
1327 /* Pointer type_info. Adds two fields, qualification mask
1328 and pointer to the pointed to type. This is really a descendant of
1329 __pbase_type_info. */
1330 ptr_desc_type_node
= create_pseudo_type_info
1331 ("__pointer_type_info", 0,
1332 build_decl (FIELD_DECL
, NULL_TREE
, integer_type_node
),
1333 build_decl (FIELD_DECL
, NULL_TREE
, type_info_ptr_type
),
1336 /* Pointer to member data type_info. Add qualifications flags,
1337 pointer to the member's type info and pointer to the class.
1338 This is really a descendant of __pbase_type_info. */
1339 ptm_desc_type_node
= create_pseudo_type_info
1340 ("__pointer_to_member_type_info", 0,
1341 build_decl (FIELD_DECL
, NULL_TREE
, integer_type_node
),
1342 build_decl (FIELD_DECL
, NULL_TREE
, type_info_ptr_type
),
1343 build_decl (FIELD_DECL
, NULL_TREE
, type_info_ptr_type
),
1346 pop_nested_namespace (abi_node
);
1349 /* Emit the type_info descriptors which are guaranteed to be in the runtime
1350 support. Generating them here guarantees consistency with the other
1351 structures. We use the following heuristic to determine when the runtime
1352 is being generated. If std::__fundamental_type_info is defined, and its
1353 destructor is defined, then the runtime is being built. */
1356 emit_support_tinfos (void)
1358 static tree
*const fundamentals
[] =
1363 &char_type_node
, &signed_char_type_node
, &unsigned_char_type_node
,
1364 &short_integer_type_node
, &short_unsigned_type_node
,
1365 &integer_type_node
, &unsigned_type_node
,
1366 &long_integer_type_node
, &long_unsigned_type_node
,
1367 &long_long_integer_type_node
, &long_long_unsigned_type_node
,
1368 &float_type_node
, &double_type_node
, &long_double_type_node
,
1372 tree bltn_type
, dtor
;
1374 push_nested_namespace (abi_node
);
1375 bltn_type
= xref_tag (class_type
,
1376 get_identifier ("__fundamental_type_info"),
1377 /*attributes=*/NULL_TREE
,
1379 pop_nested_namespace (abi_node
);
1380 if (!COMPLETE_TYPE_P (bltn_type
))
1382 dtor
= TREE_VEC_ELT (CLASSTYPE_METHOD_VEC (bltn_type
), 1);
1383 if (DECL_EXTERNAL (dtor
))
1386 for (ix
= 0; fundamentals
[ix
]; ix
++)
1388 tree bltn
= *fundamentals
[ix
];
1389 tree bltn_ptr
= build_pointer_type (bltn
);
1390 tree bltn_const_ptr
= build_pointer_type
1391 (build_qualified_type (bltn
, TYPE_QUAL_CONST
));
1394 tinfo
= get_tinfo_decl (bltn
);
1395 TREE_USED (tinfo
) = 1;
1396 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (tinfo
)) = 1;
1398 tinfo
= get_tinfo_decl (bltn_ptr
);
1399 TREE_USED (tinfo
) = 1;
1400 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (tinfo
)) = 1;
1402 tinfo
= get_tinfo_decl (bltn_const_ptr
);
1403 TREE_USED (tinfo
) = 1;
1404 TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (tinfo
)) = 1;
1408 /* Return true, iff T is a type_info variable which has not had a
1409 definition emitted for it. */
1412 unemitted_tinfo_decl_p (tree t
, void *data ATTRIBUTE_UNUSED
)
1414 if (/* It's a var decl */
1415 TREE_CODE (t
) == VAR_DECL
1416 /* which has a name */
1418 /* whose name points back to itself */
1419 && IDENTIFIER_GLOBAL_VALUE (DECL_NAME (t
)) == t
1420 /* whose name's type is non-null */
1421 && TREE_TYPE (DECL_NAME (t
))
1422 /* and whose type is a struct */
1423 && TREE_CODE (TREE_TYPE (t
)) == RECORD_TYPE
1425 && TYPE_FIELDS (TREE_TYPE (t
))
1426 /* which is our pseudo type info */
1427 && TREE_TYPE (TYPE_FIELDS (TREE_TYPE (t
))) == ti_desc_type_node
)
1432 /* Finish a type info decl. DECL_PTR is a pointer to an unemitted
1433 tinfo decl. Determine whether it needs emitting, and if so
1434 generate the initializer. */
1437 emit_tinfo_decl (tree
*decl_ptr
, void *data ATTRIBUTE_UNUSED
)
1439 tree decl
= *decl_ptr
;
1440 tree type
= TREE_TYPE (DECL_NAME (decl
));
1442 int in_library
= typeinfo_in_lib_p (type
);
1443 tree var_desc
, var_init
;
1445 import_export_tinfo (decl
, type
, in_library
);
1446 if (DECL_REALLY_EXTERN (decl
) || !DECL_NEEDED_P (decl
))
1449 if (!doing_runtime
&& in_library
)
1453 var_desc
= get_pseudo_ti_desc (type
);
1454 var_init
= get_pseudo_ti_init (type
, var_desc
, &non_public
);
1456 DECL_EXTERNAL (decl
) = 0;
1457 TREE_PUBLIC (decl
) = !non_public
;
1459 DECL_COMDAT (decl
) = 0;
1461 DECL_INITIAL (decl
) = var_init
;
1462 cp_finish_decl (decl
, var_init
, NULL_TREE
, 0);
1463 /* cp_finish_decl will have dealt with linkage. */
1465 /* Say we've dealt with it. */
1466 TREE_TYPE (DECL_NAME (decl
)) = NULL_TREE
;