Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / gcc / cp / rtti.c
bloba08a3ee5cb755e0691ff26cec29f8fc2f1cd6531
1 /* RunTime Type Identification
2 Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
3 2005
4 Free Software Foundation, Inc.
5 Mostly written by Jason Merrill (jason@cygnus.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
12 any later version.
14 GCC is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to
21 the Free Software Foundation, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, USA. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "cp-tree.h"
30 #include "flags.h"
31 #include "output.h"
32 #include "assert.h"
33 #include "toplev.h"
34 #include "convert.h"
36 /* C++ returns type information to the user in struct type_info
37 objects. We also use type information to implement dynamic_cast and
38 exception handlers. Type information for a particular type is
39 indicated with an ABI defined structure derived from type_info.
40 This would all be very straight forward, but for the fact that the
41 runtime library provides the definitions of the type_info structure
42 and the ABI defined derived classes. We cannot build declarations
43 of them directly in the compiler, but we need to layout objects of
44 their type. Somewhere we have to lie.
46 We define layout compatible POD-structs with compiler-defined names
47 and generate the appropriate initializations for them (complete
48 with explicit mention of their vtable). When we have to provide a
49 type_info to the user we reinterpret_cast the internal compiler
50 type to type_info. A well formed program can only explicitly refer
51 to the type_infos of complete types (& cv void). However, we chain
52 pointer type_infos to the pointed-to-type, and that can be
53 incomplete. We only need the addresses of such incomplete
54 type_info objects for static initialization.
56 The type information VAR_DECL of a type is held on the
57 IDENTIFIER_GLOBAL_VALUE of the type's mangled name. That VAR_DECL
58 will be the internal type. It will usually have the correct
59 internal type reflecting the kind of type it represents (pointer,
60 array, function, class, inherited class, etc). When the type it
61 represents is incomplete, it will have the internal type
62 corresponding to type_info. That will only happen at the end of
63 translation, when we are emitting the type info objects. */
65 /* Accessors for the type_info objects. We need to remember several things
66 about each of the type_info types. The global tree nodes such as
67 bltn_desc_type_node are TREE_LISTs, and these macros are used to access
68 the required information. */
69 /* The RECORD_TYPE of a type_info derived class. */
70 #define TINFO_PSEUDO_TYPE(NODE) TREE_TYPE (NODE)
71 /* The VAR_DECL of the vtable for the type_info derived class.
72 This is only filled in at the end of the translation. */
73 #define TINFO_VTABLE_DECL(NODE) TREE_VALUE (NODE)
74 /* The IDENTIFIER_NODE naming the real class. */
75 #define TINFO_REAL_NAME(NODE) TREE_PURPOSE (NODE)
77 /* A vector of all tinfo decls that haven't yet been emitted. */
78 VEC (tree) *unemitted_tinfo_decls;
80 static tree build_headof (tree);
81 static tree ifnonnull (tree, tree);
82 static tree tinfo_name (tree);
83 static tree build_dynamic_cast_1 (tree, tree);
84 static tree throw_bad_cast (void);
85 static tree throw_bad_typeid (void);
86 static tree get_tinfo_decl_dynamic (tree);
87 static tree get_tinfo_ptr (tree);
88 static bool typeid_ok_p (void);
89 static int qualifier_flags (tree);
90 static bool target_incomplete_p (tree);
91 static tree tinfo_base_init (tree, tree);
92 static tree generic_initializer (tree, tree);
93 static tree class_initializer (tree, tree, tree);
94 static tree create_pseudo_type_info (const char *, int, ...);
95 static tree get_pseudo_ti_init (tree, tree);
96 static tree get_pseudo_ti_desc (tree);
97 static void create_tinfo_types (void);
98 static bool typeinfo_in_lib_p (tree);
100 static int doing_runtime = 0;
103 /* Declare language defined type_info type and a pointer to const
104 type_info. This is incomplete here, and will be completed when
105 the user #includes <typeinfo>. There are language defined
106 restrictions on what can be done until that is included. Create
107 the internal versions of the ABI types. */
109 void
110 init_rtti_processing (void)
112 tree type_info_type;
114 push_namespace (std_identifier);
115 type_info_type = xref_tag (class_type, get_identifier ("type_info"),
116 /*tag_scope=*/ts_global, false);
117 pop_namespace ();
118 const_type_info_type_node
119 = build_qualified_type (type_info_type, TYPE_QUAL_CONST);
120 type_info_ptr_type = build_pointer_type (const_type_info_type_node);
122 unemitted_tinfo_decls = VEC_alloc (tree, 124);
124 create_tinfo_types ();
127 /* Given the expression EXP of type `class *', return the head of the
128 object pointed to by EXP with type cv void*, if the class has any
129 virtual functions (TYPE_POLYMORPHIC_P), else just return the
130 expression. */
132 static tree
133 build_headof (tree exp)
135 tree type = TREE_TYPE (exp);
136 tree offset;
137 tree index;
139 gcc_assert (TREE_CODE (type) == POINTER_TYPE);
140 type = TREE_TYPE (type);
142 if (!TYPE_POLYMORPHIC_P (type))
143 return exp;
145 /* We use this a couple of times below, protect it. */
146 exp = save_expr (exp);
148 /* The offset-to-top field is at index -2 from the vptr. */
149 index = build_int_cst (NULL_TREE,
150 -2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
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 build2 (PLUS_EXPR, type, exp,
157 convert_to_integer (ptrdiff_type_node, offset));
160 /* Get a bad_cast node for the program to throw...
162 See libstdc++/exception.cc for __throw_bad_cast */
164 static tree
165 throw_bad_cast (void)
167 tree fn = get_identifier ("__cxa_bad_cast");
168 if (!get_global_value_if_present (fn, &fn))
169 fn = push_throw_library_fn (fn, build_function_type (ptr_type_node,
170 void_list_node));
172 return build_cxx_call (fn, NULL_TREE);
175 /* Return an expression for "__cxa_bad_typeid()". The expression
176 returned is an lvalue of type "const std::type_info". */
178 static tree
179 throw_bad_typeid (void)
181 tree fn = get_identifier ("__cxa_bad_typeid");
182 if (!get_global_value_if_present (fn, &fn))
184 tree t;
186 t = build_reference_type (const_type_info_type_node);
187 t = build_function_type (t, void_list_node);
188 fn = push_throw_library_fn (fn, t);
191 return build_cxx_call (fn, NULL_TREE);
194 /* Return an lvalue expression whose type is "const std::type_info"
195 and whose value indicates the type of the expression EXP. If EXP
196 is a reference to a polymorphic class, return the dynamic type;
197 otherwise return the static type of the expression. */
199 static tree
200 get_tinfo_decl_dynamic (tree exp)
202 tree type;
203 tree t;
205 if (exp == error_mark_node)
206 return error_mark_node;
208 /* peel back references, so they match. */
209 type = non_reference (TREE_TYPE (exp));
211 /* Peel off cv qualifiers. */
212 type = TYPE_MAIN_VARIANT (type);
214 if (!VOID_TYPE_P (type))
215 type = complete_type_or_else (type, exp);
217 if (!type)
218 return error_mark_node;
220 /* If exp is a reference to polymorphic type, get the real type_info. */
221 if (TYPE_POLYMORPHIC_P (type) && ! resolves_to_fixed_type_p (exp, 0))
223 /* build reference to type_info from vtable. */
224 tree index;
226 /* The RTTI information is at index -1. */
227 index = build_int_cst (NULL_TREE,
228 -1 * TARGET_VTABLE_DATA_ENTRY_DISTANCE);
229 t = build_vtbl_ref (exp, index);
230 t = convert (type_info_ptr_type, t);
232 else
233 /* Otherwise return the type_info for the static type of the expr. */
234 t = get_tinfo_ptr (TYPE_MAIN_VARIANT (type));
236 return build_indirect_ref (t, NULL);
239 static bool
240 typeid_ok_p (void)
242 if (! flag_rtti)
244 error ("cannot use typeid with -fno-rtti");
245 return false;
248 if (!COMPLETE_TYPE_P (const_type_info_type_node))
250 error ("must #include <typeinfo> before using typeid");
251 return false;
254 return true;
257 /* Return an expression for "typeid(EXP)". The expression returned is
258 an lvalue of type "const std::type_info". */
260 tree
261 build_typeid (tree exp)
263 tree cond = NULL_TREE;
264 int nonnull = 0;
266 if (exp == error_mark_node || !typeid_ok_p ())
267 return error_mark_node;
269 if (processing_template_decl)
270 return build_min (TYPEID_EXPR, const_type_info_type_node, exp);
272 if (TREE_CODE (exp) == INDIRECT_REF
273 && TREE_CODE (TREE_TYPE (TREE_OPERAND (exp, 0))) == POINTER_TYPE
274 && TYPE_POLYMORPHIC_P (TREE_TYPE (exp))
275 && ! resolves_to_fixed_type_p (exp, &nonnull)
276 && ! nonnull)
278 exp = stabilize_reference (exp);
279 cond = cp_convert (boolean_type_node, TREE_OPERAND (exp, 0));
282 exp = get_tinfo_decl_dynamic (exp);
284 if (exp == error_mark_node)
285 return error_mark_node;
287 if (cond)
289 tree bad = throw_bad_typeid ();
291 exp = build3 (COND_EXPR, TREE_TYPE (exp), cond, exp, bad);
294 return exp;
297 /* Generate the NTBS name of a type. */
298 static tree
299 tinfo_name (tree type)
301 const char *name;
302 tree name_string;
304 name = mangle_type_string (type);
305 name_string = fix_string_type (build_string (strlen (name) + 1, name));
306 return name_string;
309 /* Return a VAR_DECL for the internal ABI defined type_info object for
310 TYPE. You must arrange that the decl is mark_used, if actually use
311 it --- decls in vtables are only used if the vtable is output. */
313 tree
314 get_tinfo_decl (tree type)
316 tree name;
317 tree d;
319 if (COMPLETE_TYPE_P (type)
320 && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
322 error ("cannot create type information for type %qT because "
323 "its size is variable",
324 type);
325 return error_mark_node;
328 if (TREE_CODE (type) == METHOD_TYPE)
329 type = build_function_type (TREE_TYPE (type),
330 TREE_CHAIN (TYPE_ARG_TYPES (type)));
332 /* For a class type, the variable is cached in the type node
333 itself. */
334 if (CLASS_TYPE_P (type))
336 d = CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type));
337 if (d)
338 return d;
341 name = mangle_typeinfo_for_type (type);
343 d = IDENTIFIER_GLOBAL_VALUE (name);
344 if (!d)
346 tree var_desc = get_pseudo_ti_desc (type);
348 d = build_lang_decl (VAR_DECL, name, TINFO_PSEUDO_TYPE (var_desc));
349 SET_DECL_ASSEMBLER_NAME (d, name);
350 /* Remember the type it is for. */
351 TREE_TYPE (name) = type;
352 DECL_TINFO_P (d) = 1;
353 DECL_ARTIFICIAL (d) = 1;
354 DECL_IGNORED_P (d) = 1;
355 TREE_READONLY (d) = 1;
356 TREE_STATIC (d) = 1;
357 /* Mark the variable as undefined -- but remember that we can
358 define it later if we need to do so. */
359 DECL_EXTERNAL (d) = 1;
360 DECL_NOT_REALLY_EXTERN (d) = 1;
361 if (CLASS_TYPE_P (type))
362 CLASSTYPE_TYPEINFO_VAR (TYPE_MAIN_VARIANT (type)) = d;
363 set_linkage_according_to_type (type, d);
364 pushdecl_top_level_and_finish (d, NULL_TREE);
366 /* Add decl to the global array of tinfo decls. */
367 VEC_safe_push (tree, unemitted_tinfo_decls, d);
370 return d;
373 /* Return a pointer to a type_info object describing TYPE, suitably
374 cast to the language defined type. */
376 static tree
377 get_tinfo_ptr (tree type)
379 tree decl = get_tinfo_decl (type);
381 mark_used (decl);
382 return build_nop (type_info_ptr_type,
383 build_address (decl));
386 /* Return the type_info object for TYPE. */
388 tree
389 get_typeid (tree type)
391 if (type == error_mark_node || !typeid_ok_p ())
392 return error_mark_node;
394 if (processing_template_decl)
395 return build_min (TYPEID_EXPR, const_type_info_type_node, type);
397 /* If the type of the type-id is a reference type, the result of the
398 typeid expression refers to a type_info object representing the
399 referenced type. */
400 type = non_reference (type);
402 /* The top-level cv-qualifiers of the lvalue expression or the type-id
403 that is the operand of typeid are always ignored. */
404 type = TYPE_MAIN_VARIANT (type);
406 if (!VOID_TYPE_P (type))
407 type = complete_type_or_else (type, NULL_TREE);
409 if (!type)
410 return error_mark_node;
412 return build_indirect_ref (get_tinfo_ptr (type), NULL);
415 /* Check whether TEST is null before returning RESULT. If TEST is used in
416 RESULT, it must have previously had a save_expr applied to it. */
418 static tree
419 ifnonnull (tree test, tree result)
421 return build3 (COND_EXPR, TREE_TYPE (result),
422 build2 (EQ_EXPR, boolean_type_node, test, integer_zero_node),
423 cp_convert (TREE_TYPE (result), integer_zero_node),
424 result);
427 /* Execute a dynamic cast, as described in section 5.2.6 of the 9/93 working
428 paper. */
430 static tree
431 build_dynamic_cast_1 (tree type, tree expr)
433 enum tree_code tc = TREE_CODE (type);
434 tree exprtype = TREE_TYPE (expr);
435 tree dcast_fn;
436 tree old_expr = expr;
437 const char *errstr = NULL;
439 /* T shall be a pointer or reference to a complete class type, or
440 `pointer to cv void''. */
441 switch (tc)
443 case POINTER_TYPE:
444 if (TREE_CODE (TREE_TYPE (type)) == VOID_TYPE)
445 break;
446 /* Fall through. */
447 case REFERENCE_TYPE:
448 if (! IS_AGGR_TYPE (TREE_TYPE (type)))
450 errstr = "target is not pointer or reference to class";
451 goto fail;
453 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (type))))
455 errstr = "target is not pointer or reference to complete type";
456 goto fail;
458 break;
460 default:
461 errstr = "target is not pointer or reference";
462 goto fail;
465 if (tc == POINTER_TYPE)
467 /* If T is a pointer type, v shall be an rvalue of a pointer to
468 complete class type, and the result is an rvalue of type T. */
470 if (TREE_CODE (exprtype) != POINTER_TYPE)
472 errstr = "source is not a pointer";
473 goto fail;
475 if (! IS_AGGR_TYPE (TREE_TYPE (exprtype)))
477 errstr = "source is not a pointer to class";
478 goto fail;
480 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (exprtype))))
482 errstr = "source is a pointer to incomplete type";
483 goto fail;
486 else
488 /* Apply trivial conversion T -> T& for dereferenced ptrs. */
489 exprtype = build_reference_type (exprtype);
490 expr = convert_to_reference (exprtype, expr, CONV_IMPLICIT,
491 LOOKUP_NORMAL, NULL_TREE);
493 /* T is a reference type, v shall be an lvalue of a complete class
494 type, and the result is an lvalue of the type referred to by T. */
496 if (! IS_AGGR_TYPE (TREE_TYPE (exprtype)))
498 errstr = "source is not of class type";
499 goto fail;
501 if (!COMPLETE_TYPE_P (complete_type (TREE_TYPE (exprtype))))
503 errstr = "source is of incomplete class type";
504 goto fail;
509 /* The dynamic_cast operator shall not cast away constness. */
510 if (!at_least_as_qualified_p (TREE_TYPE (type),
511 TREE_TYPE (exprtype)))
513 errstr = "conversion casts away constness";
514 goto fail;
517 /* If *type is an unambiguous accessible base class of *exprtype,
518 convert statically. */
520 tree binfo;
522 binfo = lookup_base (TREE_TYPE (exprtype), TREE_TYPE (type),
523 ba_check, NULL);
525 if (binfo)
527 expr = build_base_path (PLUS_EXPR, convert_from_reference (expr),
528 binfo, 0);
529 if (TREE_CODE (exprtype) == POINTER_TYPE)
530 expr = non_lvalue (expr);
531 return expr;
535 /* Otherwise *exprtype must be a polymorphic class (have a vtbl). */
536 if (TYPE_POLYMORPHIC_P (TREE_TYPE (exprtype)))
538 tree expr1;
539 /* if TYPE is `void *', return pointer to complete object. */
540 if (tc == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (type)))
542 /* if b is an object, dynamic_cast<void *>(&b) == (void *)&b. */
543 if (TREE_CODE (expr) == ADDR_EXPR
544 && TREE_CODE (TREE_OPERAND (expr, 0)) == VAR_DECL
545 && TREE_CODE (TREE_TYPE (TREE_OPERAND (expr, 0))) == RECORD_TYPE)
546 return build1 (NOP_EXPR, type, expr);
548 /* Since expr is used twice below, save it. */
549 expr = save_expr (expr);
551 expr1 = build_headof (expr);
552 if (TREE_TYPE (expr1) != type)
553 expr1 = build1 (NOP_EXPR, type, expr1);
554 return ifnonnull (expr, expr1);
556 else
558 tree retval;
559 tree result, td2, td3, elems;
560 tree static_type, target_type, boff;
562 /* If we got here, we can't convert statically. Therefore,
563 dynamic_cast<D&>(b) (b an object) cannot succeed. */
564 if (tc == REFERENCE_TYPE)
566 if (TREE_CODE (old_expr) == VAR_DECL
567 && TREE_CODE (TREE_TYPE (old_expr)) == RECORD_TYPE)
569 tree expr = throw_bad_cast ();
570 warning ("dynamic_cast of %q#D to %q#T can never succeed",
571 old_expr, type);
572 /* Bash it to the expected type. */
573 TREE_TYPE (expr) = type;
574 return expr;
577 /* Ditto for dynamic_cast<D*>(&b). */
578 else if (TREE_CODE (expr) == ADDR_EXPR)
580 tree op = TREE_OPERAND (expr, 0);
581 if (TREE_CODE (op) == VAR_DECL
582 && TREE_CODE (TREE_TYPE (op)) == RECORD_TYPE)
584 warning ("dynamic_cast of %q#D to %q#T can never succeed",
585 op, type);
586 retval = build_int_cst (type, 0);
587 return retval;
591 target_type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
592 static_type = TYPE_MAIN_VARIANT (TREE_TYPE (exprtype));
593 td2 = get_tinfo_decl (target_type);
594 mark_used (td2);
595 td2 = build_unary_op (ADDR_EXPR, td2, 0);
596 td3 = get_tinfo_decl (static_type);
597 mark_used (td3);
598 td3 = build_unary_op (ADDR_EXPR, td3, 0);
600 /* Determine how T and V are related. */
601 boff = dcast_base_hint (static_type, target_type);
603 /* Since expr is used twice below, save it. */
604 expr = save_expr (expr);
606 expr1 = expr;
607 if (tc == REFERENCE_TYPE)
608 expr1 = build_unary_op (ADDR_EXPR, expr1, 0);
610 elems = tree_cons
611 (NULL_TREE, expr1, tree_cons
612 (NULL_TREE, td3, tree_cons
613 (NULL_TREE, td2, tree_cons
614 (NULL_TREE, boff, NULL_TREE))));
616 dcast_fn = dynamic_cast_node;
617 if (!dcast_fn)
619 tree tmp;
620 tree tinfo_ptr;
621 tree ns = abi_node;
622 const char *name;
624 push_nested_namespace (ns);
625 tinfo_ptr = xref_tag (class_type,
626 get_identifier ("__class_type_info"),
627 /*tag_scope=*/ts_global, false);
629 tinfo_ptr = build_pointer_type
630 (build_qualified_type
631 (tinfo_ptr, TYPE_QUAL_CONST));
632 name = "__dynamic_cast";
633 tmp = tree_cons
634 (NULL_TREE, const_ptr_type_node, tree_cons
635 (NULL_TREE, tinfo_ptr, tree_cons
636 (NULL_TREE, tinfo_ptr, tree_cons
637 (NULL_TREE, ptrdiff_type_node, void_list_node))));
638 tmp = build_function_type (ptr_type_node, tmp);
639 dcast_fn = build_library_fn_ptr (name, tmp);
640 DECL_IS_PURE (dcast_fn) = 1;
641 pop_nested_namespace (ns);
642 dynamic_cast_node = dcast_fn;
644 result = build_cxx_call (dcast_fn, elems);
646 if (tc == REFERENCE_TYPE)
648 tree bad = throw_bad_cast ();
650 result = save_expr (result);
651 return build3 (COND_EXPR, type, result, result, bad);
654 /* Now back to the type we want from a void*. */
655 result = cp_convert (type, result);
656 return ifnonnull (expr, result);
659 else
660 errstr = "source type is not polymorphic";
662 fail:
663 error ("cannot dynamic_cast %qE (of type %q#T) to type %q#T (%s)",
664 expr, exprtype, type, errstr);
665 return error_mark_node;
668 tree
669 build_dynamic_cast (tree type, tree expr)
671 if (type == error_mark_node || expr == error_mark_node)
672 return error_mark_node;
674 if (processing_template_decl)
676 expr = build_min (DYNAMIC_CAST_EXPR, type, expr);
677 TREE_SIDE_EFFECTS (expr) = 1;
679 return expr;
682 return convert_from_reference (build_dynamic_cast_1 (type, expr));
685 /* Return the runtime bit mask encoding the qualifiers of TYPE. */
687 static int
688 qualifier_flags (tree type)
690 int flags = 0;
691 int quals = cp_type_quals (type);
693 if (quals & TYPE_QUAL_CONST)
694 flags |= 1;
695 if (quals & TYPE_QUAL_VOLATILE)
696 flags |= 2;
697 if (quals & TYPE_QUAL_RESTRICT)
698 flags |= 4;
699 return flags;
702 /* Return true, if the pointer chain TYPE ends at an incomplete type, or
703 contains a pointer to member of an incomplete class. */
705 static bool
706 target_incomplete_p (tree type)
708 while (true)
709 if (TYPE_PTRMEM_P (type))
711 if (!COMPLETE_TYPE_P (TYPE_PTRMEM_CLASS_TYPE (type)))
712 return true;
713 type = TYPE_PTRMEM_POINTED_TO_TYPE (type);
715 else if (TREE_CODE (type) == POINTER_TYPE)
716 type = TREE_TYPE (type);
717 else
718 return !COMPLETE_OR_VOID_TYPE_P (type);
721 /* Returns true if TYPE involves an incomplete class type; in that
722 case, typeinfo variables for TYPE should be emitted with internal
723 linkage. */
725 static bool
726 involves_incomplete_p (tree type)
728 switch (TREE_CODE (type))
730 case POINTER_TYPE:
731 return target_incomplete_p (TREE_TYPE (type));
733 case OFFSET_TYPE:
734 ptrmem:
735 return
736 (target_incomplete_p (TYPE_PTRMEM_POINTED_TO_TYPE (type))
737 || !COMPLETE_TYPE_P (TYPE_PTRMEM_CLASS_TYPE (type)));
739 case RECORD_TYPE:
740 if (TYPE_PTRMEMFUNC_P (type))
741 goto ptrmem;
742 /* Fall through. */
743 case UNION_TYPE:
744 if (!COMPLETE_TYPE_P (type))
745 return true;
747 default:
748 /* All other types do not involve incomplete class types. */
749 return false;
753 /* Return a CONSTRUCTOR for the common part of the type_info objects. This
754 is the vtable pointer and NTBS name. The NTBS name is emitted as a
755 comdat const char array, so it becomes a unique key for the type. Generate
756 and emit that VAR_DECL here. (We can't always emit the type_info itself
757 as comdat, because of pointers to incomplete.) */
759 static tree
760 tinfo_base_init (tree desc, tree target)
762 tree init = NULL_TREE;
763 tree name_decl;
764 tree vtable_ptr;
767 tree name_name;
769 /* Generate the NTBS array variable. */
770 tree name_type = build_cplus_array_type
771 (build_qualified_type (char_type_node, TYPE_QUAL_CONST),
772 NULL_TREE);
773 tree name_string = tinfo_name (target);
775 /* Determine the name of the variable -- and remember with which
776 type it is associated. */
777 name_name = mangle_typeinfo_string_for_type (target);
778 TREE_TYPE (name_name) = target;
780 name_decl = build_lang_decl (VAR_DECL, name_name, name_type);
781 SET_DECL_ASSEMBLER_NAME (name_decl, name_name);
782 DECL_ARTIFICIAL (name_decl) = 1;
783 DECL_IGNORED_P (name_decl) = 1;
784 TREE_READONLY (name_decl) = 1;
785 TREE_STATIC (name_decl) = 1;
786 DECL_EXTERNAL (name_decl) = 0;
787 DECL_TINFO_P (name_decl) = 1;
788 if (involves_incomplete_p (target))
790 TREE_PUBLIC (name_decl) = 0;
791 DECL_INTERFACE_KNOWN (name_decl) = 1;
793 else
794 set_linkage_according_to_type (target, name_decl);
795 import_export_decl (name_decl);
796 DECL_INITIAL (name_decl) = name_string;
797 mark_used (name_decl);
798 pushdecl_top_level_and_finish (name_decl, name_string);
801 vtable_ptr = TINFO_VTABLE_DECL (desc);
802 if (!vtable_ptr)
804 tree real_type;
806 push_nested_namespace (abi_node);
807 real_type = xref_tag (class_type, TINFO_REAL_NAME (desc),
808 /*tag_scope=*/ts_global, false);
809 pop_nested_namespace (abi_node);
811 if (!COMPLETE_TYPE_P (real_type))
813 /* We never saw a definition of this type, so we need to
814 tell the compiler that this is an exported class, as
815 indeed all of the __*_type_info classes are. */
816 SET_CLASSTYPE_INTERFACE_KNOWN (real_type);
817 CLASSTYPE_INTERFACE_ONLY (real_type) = 1;
820 vtable_ptr = get_vtable_decl (real_type, /*complete=*/1);
821 vtable_ptr = build_unary_op (ADDR_EXPR, vtable_ptr, 0);
823 /* We need to point into the middle of the vtable. */
824 vtable_ptr = build2
825 (PLUS_EXPR, TREE_TYPE (vtable_ptr), vtable_ptr,
826 size_binop (MULT_EXPR,
827 size_int (2 * TARGET_VTABLE_DATA_ENTRY_DISTANCE),
828 TYPE_SIZE_UNIT (vtable_entry_type)));
830 TINFO_VTABLE_DECL (desc) = vtable_ptr;
833 init = tree_cons (NULL_TREE, vtable_ptr, init);
835 init = tree_cons (NULL_TREE, decay_conversion (name_decl), init);
837 init = build_constructor (NULL_TREE, nreverse (init));
838 TREE_CONSTANT (init) = 1;
839 TREE_INVARIANT (init) = 1;
840 TREE_STATIC (init) = 1;
841 init = tree_cons (NULL_TREE, init, NULL_TREE);
843 return init;
846 /* Return the CONSTRUCTOR expr for a type_info of TYPE. DESC provides the
847 information about the particular type_info derivation, which adds no
848 additional fields to the type_info base. */
850 static tree
851 generic_initializer (tree desc, tree target)
853 tree init = tinfo_base_init (desc, target);
855 init = build_constructor (NULL_TREE, init);
856 TREE_CONSTANT (init) = 1;
857 TREE_INVARIANT (init) = 1;
858 TREE_STATIC (init) = 1;
859 return init;
862 /* Return the CONSTRUCTOR expr for a type_info of pointer TYPE.
863 DESC provides information about the particular type_info derivation,
864 which adds target type and qualifier flags members to the type_info base. */
866 static tree
867 ptr_initializer (tree desc, tree target)
869 tree init = tinfo_base_init (desc, target);
870 tree to = TREE_TYPE (target);
871 int flags = qualifier_flags (to);
872 bool incomplete = target_incomplete_p (to);
874 if (incomplete)
875 flags |= 8;
876 init = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, flags), init);
877 init = tree_cons (NULL_TREE,
878 get_tinfo_ptr (TYPE_MAIN_VARIANT (to)),
879 init);
881 init = build_constructor (NULL_TREE, nreverse (init));
882 TREE_CONSTANT (init) = 1;
883 TREE_INVARIANT (init) = 1;
884 TREE_STATIC (init) = 1;
885 return init;
888 /* Return the CONSTRUCTOR expr for a type_info of pointer to member data TYPE.
889 DESC provides information about the particular type_info derivation,
890 which adds class, target type and qualifier flags members to the type_info
891 base. */
893 static tree
894 ptm_initializer (tree desc, tree target)
896 tree init = tinfo_base_init (desc, target);
897 tree to = TYPE_PTRMEM_POINTED_TO_TYPE (target);
898 tree klass = TYPE_PTRMEM_CLASS_TYPE (target);
899 int flags = qualifier_flags (to);
900 bool incomplete = target_incomplete_p (to);
902 if (incomplete)
903 flags |= 0x8;
904 if (!COMPLETE_TYPE_P (klass))
905 flags |= 0x10;
906 init = tree_cons (NULL_TREE, build_int_cst (NULL_TREE, flags), init);
907 init = tree_cons (NULL_TREE,
908 get_tinfo_ptr (TYPE_MAIN_VARIANT (to)),
909 init);
910 init = tree_cons (NULL_TREE,
911 get_tinfo_ptr (klass),
912 init);
914 init = build_constructor (NULL_TREE, nreverse (init));
915 TREE_CONSTANT (init) = 1;
916 TREE_INVARIANT (init) = 1;
917 TREE_STATIC (init) = 1;
918 return init;
921 /* Return the CONSTRUCTOR expr for a type_info of class TYPE.
922 DESC provides information about the particular __class_type_info derivation,
923 which adds hint flags and TRAIL initializers to the type_info base. */
925 static tree
926 class_initializer (tree desc, tree target, tree trail)
928 tree init = tinfo_base_init (desc, target);
930 TREE_CHAIN (init) = trail;
931 init = build_constructor (NULL_TREE, init);
932 TREE_CONSTANT (init) = 1;
933 TREE_INVARIANT (init) = 1;
934 TREE_STATIC (init) = 1;
935 return init;
938 /* Returns true if the typeinfo for type should be placed in
939 the runtime library. */
941 static bool
942 typeinfo_in_lib_p (tree type)
944 /* The typeinfo objects for `T*' and `const T*' are in the runtime
945 library for simple types T. */
946 if (TREE_CODE (type) == POINTER_TYPE
947 && (cp_type_quals (TREE_TYPE (type)) == TYPE_QUAL_CONST
948 || cp_type_quals (TREE_TYPE (type)) == TYPE_UNQUALIFIED))
949 type = TREE_TYPE (type);
951 switch (TREE_CODE (type))
953 case INTEGER_TYPE:
954 case BOOLEAN_TYPE:
955 case CHAR_TYPE:
956 case REAL_TYPE:
957 case VOID_TYPE:
958 return true;
960 default:
961 return false;
965 /* Generate the initializer for the type info describing TYPE. */
967 static tree
968 get_pseudo_ti_init (tree type, tree var_desc)
970 gcc_assert (at_eof);
971 switch (TREE_CODE (type))
973 case OFFSET_TYPE:
974 return ptm_initializer (var_desc, type);
975 case POINTER_TYPE:
976 return ptr_initializer (var_desc, type);
977 case ENUMERAL_TYPE:
978 return generic_initializer (var_desc, type);
979 break;
980 case FUNCTION_TYPE:
981 return generic_initializer (var_desc, type);
982 break;
983 case ARRAY_TYPE:
984 return generic_initializer (var_desc, type);
985 break;
986 case UNION_TYPE:
987 case RECORD_TYPE:
988 if (TYPE_PTRMEMFUNC_P (type))
989 return ptm_initializer (var_desc, type);
990 else if (var_desc == class_desc_type_node)
991 return class_initializer (var_desc, type, NULL_TREE);
992 else if (var_desc == si_class_desc_type_node)
994 tree base_binfo = BINFO_BASE_BINFO (TYPE_BINFO (type), 0);
995 tree tinfo = get_tinfo_ptr (BINFO_TYPE (base_binfo));
996 tree base_inits = tree_cons (NULL_TREE, tinfo, NULL_TREE);
998 return class_initializer (var_desc, type, base_inits);
1000 else
1002 int hint = ((CLASSTYPE_REPEATED_BASE_P (type) << 0)
1003 | (CLASSTYPE_DIAMOND_SHAPED_P (type) << 1));
1004 tree binfo = TYPE_BINFO (type);
1005 int nbases = BINFO_N_BASE_BINFOS (binfo);
1006 VEC (tree) *base_accesses = BINFO_BASE_ACCESSES (binfo);
1007 tree base_inits = NULL_TREE;
1008 int ix;
1010 /* Generate the base information initializer. */
1011 for (ix = nbases; ix--;)
1013 tree base_binfo = BINFO_BASE_BINFO (binfo, ix);
1014 tree base_init = NULL_TREE;
1015 int flags = 0;
1016 tree tinfo;
1017 tree offset;
1019 if (VEC_index (tree, base_accesses, ix) == access_public_node)
1020 flags |= 2;
1021 tinfo = get_tinfo_ptr (BINFO_TYPE (base_binfo));
1022 if (BINFO_VIRTUAL_P (base_binfo))
1024 /* We store the vtable offset at which the virtual
1025 base offset can be found. */
1026 offset = BINFO_VPTR_FIELD (base_binfo);
1027 offset = convert (sizetype, offset);
1028 flags |= 1;
1030 else
1031 offset = BINFO_OFFSET (base_binfo);
1033 /* Combine offset and flags into one field. */
1034 offset = cp_build_binary_op (LSHIFT_EXPR, offset,
1035 build_int_cst (NULL_TREE, 8));
1036 offset = cp_build_binary_op (BIT_IOR_EXPR, offset,
1037 build_int_cst (NULL_TREE, flags));
1038 base_init = tree_cons (NULL_TREE, offset, base_init);
1039 base_init = tree_cons (NULL_TREE, tinfo, base_init);
1040 base_init = build_constructor (NULL_TREE, base_init);
1041 base_inits = tree_cons (NULL_TREE, base_init, base_inits);
1043 base_inits = build_constructor (NULL_TREE, base_inits);
1044 base_inits = tree_cons (NULL_TREE, base_inits, NULL_TREE);
1045 /* Prepend the number of bases. */
1046 base_inits = tree_cons (NULL_TREE,
1047 build_int_cst (NULL_TREE, nbases),
1048 base_inits);
1049 /* Prepend the hint flags. */
1050 base_inits = tree_cons (NULL_TREE,
1051 build_int_cst (NULL_TREE, hint),
1052 base_inits);
1054 return class_initializer (var_desc, type, base_inits);
1056 break;
1058 default:
1059 return generic_initializer (var_desc, type);
1063 /* Generate the RECORD_TYPE containing the data layout of a type_info
1064 derivative as used by the runtime. This layout must be consistent with
1065 that defined in the runtime support. Also generate the VAR_DECL for the
1066 type's vtable. We explicitly manage the vtable member, and name it for
1067 real type as used in the runtime. The RECORD type has a different name,
1068 to avoid collisions. Return a TREE_LIST who's TINFO_PSEUDO_TYPE
1069 is the generated type and TINFO_VTABLE_NAME is the name of the
1070 vtable. We have to delay generating the VAR_DECL of the vtable
1071 until the end of the translation, when we'll have seen the library
1072 definition, if there was one.
1074 REAL_NAME is the runtime's name of the type. Trailing arguments are
1075 additional FIELD_DECL's for the structure. The final argument must be
1076 NULL. */
1078 static tree
1079 create_pseudo_type_info (const char *real_name, int ident, ...)
1081 tree pseudo_type;
1082 char *pseudo_name;
1083 tree fields;
1084 tree field_decl;
1085 tree result;
1086 va_list ap;
1088 va_start (ap, ident);
1090 /* Generate the pseudo type name. */
1091 pseudo_name = alloca (strlen (real_name) + 30);
1092 strcpy (pseudo_name, real_name);
1093 strcat (pseudo_name, "_pseudo");
1094 if (ident)
1095 sprintf (pseudo_name + strlen (pseudo_name), "%d", ident);
1097 /* First field is the pseudo type_info base class. */
1098 fields = build_decl (FIELD_DECL, NULL_TREE, ti_desc_type_node);
1100 /* Now add the derived fields. */
1101 while ((field_decl = va_arg (ap, tree)))
1103 TREE_CHAIN (field_decl) = fields;
1104 fields = field_decl;
1107 /* Create the pseudo type. */
1108 pseudo_type = make_aggr_type (RECORD_TYPE);
1109 finish_builtin_struct (pseudo_type, pseudo_name, fields, NULL_TREE);
1110 CLASSTYPE_AS_BASE (pseudo_type) = pseudo_type;
1112 result = tree_cons (NULL_TREE, NULL_TREE, NULL_TREE);
1113 TINFO_REAL_NAME (result) = get_identifier (real_name);
1114 TINFO_PSEUDO_TYPE (result) =
1115 cp_build_qualified_type (pseudo_type, TYPE_QUAL_CONST);
1117 va_end (ap);
1118 return result;
1121 /* Return a pseudo type info type node used to describe TYPE. TYPE
1122 must be a complete type (or cv void), except at the end of the
1123 translation unit. */
1125 static tree
1126 get_pseudo_ti_desc (tree type)
1128 switch (TREE_CODE (type))
1130 case OFFSET_TYPE:
1131 return ptm_desc_type_node;
1132 case POINTER_TYPE:
1133 return ptr_desc_type_node;
1134 case ENUMERAL_TYPE:
1135 return enum_desc_type_node;
1136 case FUNCTION_TYPE:
1137 return func_desc_type_node;
1138 case ARRAY_TYPE:
1139 return ary_desc_type_node;
1140 case UNION_TYPE:
1141 case RECORD_TYPE:
1142 if (TYPE_PTRMEMFUNC_P (type))
1143 return ptm_desc_type_node;
1144 else if (!COMPLETE_TYPE_P (type))
1146 if (!at_eof)
1147 cxx_incomplete_type_error (NULL_TREE, type);
1148 return class_desc_type_node;
1150 else if (!BINFO_N_BASE_BINFOS (TYPE_BINFO (type)))
1151 return class_desc_type_node;
1152 else
1154 tree binfo = TYPE_BINFO (type);
1155 VEC (tree) *base_accesses = BINFO_BASE_ACCESSES (binfo);
1156 tree base_binfo = BINFO_BASE_BINFO (binfo, 0);
1157 int num_bases = BINFO_N_BASE_BINFOS (binfo);
1159 if (num_bases == 1
1160 && VEC_index (tree, base_accesses, 0) == access_public_node
1161 && !BINFO_VIRTUAL_P (base_binfo)
1162 && integer_zerop (BINFO_OFFSET (base_binfo)))
1163 /* single non-virtual public. */
1164 return si_class_desc_type_node;
1165 else
1167 tree var_desc;
1168 tree array_domain, base_array;
1170 if (TREE_VEC_LENGTH (vmi_class_desc_type_node) <= num_bases)
1172 int ix;
1173 tree extend = make_tree_vec (num_bases + 5);
1175 for (ix = TREE_VEC_LENGTH (vmi_class_desc_type_node); ix--;)
1176 TREE_VEC_ELT (extend, ix)
1177 = TREE_VEC_ELT (vmi_class_desc_type_node, ix);
1178 vmi_class_desc_type_node = extend;
1180 var_desc = TREE_VEC_ELT (vmi_class_desc_type_node, num_bases);
1181 if (var_desc)
1182 return var_desc;
1184 /* Create the array of __base_class_type_info entries.
1185 G++ 3.2 allocated an array that had one too many
1186 entries, and then filled that extra entries with
1187 zeros. */
1188 if (abi_version_at_least (2))
1189 array_domain = build_index_type (size_int (num_bases - 1));
1190 else
1191 array_domain = build_index_type (size_int (num_bases));
1192 base_array =
1193 build_array_type (base_desc_type_node, array_domain);
1195 push_nested_namespace (abi_node);
1196 var_desc = create_pseudo_type_info
1197 ("__vmi_class_type_info", num_bases,
1198 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
1199 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
1200 build_decl (FIELD_DECL, NULL_TREE, base_array),
1201 NULL);
1202 pop_nested_namespace (abi_node);
1204 TREE_VEC_ELT (vmi_class_desc_type_node, num_bases) = var_desc;
1205 return var_desc;
1208 default:
1209 return bltn_desc_type_node;
1213 /* Make sure the required builtin types exist for generating the type_info
1214 variable definitions. */
1216 static void
1217 create_tinfo_types (void)
1219 gcc_assert (!ti_desc_type_node);
1221 push_nested_namespace (abi_node);
1223 /* Create the internal type_info structure. This is used as a base for
1224 the other structures. */
1226 tree field, fields;
1228 ti_desc_type_node = make_aggr_type (RECORD_TYPE);
1229 field = build_decl (FIELD_DECL, NULL_TREE, const_ptr_type_node);
1230 fields = field;
1232 field = build_decl (FIELD_DECL, NULL_TREE, const_string_type_node);
1233 TREE_CHAIN (field) = fields;
1234 fields = field;
1236 finish_builtin_struct (ti_desc_type_node, "__type_info_pseudo",
1237 fields, NULL_TREE);
1238 TYPE_HAS_CONSTRUCTOR (ti_desc_type_node) = 1;
1241 /* Fundamental type_info */
1242 bltn_desc_type_node = create_pseudo_type_info
1243 ("__fundamental_type_info", 0,
1244 NULL);
1246 /* Array, function and enum type_info. No additional fields. */
1247 ary_desc_type_node = create_pseudo_type_info
1248 ("__array_type_info", 0,
1249 NULL);
1250 func_desc_type_node = create_pseudo_type_info
1251 ("__function_type_info", 0,
1252 NULL);
1253 enum_desc_type_node = create_pseudo_type_info
1254 ("__enum_type_info", 0,
1255 NULL);
1257 /* Class type_info. Add a flags field. */
1258 class_desc_type_node = create_pseudo_type_info
1259 ("__class_type_info", 0,
1260 NULL);
1262 /* Single public non-virtual base class. Add pointer to base class.
1263 This is really a descendant of __class_type_info. */
1264 si_class_desc_type_node = create_pseudo_type_info
1265 ("__si_class_type_info", 0,
1266 build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type),
1267 NULL);
1269 /* Base class internal helper. Pointer to base type, offset to base,
1270 flags. */
1272 tree field, fields;
1274 field = build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type);
1275 fields = field;
1277 field = build_decl (FIELD_DECL, NULL_TREE, integer_types[itk_long]);
1278 TREE_CHAIN (field) = fields;
1279 fields = field;
1281 base_desc_type_node = make_aggr_type (RECORD_TYPE);
1282 finish_builtin_struct (base_desc_type_node, "__base_class_type_info_pseudo",
1283 fields, NULL_TREE);
1284 TYPE_HAS_CONSTRUCTOR (base_desc_type_node) = 1;
1287 /* General hierarchy is created as necessary in this vector. */
1288 vmi_class_desc_type_node = make_tree_vec (10);
1290 /* Pointer type_info. Adds two fields, qualification mask
1291 and pointer to the pointed to type. This is really a descendant of
1292 __pbase_type_info. */
1293 ptr_desc_type_node = create_pseudo_type_info
1294 ("__pointer_type_info", 0,
1295 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
1296 build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type),
1297 NULL);
1299 /* Pointer to member data type_info. Add qualifications flags,
1300 pointer to the member's type info and pointer to the class.
1301 This is really a descendant of __pbase_type_info. */
1302 ptm_desc_type_node = create_pseudo_type_info
1303 ("__pointer_to_member_type_info", 0,
1304 build_decl (FIELD_DECL, NULL_TREE, integer_type_node),
1305 build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type),
1306 build_decl (FIELD_DECL, NULL_TREE, type_info_ptr_type),
1307 NULL);
1309 pop_nested_namespace (abi_node);
1312 /* Emit the type_info descriptors which are guaranteed to be in the runtime
1313 support. Generating them here guarantees consistency with the other
1314 structures. We use the following heuristic to determine when the runtime
1315 is being generated. If std::__fundamental_type_info is defined, and its
1316 destructor is defined, then the runtime is being built. */
1318 void
1319 emit_support_tinfos (void)
1321 static tree *const fundamentals[] =
1323 &void_type_node,
1324 &boolean_type_node,
1325 &wchar_type_node,
1326 &char_type_node, &signed_char_type_node, &unsigned_char_type_node,
1327 &short_integer_type_node, &short_unsigned_type_node,
1328 &integer_type_node, &unsigned_type_node,
1329 &long_integer_type_node, &long_unsigned_type_node,
1330 &long_long_integer_type_node, &long_long_unsigned_type_node,
1331 &float_type_node, &double_type_node, &long_double_type_node,
1334 int ix;
1335 tree bltn_type, dtor;
1337 push_nested_namespace (abi_node);
1338 bltn_type = xref_tag (class_type,
1339 get_identifier ("__fundamental_type_info"),
1340 /*tag_scope=*/ts_global, false);
1341 pop_nested_namespace (abi_node);
1342 if (!COMPLETE_TYPE_P (bltn_type))
1343 return;
1344 dtor = CLASSTYPE_DESTRUCTORS (bltn_type);
1345 if (!dtor || DECL_EXTERNAL (dtor))
1346 return;
1347 doing_runtime = 1;
1348 for (ix = 0; fundamentals[ix]; ix++)
1350 tree bltn = *fundamentals[ix];
1351 tree types[3];
1352 int i;
1354 types[0] = bltn;
1355 types[1] = build_pointer_type (bltn);
1356 types[2] = build_pointer_type (build_qualified_type (bltn,
1357 TYPE_QUAL_CONST));
1359 for (i = 0; i < 3; ++i)
1361 tree tinfo;
1363 tinfo = get_tinfo_decl (types[i]);
1364 TREE_USED (tinfo) = 1;
1365 mark_needed (tinfo);
1366 /* The C++ ABI requires that these objects be COMDAT. But,
1367 On systems without weak symbols, initialized COMDAT
1368 objects are emitted with internal linkage. (See
1369 comdat_linkage for details.) Since we want these objects
1370 to have external linkage so that copies do not have to be
1371 emitted in code outside the runtime library, we make them
1372 non-COMDAT here. */
1373 if (!flag_weak)
1375 gcc_assert (TREE_PUBLIC (tinfo) && !DECL_COMDAT (tinfo));
1376 DECL_INTERFACE_KNOWN (tinfo) = 1;
1382 /* Finish a type info decl. DECL_PTR is a pointer to an unemitted
1383 tinfo decl. Determine whether it needs emitting, and if so
1384 generate the initializer. */
1386 bool
1387 emit_tinfo_decl (tree decl)
1389 tree type = TREE_TYPE (DECL_NAME (decl));
1390 int in_library = typeinfo_in_lib_p (type);
1391 tree var_desc, var_init;
1393 gcc_assert (DECL_TINFO_P (decl));
1395 if (in_library)
1397 if (doing_runtime)
1398 DECL_EXTERNAL (decl) = 0;
1399 else
1401 /* If we're not in the runtime, then DECL (which is already
1402 DECL_EXTERNAL) will not be defined here. */
1403 DECL_INTERFACE_KNOWN (decl) = 1;
1404 return false;
1407 else if (involves_incomplete_p (type))
1409 if (!decl_needed_p (decl))
1410 return false;
1411 /* If TYPE involves an incomplete class type, then the typeinfo
1412 object will be emitted with internal linkage. There is no
1413 way to know whether or not types are incomplete until the end
1414 of the compilation, so this determination must be deferred
1415 until this point. */
1416 TREE_PUBLIC (decl) = 0;
1417 DECL_EXTERNAL (decl) = 0;
1418 DECL_INTERFACE_KNOWN (decl) = 1;
1421 import_export_decl (decl);
1422 if (DECL_NOT_REALLY_EXTERN (decl) && decl_needed_p (decl))
1424 DECL_EXTERNAL (decl) = 0;
1425 var_desc = get_pseudo_ti_desc (type);
1426 var_init = get_pseudo_ti_init (type, var_desc);
1427 DECL_INITIAL (decl) = var_init;
1428 mark_used (decl);
1429 cp_finish_decl (decl, var_init, NULL_TREE, 0);
1430 return true;
1432 else
1433 return false;