blob: 4ca315ca249d1a20b583a5c03ed7feba32495633 [file] [log] [blame]
Guy Benyei11169dd2012-12-18 14:30:41 +00001//===--- CGCXXRTTI.cpp - Emit LLVM Code for C++ RTTI descriptors ----------===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This contains code dealing with C++ code generation of RTTI descriptors.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CodeGenModule.h"
15#include "CGCXXABI.h"
16#include "CGObjCRuntime.h"
17#include "clang/AST/RecordLayout.h"
18#include "clang/AST/Type.h"
19#include "clang/Frontend/CodeGenOptions.h"
20
21using namespace clang;
22using namespace CodeGen;
23
24namespace {
Warren Hunt5c2b4ea2014-05-23 16:07:43 +000025class ItaniumRTTIBuilder {
Guy Benyei11169dd2012-12-18 14:30:41 +000026 CodeGenModule &CGM; // Per-module state.
27 llvm::LLVMContext &VMContext;
28
29 /// Fields - The fields of the RTTI descriptor currently being built.
30 SmallVector<llvm::Constant *, 16> Fields;
31
32 /// GetAddrOfTypeName - Returns the mangled type name of the given type.
33 llvm::GlobalVariable *
34 GetAddrOfTypeName(QualType Ty, llvm::GlobalVariable::LinkageTypes Linkage);
35
36 /// GetAddrOfExternalRTTIDescriptor - Returns the constant for the RTTI
37 /// descriptor of the given type.
38 llvm::Constant *GetAddrOfExternalRTTIDescriptor(QualType Ty);
39
40 /// BuildVTablePointer - Build the vtable pointer for the given type.
41 void BuildVTablePointer(const Type *Ty);
42
43 /// BuildSIClassTypeInfo - Build an abi::__si_class_type_info, used for single
44 /// inheritance, according to the Itanium C++ ABI, 2.9.5p6b.
45 void BuildSIClassTypeInfo(const CXXRecordDecl *RD);
46
47 /// BuildVMIClassTypeInfo - Build an abi::__vmi_class_type_info, used for
48 /// classes with bases that do not satisfy the abi::__si_class_type_info
49 /// constraints, according ti the Itanium C++ ABI, 2.9.5p5c.
50 void BuildVMIClassTypeInfo(const CXXRecordDecl *RD);
51
52 /// BuildPointerTypeInfo - Build an abi::__pointer_type_info struct, used
53 /// for pointer types.
54 void BuildPointerTypeInfo(QualType PointeeTy);
55
56 /// BuildObjCObjectTypeInfo - Build the appropriate kind of
57 /// type_info for an object type.
58 void BuildObjCObjectTypeInfo(const ObjCObjectType *Ty);
59
60 /// BuildPointerToMemberTypeInfo - Build an abi::__pointer_to_member_type_info
61 /// struct, used for member pointer types.
62 void BuildPointerToMemberTypeInfo(const MemberPointerType *Ty);
63
64public:
Warren Hunt5c2b4ea2014-05-23 16:07:43 +000065 ItaniumRTTIBuilder(CodeGenModule &CGM) : CGM(CGM),
Guy Benyei11169dd2012-12-18 14:30:41 +000066 VMContext(CGM.getModule().getContext()) { }
67
68 // Pointer type info flags.
69 enum {
70 /// PTI_Const - Type has const qualifier.
71 PTI_Const = 0x1,
72
73 /// PTI_Volatile - Type has volatile qualifier.
74 PTI_Volatile = 0x2,
75
76 /// PTI_Restrict - Type has restrict qualifier.
77 PTI_Restrict = 0x4,
78
79 /// PTI_Incomplete - Type is incomplete.
80 PTI_Incomplete = 0x8,
81
82 /// PTI_ContainingClassIncomplete - Containing class is incomplete.
83 /// (in pointer to member).
84 PTI_ContainingClassIncomplete = 0x10
85 };
86
87 // VMI type info flags.
88 enum {
89 /// VMI_NonDiamondRepeat - Class has non-diamond repeated inheritance.
90 VMI_NonDiamondRepeat = 0x1,
91
92 /// VMI_DiamondShaped - Class is diamond shaped.
93 VMI_DiamondShaped = 0x2
94 };
95
96 // Base class type info flags.
97 enum {
98 /// BCTI_Virtual - Base class is virtual.
99 BCTI_Virtual = 0x1,
100
101 /// BCTI_Public - Base class is public.
102 BCTI_Public = 0x2
103 };
104
105 /// BuildTypeInfo - Build the RTTI type info struct for the given type.
106 ///
107 /// \param Force - true to force the creation of this RTTI value
108 llvm::Constant *BuildTypeInfo(QualType Ty, bool Force = false);
109};
110}
111
112llvm::GlobalVariable *
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000113ItaniumRTTIBuilder::GetAddrOfTypeName(QualType Ty,
Guy Benyei11169dd2012-12-18 14:30:41 +0000114 llvm::GlobalVariable::LinkageTypes Linkage) {
115 SmallString<256> OutName;
116 llvm::raw_svector_ostream Out(OutName);
117 CGM.getCXXABI().getMangleContext().mangleCXXRTTIName(Ty, Out);
118 Out.flush();
119 StringRef Name = OutName.str();
120
121 // We know that the mangled name of the type starts at index 4 of the
122 // mangled name of the typename, so we can just index into it in order to
123 // get the mangled name of the type.
124 llvm::Constant *Init = llvm::ConstantDataArray::getString(VMContext,
125 Name.substr(4));
126
127 llvm::GlobalVariable *GV =
128 CGM.CreateOrReplaceCXXRuntimeVariable(Name, Init->getType(), Linkage);
129
130 GV->setInitializer(Init);
131
132 return GV;
133}
134
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000135llvm::Constant *
136ItaniumRTTIBuilder::GetAddrOfExternalRTTIDescriptor(QualType Ty) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000137 // Mangle the RTTI name.
138 SmallString<256> OutName;
139 llvm::raw_svector_ostream Out(OutName);
140 CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty, Out);
141 Out.flush();
142 StringRef Name = OutName.str();
143
144 // Look for an existing global.
145 llvm::GlobalVariable *GV = CGM.getModule().getNamedGlobal(Name);
146
147 if (!GV) {
148 // Create a new global variable.
149 GV = new llvm::GlobalVariable(CGM.getModule(), CGM.Int8PtrTy,
150 /*Constant=*/true,
Craig Topper8a13c412014-05-21 05:09:00 +0000151 llvm::GlobalValue::ExternalLinkage, nullptr,
152 Name);
Guy Benyei11169dd2012-12-18 14:30:41 +0000153 }
154
155 return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
156}
157
158/// TypeInfoIsInStandardLibrary - Given a builtin type, returns whether the type
159/// info for that type is defined in the standard library.
160static bool TypeInfoIsInStandardLibrary(const BuiltinType *Ty) {
161 // Itanium C++ ABI 2.9.2:
162 // Basic type information (e.g. for "int", "bool", etc.) will be kept in
163 // the run-time support library. Specifically, the run-time support
164 // library should contain type_info objects for the types X, X* and
165 // X const*, for every X in: void, std::nullptr_t, bool, wchar_t, char,
166 // unsigned char, signed char, short, unsigned short, int, unsigned int,
167 // long, unsigned long, long long, unsigned long long, float, double,
168 // long double, char16_t, char32_t, and the IEEE 754r decimal and
169 // half-precision floating point types.
170 switch (Ty->getKind()) {
171 case BuiltinType::Void:
172 case BuiltinType::NullPtr:
173 case BuiltinType::Bool:
174 case BuiltinType::WChar_S:
175 case BuiltinType::WChar_U:
176 case BuiltinType::Char_U:
177 case BuiltinType::Char_S:
178 case BuiltinType::UChar:
179 case BuiltinType::SChar:
180 case BuiltinType::Short:
181 case BuiltinType::UShort:
182 case BuiltinType::Int:
183 case BuiltinType::UInt:
184 case BuiltinType::Long:
185 case BuiltinType::ULong:
186 case BuiltinType::LongLong:
187 case BuiltinType::ULongLong:
188 case BuiltinType::Half:
189 case BuiltinType::Float:
190 case BuiltinType::Double:
191 case BuiltinType::LongDouble:
192 case BuiltinType::Char16:
193 case BuiltinType::Char32:
194 case BuiltinType::Int128:
195 case BuiltinType::UInt128:
Guy Benyeid8a08ea2012-12-18 14:38:23 +0000196 case BuiltinType::OCLImage1d:
197 case BuiltinType::OCLImage1dArray:
198 case BuiltinType::OCLImage1dBuffer:
199 case BuiltinType::OCLImage2d:
200 case BuiltinType::OCLImage2dArray:
201 case BuiltinType::OCLImage3d:
Guy Benyei61054192013-02-07 10:55:47 +0000202 case BuiltinType::OCLSampler:
Guy Benyei1b4fb3e2013-01-20 12:31:11 +0000203 case BuiltinType::OCLEvent:
Guy Benyei11169dd2012-12-18 14:30:41 +0000204 return true;
205
206 case BuiltinType::Dependent:
207#define BUILTIN_TYPE(Id, SingletonId)
208#define PLACEHOLDER_TYPE(Id, SingletonId) \
209 case BuiltinType::Id:
210#include "clang/AST/BuiltinTypes.def"
211 llvm_unreachable("asking for RRTI for a placeholder type!");
212
213 case BuiltinType::ObjCId:
214 case BuiltinType::ObjCClass:
215 case BuiltinType::ObjCSel:
216 llvm_unreachable("FIXME: Objective-C types are unsupported!");
217 }
218
219 llvm_unreachable("Invalid BuiltinType Kind!");
220}
221
222static bool TypeInfoIsInStandardLibrary(const PointerType *PointerTy) {
223 QualType PointeeTy = PointerTy->getPointeeType();
224 const BuiltinType *BuiltinTy = dyn_cast<BuiltinType>(PointeeTy);
225 if (!BuiltinTy)
226 return false;
227
228 // Check the qualifiers.
229 Qualifiers Quals = PointeeTy.getQualifiers();
230 Quals.removeConst();
231
232 if (!Quals.empty())
233 return false;
234
235 return TypeInfoIsInStandardLibrary(BuiltinTy);
236}
237
238/// IsStandardLibraryRTTIDescriptor - Returns whether the type
239/// information for the given type exists in the standard library.
240static bool IsStandardLibraryRTTIDescriptor(QualType Ty) {
241 // Type info for builtin types is defined in the standard library.
242 if (const BuiltinType *BuiltinTy = dyn_cast<BuiltinType>(Ty))
243 return TypeInfoIsInStandardLibrary(BuiltinTy);
244
245 // Type info for some pointer types to builtin types is defined in the
246 // standard library.
247 if (const PointerType *PointerTy = dyn_cast<PointerType>(Ty))
248 return TypeInfoIsInStandardLibrary(PointerTy);
249
250 return false;
251}
252
253/// ShouldUseExternalRTTIDescriptor - Returns whether the type information for
254/// the given type exists somewhere else, and that we should not emit the type
255/// information in this translation unit. Assumes that it is not a
256/// standard-library type.
John McCall6bd2a892013-01-25 22:31:03 +0000257static bool ShouldUseExternalRTTIDescriptor(CodeGenModule &CGM,
258 QualType Ty) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000259 ASTContext &Context = CGM.getContext();
260
John McCall6bd2a892013-01-25 22:31:03 +0000261 // If RTTI is disabled, assume it might be disabled in the
262 // translation unit that defines any potential key function, too.
Guy Benyei11169dd2012-12-18 14:30:41 +0000263 if (!Context.getLangOpts().RTTI) return false;
264
265 if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
266 const CXXRecordDecl *RD = cast<CXXRecordDecl>(RecordTy->getDecl());
267 if (!RD->hasDefinition())
268 return false;
269
270 if (!RD->isDynamicClass())
271 return false;
272
John McCall6bd2a892013-01-25 22:31:03 +0000273 // FIXME: this may need to be reconsidered if the key function
274 // changes.
275 return CGM.getVTables().isVTableExternal(RD);
Guy Benyei11169dd2012-12-18 14:30:41 +0000276 }
277
278 return false;
279}
280
281/// IsIncompleteClassType - Returns whether the given record type is incomplete.
282static bool IsIncompleteClassType(const RecordType *RecordTy) {
283 return !RecordTy->getDecl()->isCompleteDefinition();
284}
285
286/// ContainsIncompleteClassType - Returns whether the given type contains an
287/// incomplete class type. This is true if
288///
289/// * The given type is an incomplete class type.
290/// * The given type is a pointer type whose pointee type contains an
291/// incomplete class type.
292/// * The given type is a member pointer type whose class is an incomplete
293/// class type.
294/// * The given type is a member pointer type whoise pointee type contains an
295/// incomplete class type.
296/// is an indirect or direct pointer to an incomplete class type.
297static bool ContainsIncompleteClassType(QualType Ty) {
298 if (const RecordType *RecordTy = dyn_cast<RecordType>(Ty)) {
299 if (IsIncompleteClassType(RecordTy))
300 return true;
301 }
302
303 if (const PointerType *PointerTy = dyn_cast<PointerType>(Ty))
304 return ContainsIncompleteClassType(PointerTy->getPointeeType());
305
306 if (const MemberPointerType *MemberPointerTy =
307 dyn_cast<MemberPointerType>(Ty)) {
308 // Check if the class type is incomplete.
309 const RecordType *ClassType = cast<RecordType>(MemberPointerTy->getClass());
310 if (IsIncompleteClassType(ClassType))
311 return true;
312
313 return ContainsIncompleteClassType(MemberPointerTy->getPointeeType());
314 }
315
316 return false;
317}
318
319/// getTypeInfoLinkage - Return the linkage that the type info and type info
320/// name constants should have for the given type.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000321llvm::GlobalVariable::LinkageTypes
322CodeGenModule::getTypeInfoLinkage(QualType Ty) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000323 // Itanium C++ ABI 2.9.5p7:
324 // In addition, it and all of the intermediate abi::__pointer_type_info
325 // structs in the chain down to the abi::__class_type_info for the
326 // incomplete class type must be prevented from resolving to the
327 // corresponding type_info structs for the complete class type, possibly
328 // by making them local static objects. Finally, a dummy class RTTI is
329 // generated for the incomplete type that will not resolve to the final
330 // complete class RTTI (because the latter need not exist), possibly by
331 // making it a local static object.
332 if (ContainsIncompleteClassType(Ty))
333 return llvm::GlobalValue::InternalLinkage;
334
335 switch (Ty->getLinkage()) {
336 case NoLinkage:
337 case InternalLinkage:
338 case UniqueExternalLinkage:
339 return llvm::GlobalValue::InternalLinkage;
340
John McCalle54d92b2014-03-10 22:27:33 +0000341 case VisibleNoLinkage:
Guy Benyei11169dd2012-12-18 14:30:41 +0000342 case ExternalLinkage:
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000343 if (!getLangOpts().RTTI) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000344 // RTTI is not enabled, which means that this type info struct is going
345 // to be used for exception handling. Give it linkonce_odr linkage.
346 return llvm::GlobalValue::LinkOnceODRLinkage;
347 }
348
349 if (const RecordType *Record = dyn_cast<RecordType>(Ty)) {
350 const CXXRecordDecl *RD = cast<CXXRecordDecl>(Record->getDecl());
351 if (RD->hasAttr<WeakAttr>())
352 return llvm::GlobalValue::WeakODRLinkage;
353 if (RD->isDynamicClass())
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000354 return getVTableLinkage(RD);
Guy Benyei11169dd2012-12-18 14:30:41 +0000355 }
356
357 return llvm::GlobalValue::LinkOnceODRLinkage;
358 }
359
360 llvm_unreachable("Invalid linkage!");
361}
362
363// CanUseSingleInheritance - Return whether the given record decl has a "single,
364// public, non-virtual base at offset zero (i.e. the derived class is dynamic
365// iff the base is)", according to Itanium C++ ABI, 2.95p6b.
366static bool CanUseSingleInheritance(const CXXRecordDecl *RD) {
367 // Check the number of bases.
368 if (RD->getNumBases() != 1)
369 return false;
370
371 // Get the base.
372 CXXRecordDecl::base_class_const_iterator Base = RD->bases_begin();
373
374 // Check that the base is not virtual.
375 if (Base->isVirtual())
376 return false;
377
378 // Check that the base is public.
379 if (Base->getAccessSpecifier() != AS_public)
380 return false;
381
382 // Check that the class is dynamic iff the base is.
383 const CXXRecordDecl *BaseDecl =
384 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
385 if (!BaseDecl->isEmpty() &&
386 BaseDecl->isDynamicClass() != RD->isDynamicClass())
387 return false;
388
389 return true;
390}
391
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000392void ItaniumRTTIBuilder::BuildVTablePointer(const Type *Ty) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000393 // abi::__class_type_info.
394 static const char * const ClassTypeInfo =
395 "_ZTVN10__cxxabiv117__class_type_infoE";
396 // abi::__si_class_type_info.
397 static const char * const SIClassTypeInfo =
398 "_ZTVN10__cxxabiv120__si_class_type_infoE";
399 // abi::__vmi_class_type_info.
400 static const char * const VMIClassTypeInfo =
401 "_ZTVN10__cxxabiv121__vmi_class_type_infoE";
402
Craig Topper8a13c412014-05-21 05:09:00 +0000403 const char *VTableName = nullptr;
Guy Benyei11169dd2012-12-18 14:30:41 +0000404
405 switch (Ty->getTypeClass()) {
406#define TYPE(Class, Base)
407#define ABSTRACT_TYPE(Class, Base)
408#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
409#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
410#define DEPENDENT_TYPE(Class, Base) case Type::Class:
411#include "clang/AST/TypeNodes.def"
412 llvm_unreachable("Non-canonical and dependent types shouldn't get here");
413
414 case Type::LValueReference:
415 case Type::RValueReference:
416 llvm_unreachable("References shouldn't get here");
417
Richard Smith27d807c2013-04-30 13:56:41 +0000418 case Type::Auto:
419 llvm_unreachable("Undeduced auto type shouldn't get here");
420
Guy Benyei11169dd2012-12-18 14:30:41 +0000421 case Type::Builtin:
422 // GCC treats vector and complex types as fundamental types.
423 case Type::Vector:
424 case Type::ExtVector:
425 case Type::Complex:
426 case Type::Atomic:
427 // FIXME: GCC treats block pointers as fundamental types?!
428 case Type::BlockPointer:
429 // abi::__fundamental_type_info.
430 VTableName = "_ZTVN10__cxxabiv123__fundamental_type_infoE";
431 break;
432
433 case Type::ConstantArray:
434 case Type::IncompleteArray:
435 case Type::VariableArray:
436 // abi::__array_type_info.
437 VTableName = "_ZTVN10__cxxabiv117__array_type_infoE";
438 break;
439
440 case Type::FunctionNoProto:
441 case Type::FunctionProto:
442 // abi::__function_type_info.
443 VTableName = "_ZTVN10__cxxabiv120__function_type_infoE";
444 break;
445
446 case Type::Enum:
447 // abi::__enum_type_info.
448 VTableName = "_ZTVN10__cxxabiv116__enum_type_infoE";
449 break;
450
451 case Type::Record: {
452 const CXXRecordDecl *RD =
453 cast<CXXRecordDecl>(cast<RecordType>(Ty)->getDecl());
454
455 if (!RD->hasDefinition() || !RD->getNumBases()) {
456 VTableName = ClassTypeInfo;
457 } else if (CanUseSingleInheritance(RD)) {
458 VTableName = SIClassTypeInfo;
459 } else {
460 VTableName = VMIClassTypeInfo;
461 }
462
463 break;
464 }
465
466 case Type::ObjCObject:
467 // Ignore protocol qualifiers.
468 Ty = cast<ObjCObjectType>(Ty)->getBaseType().getTypePtr();
469
470 // Handle id and Class.
471 if (isa<BuiltinType>(Ty)) {
472 VTableName = ClassTypeInfo;
473 break;
474 }
475
476 assert(isa<ObjCInterfaceType>(Ty));
477 // Fall through.
478
479 case Type::ObjCInterface:
480 if (cast<ObjCInterfaceType>(Ty)->getDecl()->getSuperClass()) {
481 VTableName = SIClassTypeInfo;
482 } else {
483 VTableName = ClassTypeInfo;
484 }
485 break;
486
487 case Type::ObjCObjectPointer:
488 case Type::Pointer:
489 // abi::__pointer_type_info.
490 VTableName = "_ZTVN10__cxxabiv119__pointer_type_infoE";
491 break;
492
493 case Type::MemberPointer:
494 // abi::__pointer_to_member_type_info.
495 VTableName = "_ZTVN10__cxxabiv129__pointer_to_member_type_infoE";
496 break;
497 }
498
499 llvm::Constant *VTable =
500 CGM.getModule().getOrInsertGlobal(VTableName, CGM.Int8PtrTy);
501
502 llvm::Type *PtrDiffTy =
503 CGM.getTypes().ConvertType(CGM.getContext().getPointerDiffType());
504
505 // The vtable address point is 2.
506 llvm::Constant *Two = llvm::ConstantInt::get(PtrDiffTy, 2);
507 VTable = llvm::ConstantExpr::getInBoundsGetElementPtr(VTable, Two);
508 VTable = llvm::ConstantExpr::getBitCast(VTable, CGM.Int8PtrTy);
509
510 Fields.push_back(VTable);
511}
512
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000513llvm::Constant *ItaniumRTTIBuilder::BuildTypeInfo(QualType Ty, bool Force) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000514 // We want to operate on the canonical type.
515 Ty = CGM.getContext().getCanonicalType(Ty);
516
517 // Check if we've already emitted an RTTI descriptor for this type.
518 SmallString<256> OutName;
519 llvm::raw_svector_ostream Out(OutName);
520 CGM.getCXXABI().getMangleContext().mangleCXXRTTI(Ty, Out);
521 Out.flush();
522 StringRef Name = OutName.str();
523
524 llvm::GlobalVariable *OldGV = CGM.getModule().getNamedGlobal(Name);
525 if (OldGV && !OldGV->isDeclaration()) {
Eli Friedmanba2778f2013-06-28 22:13:27 +0000526 assert(!OldGV->hasAvailableExternallyLinkage() &&
527 "available_externally typeinfos not yet implemented");
Guy Benyei11169dd2012-12-18 14:30:41 +0000528
529 return llvm::ConstantExpr::getBitCast(OldGV, CGM.Int8PtrTy);
530 }
531
532 // Check if there is already an external RTTI descriptor for this type.
533 bool IsStdLib = IsStandardLibraryRTTIDescriptor(Ty);
534 if (!Force && (IsStdLib || ShouldUseExternalRTTIDescriptor(CGM, Ty)))
535 return GetAddrOfExternalRTTIDescriptor(Ty);
536
537 // Emit the standard library with external linkage.
538 llvm::GlobalVariable::LinkageTypes Linkage;
539 if (IsStdLib)
540 Linkage = llvm::GlobalValue::ExternalLinkage;
541 else
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000542 Linkage = CGM.getTypeInfoLinkage(Ty);
Guy Benyei11169dd2012-12-18 14:30:41 +0000543
544 // Add the vtable pointer.
545 BuildVTablePointer(cast<Type>(Ty));
546
547 // And the name.
548 llvm::GlobalVariable *TypeName = GetAddrOfTypeName(Ty, Linkage);
Tim Northover65f582f2014-03-30 17:32:48 +0000549 llvm::Constant *TypeNameField;
Guy Benyei11169dd2012-12-18 14:30:41 +0000550
Tim Northover618ca292014-03-29 15:09:55 +0000551 // If we're supposed to demote the visibility, be sure to set a flag
552 // to use a string comparison for type_info comparisons.
Tim Northover65f582f2014-03-30 17:32:48 +0000553 CGCXXABI::RTTIUniquenessKind RTTIUniqueness =
554 CGM.getCXXABI().classifyRTTIUniqueness(Ty, Linkage);
555 if (RTTIUniqueness != CGCXXABI::RUK_Unique) {
Tim Northover618ca292014-03-29 15:09:55 +0000556 // The flag is the sign bit, which on ARM64 is defined to be clear
557 // for global pointers. This is very ARM64-specific.
Tim Northover65f582f2014-03-30 17:32:48 +0000558 TypeNameField = llvm::ConstantExpr::getPtrToInt(TypeName, CGM.Int64Ty);
Tim Northover618ca292014-03-29 15:09:55 +0000559 llvm::Constant *flag =
560 llvm::ConstantInt::get(CGM.Int64Ty, ((uint64_t)1) << 63);
Tim Northover65f582f2014-03-30 17:32:48 +0000561 TypeNameField = llvm::ConstantExpr::getAdd(TypeNameField, flag);
562 TypeNameField =
563 llvm::ConstantExpr::getIntToPtr(TypeNameField, CGM.Int8PtrTy);
Tim Northover618ca292014-03-29 15:09:55 +0000564 } else {
Tim Northover65f582f2014-03-30 17:32:48 +0000565 TypeNameField = llvm::ConstantExpr::getBitCast(TypeName, CGM.Int8PtrTy);
Tim Northover618ca292014-03-29 15:09:55 +0000566 }
Tim Northover65f582f2014-03-30 17:32:48 +0000567 Fields.push_back(TypeNameField);
Guy Benyei11169dd2012-12-18 14:30:41 +0000568
569 switch (Ty->getTypeClass()) {
570#define TYPE(Class, Base)
571#define ABSTRACT_TYPE(Class, Base)
572#define NON_CANONICAL_UNLESS_DEPENDENT_TYPE(Class, Base) case Type::Class:
573#define NON_CANONICAL_TYPE(Class, Base) case Type::Class:
574#define DEPENDENT_TYPE(Class, Base) case Type::Class:
575#include "clang/AST/TypeNodes.def"
576 llvm_unreachable("Non-canonical and dependent types shouldn't get here");
577
578 // GCC treats vector types as fundamental types.
579 case Type::Builtin:
580 case Type::Vector:
581 case Type::ExtVector:
582 case Type::Complex:
583 case Type::BlockPointer:
584 // Itanium C++ ABI 2.9.5p4:
585 // abi::__fundamental_type_info adds no data members to std::type_info.
586 break;
587
588 case Type::LValueReference:
589 case Type::RValueReference:
590 llvm_unreachable("References shouldn't get here");
591
Richard Smith27d807c2013-04-30 13:56:41 +0000592 case Type::Auto:
593 llvm_unreachable("Undeduced auto type shouldn't get here");
594
Guy Benyei11169dd2012-12-18 14:30:41 +0000595 case Type::ConstantArray:
596 case Type::IncompleteArray:
597 case Type::VariableArray:
598 // Itanium C++ ABI 2.9.5p5:
599 // abi::__array_type_info adds no data members to std::type_info.
600 break;
601
602 case Type::FunctionNoProto:
603 case Type::FunctionProto:
604 // Itanium C++ ABI 2.9.5p5:
605 // abi::__function_type_info adds no data members to std::type_info.
606 break;
607
608 case Type::Enum:
609 // Itanium C++ ABI 2.9.5p5:
610 // abi::__enum_type_info adds no data members to std::type_info.
611 break;
612
613 case Type::Record: {
614 const CXXRecordDecl *RD =
615 cast<CXXRecordDecl>(cast<RecordType>(Ty)->getDecl());
616 if (!RD->hasDefinition() || !RD->getNumBases()) {
617 // We don't need to emit any fields.
618 break;
619 }
620
621 if (CanUseSingleInheritance(RD))
622 BuildSIClassTypeInfo(RD);
623 else
624 BuildVMIClassTypeInfo(RD);
625
626 break;
627 }
628
629 case Type::ObjCObject:
630 case Type::ObjCInterface:
631 BuildObjCObjectTypeInfo(cast<ObjCObjectType>(Ty));
632 break;
633
634 case Type::ObjCObjectPointer:
635 BuildPointerTypeInfo(cast<ObjCObjectPointerType>(Ty)->getPointeeType());
636 break;
637
638 case Type::Pointer:
639 BuildPointerTypeInfo(cast<PointerType>(Ty)->getPointeeType());
640 break;
641
642 case Type::MemberPointer:
643 BuildPointerToMemberTypeInfo(cast<MemberPointerType>(Ty));
644 break;
645
646 case Type::Atomic:
647 // No fields, at least for the moment.
648 break;
649 }
650
651 llvm::Constant *Init = llvm::ConstantStruct::getAnon(Fields);
652
653 llvm::GlobalVariable *GV =
654 new llvm::GlobalVariable(CGM.getModule(), Init->getType(),
655 /*Constant=*/true, Linkage, Init, Name);
656
657 // If there's already an old global variable, replace it with the new one.
658 if (OldGV) {
659 GV->takeName(OldGV);
660 llvm::Constant *NewPtr =
661 llvm::ConstantExpr::getBitCast(GV, OldGV->getType());
662 OldGV->replaceAllUsesWith(NewPtr);
663 OldGV->eraseFromParent();
664 }
665
John McCall57420b32014-02-08 03:26:05 +0000666 // The Itanium ABI specifies that type_info objects must be globally
667 // unique, with one exception: if the type is an incomplete class
668 // type or a (possibly indirect) pointer to one. That exception
669 // affects the general case of comparing type_info objects produced
670 // by the typeid operator, which is why the comparison operators on
671 // std::type_info generally use the type_info name pointers instead
672 // of the object addresses. However, the language's built-in uses
673 // of RTTI generally require class types to be complete, even when
674 // manipulating pointers to those class types. This allows the
675 // implementation of dynamic_cast to rely on address equality tests,
676 // which is much faster.
677
678 // All of this is to say that it's important that both the type_info
679 // object and the type_info name be uniqued when weakly emitted.
680
John McCall8f80a612014-02-08 00:41:16 +0000681 // Give the type_info object and name the formal visibility of the
682 // type itself.
Duncan P. N. Exon Smith48bc2682014-05-05 17:38:39 +0000683 llvm::GlobalValue::VisibilityTypes llvmVisibility;
Duncan P. N. Exon Smith4434d362014-05-07 22:36:11 +0000684 if (llvm::GlobalValue::isLocalLinkage(Linkage))
685 // If the linkage is local, only default visibility makes sense.
686 llvmVisibility = llvm::GlobalValue::DefaultVisibility;
687 else if (RTTIUniqueness == CGCXXABI::RUK_NonUniqueHidden)
Duncan P. N. Exon Smith48bc2682014-05-05 17:38:39 +0000688 llvmVisibility = llvm::GlobalValue::HiddenVisibility;
689 else
690 llvmVisibility = CodeGenModule::GetLLVMVisibility(Ty->getVisibility());
John McCall8f80a612014-02-08 00:41:16 +0000691 TypeName->setVisibility(llvmVisibility);
692 GV->setVisibility(llvmVisibility);
Guy Benyei11169dd2012-12-18 14:30:41 +0000693
Guy Benyei11169dd2012-12-18 14:30:41 +0000694 return llvm::ConstantExpr::getBitCast(GV, CGM.Int8PtrTy);
695}
696
697/// ComputeQualifierFlags - Compute the pointer type info flags from the
698/// given qualifier.
699static unsigned ComputeQualifierFlags(Qualifiers Quals) {
700 unsigned Flags = 0;
701
702 if (Quals.hasConst())
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000703 Flags |= ItaniumRTTIBuilder::PTI_Const;
Guy Benyei11169dd2012-12-18 14:30:41 +0000704 if (Quals.hasVolatile())
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000705 Flags |= ItaniumRTTIBuilder::PTI_Volatile;
Guy Benyei11169dd2012-12-18 14:30:41 +0000706 if (Quals.hasRestrict())
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000707 Flags |= ItaniumRTTIBuilder::PTI_Restrict;
Guy Benyei11169dd2012-12-18 14:30:41 +0000708
709 return Flags;
710}
711
712/// BuildObjCObjectTypeInfo - Build the appropriate kind of type_info
713/// for the given Objective-C object type.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000714void ItaniumRTTIBuilder::BuildObjCObjectTypeInfo(const ObjCObjectType *OT) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000715 // Drop qualifiers.
716 const Type *T = OT->getBaseType().getTypePtr();
717 assert(isa<BuiltinType>(T) || isa<ObjCInterfaceType>(T));
718
719 // The builtin types are abi::__class_type_infos and don't require
720 // extra fields.
721 if (isa<BuiltinType>(T)) return;
722
723 ObjCInterfaceDecl *Class = cast<ObjCInterfaceType>(T)->getDecl();
724 ObjCInterfaceDecl *Super = Class->getSuperClass();
725
726 // Root classes are also __class_type_info.
727 if (!Super) return;
728
729 QualType SuperTy = CGM.getContext().getObjCInterfaceType(Super);
730
731 // Everything else is single inheritance.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000732 llvm::Constant *BaseTypeInfo = ItaniumRTTIBuilder(CGM).BuildTypeInfo(SuperTy);
Guy Benyei11169dd2012-12-18 14:30:41 +0000733 Fields.push_back(BaseTypeInfo);
734}
735
736/// BuildSIClassTypeInfo - Build an abi::__si_class_type_info, used for single
737/// inheritance, according to the Itanium C++ ABI, 2.95p6b.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000738void ItaniumRTTIBuilder::BuildSIClassTypeInfo(const CXXRecordDecl *RD) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000739 // Itanium C++ ABI 2.9.5p6b:
740 // It adds to abi::__class_type_info a single member pointing to the
741 // type_info structure for the base type,
742 llvm::Constant *BaseTypeInfo =
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000743 ItaniumRTTIBuilder(CGM).BuildTypeInfo(RD->bases_begin()->getType());
Guy Benyei11169dd2012-12-18 14:30:41 +0000744 Fields.push_back(BaseTypeInfo);
745}
746
747namespace {
748 /// SeenBases - Contains virtual and non-virtual bases seen when traversing
749 /// a class hierarchy.
750 struct SeenBases {
751 llvm::SmallPtrSet<const CXXRecordDecl *, 16> NonVirtualBases;
752 llvm::SmallPtrSet<const CXXRecordDecl *, 16> VirtualBases;
753 };
754}
755
756/// ComputeVMIClassTypeInfoFlags - Compute the value of the flags member in
757/// abi::__vmi_class_type_info.
758///
759static unsigned ComputeVMIClassTypeInfoFlags(const CXXBaseSpecifier *Base,
760 SeenBases &Bases) {
761
762 unsigned Flags = 0;
763
764 const CXXRecordDecl *BaseDecl =
765 cast<CXXRecordDecl>(Base->getType()->getAs<RecordType>()->getDecl());
766
767 if (Base->isVirtual()) {
768 // Mark the virtual base as seen.
769 if (!Bases.VirtualBases.insert(BaseDecl)) {
770 // If this virtual base has been seen before, then the class is diamond
771 // shaped.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000772 Flags |= ItaniumRTTIBuilder::VMI_DiamondShaped;
Guy Benyei11169dd2012-12-18 14:30:41 +0000773 } else {
774 if (Bases.NonVirtualBases.count(BaseDecl))
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000775 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
Guy Benyei11169dd2012-12-18 14:30:41 +0000776 }
777 } else {
778 // Mark the non-virtual base as seen.
779 if (!Bases.NonVirtualBases.insert(BaseDecl)) {
780 // If this non-virtual base has been seen before, then the class has non-
781 // diamond shaped repeated inheritance.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000782 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
Guy Benyei11169dd2012-12-18 14:30:41 +0000783 } else {
784 if (Bases.VirtualBases.count(BaseDecl))
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000785 Flags |= ItaniumRTTIBuilder::VMI_NonDiamondRepeat;
Guy Benyei11169dd2012-12-18 14:30:41 +0000786 }
787 }
788
789 // Walk all bases.
Aaron Ballman574705e2014-03-13 15:41:46 +0000790 for (const auto &I : BaseDecl->bases())
791 Flags |= ComputeVMIClassTypeInfoFlags(&I, Bases);
Guy Benyei11169dd2012-12-18 14:30:41 +0000792
793 return Flags;
794}
795
796static unsigned ComputeVMIClassTypeInfoFlags(const CXXRecordDecl *RD) {
797 unsigned Flags = 0;
798 SeenBases Bases;
799
800 // Walk all bases.
Aaron Ballman574705e2014-03-13 15:41:46 +0000801 for (const auto &I : RD->bases())
802 Flags |= ComputeVMIClassTypeInfoFlags(&I, Bases);
Guy Benyei11169dd2012-12-18 14:30:41 +0000803
804 return Flags;
805}
806
807/// BuildVMIClassTypeInfo - Build an abi::__vmi_class_type_info, used for
808/// classes with bases that do not satisfy the abi::__si_class_type_info
809/// constraints, according ti the Itanium C++ ABI, 2.9.5p5c.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000810void ItaniumRTTIBuilder::BuildVMIClassTypeInfo(const CXXRecordDecl *RD) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000811 llvm::Type *UnsignedIntLTy =
812 CGM.getTypes().ConvertType(CGM.getContext().UnsignedIntTy);
813
814 // Itanium C++ ABI 2.9.5p6c:
815 // __flags is a word with flags describing details about the class
816 // structure, which may be referenced by using the __flags_masks
817 // enumeration. These flags refer to both direct and indirect bases.
818 unsigned Flags = ComputeVMIClassTypeInfoFlags(RD);
819 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
820
821 // Itanium C++ ABI 2.9.5p6c:
822 // __base_count is a word with the number of direct proper base class
823 // descriptions that follow.
824 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, RD->getNumBases()));
825
826 if (!RD->getNumBases())
827 return;
828
829 llvm::Type *LongLTy =
830 CGM.getTypes().ConvertType(CGM.getContext().LongTy);
831
832 // Now add the base class descriptions.
833
834 // Itanium C++ ABI 2.9.5p6c:
835 // __base_info[] is an array of base class descriptions -- one for every
836 // direct proper base. Each description is of the type:
837 //
838 // struct abi::__base_class_type_info {
839 // public:
840 // const __class_type_info *__base_type;
841 // long __offset_flags;
842 //
843 // enum __offset_flags_masks {
844 // __virtual_mask = 0x1,
845 // __public_mask = 0x2,
846 // __offset_shift = 8
847 // };
848 // };
Aaron Ballman574705e2014-03-13 15:41:46 +0000849 for (const auto &Base : RD->bases()) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000850 // The __base_type member points to the RTTI for the base type.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000851 Fields.push_back(ItaniumRTTIBuilder(CGM).BuildTypeInfo(Base.getType()));
Guy Benyei11169dd2012-12-18 14:30:41 +0000852
853 const CXXRecordDecl *BaseDecl =
Aaron Ballman574705e2014-03-13 15:41:46 +0000854 cast<CXXRecordDecl>(Base.getType()->getAs<RecordType>()->getDecl());
Guy Benyei11169dd2012-12-18 14:30:41 +0000855
856 int64_t OffsetFlags = 0;
857
858 // All but the lower 8 bits of __offset_flags are a signed offset.
859 // For a non-virtual base, this is the offset in the object of the base
860 // subobject. For a virtual base, this is the offset in the virtual table of
861 // the virtual base offset for the virtual base referenced (negative).
862 CharUnits Offset;
Aaron Ballman574705e2014-03-13 15:41:46 +0000863 if (Base.isVirtual())
Guy Benyei11169dd2012-12-18 14:30:41 +0000864 Offset =
Timur Iskhodzhanov58776632013-11-05 15:54:58 +0000865 CGM.getItaniumVTableContext().getVirtualBaseOffsetOffset(RD, BaseDecl);
Guy Benyei11169dd2012-12-18 14:30:41 +0000866 else {
867 const ASTRecordLayout &Layout = CGM.getContext().getASTRecordLayout(RD);
868 Offset = Layout.getBaseClassOffset(BaseDecl);
869 };
870
871 OffsetFlags = uint64_t(Offset.getQuantity()) << 8;
872
873 // The low-order byte of __offset_flags contains flags, as given by the
874 // masks from the enumeration __offset_flags_masks.
Aaron Ballman574705e2014-03-13 15:41:46 +0000875 if (Base.isVirtual())
Guy Benyei11169dd2012-12-18 14:30:41 +0000876 OffsetFlags |= BCTI_Virtual;
Aaron Ballman574705e2014-03-13 15:41:46 +0000877 if (Base.getAccessSpecifier() == AS_public)
Guy Benyei11169dd2012-12-18 14:30:41 +0000878 OffsetFlags |= BCTI_Public;
879
880 Fields.push_back(llvm::ConstantInt::get(LongLTy, OffsetFlags));
881 }
882}
883
884/// BuildPointerTypeInfo - Build an abi::__pointer_type_info struct,
885/// used for pointer types.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000886void ItaniumRTTIBuilder::BuildPointerTypeInfo(QualType PointeeTy) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000887 Qualifiers Quals;
888 QualType UnqualifiedPointeeTy =
889 CGM.getContext().getUnqualifiedArrayType(PointeeTy, Quals);
890
891 // Itanium C++ ABI 2.9.5p7:
892 // __flags is a flag word describing the cv-qualification and other
893 // attributes of the type pointed to
894 unsigned Flags = ComputeQualifierFlags(Quals);
895
896 // Itanium C++ ABI 2.9.5p7:
897 // When the abi::__pbase_type_info is for a direct or indirect pointer to an
898 // incomplete class type, the incomplete target type flag is set.
899 if (ContainsIncompleteClassType(UnqualifiedPointeeTy))
900 Flags |= PTI_Incomplete;
901
902 llvm::Type *UnsignedIntLTy =
903 CGM.getTypes().ConvertType(CGM.getContext().UnsignedIntTy);
904 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
905
906 // Itanium C++ ABI 2.9.5p7:
907 // __pointee is a pointer to the std::type_info derivation for the
908 // unqualified type being pointed to.
909 llvm::Constant *PointeeTypeInfo =
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000910 ItaniumRTTIBuilder(CGM).BuildTypeInfo(UnqualifiedPointeeTy);
Guy Benyei11169dd2012-12-18 14:30:41 +0000911 Fields.push_back(PointeeTypeInfo);
912}
913
914/// BuildPointerToMemberTypeInfo - Build an abi::__pointer_to_member_type_info
915/// struct, used for member pointer types.
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000916void
917ItaniumRTTIBuilder::BuildPointerToMemberTypeInfo(const MemberPointerType *Ty) {
Guy Benyei11169dd2012-12-18 14:30:41 +0000918 QualType PointeeTy = Ty->getPointeeType();
919
920 Qualifiers Quals;
921 QualType UnqualifiedPointeeTy =
922 CGM.getContext().getUnqualifiedArrayType(PointeeTy, Quals);
923
924 // Itanium C++ ABI 2.9.5p7:
925 // __flags is a flag word describing the cv-qualification and other
926 // attributes of the type pointed to.
927 unsigned Flags = ComputeQualifierFlags(Quals);
928
929 const RecordType *ClassType = cast<RecordType>(Ty->getClass());
930
931 // Itanium C++ ABI 2.9.5p7:
932 // When the abi::__pbase_type_info is for a direct or indirect pointer to an
933 // incomplete class type, the incomplete target type flag is set.
934 if (ContainsIncompleteClassType(UnqualifiedPointeeTy))
935 Flags |= PTI_Incomplete;
936
937 if (IsIncompleteClassType(ClassType))
938 Flags |= PTI_ContainingClassIncomplete;
939
940 llvm::Type *UnsignedIntLTy =
941 CGM.getTypes().ConvertType(CGM.getContext().UnsignedIntTy);
942 Fields.push_back(llvm::ConstantInt::get(UnsignedIntLTy, Flags));
943
944 // Itanium C++ ABI 2.9.5p7:
945 // __pointee is a pointer to the std::type_info derivation for the
946 // unqualified type being pointed to.
947 llvm::Constant *PointeeTypeInfo =
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000948 ItaniumRTTIBuilder(CGM).BuildTypeInfo(UnqualifiedPointeeTy);
Guy Benyei11169dd2012-12-18 14:30:41 +0000949 Fields.push_back(PointeeTypeInfo);
950
951 // Itanium C++ ABI 2.9.5p9:
952 // __context is a pointer to an abi::__class_type_info corresponding to the
953 // class type containing the member pointed to
954 // (e.g., the "A" in "int A::*").
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000955 Fields.push_back(
956 ItaniumRTTIBuilder(CGM).BuildTypeInfo(QualType(ClassType, 0)));
Guy Benyei11169dd2012-12-18 14:30:41 +0000957}
958
959llvm::Constant *CodeGenModule::GetAddrOfRTTIDescriptor(QualType Ty,
960 bool ForEH) {
961 // Return a bogus pointer if RTTI is disabled, unless it's for EH.
962 // FIXME: should we even be calling this method if RTTI is disabled
963 // and it's not for EH?
964 if (!ForEH && !getLangOpts().RTTI)
965 return llvm::Constant::getNullValue(Int8PtrTy);
966
967 if (ForEH && Ty->isObjCObjectPointerType() &&
968 LangOpts.ObjCRuntime.isGNUFamily())
969 return ObjCRuntime->GetEHType(Ty);
970
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000971 if (getTarget().getCXXABI().isMicrosoft())
972 return getMSTypeDescriptor(Ty);
973 return ItaniumRTTIBuilder(*this).BuildTypeInfo(Ty);
Guy Benyei11169dd2012-12-18 14:30:41 +0000974}
975
976void CodeGenModule::EmitFundamentalRTTIDescriptor(QualType Type) {
977 QualType PointerType = Context.getPointerType(Type);
978 QualType PointerTypeConst = Context.getPointerType(Type.withConst());
Warren Hunt5c2b4ea2014-05-23 16:07:43 +0000979 ItaniumRTTIBuilder(*this).BuildTypeInfo(Type, true);
980 ItaniumRTTIBuilder(*this).BuildTypeInfo(PointerType, true);
981 ItaniumRTTIBuilder(*this).BuildTypeInfo(PointerTypeConst, true);
Guy Benyei11169dd2012-12-18 14:30:41 +0000982}
983
984void CodeGenModule::EmitFundamentalRTTIDescriptors() {
985 QualType FundamentalTypes[] = { Context.VoidTy, Context.NullPtrTy,
986 Context.BoolTy, Context.WCharTy,
987 Context.CharTy, Context.UnsignedCharTy,
988 Context.SignedCharTy, Context.ShortTy,
989 Context.UnsignedShortTy, Context.IntTy,
990 Context.UnsignedIntTy, Context.LongTy,
991 Context.UnsignedLongTy, Context.LongLongTy,
Yunzhong Gao06770f92014-04-17 02:26:26 +0000992 Context.UnsignedLongLongTy,
993 Context.HalfTy, Context.FloatTy,
Guy Benyei11169dd2012-12-18 14:30:41 +0000994 Context.DoubleTy, Context.LongDoubleTy,
995 Context.Char16Ty, Context.Char32Ty };
Craig Toppere5ce8312013-07-15 03:38:40 +0000996 for (unsigned i = 0; i < llvm::array_lengthof(FundamentalTypes); ++i)
Guy Benyei11169dd2012-12-18 14:30:41 +0000997 EmitFundamentalRTTIDescriptor(FundamentalTypes[i]);
998}