blob: b437f3dfbd61f04b0da1e6df14e3249ab3730f22 [file] [log] [blame]
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +00001//===--- CGDebugInfo.cpp - Emit Debug Information for a Module ------------===//
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 coordinates the debug information generation while generating code.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CGDebugInfo.h"
15#include "CodeGenModule.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000016#include "clang/AST/ASTContext.h"
Devang Patel9ca36b62009-02-26 21:10:26 +000017#include "clang/AST/DeclObjC.h"
Chris Lattner3cc5c402008-11-11 07:01:36 +000018#include "clang/AST/Expr.h"
Daniel Dunbare91593e2008-08-11 04:54:23 +000019#include "clang/AST/RecordLayout.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000020#include "clang/Basic/SourceManager.h"
21#include "clang/Basic/FileManager.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000022#include "llvm/Constants.h"
23#include "llvm/DerivedTypes.h"
24#include "llvm/Instructions.h"
25#include "llvm/Intrinsics.h"
26#include "llvm/Module.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000027#include "llvm/ADT/StringExtras.h"
28#include "llvm/ADT/SmallVector.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000029#include "llvm/Support/Dwarf.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000030#include "llvm/Target/TargetMachine.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000031using namespace clang;
32using namespace clang::CodeGen;
33
34CGDebugInfo::CGDebugInfo(CodeGenModule *m)
Chris Lattner9c85ba32008-11-10 06:08:34 +000035 : M(m), DebugFactory(M->getModule()) {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000036}
37
Chris Lattner9c85ba32008-11-10 06:08:34 +000038CGDebugInfo::~CGDebugInfo() {
Daniel Dunbar66031a52008-10-17 16:15:48 +000039 assert(RegionStack.empty() && "Region stack mismatch, stack not empty!");
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000040}
41
Chris Lattner9c85ba32008-11-10 06:08:34 +000042void CGDebugInfo::setLocation(SourceLocation Loc) {
43 if (Loc.isValid())
Chris Lattnerf7cf85b2009-01-16 07:36:28 +000044 CurLoc = M->getContext().getSourceManager().getInstantiationLoc(Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000045}
46
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000047/// getOrCreateCompileUnit - Get the compile unit from the cache or create a new
Daniel Dunbar25f51dd2008-10-24 08:38:36 +000048/// one if necessary. This returns null for invalid source locations.
Chris Lattner9c85ba32008-11-10 06:08:34 +000049llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
Daniel Dunbar831570c2009-01-22 00:09:25 +000050 // FIXME: Until we do a complete job of emitting debug information,
51 // we need to support making dummy compile units so that we generate
52 // "well formed" debug info.
53 const FileEntry *FE = 0;
Daniel Dunbar25f51dd2008-10-24 08:38:36 +000054
Devang Patel77820222009-02-24 23:16:03 +000055 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattner515455a2009-03-25 03:28:08 +000056 bool isMain;
Daniel Dunbar831570c2009-01-22 00:09:25 +000057 if (Loc.isValid()) {
Daniel Dunbar831570c2009-01-22 00:09:25 +000058 Loc = SM.getInstantiationLoc(Loc);
59 FE = SM.getFileEntryForID(SM.getFileID(Loc));
Chris Lattner515455a2009-03-25 03:28:08 +000060 isMain = SM.getFileID(Loc) == SM.getMainFileID();
Devang Patel77820222009-02-24 23:16:03 +000061 } else {
62 // If Loc is not valid then use main file id.
63 FE = SM.getFileEntryForID(SM.getMainFileID());
Chris Lattner515455a2009-03-25 03:28:08 +000064 isMain = true;
Daniel Dunbar831570c2009-01-22 00:09:25 +000065 }
66
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000067 // See if this compile unit has been used before.
Chris Lattner9c85ba32008-11-10 06:08:34 +000068 llvm::DICompileUnit &Unit = CompileUnitCache[FE];
69 if (!Unit.isNull()) return Unit;
70
71 // Get source file information.
Daniel Dunbar831570c2009-01-22 00:09:25 +000072 const char *FileName = FE ? FE->getName() : "<unknown>";
Daniel Dunbarf8e58d02009-02-07 00:40:41 +000073 const char *DirName = FE ? FE->getDir()->getName() : "<unknown>";
Daniel Dunbar2104bf92008-10-24 00:46:51 +000074
Chris Lattner515455a2009-03-25 03:28:08 +000075 const LangOptions &LO = M->getLangOptions();
76 unsigned LangTag;
77 if (LO.CPlusPlus) {
78 if (LO.ObjC1)
79 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
80 else
81 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
82 } else if (LO.ObjC1) {
Devang Patel8d9aefc2009-03-24 20:35:51 +000083 LangTag = llvm::dwarf::DW_LANG_ObjC;
Chris Lattner515455a2009-03-25 03:28:08 +000084 } else if (LO.C99) {
Devang Patel8d9aefc2009-03-24 20:35:51 +000085 LangTag = llvm::dwarf::DW_LANG_C99;
Chris Lattner515455a2009-03-25 03:28:08 +000086 } else {
87 LangTag = llvm::dwarf::DW_LANG_C89;
88 }
Devang Patel8d9aefc2009-03-24 20:35:51 +000089
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000090 // Create new compile unit.
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000091 // FIXME: Do not know how to get clang version yet.
Devang Patelc20482b2009-03-19 00:23:53 +000092 // FIXME: Encode command line options.
93 // FIXME: Encode optimization level.
Devang Patel8d9aefc2009-03-24 20:35:51 +000094 return Unit = DebugFactory.CreateCompileUnit(LangTag, FileName, DirName,
95 "clang", isMain);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000096}
97
Devang Patel65e99f22009-02-25 01:36:11 +000098/// CreateType - Get the Basic type from the cache or create a new
Chris Lattner9c85ba32008-11-10 06:08:34 +000099/// one if necessary.
100llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT,
Devang Patel65e99f22009-02-25 01:36:11 +0000101 llvm::DICompileUnit Unit) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000102 unsigned Encoding = 0;
103 switch (BT->getKind()) {
104 default:
105 case BuiltinType::Void:
106 return llvm::DIType();
107 case BuiltinType::UChar:
108 case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break;
109 case BuiltinType::Char_S:
110 case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break;
111 case BuiltinType::UShort:
112 case BuiltinType::UInt:
113 case BuiltinType::ULong:
114 case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break;
115 case BuiltinType::Short:
116 case BuiltinType::Int:
117 case BuiltinType::Long:
118 case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break;
119 case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break;
120 case BuiltinType::Float:
121 case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break;
122 }
123 // Bit size, align and offset of the type.
124 uint64_t Size = M->getContext().getTypeSize(BT);
125 uint64_t Align = M->getContext().getTypeAlign(BT);
126 uint64_t Offset = 0;
127
128 return DebugFactory.CreateBasicType(Unit, BT->getName(), Unit, 0, Size, Align,
129 Offset, /*flags*/ 0, Encoding);
130}
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000131
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000132/// getOrCreateCVRType - Get the CVR qualified type from the cache or create
133/// a new one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000134llvm::DIType CGDebugInfo::CreateCVRType(QualType Ty, llvm::DICompileUnit Unit) {
135 // We will create one Derived type for one qualifier and recurse to handle any
136 // additional ones.
137 llvm::DIType FromTy;
138 unsigned Tag;
139 if (Ty.isConstQualified()) {
140 Tag = llvm::dwarf::DW_TAG_const_type;
141 Ty.removeConst();
142 FromTy = getOrCreateType(Ty, Unit);
143 } else if (Ty.isVolatileQualified()) {
144 Tag = llvm::dwarf::DW_TAG_volatile_type;
145 Ty.removeVolatile();
146 FromTy = getOrCreateType(Ty, Unit);
147 } else {
148 assert(Ty.isRestrictQualified() && "Unknown type qualifier for debug info");
149 Tag = llvm::dwarf::DW_TAG_restrict_type;
150 Ty.removeRestrict();
151 FromTy = getOrCreateType(Ty, Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000152 }
Chris Lattner9c85ba32008-11-10 06:08:34 +0000153
Daniel Dunbar3845f862008-10-31 03:54:29 +0000154 // No need to fill in the Name, Line, Size, Alignment, Offset in case of
155 // CVR derived types.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000156 return DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
157 0, 0, 0, 0, 0, FromTy);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000158}
159
Chris Lattner9c85ba32008-11-10 06:08:34 +0000160llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
161 llvm::DICompileUnit Unit) {
162 llvm::DIType EltTy = getOrCreateType(Ty->getPointeeType(), Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000163
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000164 // Bit size, align and offset of the type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000165 uint64_t Size = M->getContext().getTypeSize(Ty);
166 uint64_t Align = M->getContext().getTypeAlign(Ty);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000167
Chris Lattner9c85ba32008-11-10 06:08:34 +0000168 return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
169 "", llvm::DICompileUnit(),
170 0, Size, Align, 0, 0, EltTy);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000171}
172
Chris Lattner9c85ba32008-11-10 06:08:34 +0000173llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty,
174 llvm::DICompileUnit Unit) {
175 // Typedefs are derived from some other type. If we have a typedef of a
176 // typedef, make sure to emit the whole chain.
177 llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
178
179 // We don't set size information, but do specify where the typedef was
180 // declared.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000181 std::string TyName = Ty->getDecl()->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000182 SourceLocation DefLoc = Ty->getDecl()->getLocation();
183 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000184
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000185 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000186 uint64_t Line = SM.getInstantiationLineNumber(DefLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000187
Chris Lattner9c85ba32008-11-10 06:08:34 +0000188 return DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, Unit,
189 TyName, DefUnit, Line, 0, 0, 0, 0, Src);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000190}
191
Chris Lattner9c85ba32008-11-10 06:08:34 +0000192llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
193 llvm::DICompileUnit Unit) {
194 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000195
Chris Lattner9c85ba32008-11-10 06:08:34 +0000196 // Add the result type at least.
197 EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit));
198
199 // Set up remainder of arguments if there is a prototype.
200 // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'!
Douglas Gregor72564e72009-02-26 23:50:07 +0000201 if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000202 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
203 EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
204 } else {
205 // FIXME: Handle () case in C. llvm-gcc doesn't do it either.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000206 }
207
Chris Lattner9c85ba32008-11-10 06:08:34 +0000208 llvm::DIArray EltTypeArray =
209 DebugFactory.GetOrCreateArray(&EltTys[0], EltTys.size());
210
211 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
212 Unit, "", llvm::DICompileUnit(),
213 0, 0, 0, 0, 0,
214 llvm::DIType(), EltTypeArray);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000215}
216
Devang Patel65e99f22009-02-25 01:36:11 +0000217/// CreateType - get structure or union type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000218llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
219 llvm::DICompileUnit Unit) {
Douglas Gregora4c46df2008-12-11 17:59:21 +0000220 RecordDecl *Decl = Ty->getDecl();
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000221
Chris Lattner9c85ba32008-11-10 06:08:34 +0000222 unsigned Tag;
223 if (Decl->isStruct())
224 Tag = llvm::dwarf::DW_TAG_structure_type;
225 else if (Decl->isUnion())
226 Tag = llvm::dwarf::DW_TAG_union_type;
227 else {
228 assert(Decl->isClass() && "Unknown RecordType!");
229 Tag = llvm::dwarf::DW_TAG_class_type;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000230 }
231
Sanjiv Gupta507de852008-06-09 10:47:41 +0000232 SourceManager &SM = M->getContext().getSourceManager();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000233
Chris Lattner9c85ba32008-11-10 06:08:34 +0000234 // Get overall information about the record type for the debug info.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000235 std::string Name = Decl->getNameAsString();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000236
Chris Lattner9c85ba32008-11-10 06:08:34 +0000237 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation());
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000238 unsigned Line = SM.getInstantiationLineNumber(Decl->getLocation());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000239
240
241 // Records and classes and unions can all be recursive. To handle them, we
242 // first generate a debug descriptor for the struct as a forward declaration.
243 // Then (if it is a definition) we go through and get debug info for all of
244 // its members. Finally, we create a descriptor for the complete type (which
245 // may refer to the forward decl if the struct is recursive) and replace all
246 // uses of the forward declaration with the final definition.
247 llvm::DIType FwdDecl =
248 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
249 llvm::DIType(), llvm::DIArray());
250
251 // If this is just a forward declaration, return it.
252 if (!Decl->getDefinition(M->getContext()))
253 return FwdDecl;
Sanjiv Gupta507de852008-06-09 10:47:41 +0000254
Chris Lattner9c85ba32008-11-10 06:08:34 +0000255 // Otherwise, insert it into the TypeCache so that recursive uses will find
256 // it.
257 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl;
258
259 // Convert all the elements.
260 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
261
262 const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(Decl);
263
264 unsigned FieldNo = 0;
Douglas Gregora4c46df2008-12-11 17:59:21 +0000265 for (RecordDecl::field_iterator I = Decl->field_begin(),
266 E = Decl->field_end();
267 I != E; ++I, ++FieldNo) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000268 FieldDecl *Field = *I;
269 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
Chris Lattner8ec03f52008-11-24 03:54:41 +0000270
271 std::string FieldName = Field->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000272
273 // Get the location for the field.
274 SourceLocation FieldDefLoc = Field->getLocation();
275 llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000276 unsigned FieldLine = SM.getInstantiationLineNumber(FieldDefLoc);
Devang Patelec9b5d52009-03-16 23:47:53 +0000277
278 QualType FType = Field->getType();
279 uint64_t FieldSize = 0;
280 unsigned FieldAlign = 0;
281 if (!FType->isIncompleteArrayType()) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000282
Devang Patelec9b5d52009-03-16 23:47:53 +0000283 // Bit size, align and offset of the type.
284 FieldSize = M->getContext().getTypeSize(FType);
285 Expr *BitWidth = Field->getBitWidth();
286 if (BitWidth)
287 FieldSize =
288 BitWidth->getIntegerConstantExprValue(M->getContext()).getZExtValue();
289
290 FieldAlign = M->getContext().getTypeAlign(FType);
291 }
292
Chris Lattner9c85ba32008-11-10 06:08:34 +0000293 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
294
295 // Create a DW_TAG_member node to remember the offset of this field in the
296 // struct. FIXME: This is an absolutely insane way to capture this
297 // information. When we gut debug info, this should be fixed.
298 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
299 FieldName, FieldDefUnit,
300 FieldLine, FieldSize, FieldAlign,
301 FieldOffset, 0, FieldTy);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000302 EltTys.push_back(FieldTy);
303 }
304
305 llvm::DIArray Elements =
306 DebugFactory.GetOrCreateArray(&EltTys[0], EltTys.size());
307
308 // Bit size, align and offset of the type.
309 uint64_t Size = M->getContext().getTypeSize(Ty);
310 uint64_t Align = M->getContext().getTypeAlign(Ty);
311
312 llvm::DIType RealDecl =
313 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
314 Align, 0, 0, llvm::DIType(), Elements);
315
316 // Now that we have a real decl for the struct, replace anything using the
317 // old decl with the new one. This will recursively update the debug info.
318 FwdDecl.getGV()->replaceAllUsesWith(RealDecl.getGV());
319 FwdDecl.getGV()->eraseFromParent();
320
321 return RealDecl;
322}
323
Devang Patel9ca36b62009-02-26 21:10:26 +0000324/// CreateType - get objective-c interface type.
325llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
326 llvm::DICompileUnit Unit) {
327 ObjCInterfaceDecl *Decl = Ty->getDecl();
328
329 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
330 SourceManager &SM = M->getContext().getSourceManager();
331
332 // Get overall information about the record type for the debug info.
333 std::string Name = Decl->getNameAsString();
334
335 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation());
336 unsigned Line = SM.getInstantiationLineNumber(Decl->getLocation());
337
338
339 // To handle recursive interface, we
340 // first generate a debug descriptor for the struct as a forward declaration.
341 // Then (if it is a definition) we go through and get debug info for all of
342 // its members. Finally, we create a descriptor for the complete type (which
343 // may refer to the forward decl if the struct is recursive) and replace all
344 // uses of the forward declaration with the final definition.
345 llvm::DIType FwdDecl =
346 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
347 llvm::DIType(), llvm::DIArray());
348
349 // If this is just a forward declaration, return it.
350 if (Decl->isForwardDecl())
351 return FwdDecl;
352
353 // Otherwise, insert it into the TypeCache so that recursive uses will find
354 // it.
355 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl;
356
357 // Convert all the elements.
358 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
359
Devang Patelfbe899f2009-03-10 21:30:26 +0000360 ObjCInterfaceDecl *SClass = Decl->getSuperClass();
361 if (SClass) {
362 llvm::DIType SClassTy =
363 getOrCreateType(M->getContext().getObjCInterfaceType(SClass), Unit);
364 llvm::DIType InhTag =
365 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
366 Unit, "", Unit, 0, 0, 0,
367 0 /* offset */, 0, SClassTy);
368 EltTys.push_back(InhTag);
369 }
370
Devang Patel9ca36b62009-02-26 21:10:26 +0000371 const ASTRecordLayout &RL = M->getContext().getASTObjCInterfaceLayout(Decl);
372
373 unsigned FieldNo = 0;
374 for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(),
375 E = Decl->ivar_end(); I != E; ++I, ++FieldNo) {
376 ObjCIvarDecl *Field = *I;
377 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
378
379 std::string FieldName = Field->getNameAsString();
380
381 // Get the location for the field.
382 SourceLocation FieldDefLoc = Field->getLocation();
383 llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
384 unsigned FieldLine = SM.getInstantiationLineNumber(FieldDefLoc);
Devang Patel99c20eb2009-03-20 18:24:39 +0000385
386 QualType FType = Field->getType();
387 uint64_t FieldSize = 0;
388 unsigned FieldAlign = 0;
Devang Patelc20482b2009-03-19 00:23:53 +0000389
Devang Patel99c20eb2009-03-20 18:24:39 +0000390 if (!FType->isIncompleteArrayType()) {
391
392 // Bit size, align and offset of the type.
393 FieldSize = M->getContext().getTypeSize(FType);
394 Expr *BitWidth = Field->getBitWidth();
395 if (BitWidth)
396 FieldSize =
397 BitWidth->getIntegerConstantExprValue(M->getContext()).getZExtValue();
398
399 FieldAlign = M->getContext().getTypeAlign(FType);
400 }
401
402 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
403
Devang Patelc20482b2009-03-19 00:23:53 +0000404 unsigned Flags = 0;
405 if (Field->getAccessControl() == ObjCIvarDecl::Protected)
406 Flags = llvm::DIType::FlagProtected;
407 else if (Field->getAccessControl() == ObjCIvarDecl::Private)
408 Flags = llvm::DIType::FlagPrivate;
409
Devang Patel9ca36b62009-02-26 21:10:26 +0000410 // Create a DW_TAG_member node to remember the offset of this field in the
411 // struct. FIXME: This is an absolutely insane way to capture this
412 // information. When we gut debug info, this should be fixed.
413 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
414 FieldName, FieldDefUnit,
415 FieldLine, FieldSize, FieldAlign,
Devang Patelc20482b2009-03-19 00:23:53 +0000416 FieldOffset, Flags, FieldTy);
Devang Patel9ca36b62009-02-26 21:10:26 +0000417 EltTys.push_back(FieldTy);
418 }
419
420 llvm::DIArray Elements =
421 DebugFactory.GetOrCreateArray(&EltTys[0], EltTys.size());
422
423 // Bit size, align and offset of the type.
424 uint64_t Size = M->getContext().getTypeSize(Ty);
425 uint64_t Align = M->getContext().getTypeAlign(Ty);
426
427 llvm::DIType RealDecl =
428 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
429 Align, 0, 0, llvm::DIType(), Elements);
430
431 // Now that we have a real decl for the struct, replace anything using the
432 // old decl with the new one. This will recursively update the debug info.
433 FwdDecl.getGV()->replaceAllUsesWith(RealDecl.getGV());
434 FwdDecl.getGV()->eraseFromParent();
435
436 return RealDecl;
437}
438
Chris Lattner9c85ba32008-11-10 06:08:34 +0000439llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty,
440 llvm::DICompileUnit Unit) {
441 EnumDecl *Decl = Ty->getDecl();
442
443 llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
444
445 // Create DIEnumerator elements for each enumerator.
Douglas Gregor44b43212008-12-11 16:49:14 +0000446 for (EnumDecl::enumerator_iterator Enum = Decl->enumerator_begin(),
447 EnumEnd = Decl->enumerator_end();
448 Enum != EnumEnd; ++Enum) {
449 Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getNameAsString(),
450 Enum->getInitVal().getZExtValue()));
Chris Lattner9c85ba32008-11-10 06:08:34 +0000451 }
452
453 // Return a CompositeType for the enum itself.
454 llvm::DIArray EltArray =
455 DebugFactory.GetOrCreateArray(&Enumerators[0], Enumerators.size());
456
Chris Lattner8ec03f52008-11-24 03:54:41 +0000457 std::string EnumName = Decl->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000458 SourceLocation DefLoc = Decl->getLocation();
459 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
460 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000461 unsigned Line = SM.getInstantiationLineNumber(DefLoc);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000462
463 // Size and align of the type.
464 uint64_t Size = M->getContext().getTypeSize(Ty);
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000465 unsigned Align = M->getContext().getTypeAlign(Ty);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000466
467 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
468 Unit, EnumName, DefUnit, Line,
469 Size, Align, 0, 0,
470 llvm::DIType(), EltArray);
471}
472
473llvm::DIType CGDebugInfo::CreateType(const TagType *Ty,
474 llvm::DICompileUnit Unit) {
475 if (const RecordType *RT = dyn_cast<RecordType>(Ty))
476 return CreateType(RT, Unit);
477 else if (const EnumType *ET = dyn_cast<EnumType>(Ty))
478 return CreateType(ET, Unit);
479
480 return llvm::DIType();
481}
482
483llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
484 llvm::DICompileUnit Unit) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000485 uint64_t Size;
486 uint64_t Align;
487
488
Nuno Lopes010d5142009-01-28 00:35:17 +0000489 // FIXME: make getTypeAlign() aware of VLAs and incomplete array types
Anders Carlsson835c9092009-01-05 01:23:29 +0000490 if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000491 Size = 0;
492 Align =
Nuno Lopes010d5142009-01-28 00:35:17 +0000493 M->getContext().getTypeAlign(M->getContext().getBaseElementType(VAT));
494 } else if (Ty->isIncompleteArrayType()) {
495 Size = 0;
496 Align = M->getContext().getTypeAlign(Ty->getElementType());
Anders Carlsson835c9092009-01-05 01:23:29 +0000497 } else {
498 // Size and align of the whole array, not the element type.
499 Size = M->getContext().getTypeSize(Ty);
500 Align = M->getContext().getTypeAlign(Ty);
501 }
Chris Lattner9c85ba32008-11-10 06:08:34 +0000502
503 // Add the dimensions of the array. FIXME: This loses CV qualifiers from
504 // interior arrays, do we care? Why aren't nested arrays represented the
505 // obvious/recursive way?
506 llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts;
507 QualType EltTy(Ty, 0);
508 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
Sanjiv Gupta507de852008-06-09 10:47:41 +0000509 uint64_t Upper = 0;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000510 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
511 Upper = CAT->getSize().getZExtValue() - 1;
512 // FIXME: Verify this is right for VLAs.
513 Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper));
514 EltTy = Ty->getElementType();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000515 }
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000516
Chris Lattner9c85ba32008-11-10 06:08:34 +0000517 llvm::DIArray SubscriptArray =
518 DebugFactory.GetOrCreateArray(&Subscripts[0], Subscripts.size());
519
520 return DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type,
521 Unit, "", llvm::DICompileUnit(),
522 0, Size, Align, 0, 0,
523 getOrCreateType(EltTy, Unit),
524 SubscriptArray);
525}
526
527
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000528/// getOrCreateType - Get the type from the cache or create a new
529/// one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000530llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
531 llvm::DICompileUnit Unit) {
532 if (Ty.isNull())
533 return llvm::DIType();
534
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000535 // Check to see if the compile unit already has created this type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000536 llvm::DIType &Slot = TypeCache[Ty.getAsOpaquePtr()];
537 if (!Slot.isNull()) return Slot;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000538
Chris Lattner9c85ba32008-11-10 06:08:34 +0000539 // Handle CVR qualifiers, which recursively handles what they refer to.
540 if (Ty.getCVRQualifiers())
541 return Slot = CreateCVRType(Ty, Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000542
543 // Work out details of type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000544 switch (Ty->getTypeClass()) {
Douglas Gregor72564e72009-02-26 23:50:07 +0000545#define TYPE(Class, Base)
546#define ABSTRACT_TYPE(Class, Base)
547#define NON_CANONICAL_TYPE(Class, Base)
548#define DEPENDENT_TYPE(Class, Base) case Type::Class:
549#include "clang/AST/TypeNodes.def"
550 assert(false && "Dependent types cannot show up in debug information");
551
Chris Lattner9c85ba32008-11-10 06:08:34 +0000552 case Type::Complex:
Sebastian Redl7c80bd62009-03-16 23:22:08 +0000553 case Type::LValueReference:
554 case Type::RValueReference:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000555 case Type::Vector:
556 case Type::ExtVector:
Fariborz Jahanianf11284a2009-02-17 18:27:45 +0000557 case Type::ExtQual:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000558 case Type::ObjCQualifiedInterface:
559 case Type::ObjCQualifiedId:
Eli Friedman00524e32009-02-27 23:15:07 +0000560 case Type::FixedWidthInt:
561 case Type::BlockPointer:
562 case Type::MemberPointer:
563 case Type::ClassTemplateSpecialization:
Douglas Gregore4e5b052009-03-19 00:18:19 +0000564 case Type::QualifiedName:
Eli Friedman00524e32009-02-27 23:15:07 +0000565 case Type::ObjCQualifiedClass:
566 // Unsupported types
Chris Lattner9c85ba32008-11-10 06:08:34 +0000567 return llvm::DIType();
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000568
Devang Patele7987062009-03-02 17:58:28 +0000569 case Type::ObjCInterface:
570 Slot = CreateType(cast<ObjCInterfaceType>(Ty), Unit); break;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000571 case Type::Builtin: Slot = CreateType(cast<BuiltinType>(Ty), Unit); break;
572 case Type::Pointer: Slot = CreateType(cast<PointerType>(Ty), Unit); break;
Douglas Gregor72564e72009-02-26 23:50:07 +0000573 case Type::Typedef: Slot = CreateType(cast<TypedefType>(Ty), Unit); break;
574 case Type::Record:
Douglas Gregor72564e72009-02-26 23:50:07 +0000575 case Type::Enum:
576 Slot = CreateType(cast<TagType>(Ty), Unit);
577 break;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000578 case Type::FunctionProto:
579 case Type::FunctionNoProto:
Chris Lattner3cc5c402008-11-11 07:01:36 +0000580 return Slot = CreateType(cast<FunctionType>(Ty), Unit);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000581
582 case Type::ConstantArray:
583 case Type::VariableArray:
584 case Type::IncompleteArray:
Chris Lattner3cc5c402008-11-11 07:01:36 +0000585 return Slot = CreateType(cast<ArrayType>(Ty), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000586 case Type::TypeOfExpr:
587 return Slot = getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr()
Chris Lattner3cc5c402008-11-11 07:01:36 +0000588 ->getType(), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000589 case Type::TypeOf:
Chris Lattner3cc5c402008-11-11 07:01:36 +0000590 return Slot = getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(),
591 Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000592 }
Chris Lattner9c85ba32008-11-10 06:08:34 +0000593
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000594 return Slot;
595}
596
597/// EmitFunctionStart - Constructs the debug code for entering a function -
598/// "llvm.dbg.func.start.".
Chris Lattner9c85ba32008-11-10 06:08:34 +0000599void CGDebugInfo::EmitFunctionStart(const char *Name, QualType ReturnType,
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000600 llvm::Function *Fn,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000601 CGBuilderTy &Builder) {
602 // FIXME: Why is this using CurLoc???
603 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000604 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000605 unsigned LineNo = SM.getInstantiationLineNumber(CurLoc);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000606
607 llvm::DISubprogram SP =
608 DebugFactory.CreateSubprogram(Unit, Name, Name, "", Unit, LineNo,
609 getOrCreateType(ReturnType, Unit),
610 Fn->hasInternalLinkage(), true/*definition*/);
611
612 DebugFactory.InsertSubprogramStart(SP, Builder.GetInsertBlock());
613
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000614 // Push function on region stack.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000615 RegionStack.push_back(SP);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000616}
617
618
Chris Lattner9c85ba32008-11-10 06:08:34 +0000619void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) {
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000620 if (CurLoc.isInvalid() || CurLoc.isMacroID()) return;
621
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000622 // Don't bother if things are the same as last time.
623 SourceManager &SM = M->getContext().getSourceManager();
624 if (CurLoc == PrevLoc
Chris Lattner30fc9332009-02-04 01:06:56 +0000625 || (SM.getInstantiationLineNumber(CurLoc) ==
626 SM.getInstantiationLineNumber(PrevLoc)
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000627 && SM.isFromSameFile(CurLoc, PrevLoc)))
628 return;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000629
630 // Update last state.
631 PrevLoc = CurLoc;
632
633 // Get the appropriate compile unit.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000634 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000635 DebugFactory.InsertStopPoint(Unit, SM.getInstantiationLineNumber(CurLoc),
636 SM.getInstantiationColumnNumber(CurLoc),
Chris Lattner9c85ba32008-11-10 06:08:34 +0000637 Builder.GetInsertBlock());
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000638}
639
640/// EmitRegionStart- Constructs the debug code for entering a declarative
641/// region - "llvm.dbg.region.start.".
Chris Lattner9c85ba32008-11-10 06:08:34 +0000642void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) {
643 llvm::DIDescriptor D;
Daniel Dunbar5273f512008-10-17 01:07:56 +0000644 if (!RegionStack.empty())
Chris Lattner9c85ba32008-11-10 06:08:34 +0000645 D = RegionStack.back();
646 D = DebugFactory.CreateBlock(D);
647 RegionStack.push_back(D);
648 DebugFactory.InsertRegionStart(D, Builder.GetInsertBlock());
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000649}
650
651/// EmitRegionEnd - Constructs the debug code for exiting a declarative
652/// region - "llvm.dbg.region.end."
Chris Lattner9c85ba32008-11-10 06:08:34 +0000653void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +0000654 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
655
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000656 // Provide an region stop point.
657 EmitStopPoint(Fn, Builder);
658
Chris Lattner9c85ba32008-11-10 06:08:34 +0000659 DebugFactory.InsertRegionEnd(RegionStack.back(), Builder.GetInsertBlock());
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000660 RegionStack.pop_back();
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000661}
662
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000663/// EmitDeclare - Emit local variable declaration debug info.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000664void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag,
665 llvm::Value *Storage, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +0000666 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
667
Chris Lattner9c85ba32008-11-10 06:08:34 +0000668 // Get location information.
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000669 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000670 unsigned Line = SM.getInstantiationLineNumber(Decl->getLocation());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000671 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
672
673 // Create the descriptor for the variable.
674 llvm::DIVariable D =
Chris Lattnerd9d22dd2008-11-24 05:29:24 +0000675 DebugFactory.CreateVariable(Tag, RegionStack.back(),Decl->getNameAsString(),
Chris Lattner9c85ba32008-11-10 06:08:34 +0000676 Unit, Line,
677 getOrCreateType(Decl->getType(), Unit));
678 // Insert an llvm.dbg.declare into the current block.
679 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock());
Sanjiv Guptacc9b1632008-05-30 10:30:31 +0000680}
681
Chris Lattner9c85ba32008-11-10 06:08:34 +0000682void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl,
683 llvm::Value *Storage,
684 CGBuilderTy &Builder) {
685 EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder);
686}
687
688/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
689/// variable declaration.
690void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
691 CGBuilderTy &Builder) {
692 EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder);
693}
694
695
696
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000697/// EmitGlobalVariable - Emit information about a global variable.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000698void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
699 const VarDecl *Decl) {
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000700 // Create global variable debug descriptor.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000701 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000702 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattnerf7cf85b2009-01-16 07:36:28 +0000703 unsigned LineNo = SM.getInstantiationLineNumber(Decl->getLocation());
Chris Lattner8ec03f52008-11-24 03:54:41 +0000704
705 std::string Name = Decl->getNameAsString();
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000706
707 QualType T = Decl->getType();
708 if (T->isIncompleteArrayType()) {
709
710 // CodeGen turns int[] into int[1] so we'll do the same here.
711 llvm::APSInt ConstVal(32);
712
713 ConstVal = 1;
714 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
715
716 T = M->getContext().getConstantArrayType(ET, ConstVal,
717 ArrayType::Normal, 0);
718 }
719
Chris Lattner9c85ba32008-11-10 06:08:34 +0000720 DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo,
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +0000721 getOrCreateType(T, Unit),
Chris Lattner9c85ba32008-11-10 06:08:34 +0000722 Var->hasInternalLinkage(),
723 true/*definition*/, Var);
Sanjiv Gupta686226b2008-06-05 08:59:10 +0000724}
725
Devang Patel9ca36b62009-02-26 21:10:26 +0000726/// EmitGlobalVariable - Emit information about an objective-c interface.
727void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
728 ObjCInterfaceDecl *Decl) {
729 // Create global variable debug descriptor.
730 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
731 SourceManager &SM = M->getContext().getSourceManager();
732 unsigned LineNo = SM.getInstantiationLineNumber(Decl->getLocation());
733
734 std::string Name = Decl->getNameAsString();
735
736 QualType T = M->getContext().buildObjCInterfaceType(Decl);
737 if (T->isIncompleteArrayType()) {
738
739 // CodeGen turns int[] into int[1] so we'll do the same here.
740 llvm::APSInt ConstVal(32);
741
742 ConstVal = 1;
743 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
744
745 T = M->getContext().getConstantArrayType(ET, ConstVal,
746 ArrayType::Normal, 0);
747 }
748
749 DebugFactory.CreateGlobalVariable(Unit, Name, Name, "", Unit, LineNo,
750 getOrCreateType(T, Unit),
751 Var->hasInternalLinkage(),
752 true/*definition*/, Var);
753}
754