blob: 8f4aeb400a16932605858a76a213d82dcfa237b0 [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"
Mike Stumpb1a6e682009-09-30 02:43:10 +000015#include "CodeGenFunction.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000016#include "CodeGenModule.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000017#include "clang/AST/ASTContext.h"
Devang Patel9ca36b62009-02-26 21:10:26 +000018#include "clang/AST/DeclObjC.h"
Chris Lattner3cc5c402008-11-11 07:01:36 +000019#include "clang/AST/Expr.h"
Anders Carlsson19cc4ab2009-07-18 19:43:29 +000020#include "clang/AST/RecordLayout.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000021#include "clang/Basic/SourceManager.h"
22#include "clang/Basic/FileManager.h"
Mike Stump5a862172009-09-15 21:48:34 +000023#include "clang/Basic/Version.h"
Devang Patel07739032009-03-27 23:16:32 +000024#include "clang/Frontend/CompileOptions.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000025#include "llvm/Constants.h"
26#include "llvm/DerivedTypes.h"
27#include "llvm/Instructions.h"
28#include "llvm/Intrinsics.h"
29#include "llvm/Module.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000030#include "llvm/ADT/StringExtras.h"
31#include "llvm/ADT/SmallVector.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000032#include "llvm/Support/Dwarf.h"
Devang Patel446c6192009-04-17 21:06:59 +000033#include "llvm/System/Path.h"
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000034#include "llvm/Target/TargetMachine.h"
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000035using namespace clang;
36using namespace clang::CodeGen;
37
Devang Patel6dba4322009-07-14 21:31:22 +000038CGDebugInfo::CGDebugInfo(CodeGenModule *m)
Mike Stump9bc093c2009-05-14 02:03:51 +000039 : M(m), isMainCompileUnitCreated(false), DebugFactory(M->getModule()),
40 BlockLiteralGenericSet(false) {
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000041}
42
Chris Lattner9c85ba32008-11-10 06:08:34 +000043CGDebugInfo::~CGDebugInfo() {
Daniel Dunbar66031a52008-10-17 16:15:48 +000044 assert(RegionStack.empty() && "Region stack mismatch, stack not empty!");
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000045}
46
Chris Lattner9c85ba32008-11-10 06:08:34 +000047void CGDebugInfo::setLocation(SourceLocation Loc) {
48 if (Loc.isValid())
Chris Lattnerf7cf85b2009-01-16 07:36:28 +000049 CurLoc = M->getContext().getSourceManager().getInstantiationLoc(Loc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +000050}
51
Devang Patel979ec2e2009-10-06 00:35:31 +000052/// getContext - Get context info for the decl.
53llvm::DIDescriptor CGDebugInfo::getContext(const VarDecl *Decl,
54 llvm::DIDescriptor &CompileUnit) {
55 if (Decl->isFileVarDecl())
56 return CompileUnit;
57 if (Decl->getDeclContext()->isFunctionOrMethod()) {
58 // Find the last subprogram in region stack.
59 for (unsigned RI = RegionStack.size(), RE = 0; RI != RE; --RI) {
60 llvm::DIDescriptor R = RegionStack[RI - 1];
61 if (R.isSubprogram())
62 return R;
63 }
64 }
65 return CompileUnit;
66}
67
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000068/// getOrCreateCompileUnit - Get the compile unit from the cache or create a new
Daniel Dunbar25f51dd2008-10-24 08:38:36 +000069/// one if necessary. This returns null for invalid source locations.
Chris Lattner9c85ba32008-11-10 06:08:34 +000070llvm::DICompileUnit CGDebugInfo::getOrCreateCompileUnit(SourceLocation Loc) {
Devang Patel446c6192009-04-17 21:06:59 +000071 // Get source file information.
72 const char *FileName = "<unknown>";
Devang Patel77820222009-02-24 23:16:03 +000073 SourceManager &SM = M->getContext().getSourceManager();
Chris Lattneradb1a6f2009-04-19 06:50:29 +000074 unsigned FID = 0;
Daniel Dunbar831570c2009-01-22 00:09:25 +000075 if (Loc.isValid()) {
Devang Patel446c6192009-04-17 21:06:59 +000076 PresumedLoc PLoc = SM.getPresumedLoc(Loc);
77 FileName = PLoc.getFilename();
78 FID = PLoc.getIncludeLoc().getRawEncoding();
Daniel Dunbar831570c2009-01-22 00:09:25 +000079 }
Mike Stump1eb44332009-09-09 15:08:12 +000080
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +000081 // See if this compile unit has been used before.
Devang Patel446c6192009-04-17 21:06:59 +000082 llvm::DICompileUnit &Unit = CompileUnitCache[FID];
Chris Lattner9c85ba32008-11-10 06:08:34 +000083 if (!Unit.isNull()) return Unit;
Daniel Dunbarc9abc042009-04-08 05:11:16 +000084
Devang Patel446c6192009-04-17 21:06:59 +000085 // Get absolute path name.
86 llvm::sys::Path AbsFileName(FileName);
87 if (!AbsFileName.isAbsolute()) {
88 llvm::sys::Path tmp = llvm::sys::Path::GetCurrentDirectory();
89 tmp.appendComponent(FileName);
90 AbsFileName = tmp;
91 }
92
Devang Patel72240d72009-06-26 18:32:22 +000093 // See if thie compile unit is representing main source file. Each source
94 // file has corresponding compile unit. There is only one main source
95 // file at a time.
96 bool isMain = false;
97 const LangOptions &LO = M->getLangOptions();
98 const char *MainFileName = LO.getMainFileName();
99 if (isMainCompileUnitCreated == false) {
100 if (MainFileName) {
101 if (!strcmp(AbsFileName.getLast().c_str(), MainFileName))
102 isMain = true;
103 } else {
104 if (Loc.isValid() && SM.isFromMainFile(Loc))
105 isMain = true;
106 }
107 if (isMain)
108 isMainCompileUnitCreated = true;
Devang Patel446c6192009-04-17 21:06:59 +0000109 }
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000110
Chris Lattner515455a2009-03-25 03:28:08 +0000111 unsigned LangTag;
112 if (LO.CPlusPlus) {
113 if (LO.ObjC1)
114 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
115 else
116 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
117 } else if (LO.ObjC1) {
Devang Patel8d9aefc2009-03-24 20:35:51 +0000118 LangTag = llvm::dwarf::DW_LANG_ObjC;
Chris Lattner515455a2009-03-25 03:28:08 +0000119 } else if (LO.C99) {
Devang Patel8d9aefc2009-03-24 20:35:51 +0000120 LangTag = llvm::dwarf::DW_LANG_C99;
Chris Lattner515455a2009-03-25 03:28:08 +0000121 } else {
122 LangTag = llvm::dwarf::DW_LANG_C89;
123 }
Devang Patel446c6192009-04-17 21:06:59 +0000124
Mike Stumpd8945d62009-10-09 18:38:12 +0000125 std::string Producer =
126#ifdef CLANG_VENDOR
127 CLANG_VENDOR
128#endif
129 "clang " CLANG_VERSION_STRING;
Chris Lattnerb95ee582009-05-02 01:04:13 +0000130 bool isOptimized = LO.Optimize;
Chris Lattner4c2577a2009-05-02 01:00:04 +0000131 const char *Flags = ""; // FIXME: Encode command line options.
132
133 // Figure out which version of the ObjC runtime we have.
134 unsigned RuntimeVers = 0;
135 if (LO.ObjC1)
136 RuntimeVers = LO.ObjCNonFragileABI ? 2 : 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000138 // Create new compile unit.
Devang Patel72240d72009-06-26 18:32:22 +0000139 return Unit = DebugFactory.CreateCompileUnit(LangTag, AbsFileName.getLast(),
Mike Stump1eb44332009-09-09 15:08:12 +0000140 AbsFileName.getDirname(),
Devang Patel72240d72009-06-26 18:32:22 +0000141 Producer, isMain, isOptimized,
142 Flags, RuntimeVers);
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000143}
144
Devang Patel65e99f22009-02-25 01:36:11 +0000145/// CreateType - Get the Basic type from the cache or create a new
Chris Lattner9c85ba32008-11-10 06:08:34 +0000146/// one if necessary.
147llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT,
Devang Patel65e99f22009-02-25 01:36:11 +0000148 llvm::DICompileUnit Unit) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000149 unsigned Encoding = 0;
150 switch (BT->getKind()) {
151 default:
152 case BuiltinType::Void:
153 return llvm::DIType();
154 case BuiltinType::UChar:
155 case BuiltinType::Char_U: Encoding = llvm::dwarf::DW_ATE_unsigned_char; break;
156 case BuiltinType::Char_S:
157 case BuiltinType::SChar: Encoding = llvm::dwarf::DW_ATE_signed_char; break;
158 case BuiltinType::UShort:
159 case BuiltinType::UInt:
160 case BuiltinType::ULong:
161 case BuiltinType::ULongLong: Encoding = llvm::dwarf::DW_ATE_unsigned; break;
162 case BuiltinType::Short:
163 case BuiltinType::Int:
164 case BuiltinType::Long:
165 case BuiltinType::LongLong: Encoding = llvm::dwarf::DW_ATE_signed; break;
166 case BuiltinType::Bool: Encoding = llvm::dwarf::DW_ATE_boolean; break;
167 case BuiltinType::Float:
Devang Patel7c173cb2009-10-12 22:28:31 +0000168 case BuiltinType::LongDouble:
Chris Lattner9c85ba32008-11-10 06:08:34 +0000169 case BuiltinType::Double: Encoding = llvm::dwarf::DW_ATE_float; break;
Mike Stump1eb44332009-09-09 15:08:12 +0000170 }
Chris Lattner9c85ba32008-11-10 06:08:34 +0000171 // Bit size, align and offset of the type.
172 uint64_t Size = M->getContext().getTypeSize(BT);
173 uint64_t Align = M->getContext().getTypeAlign(BT);
174 uint64_t Offset = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000175
Devang Patelca80a5f2009-10-20 19:55:01 +0000176 llvm::DIType DbgTy =
177 DebugFactory.CreateBasicType(Unit,
178 BT->getName(M->getContext().getLangOptions()),
179 Unit, 0, Size, Align,
180 Offset, /*flags*/ 0, Encoding);
181
182 TypeCache[QualType(BT, 0).getAsOpaquePtr()] = DbgTy.getNode();
183 return DbgTy;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000184}
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000185
Chris Lattnerb7003772009-04-23 06:13:01 +0000186llvm::DIType CGDebugInfo::CreateType(const ComplexType *Ty,
187 llvm::DICompileUnit Unit) {
188 // Bit size, align and offset of the type.
189 unsigned Encoding = llvm::dwarf::DW_ATE_complex_float;
190 if (Ty->isComplexIntegerType())
191 Encoding = llvm::dwarf::DW_ATE_lo_user;
Mike Stump1eb44332009-09-09 15:08:12 +0000192
Chris Lattnerb7003772009-04-23 06:13:01 +0000193 uint64_t Size = M->getContext().getTypeSize(Ty);
194 uint64_t Align = M->getContext().getTypeAlign(Ty);
195 uint64_t Offset = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000196
Devang Patelca80a5f2009-10-20 19:55:01 +0000197 llvm::DIType DbgTy =
198 DebugFactory.CreateBasicType(Unit, "complex",
199 Unit, 0, Size, Align,
200 Offset, /*flags*/ 0, Encoding);
201 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
202 return DbgTy;
Chris Lattnerb7003772009-04-23 06:13:01 +0000203}
204
John McCalla1805292009-09-25 01:40:47 +0000205/// CreateCVRType - Get the qualified type from the cache or create
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000206/// a new one if necessary.
John McCalla1805292009-09-25 01:40:47 +0000207llvm::DIType CGDebugInfo::CreateQualifiedType(QualType Ty, llvm::DICompileUnit Unit) {
208 QualifierCollector Qc;
209 const Type *T = Qc.strip(Ty);
210
211 // Ignore these qualifiers for now.
212 Qc.removeObjCGCAttr();
213 Qc.removeAddressSpace();
214
Chris Lattner9c85ba32008-11-10 06:08:34 +0000215 // We will create one Derived type for one qualifier and recurse to handle any
216 // additional ones.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000217 unsigned Tag;
John McCalla1805292009-09-25 01:40:47 +0000218 if (Qc.hasConst()) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000219 Tag = llvm::dwarf::DW_TAG_const_type;
John McCalla1805292009-09-25 01:40:47 +0000220 Qc.removeConst();
221 } else if (Qc.hasVolatile()) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000222 Tag = llvm::dwarf::DW_TAG_volatile_type;
John McCalla1805292009-09-25 01:40:47 +0000223 Qc.removeVolatile();
224 } else if (Qc.hasRestrict()) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000225 Tag = llvm::dwarf::DW_TAG_restrict_type;
John McCalla1805292009-09-25 01:40:47 +0000226 Qc.removeRestrict();
227 } else {
228 assert(Qc.empty() && "Unknown type qualifier for debug info");
229 return getOrCreateType(QualType(T, 0), Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000230 }
Mike Stump1eb44332009-09-09 15:08:12 +0000231
John McCalla1805292009-09-25 01:40:47 +0000232 llvm::DIType FromTy = getOrCreateType(Qc.apply(T), Unit);
233
Daniel Dunbar3845f862008-10-31 03:54:29 +0000234 // No need to fill in the Name, Line, Size, Alignment, Offset in case of
235 // CVR derived types.
Devang Patelca80a5f2009-10-20 19:55:01 +0000236 llvm::DIType DbgTy =
237 DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
238 0, 0, 0, 0, 0, FromTy);
239 TypeCache[Ty.getAsOpaquePtr()] = DbgTy.getNode();
240 return DbgTy;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000241}
242
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000243llvm::DIType CGDebugInfo::CreateType(const ObjCObjectPointerType *Ty,
244 llvm::DICompileUnit Unit) {
Devang Patelca80a5f2009-10-20 19:55:01 +0000245 llvm::DIType DbgTy =
Anders Carlssona031b352009-11-06 19:19:55 +0000246 CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
247 Ty->getPointeeType(), Unit);
Devang Patelca80a5f2009-10-20 19:55:01 +0000248 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
249 return DbgTy;
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000250}
251
Chris Lattner9c85ba32008-11-10 06:08:34 +0000252llvm::DIType CGDebugInfo::CreateType(const PointerType *Ty,
253 llvm::DICompileUnit Unit) {
Anders Carlssona031b352009-11-06 19:19:55 +0000254 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
255 Ty->getPointeeType(), Unit);
256}
257
258llvm::DIType CGDebugInfo::CreatePointerLikeType(unsigned Tag,
259 const Type *Ty,
260 QualType PointeeTy,
261 llvm::DICompileUnit Unit) {
262 llvm::DIType EltTy = getOrCreateType(PointeeTy, Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000263
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000264 // Bit size, align and offset of the type.
Anders Carlssona031b352009-11-06 19:19:55 +0000265
266 // Size is always the size of a pointer. We can't use getTypeSize here
267 // because that does not return the correct value for references.
268 uint64_t Size =
269 M->getContext().Target.getPointerWidth(PointeeTy.getAddressSpace());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000270 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000271
Devang Patelca80a5f2009-10-20 19:55:01 +0000272 return
Anders Carlssona031b352009-11-06 19:19:55 +0000273 DebugFactory.CreateDerivedType(Tag, Unit, "", llvm::DICompileUnit(),
Devang Patelca80a5f2009-10-20 19:55:01 +0000274 0, Size, Align, 0, 0, EltTy);
Anders Carlssona031b352009-11-06 19:19:55 +0000275
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000276}
277
Mike Stump9bc093c2009-05-14 02:03:51 +0000278llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
279 llvm::DICompileUnit Unit) {
280 if (BlockLiteralGenericSet)
281 return BlockLiteralGeneric;
282
283 llvm::DICompileUnit DefUnit;
284 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
285
286 llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
287
288 llvm::DIType FieldTy;
289
290 QualType FType;
291 uint64_t FieldSize, FieldOffset;
292 unsigned FieldAlign;
293
294 llvm::DIArray Elements;
295 llvm::DIType EltTy, DescTy;
296
297 FieldOffset = 0;
298 FType = M->getContext().UnsignedLongTy;
299 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
300 FieldSize = M->getContext().getTypeSize(FType);
301 FieldAlign = M->getContext().getTypeAlign(FType);
302 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
303 "reserved", DefUnit,
304 0, FieldSize, FieldAlign,
305 FieldOffset, 0, FieldTy);
306 EltTys.push_back(FieldTy);
307
308 FieldOffset += FieldSize;
309 FType = M->getContext().UnsignedLongTy;
310 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
311 FieldSize = M->getContext().getTypeSize(FType);
312 FieldAlign = M->getContext().getTypeAlign(FType);
313 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
314 "Size", DefUnit,
315 0, FieldSize, FieldAlign,
316 FieldOffset, 0, FieldTy);
317 EltTys.push_back(FieldTy);
318
319 FieldOffset += FieldSize;
Daniel Dunbarca308df2009-05-26 19:40:20 +0000320 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump9bc093c2009-05-14 02:03:51 +0000321 EltTys.clear();
322
Mike Stump3d363c52009-10-02 02:30:50 +0000323 unsigned Flags = llvm::DIType::FlagAppleBlock;
324
Mike Stump9bc093c2009-05-14 02:03:51 +0000325 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_descriptor",
Mike Stump3d363c52009-10-02 02:30:50 +0000326 DefUnit, 0, FieldOffset, 0, 0, Flags,
Mike Stump9bc093c2009-05-14 02:03:51 +0000327 llvm::DIType(), Elements);
Mike Stump1eb44332009-09-09 15:08:12 +0000328
Mike Stump9bc093c2009-05-14 02:03:51 +0000329 // Bit size, align and offset of the type.
330 uint64_t Size = M->getContext().getTypeSize(Ty);
331 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000332
Mike Stump9bc093c2009-05-14 02:03:51 +0000333 DescTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type,
334 Unit, "", llvm::DICompileUnit(),
335 0, Size, Align, 0, 0, EltTy);
336
337 FieldOffset = 0;
338 FType = M->getContext().getPointerType(M->getContext().VoidTy);
339 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
340 FieldSize = M->getContext().getTypeSize(FType);
341 FieldAlign = M->getContext().getTypeAlign(FType);
342 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
343 "__isa", DefUnit,
344 0, FieldSize, FieldAlign,
345 FieldOffset, 0, FieldTy);
346 EltTys.push_back(FieldTy);
347
348 FieldOffset += FieldSize;
349 FType = M->getContext().IntTy;
350 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
351 FieldSize = M->getContext().getTypeSize(FType);
352 FieldAlign = M->getContext().getTypeAlign(FType);
353 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
354 "__flags", DefUnit,
355 0, FieldSize, FieldAlign,
356 FieldOffset, 0, FieldTy);
357 EltTys.push_back(FieldTy);
358
359 FieldOffset += FieldSize;
360 FType = M->getContext().IntTy;
361 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
362 FieldSize = M->getContext().getTypeSize(FType);
363 FieldAlign = M->getContext().getTypeAlign(FType);
364 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
365 "__reserved", DefUnit,
366 0, FieldSize, FieldAlign,
367 FieldOffset, 0, FieldTy);
368 EltTys.push_back(FieldTy);
369
370 FieldOffset += FieldSize;
371 FType = M->getContext().getPointerType(M->getContext().VoidTy);
372 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
373 FieldSize = M->getContext().getTypeSize(FType);
374 FieldAlign = M->getContext().getTypeAlign(FType);
375 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
376 "__FuncPtr", DefUnit,
377 0, FieldSize, FieldAlign,
378 FieldOffset, 0, FieldTy);
379 EltTys.push_back(FieldTy);
380
381 FieldOffset += FieldSize;
382 FType = M->getContext().getPointerType(M->getContext().VoidTy);
383 FieldTy = DescTy;
384 FieldSize = M->getContext().getTypeSize(Ty);
385 FieldAlign = M->getContext().getTypeAlign(Ty);
386 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
387 "__descriptor", DefUnit,
388 0, FieldSize, FieldAlign,
389 FieldOffset, 0, FieldTy);
390 EltTys.push_back(FieldTy);
391
392 FieldOffset += FieldSize;
Daniel Dunbarca308df2009-05-26 19:40:20 +0000393 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump9bc093c2009-05-14 02:03:51 +0000394
395 EltTy = DebugFactory.CreateCompositeType(Tag, Unit, "__block_literal_generic",
Mike Stump944e7052009-10-02 02:23:37 +0000396 DefUnit, 0, FieldOffset, 0, 0, Flags,
Mike Stump9bc093c2009-05-14 02:03:51 +0000397 llvm::DIType(), Elements);
Mike Stump1eb44332009-09-09 15:08:12 +0000398
Mike Stump9bc093c2009-05-14 02:03:51 +0000399 BlockLiteralGenericSet = true;
400 BlockLiteralGeneric
401 = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_pointer_type, Unit,
402 "", llvm::DICompileUnit(),
403 0, Size, Align, 0, 0, EltTy);
404 return BlockLiteralGeneric;
405}
406
Chris Lattner9c85ba32008-11-10 06:08:34 +0000407llvm::DIType CGDebugInfo::CreateType(const TypedefType *Ty,
408 llvm::DICompileUnit Unit) {
409 // Typedefs are derived from some other type. If we have a typedef of a
410 // typedef, make sure to emit the whole chain.
411 llvm::DIType Src = getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000412
Chris Lattner9c85ba32008-11-10 06:08:34 +0000413 // We don't set size information, but do specify where the typedef was
414 // declared.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000415 std::string TyName = Ty->getDecl()->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000416 SourceLocation DefLoc = Ty->getDecl()->getLocation();
417 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000418
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000419 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000420 PresumedLoc PLoc = SM.getPresumedLoc(DefLoc);
421 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000422
Devang Patelca80a5f2009-10-20 19:55:01 +0000423 llvm::DIType DbgTy =
424 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_typedef, Unit,
425 TyName, DefUnit, Line, 0, 0, 0, 0, Src);
426 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
427 return DbgTy;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000428}
429
Chris Lattner9c85ba32008-11-10 06:08:34 +0000430llvm::DIType CGDebugInfo::CreateType(const FunctionType *Ty,
431 llvm::DICompileUnit Unit) {
432 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000433
Chris Lattner9c85ba32008-11-10 06:08:34 +0000434 // Add the result type at least.
435 EltTys.push_back(getOrCreateType(Ty->getResultType(), Unit));
Mike Stump1eb44332009-09-09 15:08:12 +0000436
Chris Lattner9c85ba32008-11-10 06:08:34 +0000437 // Set up remainder of arguments if there is a prototype.
438 // FIXME: IF NOT, HOW IS THIS REPRESENTED? llvm-gcc doesn't represent '...'!
Douglas Gregor72564e72009-02-26 23:50:07 +0000439 if (const FunctionProtoType *FTP = dyn_cast<FunctionProtoType>(Ty)) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000440 for (unsigned i = 0, e = FTP->getNumArgs(); i != e; ++i)
441 EltTys.push_back(getOrCreateType(FTP->getArgType(i), Unit));
442 } else {
443 // FIXME: Handle () case in C. llvm-gcc doesn't do it either.
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000444 }
445
Chris Lattner9c85ba32008-11-10 06:08:34 +0000446 llvm::DIArray EltTypeArray =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000447 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Mike Stump1eb44332009-09-09 15:08:12 +0000448
Devang Patelca80a5f2009-10-20 19:55:01 +0000449 llvm::DIType DbgTy =
450 DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_subroutine_type,
451 Unit, "", llvm::DICompileUnit(),
452 0, 0, 0, 0, 0,
453 llvm::DIType(), EltTypeArray);
454 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
455 return DbgTy;
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000456}
457
Devang Patel65e99f22009-02-25 01:36:11 +0000458/// CreateType - get structure or union type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000459llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty,
460 llvm::DICompileUnit Unit) {
Douglas Gregora4c46df2008-12-11 17:59:21 +0000461 RecordDecl *Decl = Ty->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000462
Chris Lattner9c85ba32008-11-10 06:08:34 +0000463 unsigned Tag;
464 if (Decl->isStruct())
465 Tag = llvm::dwarf::DW_TAG_structure_type;
466 else if (Decl->isUnion())
467 Tag = llvm::dwarf::DW_TAG_union_type;
468 else {
469 assert(Decl->isClass() && "Unknown RecordType!");
470 Tag = llvm::dwarf::DW_TAG_class_type;
Sanjiv Guptaf58c27a2008-06-07 04:46:53 +0000471 }
472
Sanjiv Gupta507de852008-06-09 10:47:41 +0000473 SourceManager &SM = M->getContext().getSourceManager();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000474
Chris Lattner9c85ba32008-11-10 06:08:34 +0000475 // Get overall information about the record type for the debug info.
Chris Lattner8ec03f52008-11-24 03:54:41 +0000476 std::string Name = Decl->getNameAsString();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000477
Devang Patel4f6fa232009-04-17 21:35:15 +0000478 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000479 llvm::DICompileUnit DefUnit;
480 unsigned Line = 0;
481 if (!PLoc.isInvalid()) {
482 DefUnit = getOrCreateCompileUnit(Decl->getLocation());
483 Line = PLoc.getLine();
484 }
Mike Stump1eb44332009-09-09 15:08:12 +0000485
Chris Lattner9c85ba32008-11-10 06:08:34 +0000486 // Records and classes and unions can all be recursive. To handle them, we
487 // first generate a debug descriptor for the struct as a forward declaration.
488 // Then (if it is a definition) we go through and get debug info for all of
489 // its members. Finally, we create a descriptor for the complete type (which
490 // may refer to the forward decl if the struct is recursive) and replace all
491 // uses of the forward declaration with the final definition.
Devang Patel0ce73f62009-07-22 18:57:00 +0000492 llvm::DICompositeType FwdDecl =
Chris Lattner9c85ba32008-11-10 06:08:34 +0000493 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
494 llvm::DIType(), llvm::DIArray());
Mike Stump1eb44332009-09-09 15:08:12 +0000495
Chris Lattner9c85ba32008-11-10 06:08:34 +0000496 // If this is just a forward declaration, return it.
497 if (!Decl->getDefinition(M->getContext()))
498 return FwdDecl;
Sanjiv Gupta507de852008-06-09 10:47:41 +0000499
Chris Lattner9c85ba32008-11-10 06:08:34 +0000500 // Otherwise, insert it into the TypeCache so that recursive uses will find
501 // it.
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000502 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000503
504 // Convert all the elements.
505 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
506
507 const ASTRecordLayout &RL = M->getContext().getASTRecordLayout(Decl);
508
509 unsigned FieldNo = 0;
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000510 for (RecordDecl::field_iterator I = Decl->field_begin(),
Mike Stump1eb44332009-09-09 15:08:12 +0000511 E = Decl->field_end();
Douglas Gregora4c46df2008-12-11 17:59:21 +0000512 I != E; ++I, ++FieldNo) {
Chris Lattner9c85ba32008-11-10 06:08:34 +0000513 FieldDecl *Field = *I;
514 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
Chris Lattner8ec03f52008-11-24 03:54:41 +0000515
516 std::string FieldName = Field->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000517
Devang Patelde135022009-04-27 22:40:36 +0000518 // Ignore unnamed fields.
519 if (FieldName.empty())
520 continue;
521
Chris Lattner9c85ba32008-11-10 06:08:34 +0000522 // Get the location for the field.
523 SourceLocation FieldDefLoc = Field->getLocation();
Devang Patel4f6fa232009-04-17 21:35:15 +0000524 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000525 llvm::DICompileUnit FieldDefUnit;
526 unsigned FieldLine = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000527
Chris Lattnerd37d9b52009-05-05 05:16:17 +0000528 if (!PLoc.isInvalid()) {
529 FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
530 FieldLine = PLoc.getLine();
531 }
Devang Patelec9b5d52009-03-16 23:47:53 +0000532
533 QualType FType = Field->getType();
534 uint64_t FieldSize = 0;
535 unsigned FieldAlign = 0;
536 if (!FType->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000537
Devang Patelec9b5d52009-03-16 23:47:53 +0000538 // Bit size, align and offset of the type.
539 FieldSize = M->getContext().getTypeSize(FType);
540 Expr *BitWidth = Field->getBitWidth();
541 if (BitWidth)
Eli Friedman9a901bb2009-04-26 19:19:15 +0000542 FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue();
Mike Stump1eb44332009-09-09 15:08:12 +0000543
Devang Patelec9b5d52009-03-16 23:47:53 +0000544 FieldAlign = M->getContext().getTypeAlign(FType);
545 }
546
Mike Stump1eb44332009-09-09 15:08:12 +0000547 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
548
Chris Lattner9c85ba32008-11-10 06:08:34 +0000549 // Create a DW_TAG_member node to remember the offset of this field in the
550 // struct. FIXME: This is an absolutely insane way to capture this
551 // information. When we gut debug info, this should be fixed.
552 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
553 FieldName, FieldDefUnit,
554 FieldLine, FieldSize, FieldAlign,
555 FieldOffset, 0, FieldTy);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000556 EltTys.push_back(FieldTy);
557 }
Mike Stump1eb44332009-09-09 15:08:12 +0000558
Chris Lattner9c85ba32008-11-10 06:08:34 +0000559 llvm::DIArray Elements =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000560 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000561
562 // Bit size, align and offset of the type.
563 uint64_t Size = M->getContext().getTypeSize(Ty);
564 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000565
Devang Patel0ce73f62009-07-22 18:57:00 +0000566 llvm::DICompositeType RealDecl =
Chris Lattner9c85ba32008-11-10 06:08:34 +0000567 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
568 Align, 0, 0, llvm::DIType(), Elements);
569
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000570 // Update TypeCache.
571 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
572
Chris Lattner9c85ba32008-11-10 06:08:34 +0000573 // Now that we have a real decl for the struct, replace anything using the
574 // old decl with the new one. This will recursively update the debug info.
Devang Patel0ce73f62009-07-22 18:57:00 +0000575 FwdDecl.replaceAllUsesWith(RealDecl);
Devang Patelfe09eab2009-07-13 17:03:14 +0000576
Chris Lattner9c85ba32008-11-10 06:08:34 +0000577 return RealDecl;
578}
579
Devang Patel9ca36b62009-02-26 21:10:26 +0000580/// CreateType - get objective-c interface type.
581llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
582 llvm::DICompileUnit Unit) {
583 ObjCInterfaceDecl *Decl = Ty->getDecl();
Mike Stump1eb44332009-09-09 15:08:12 +0000584
Devang Patel9ca36b62009-02-26 21:10:26 +0000585 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
586 SourceManager &SM = M->getContext().getSourceManager();
587
588 // Get overall information about the record type for the debug info.
589 std::string Name = Decl->getNameAsString();
590
591 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(Decl->getLocation());
Devang Patel4f6fa232009-04-17 21:35:15 +0000592 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
593 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
594
Mike Stump1eb44332009-09-09 15:08:12 +0000595
Daniel Dunbard86d3362009-05-18 20:51:58 +0000596 unsigned RuntimeLang = DefUnit.getLanguage();
Chris Lattnerac7c8142009-05-02 01:13:16 +0000597
Devang Patel9ca36b62009-02-26 21:10:26 +0000598 // To handle recursive interface, we
599 // first generate a debug descriptor for the struct as a forward declaration.
600 // Then (if it is a definition) we go through and get debug info for all of
601 // its members. Finally, we create a descriptor for the complete type (which
602 // may refer to the forward decl if the struct is recursive) and replace all
603 // uses of the forward declaration with the final definition.
Devang Patel6c1fddf2009-07-27 18:42:03 +0000604 llvm::DICompositeType FwdDecl =
Devang Patel9ca36b62009-02-26 21:10:26 +0000605 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, 0, 0, 0, 0,
Chris Lattnerac7c8142009-05-02 01:13:16 +0000606 llvm::DIType(), llvm::DIArray(),
607 RuntimeLang);
Mike Stump1eb44332009-09-09 15:08:12 +0000608
Devang Patel9ca36b62009-02-26 21:10:26 +0000609 // If this is just a forward declaration, return it.
610 if (Decl->isForwardDecl())
611 return FwdDecl;
612
613 // Otherwise, insert it into the TypeCache so that recursive uses will find
614 // it.
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000615 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = FwdDecl.getNode();
Devang Patel9ca36b62009-02-26 21:10:26 +0000616
617 // Convert all the elements.
618 llvm::SmallVector<llvm::DIDescriptor, 16> EltTys;
619
Devang Patelfbe899f2009-03-10 21:30:26 +0000620 ObjCInterfaceDecl *SClass = Decl->getSuperClass();
621 if (SClass) {
Mike Stump1eb44332009-09-09 15:08:12 +0000622 llvm::DIType SClassTy =
Devang Patelfbe899f2009-03-10 21:30:26 +0000623 getOrCreateType(M->getContext().getObjCInterfaceType(SClass), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000624 llvm::DIType InhTag =
Devang Patelfbe899f2009-03-10 21:30:26 +0000625 DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_inheritance,
Chris Lattner9e55b8a2009-05-05 05:05:36 +0000626 Unit, "", llvm::DICompileUnit(), 0, 0, 0,
Devang Patelfbe899f2009-03-10 21:30:26 +0000627 0 /* offset */, 0, SClassTy);
628 EltTys.push_back(InhTag);
629 }
630
Devang Patel9ca36b62009-02-26 21:10:26 +0000631 const ASTRecordLayout &RL = M->getContext().getASTObjCInterfaceLayout(Decl);
632
633 unsigned FieldNo = 0;
634 for (ObjCInterfaceDecl::ivar_iterator I = Decl->ivar_begin(),
635 E = Decl->ivar_end(); I != E; ++I, ++FieldNo) {
636 ObjCIvarDecl *Field = *I;
637 llvm::DIType FieldTy = getOrCreateType(Field->getType(), Unit);
638
639 std::string FieldName = Field->getNameAsString();
640
Devang Patelde135022009-04-27 22:40:36 +0000641 // Ignore unnamed fields.
642 if (FieldName.empty())
643 continue;
644
Devang Patel9ca36b62009-02-26 21:10:26 +0000645 // Get the location for the field.
646 SourceLocation FieldDefLoc = Field->getLocation();
647 llvm::DICompileUnit FieldDefUnit = getOrCreateCompileUnit(FieldDefLoc);
Devang Patel4f6fa232009-04-17 21:35:15 +0000648 PresumedLoc PLoc = SM.getPresumedLoc(FieldDefLoc);
649 unsigned FieldLine = PLoc.isInvalid() ? 0 : PLoc.getLine();
650
Mike Stump1eb44332009-09-09 15:08:12 +0000651
Devang Patel99c20eb2009-03-20 18:24:39 +0000652 QualType FType = Field->getType();
653 uint64_t FieldSize = 0;
654 unsigned FieldAlign = 0;
Devang Patelc20482b2009-03-19 00:23:53 +0000655
Devang Patel99c20eb2009-03-20 18:24:39 +0000656 if (!FType->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +0000657
Devang Patel99c20eb2009-03-20 18:24:39 +0000658 // Bit size, align and offset of the type.
659 FieldSize = M->getContext().getTypeSize(FType);
660 Expr *BitWidth = Field->getBitWidth();
661 if (BitWidth)
Eli Friedman9a901bb2009-04-26 19:19:15 +0000662 FieldSize = BitWidth->EvaluateAsInt(M->getContext()).getZExtValue();
663
Devang Patel99c20eb2009-03-20 18:24:39 +0000664 FieldAlign = M->getContext().getTypeAlign(FType);
665 }
666
Mike Stump1eb44332009-09-09 15:08:12 +0000667 uint64_t FieldOffset = RL.getFieldOffset(FieldNo);
668
Devang Patelc20482b2009-03-19 00:23:53 +0000669 unsigned Flags = 0;
670 if (Field->getAccessControl() == ObjCIvarDecl::Protected)
671 Flags = llvm::DIType::FlagProtected;
672 else if (Field->getAccessControl() == ObjCIvarDecl::Private)
673 Flags = llvm::DIType::FlagPrivate;
Mike Stump1eb44332009-09-09 15:08:12 +0000674
Devang Patel9ca36b62009-02-26 21:10:26 +0000675 // Create a DW_TAG_member node to remember the offset of this field in the
676 // struct. FIXME: This is an absolutely insane way to capture this
677 // information. When we gut debug info, this should be fixed.
678 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
679 FieldName, FieldDefUnit,
680 FieldLine, FieldSize, FieldAlign,
Devang Patelc20482b2009-03-19 00:23:53 +0000681 FieldOffset, Flags, FieldTy);
Devang Patel9ca36b62009-02-26 21:10:26 +0000682 EltTys.push_back(FieldTy);
683 }
Mike Stump1eb44332009-09-09 15:08:12 +0000684
Devang Patel9ca36b62009-02-26 21:10:26 +0000685 llvm::DIArray Elements =
Jay Foadbeaaccd2009-05-21 09:52:38 +0000686 DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
Devang Patel9ca36b62009-02-26 21:10:26 +0000687
688 // Bit size, align and offset of the type.
689 uint64_t Size = M->getContext().getTypeSize(Ty);
690 uint64_t Align = M->getContext().getTypeAlign(Ty);
Mike Stump1eb44332009-09-09 15:08:12 +0000691
Devang Patel6c1fddf2009-07-27 18:42:03 +0000692 llvm::DICompositeType RealDecl =
Devang Patel9ca36b62009-02-26 21:10:26 +0000693 DebugFactory.CreateCompositeType(Tag, Unit, Name, DefUnit, Line, Size,
Chris Lattnerac7c8142009-05-02 01:13:16 +0000694 Align, 0, 0, llvm::DIType(), Elements,
695 RuntimeLang);
Devang Patel9ca36b62009-02-26 21:10:26 +0000696
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000697 // Update TypeCache.
698 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = RealDecl.getNode();
699
Devang Patel9ca36b62009-02-26 21:10:26 +0000700 // Now that we have a real decl for the struct, replace anything using the
701 // old decl with the new one. This will recursively update the debug info.
Devang Patel6c1fddf2009-07-27 18:42:03 +0000702 FwdDecl.replaceAllUsesWith(RealDecl);
Devang Patelfe09eab2009-07-13 17:03:14 +0000703
Devang Patel9ca36b62009-02-26 21:10:26 +0000704 return RealDecl;
705}
706
Chris Lattner9c85ba32008-11-10 06:08:34 +0000707llvm::DIType CGDebugInfo::CreateType(const EnumType *Ty,
708 llvm::DICompileUnit Unit) {
709 EnumDecl *Decl = Ty->getDecl();
710
711 llvm::SmallVector<llvm::DIDescriptor, 32> Enumerators;
712
713 // Create DIEnumerator elements for each enumerator.
Mike Stump1eb44332009-09-09 15:08:12 +0000714 for (EnumDecl::enumerator_iterator
Argyrios Kyrtzidis17945a02009-06-30 02:36:12 +0000715 Enum = Decl->enumerator_begin(), EnumEnd = Decl->enumerator_end();
Douglas Gregor44b43212008-12-11 16:49:14 +0000716 Enum != EnumEnd; ++Enum) {
717 Enumerators.push_back(DebugFactory.CreateEnumerator(Enum->getNameAsString(),
718 Enum->getInitVal().getZExtValue()));
Chris Lattner9c85ba32008-11-10 06:08:34 +0000719 }
Mike Stump1eb44332009-09-09 15:08:12 +0000720
Chris Lattner9c85ba32008-11-10 06:08:34 +0000721 // Return a CompositeType for the enum itself.
722 llvm::DIArray EltArray =
Jay Foadbeaaccd2009-05-21 09:52:38 +0000723 DebugFactory.GetOrCreateArray(Enumerators.data(), Enumerators.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000724
Chris Lattner8ec03f52008-11-24 03:54:41 +0000725 std::string EnumName = Decl->getNameAsString();
Chris Lattner9c85ba32008-11-10 06:08:34 +0000726 SourceLocation DefLoc = Decl->getLocation();
727 llvm::DICompileUnit DefUnit = getOrCreateCompileUnit(DefLoc);
728 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +0000729 PresumedLoc PLoc = SM.getPresumedLoc(DefLoc);
730 unsigned Line = PLoc.isInvalid() ? 0 : PLoc.getLine();
731
Mike Stump1eb44332009-09-09 15:08:12 +0000732
Chris Lattner9c85ba32008-11-10 06:08:34 +0000733 // Size and align of the type.
Eli Friedman3189e4b2009-05-04 04:39:55 +0000734 uint64_t Size = 0;
735 unsigned Align = 0;
736 if (!Ty->isIncompleteType()) {
737 Size = M->getContext().getTypeSize(Ty);
738 Align = M->getContext().getTypeAlign(Ty);
739 }
Mike Stump1eb44332009-09-09 15:08:12 +0000740
Devang Patelca80a5f2009-10-20 19:55:01 +0000741 llvm::DIType DbgTy =
742 DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_enumeration_type,
743 Unit, EnumName, DefUnit, Line,
744 Size, Align, 0, 0,
745 llvm::DIType(), EltArray);
746
747 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
748 return DbgTy;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000749}
750
751llvm::DIType CGDebugInfo::CreateType(const TagType *Ty,
752 llvm::DICompileUnit Unit) {
753 if (const RecordType *RT = dyn_cast<RecordType>(Ty))
754 return CreateType(RT, Unit);
755 else if (const EnumType *ET = dyn_cast<EnumType>(Ty))
756 return CreateType(ET, Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000757
Chris Lattner9c85ba32008-11-10 06:08:34 +0000758 return llvm::DIType();
759}
760
761llvm::DIType CGDebugInfo::CreateType(const ArrayType *Ty,
762 llvm::DICompileUnit Unit) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000763 uint64_t Size;
764 uint64_t Align;
Mike Stump1eb44332009-09-09 15:08:12 +0000765
766
Nuno Lopes010d5142009-01-28 00:35:17 +0000767 // FIXME: make getTypeAlign() aware of VLAs and incomplete array types
Anders Carlsson835c9092009-01-05 01:23:29 +0000768 if (const VariableArrayType *VAT = dyn_cast<VariableArrayType>(Ty)) {
Anders Carlsson835c9092009-01-05 01:23:29 +0000769 Size = 0;
770 Align =
Nuno Lopes010d5142009-01-28 00:35:17 +0000771 M->getContext().getTypeAlign(M->getContext().getBaseElementType(VAT));
772 } else if (Ty->isIncompleteArrayType()) {
773 Size = 0;
774 Align = M->getContext().getTypeAlign(Ty->getElementType());
Anders Carlsson835c9092009-01-05 01:23:29 +0000775 } else {
776 // Size and align of the whole array, not the element type.
777 Size = M->getContext().getTypeSize(Ty);
778 Align = M->getContext().getTypeAlign(Ty);
779 }
Mike Stump1eb44332009-09-09 15:08:12 +0000780
Chris Lattner9c85ba32008-11-10 06:08:34 +0000781 // Add the dimensions of the array. FIXME: This loses CV qualifiers from
782 // interior arrays, do we care? Why aren't nested arrays represented the
783 // obvious/recursive way?
784 llvm::SmallVector<llvm::DIDescriptor, 8> Subscripts;
785 QualType EltTy(Ty, 0);
786 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
Sanjiv Gupta507de852008-06-09 10:47:41 +0000787 uint64_t Upper = 0;
Mike Stump1eb44332009-09-09 15:08:12 +0000788 if (const ConstantArrayType *CAT = dyn_cast<ConstantArrayType>(Ty))
Devang Patel5a6bfe32009-08-14 20:57:45 +0000789 if (CAT->getSize().getZExtValue())
Mike Stump1eb44332009-09-09 15:08:12 +0000790 Upper = CAT->getSize().getZExtValue() - 1;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000791 // FIXME: Verify this is right for VLAs.
792 Subscripts.push_back(DebugFactory.GetOrCreateSubrange(0, Upper));
793 EltTy = Ty->getElementType();
Sanjiv Gupta507de852008-06-09 10:47:41 +0000794 }
Mike Stump1eb44332009-09-09 15:08:12 +0000795
Chris Lattner9c85ba32008-11-10 06:08:34 +0000796 llvm::DIArray SubscriptArray =
Daniel Dunbarca308df2009-05-26 19:40:20 +0000797 DebugFactory.GetOrCreateArray(Subscripts.data(), Subscripts.size());
Chris Lattner9c85ba32008-11-10 06:08:34 +0000798
Devang Patelca80a5f2009-10-20 19:55:01 +0000799 llvm::DIType DbgTy =
800 DebugFactory.CreateCompositeType(llvm::dwarf::DW_TAG_array_type,
801 Unit, "", llvm::DICompileUnit(),
802 0, Size, Align, 0, 0,
803 getOrCreateType(EltTy, Unit),
804 SubscriptArray);
805
806 TypeCache[QualType(Ty, 0).getAsOpaquePtr()] = DbgTy.getNode();
807 return DbgTy;
Chris Lattner9c85ba32008-11-10 06:08:34 +0000808}
809
Anders Carlssona031b352009-11-06 19:19:55 +0000810llvm::DIType CGDebugInfo::CreateType(const LValueReferenceType *Ty,
811 llvm::DICompileUnit Unit) {
812 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type,
813 Ty, Ty->getPointeeType(), Unit);
814}
Chris Lattner9c85ba32008-11-10 06:08:34 +0000815
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000816/// getOrCreateType - Get the type from the cache or create a new
817/// one if necessary.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000818llvm::DIType CGDebugInfo::getOrCreateType(QualType Ty,
819 llvm::DICompileUnit Unit) {
820 if (Ty.isNull())
821 return llvm::DIType();
Mike Stump1eb44332009-09-09 15:08:12 +0000822
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000823 // Check for existing entry.
Daniel Dunbar65f13c32009-09-19 20:17:48 +0000824 std::map<void *, llvm::WeakVH>::iterator it =
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000825 TypeCache.find(Ty.getAsOpaquePtr());
Daniel Dunbar65f13c32009-09-19 20:17:48 +0000826 if (it != TypeCache.end()) {
827 // Verify that the debug info still exists.
828 if (&*it->second)
829 return llvm::DIType(cast<llvm::MDNode>(it->second));
830 }
Daniel Dunbar03faac32009-09-19 19:27:14 +0000831
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000832 // Otherwise create the type.
833 llvm::DIType Res = CreateTypeNode(Ty, Unit);
Daniel Dunbar23e81ba2009-09-19 19:27:24 +0000834 return Res;
Daniel Dunbar03faac32009-09-19 19:27:14 +0000835}
836
837/// getOrCreateTypeNode - Get the type metadata node from the cache or create a
838/// new one if necessary.
839llvm::DIType CGDebugInfo::CreateTypeNode(QualType Ty,
840 llvm::DICompileUnit Unit) {
John McCalla1805292009-09-25 01:40:47 +0000841 // Handle qualifiers, which recursively handles what they refer to.
842 if (Ty.hasQualifiers())
843 return CreateQualifiedType(Ty, Unit);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000844
845 // Work out details of type.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000846 switch (Ty->getTypeClass()) {
Douglas Gregor72564e72009-02-26 23:50:07 +0000847#define TYPE(Class, Base)
848#define ABSTRACT_TYPE(Class, Base)
849#define NON_CANONICAL_TYPE(Class, Base)
850#define DEPENDENT_TYPE(Class, Base) case Type::Class:
851#include "clang/AST/TypeNodes.def"
852 assert(false && "Dependent types cannot show up in debug information");
Argyrios Kyrtzidis1bb8a452009-08-19 01:28:17 +0000853
Anders Carlssonbfe69952009-11-06 18:24:04 +0000854 // FIXME: Handle these.
855 case Type::ExtVector:
856 case Type::Vector:
857 return llvm::DIType();
Daniel Dunbar03faac32009-09-19 19:27:14 +0000858 default:
Anders Carlssonb9381182009-11-06 17:01:39 +0000859 assert(false && "Unhandled type class!");
Chris Lattner9c85ba32008-11-10 06:08:34 +0000860 return llvm::DIType();
Daniel Dunbar9df4bb32009-07-14 01:20:56 +0000861 case Type::ObjCObjectPointer:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000862 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000863 case Type::ObjCInterface:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000864 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
865 case Type::Builtin: return CreateType(cast<BuiltinType>(Ty), Unit);
866 case Type::Complex: return CreateType(cast<ComplexType>(Ty), Unit);
867 case Type::Pointer: return CreateType(cast<PointerType>(Ty), Unit);
Mike Stump9bc093c2009-05-14 02:03:51 +0000868 case Type::BlockPointer:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000869 return CreateType(cast<BlockPointerType>(Ty), Unit);
870 case Type::Typedef: return CreateType(cast<TypedefType>(Ty), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000871 case Type::Record:
Douglas Gregor72564e72009-02-26 23:50:07 +0000872 case Type::Enum:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000873 return CreateType(cast<TagType>(Ty), Unit);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000874 case Type::FunctionProto:
875 case Type::FunctionNoProto:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000876 return CreateType(cast<FunctionType>(Ty), Unit);
John McCall7da24312009-09-05 00:15:47 +0000877 case Type::Elaborated:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000878 return getOrCreateType(cast<ElaboratedType>(Ty)->getUnderlyingType(),
879 Unit);
Mike Stump1eb44332009-09-09 15:08:12 +0000880
Chris Lattner9c85ba32008-11-10 06:08:34 +0000881 case Type::ConstantArray:
882 case Type::VariableArray:
883 case Type::IncompleteArray:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000884 return CreateType(cast<ArrayType>(Ty), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000885 case Type::TypeOfExpr:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000886 return getOrCreateType(cast<TypeOfExprType>(Ty)->getUnderlyingExpr()
887 ->getType(), Unit);
Douglas Gregor72564e72009-02-26 23:50:07 +0000888 case Type::TypeOf:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000889 return getOrCreateType(cast<TypeOfType>(Ty)->getUnderlyingType(), Unit);
Anders Carlsson395b4752009-06-24 19:06:50 +0000890 case Type::Decltype:
Daniel Dunbar03faac32009-09-19 19:27:14 +0000891 return getOrCreateType(cast<DecltypeType>(Ty)->getUnderlyingType(), Unit);
Anders Carlssonba397fe2009-11-06 18:45:16 +0000892
893 case Type::QualifiedName: {
894 const QualifiedNameType *T = cast<QualifiedNameType>(Ty);
895 return CreateTypeNode(T->getNamedType(), Unit);
896 }
897
898 case Type::SubstTemplateTypeParm: {
899 const SubstTemplateTypeParmType *T = cast<SubstTemplateTypeParmType>(Ty);
900 return CreateTypeNode(T->getReplacementType(), Unit);
901 }
902
Anders Carlssona031b352009-11-06 19:19:55 +0000903 case Type::TemplateSpecialization: {
904 const TemplateSpecializationType *T = cast<TemplateSpecializationType>(Ty);
905 return CreateTypeNode(T->desugar(), Unit);
906 }
907
908 case Type::LValueReference:
909 return CreateType(cast<LValueReferenceType>(Ty), Unit);
910
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000911 }
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000912}
913
914/// EmitFunctionStart - Constructs the debug code for entering a function -
915/// "llvm.dbg.func.start.".
Mike Stump91cc8152009-10-23 01:52:13 +0000916void CGDebugInfo::EmitFunctionStart(const char *Name, QualType FnType,
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000917 llvm::Function *Fn,
Chris Lattner9c85ba32008-11-10 06:08:34 +0000918 CGBuilderTy &Builder) {
Devang Patel6dba4322009-07-14 21:31:22 +0000919 const char *LinkageName = Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000920
Daniel Dunbara2893932009-05-13 23:08:57 +0000921 // Skip the asm prefix if it exists.
Daniel Dunbarbbd53af2009-05-14 01:45:24 +0000922 //
923 // FIXME: This should probably be the unmangled name?
Daniel Dunbara2893932009-05-13 23:08:57 +0000924 if (Name[0] == '\01')
925 ++Name;
Mike Stump1eb44332009-09-09 15:08:12 +0000926
Chris Lattner9c85ba32008-11-10 06:08:34 +0000927 // FIXME: Why is this using CurLoc???
928 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000929 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel0f78fea2009-04-08 19:47:04 +0000930 unsigned LineNo = SM.getPresumedLoc(CurLoc).getLine();
Mike Stump1eb44332009-09-09 15:08:12 +0000931
Chris Lattner9c85ba32008-11-10 06:08:34 +0000932 llvm::DISubprogram SP =
Devang Patel6dba4322009-07-14 21:31:22 +0000933 DebugFactory.CreateSubprogram(Unit, Name, Name, LinkageName, Unit, LineNo,
Mike Stump91cc8152009-10-23 01:52:13 +0000934 getOrCreateType(FnType, Unit),
Chris Lattner9c85ba32008-11-10 06:08:34 +0000935 Fn->hasInternalLinkage(), true/*definition*/);
Mike Stump1eb44332009-09-09 15:08:12 +0000936
Devang Patel6e461bf2009-10-06 21:53:41 +0000937#ifndef ATTACH_DEBUG_INFO_TO_AN_INSN
938 DebugFactory.InsertSubprogramStart(SP, Builder.GetInsertBlock());
939#endif
Mike Stump1eb44332009-09-09 15:08:12 +0000940
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000941 // Push function on region stack.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000942 RegionStack.push_back(SP);
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000943}
944
945
Chris Lattner9c85ba32008-11-10 06:08:34 +0000946void CGDebugInfo::EmitStopPoint(llvm::Function *Fn, CGBuilderTy &Builder) {
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +0000947 if (CurLoc.isInvalid() || CurLoc.isMacroID()) return;
Mike Stump1eb44332009-09-09 15:08:12 +0000948
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000949 // Don't bother if things are the same as last time.
950 SourceManager &SM = M->getContext().getSourceManager();
Mike Stump1eb44332009-09-09 15:08:12 +0000951 if (CurLoc == PrevLoc
Chris Lattner30fc9332009-02-04 01:06:56 +0000952 || (SM.getInstantiationLineNumber(CurLoc) ==
953 SM.getInstantiationLineNumber(PrevLoc)
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000954 && SM.isFromSameFile(CurLoc, PrevLoc)))
955 return;
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000956
957 // Update last state.
958 PrevLoc = CurLoc;
959
960 // Get the appropriate compile unit.
Chris Lattner9c85ba32008-11-10 06:08:34 +0000961 llvm::DICompileUnit Unit = getOrCreateCompileUnit(CurLoc);
Devang Patel0f78fea2009-04-08 19:47:04 +0000962 PresumedLoc PLoc = SM.getPresumedLoc(CurLoc);
Devang Patelbbd9fa42009-10-06 18:36:08 +0000963
964#ifdef ATTACH_DEBUG_INFO_TO_AN_INSN
965 llvm::DIDescriptor DR = RegionStack.back();
966 llvm::DIScope DS = llvm::DIScope(DR.getNode());
967 llvm::DILocation DO(NULL);
968 llvm::DILocation DL =
969 DebugFactory.CreateLocation(PLoc.getLine(), PLoc.getColumn(),
970 DS, DO);
971 Builder.SetCurrentDebugLocation(DL.getNode());
972#else
Devang Patel0f78fea2009-04-08 19:47:04 +0000973 DebugFactory.InsertStopPoint(Unit, PLoc.getLine(), PLoc.getColumn(),
Mike Stump1eb44332009-09-09 15:08:12 +0000974 Builder.GetInsertBlock());
Devang Patelbbd9fa42009-10-06 18:36:08 +0000975#endif
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000976}
977
978/// EmitRegionStart- Constructs the debug code for entering a declarative
979/// region - "llvm.dbg.region.start.".
Chris Lattner9c85ba32008-11-10 06:08:34 +0000980void CGDebugInfo::EmitRegionStart(llvm::Function *Fn, CGBuilderTy &Builder) {
981 llvm::DIDescriptor D;
Daniel Dunbar5273f512008-10-17 01:07:56 +0000982 if (!RegionStack.empty())
Chris Lattner9c85ba32008-11-10 06:08:34 +0000983 D = RegionStack.back();
Devang Patel49a8b982009-08-31 22:00:32 +0000984 D = DebugFactory.CreateLexicalBlock(D);
Chris Lattner9c85ba32008-11-10 06:08:34 +0000985 RegionStack.push_back(D);
Devang Patelbbd9fa42009-10-06 18:36:08 +0000986#ifndef ATTACH_DEBUG_INFO_TO_AN_INSN
Chris Lattner9c85ba32008-11-10 06:08:34 +0000987 DebugFactory.InsertRegionStart(D, Builder.GetInsertBlock());
Devang Patelbbd9fa42009-10-06 18:36:08 +0000988#endif
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000989}
990
991/// EmitRegionEnd - Constructs the debug code for exiting a declarative
992/// region - "llvm.dbg.region.end."
Chris Lattner9c85ba32008-11-10 06:08:34 +0000993void CGDebugInfo::EmitRegionEnd(llvm::Function *Fn, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +0000994 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
995
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +0000996 // Provide an region stop point.
997 EmitStopPoint(Fn, Builder);
Mike Stump1eb44332009-09-09 15:08:12 +0000998
Devang Patelbbd9fa42009-10-06 18:36:08 +0000999#ifndef ATTACH_DEBUG_INFO_TO_AN_INSN
Chris Lattner9c85ba32008-11-10 06:08:34 +00001000 DebugFactory.InsertRegionEnd(RegionStack.back(), Builder.GetInsertBlock());
Devang Patelbbd9fa42009-10-06 18:36:08 +00001001#endif
Sanjiv Gupta1c6a38b2008-05-25 05:15:42 +00001002 RegionStack.pop_back();
Sanjiv Guptae8b9f5b2008-05-08 08:54:20 +00001003}
1004
Sanjiv Guptacc9b1632008-05-30 10:30:31 +00001005/// EmitDeclare - Emit local variable declaration debug info.
Chris Lattner9c85ba32008-11-10 06:08:34 +00001006void CGDebugInfo::EmitDeclare(const VarDecl *Decl, unsigned Tag,
1007 llvm::Value *Storage, CGBuilderTy &Builder) {
Daniel Dunbar5273f512008-10-17 01:07:56 +00001008 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
1009
Devang Patel07739032009-03-27 23:16:32 +00001010 // Do not emit variable debug information while generating optimized code.
1011 // The llvm optimizer and code generator are not yet ready to support
1012 // optimized code debugging.
1013 const CompileOptions &CO = M->getCompileOpts();
1014 if (CO.OptimizationLevel)
1015 return;
1016
Chris Lattner650cea92009-05-05 04:57:08 +00001017 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
Mike Stump39605b42009-09-22 02:12:52 +00001018 QualType Type = Decl->getType();
1019 llvm::DIType Ty = getOrCreateType(Type, Unit);
1020 if (Decl->hasAttr<BlocksAttr>()) {
1021 llvm::DICompileUnit DefUnit;
1022 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
1023
1024 llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
1025
1026 llvm::DIType FieldTy;
1027
1028 QualType FType;
1029 uint64_t FieldSize, FieldOffset;
1030 unsigned FieldAlign;
1031
1032 llvm::DIArray Elements;
1033 llvm::DIType EltTy;
1034
1035 // Build up structure for the byref. See BuildByRefType.
1036 FieldOffset = 0;
1037 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1038 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1039 FieldSize = M->getContext().getTypeSize(FType);
1040 FieldAlign = M->getContext().getTypeAlign(FType);
1041 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1042 "__isa", DefUnit,
1043 0, FieldSize, FieldAlign,
1044 FieldOffset, 0, FieldTy);
1045 EltTys.push_back(FieldTy);
1046 FieldOffset += FieldSize;
1047
1048 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1049 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1050 FieldSize = M->getContext().getTypeSize(FType);
1051 FieldAlign = M->getContext().getTypeAlign(FType);
1052 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1053 "__forwarding", DefUnit,
1054 0, FieldSize, FieldAlign,
1055 FieldOffset, 0, FieldTy);
1056 EltTys.push_back(FieldTy);
1057 FieldOffset += FieldSize;
1058
1059 FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
1060 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1061 FieldSize = M->getContext().getTypeSize(FType);
1062 FieldAlign = M->getContext().getTypeAlign(FType);
1063 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1064 "__flags", DefUnit,
1065 0, FieldSize, FieldAlign,
1066 FieldOffset, 0, FieldTy);
1067 EltTys.push_back(FieldTy);
1068 FieldOffset += FieldSize;
1069
1070 FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
1071 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1072 FieldSize = M->getContext().getTypeSize(FType);
1073 FieldAlign = M->getContext().getTypeAlign(FType);
1074 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1075 "__size", DefUnit,
1076 0, FieldSize, FieldAlign,
1077 FieldOffset, 0, FieldTy);
1078 EltTys.push_back(FieldTy);
1079 FieldOffset += FieldSize;
1080
1081 bool HasCopyAndDispose = M->BlockRequiresCopying(Type);
1082 if (HasCopyAndDispose) {
1083 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1084 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1085 FieldSize = M->getContext().getTypeSize(FType);
1086 FieldAlign = M->getContext().getTypeAlign(FType);
1087 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1088 "__copy_helper", DefUnit,
1089 0, FieldSize, FieldAlign,
1090 FieldOffset, 0, FieldTy);
1091 EltTys.push_back(FieldTy);
1092 FieldOffset += FieldSize;
1093
1094 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1095 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1096 FieldSize = M->getContext().getTypeSize(FType);
1097 FieldAlign = M->getContext().getTypeAlign(FType);
1098 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1099 "__destroy_helper", DefUnit,
1100 0, FieldSize, FieldAlign,
1101 FieldOffset, 0, FieldTy);
1102 EltTys.push_back(FieldTy);
1103 FieldOffset += FieldSize;
1104 }
1105
1106 unsigned Align = M->getContext().getDeclAlignInBytes(Decl);
1107 if (Align > M->getContext().Target.getPointerAlign(0) / 8) {
1108 unsigned AlignedOffsetInBytes
Mike Stumpfd47b312009-09-22 02:44:17 +00001109 = llvm::RoundUpToAlignment(FieldOffset/8, Align);
Mike Stump39605b42009-09-22 02:12:52 +00001110 unsigned NumPaddingBytes
Mike Stumpfd47b312009-09-22 02:44:17 +00001111 = AlignedOffsetInBytes - FieldOffset/8;
Mike Stump39605b42009-09-22 02:12:52 +00001112
1113 if (NumPaddingBytes > 0) {
1114 llvm::APInt pad(32, NumPaddingBytes);
1115 FType = M->getContext().getConstantArrayType(M->getContext().CharTy,
1116 pad, ArrayType::Normal, 0);
1117 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1118 FieldSize = M->getContext().getTypeSize(FType);
1119 FieldAlign = M->getContext().getTypeAlign(FType);
1120 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member,
1121 Unit, "", DefUnit,
1122 0, FieldSize, FieldAlign,
1123 FieldOffset, 0, FieldTy);
1124 EltTys.push_back(FieldTy);
1125 FieldOffset += FieldSize;
1126 }
1127 }
1128
1129 FType = Type;
1130 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1131 FieldSize = M->getContext().getTypeSize(FType);
Mike Stumpfd47b312009-09-22 02:44:17 +00001132 FieldAlign = Align*8;
Mike Stump39605b42009-09-22 02:12:52 +00001133 std::string Name = Decl->getNameAsString();
1134
1135 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1136 Name, DefUnit,
1137 0, FieldSize, FieldAlign,
1138 FieldOffset, 0, FieldTy);
1139 EltTys.push_back(FieldTy);
1140 FieldOffset += FieldSize;
1141
1142 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
1143
1144 unsigned Flags = llvm::DIType::FlagBlockByrefStruct;
1145
1146 Ty = DebugFactory.CreateCompositeType(Tag, Unit, "",
1147 llvm::DICompileUnit(),
1148 0, FieldOffset, 0, 0, Flags,
1149 llvm::DIType(), Elements);
1150 }
Chris Lattner650cea92009-05-05 04:57:08 +00001151
Chris Lattner9c85ba32008-11-10 06:08:34 +00001152 // Get location information.
Sanjiv Guptacc9b1632008-05-30 10:30:31 +00001153 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +00001154 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
Chris Lattner650cea92009-05-05 04:57:08 +00001155 unsigned Line = 0;
1156 if (!PLoc.isInvalid())
1157 Line = PLoc.getLine();
1158 else
1159 Unit = llvm::DICompileUnit();
1160
Mike Stump1eb44332009-09-09 15:08:12 +00001161
Chris Lattner9c85ba32008-11-10 06:08:34 +00001162 // Create the descriptor for the variable.
Mike Stump1eb44332009-09-09 15:08:12 +00001163 llvm::DIVariable D =
Chris Lattnerd9d22dd2008-11-24 05:29:24 +00001164 DebugFactory.CreateVariable(Tag, RegionStack.back(),Decl->getNameAsString(),
Chris Lattner650cea92009-05-05 04:57:08 +00001165 Unit, Line, Ty);
Chris Lattner9c85ba32008-11-10 06:08:34 +00001166 // Insert an llvm.dbg.declare into the current block.
1167 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertBlock());
Sanjiv Guptacc9b1632008-05-30 10:30:31 +00001168}
1169
Mike Stumpb1a6e682009-09-30 02:43:10 +00001170/// EmitDeclare - Emit local variable declaration debug info.
1171void CGDebugInfo::EmitDeclare(const BlockDeclRefExpr *BDRE, unsigned Tag,
1172 llvm::Value *Storage, CGBuilderTy &Builder,
1173 CodeGenFunction *CGF) {
1174 const ValueDecl *Decl = BDRE->getDecl();
1175 assert(!RegionStack.empty() && "Region stack mismatch, stack empty!");
1176
1177 // Do not emit variable debug information while generating optimized code.
1178 // The llvm optimizer and code generator are not yet ready to support
1179 // optimized code debugging.
1180 const CompileOptions &CO = M->getCompileOpts();
Mike Stumpb289b3f2009-10-01 22:29:41 +00001181 if (CO.OptimizationLevel || Builder.GetInsertBlock() == 0)
Mike Stumpb1a6e682009-09-30 02:43:10 +00001182 return;
1183
1184 uint64_t XOffset = 0;
1185 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
1186 QualType Type = Decl->getType();
1187 llvm::DIType Ty = getOrCreateType(Type, Unit);
1188 if (Decl->hasAttr<BlocksAttr>()) {
1189 llvm::DICompileUnit DefUnit;
1190 unsigned Tag = llvm::dwarf::DW_TAG_structure_type;
1191
1192 llvm::SmallVector<llvm::DIDescriptor, 5> EltTys;
1193
1194 llvm::DIType FieldTy;
1195
1196 QualType FType;
1197 uint64_t FieldSize, FieldOffset;
1198 unsigned FieldAlign;
1199
1200 llvm::DIArray Elements;
1201 llvm::DIType EltTy;
1202
1203 // Build up structure for the byref. See BuildByRefType.
1204 FieldOffset = 0;
1205 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1206 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1207 FieldSize = M->getContext().getTypeSize(FType);
1208 FieldAlign = M->getContext().getTypeAlign(FType);
1209 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1210 "__isa", DefUnit,
1211 0, FieldSize, FieldAlign,
1212 FieldOffset, 0, FieldTy);
1213 EltTys.push_back(FieldTy);
1214 FieldOffset += FieldSize;
1215
1216 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1217 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1218 FieldSize = M->getContext().getTypeSize(FType);
1219 FieldAlign = M->getContext().getTypeAlign(FType);
1220 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1221 "__forwarding", DefUnit,
1222 0, FieldSize, FieldAlign,
1223 FieldOffset, 0, FieldTy);
1224 EltTys.push_back(FieldTy);
1225 FieldOffset += FieldSize;
1226
1227 FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
1228 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1229 FieldSize = M->getContext().getTypeSize(FType);
1230 FieldAlign = M->getContext().getTypeAlign(FType);
1231 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1232 "__flags", DefUnit,
1233 0, FieldSize, FieldAlign,
1234 FieldOffset, 0, FieldTy);
1235 EltTys.push_back(FieldTy);
1236 FieldOffset += FieldSize;
1237
1238 FType = M->getContext().getFixedWidthIntType(32, true); // Int32Ty;
1239 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1240 FieldSize = M->getContext().getTypeSize(FType);
1241 FieldAlign = M->getContext().getTypeAlign(FType);
1242 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1243 "__size", DefUnit,
1244 0, FieldSize, FieldAlign,
1245 FieldOffset, 0, FieldTy);
1246 EltTys.push_back(FieldTy);
1247 FieldOffset += FieldSize;
1248
1249 bool HasCopyAndDispose = M->BlockRequiresCopying(Type);
1250 if (HasCopyAndDispose) {
1251 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1252 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1253 FieldSize = M->getContext().getTypeSize(FType);
1254 FieldAlign = M->getContext().getTypeAlign(FType);
1255 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1256 "__copy_helper", DefUnit,
1257 0, FieldSize, FieldAlign,
1258 FieldOffset, 0, FieldTy);
1259 EltTys.push_back(FieldTy);
1260 FieldOffset += FieldSize;
1261
1262 FType = M->getContext().getPointerType(M->getContext().VoidTy);
1263 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1264 FieldSize = M->getContext().getTypeSize(FType);
1265 FieldAlign = M->getContext().getTypeAlign(FType);
1266 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1267 "__destroy_helper", DefUnit,
1268 0, FieldSize, FieldAlign,
1269 FieldOffset, 0, FieldTy);
1270 EltTys.push_back(FieldTy);
1271 FieldOffset += FieldSize;
1272 }
1273
1274 unsigned Align = M->getContext().getDeclAlignInBytes(Decl);
1275 if (Align > M->getContext().Target.getPointerAlign(0) / 8) {
1276 unsigned AlignedOffsetInBytes
1277 = llvm::RoundUpToAlignment(FieldOffset/8, Align);
1278 unsigned NumPaddingBytes
1279 = AlignedOffsetInBytes - FieldOffset/8;
1280
1281 if (NumPaddingBytes > 0) {
1282 llvm::APInt pad(32, NumPaddingBytes);
1283 FType = M->getContext().getConstantArrayType(M->getContext().CharTy,
1284 pad, ArrayType::Normal, 0);
1285 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1286 FieldSize = M->getContext().getTypeSize(FType);
1287 FieldAlign = M->getContext().getTypeAlign(FType);
1288 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member,
1289 Unit, "", DefUnit,
1290 0, FieldSize, FieldAlign,
1291 FieldOffset, 0, FieldTy);
1292 EltTys.push_back(FieldTy);
1293 FieldOffset += FieldSize;
1294 }
1295 }
1296
1297 FType = Type;
1298 FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
1299 FieldSize = M->getContext().getTypeSize(FType);
1300 FieldAlign = Align*8;
1301 std::string Name = Decl->getNameAsString();
1302
1303 XOffset = FieldOffset;
1304 FieldTy = DebugFactory.CreateDerivedType(llvm::dwarf::DW_TAG_member, Unit,
1305 Name, DefUnit,
1306 0, FieldSize, FieldAlign,
1307 FieldOffset, 0, FieldTy);
1308 EltTys.push_back(FieldTy);
1309 FieldOffset += FieldSize;
1310
1311 Elements = DebugFactory.GetOrCreateArray(EltTys.data(), EltTys.size());
1312
1313 unsigned Flags = llvm::DIType::FlagBlockByrefStruct;
1314
1315 Ty = DebugFactory.CreateCompositeType(Tag, Unit, "",
1316 llvm::DICompileUnit(),
1317 0, FieldOffset, 0, 0, Flags,
1318 llvm::DIType(), Elements);
1319 }
1320
1321 // Get location information.
1322 SourceManager &SM = M->getContext().getSourceManager();
1323 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
1324 unsigned Line = 0;
1325 if (!PLoc.isInvalid())
1326 Line = PLoc.getLine();
1327 else
1328 Unit = llvm::DICompileUnit();
1329
1330 uint64_t offset = CGF->BlockDecls[Decl];
1331 llvm::SmallVector<llvm::Value *, 9> addr;
1332 llvm::LLVMContext &VMContext = M->getLLVMContext();
1333 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1334 llvm::DIFactory::OpDeref));
1335 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1336 llvm::DIFactory::OpPlus));
1337 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1338 offset));
1339 if (BDRE->isByRef()) {
1340 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1341 llvm::DIFactory::OpDeref));
1342 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1343 llvm::DIFactory::OpPlus));
1344 offset = CGF->LLVMPointerWidth/8; // offset of __forwarding field
1345 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1346 offset));
1347 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1348 llvm::DIFactory::OpDeref));
1349 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1350 llvm::DIFactory::OpPlus));
1351 offset = XOffset/8; // offset of x field
1352 addr.push_back(llvm::ConstantInt::get(llvm::Type::getInt64Ty(VMContext),
1353 offset));
1354 }
1355
1356 // Create the descriptor for the variable.
1357 llvm::DIVariable D =
1358 DebugFactory.CreateComplexVariable(Tag, RegionStack.back(),
1359 Decl->getNameAsString(), Unit, Line, Ty,
1360 addr);
1361 // Insert an llvm.dbg.declare into the current block.
Mike Stumpb289b3f2009-10-01 22:29:41 +00001362 DebugFactory.InsertDeclare(Storage, D, Builder.GetInsertPoint());
Mike Stumpb1a6e682009-09-30 02:43:10 +00001363}
1364
Chris Lattner9c85ba32008-11-10 06:08:34 +00001365void CGDebugInfo::EmitDeclareOfAutoVariable(const VarDecl *Decl,
1366 llvm::Value *Storage,
1367 CGBuilderTy &Builder) {
1368 EmitDeclare(Decl, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder);
1369}
1370
Mike Stumpb1a6e682009-09-30 02:43:10 +00001371void CGDebugInfo::EmitDeclareOfBlockDeclRefVariable(
1372 const BlockDeclRefExpr *BDRE, llvm::Value *Storage, CGBuilderTy &Builder,
1373 CodeGenFunction *CGF) {
1374 EmitDeclare(BDRE, llvm::dwarf::DW_TAG_auto_variable, Storage, Builder, CGF);
1375}
1376
Chris Lattner9c85ba32008-11-10 06:08:34 +00001377/// EmitDeclareOfArgVariable - Emit call to llvm.dbg.declare for an argument
1378/// variable declaration.
1379void CGDebugInfo::EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI,
1380 CGBuilderTy &Builder) {
1381 EmitDeclare(Decl, llvm::dwarf::DW_TAG_arg_variable, AI, Builder);
1382}
1383
1384
1385
Sanjiv Gupta686226b2008-06-05 08:59:10 +00001386/// EmitGlobalVariable - Emit information about a global variable.
Mike Stump1eb44332009-09-09 15:08:12 +00001387void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
Chris Lattner9c85ba32008-11-10 06:08:34 +00001388 const VarDecl *Decl) {
Devang Patel07739032009-03-27 23:16:32 +00001389
Sanjiv Gupta686226b2008-06-05 08:59:10 +00001390 // Create global variable debug descriptor.
Chris Lattner9c85ba32008-11-10 06:08:34 +00001391 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
Sanjiv Gupta686226b2008-06-05 08:59:10 +00001392 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +00001393 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
1394 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
Chris Lattner8ec03f52008-11-24 03:54:41 +00001395
Sanjiv Gupta2d7bc3e2009-10-14 15:08:34 +00001396 std::string Name = Var->getName();
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +00001397
1398 QualType T = Decl->getType();
1399 if (T->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001400
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +00001401 // CodeGen turns int[] into int[1] so we'll do the same here.
1402 llvm::APSInt ConstVal(32);
Mike Stump1eb44332009-09-09 15:08:12 +00001403
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +00001404 ConstVal = 1;
1405 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
Mike Stump1eb44332009-09-09 15:08:12 +00001406
1407 T = M->getContext().getConstantArrayType(ET, ConstVal,
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +00001408 ArrayType::Normal, 0);
1409 }
1410
Devang Patel979ec2e2009-10-06 00:35:31 +00001411 DebugFactory.CreateGlobalVariable(getContext(Decl, Unit),
Devang Patelf6a39b72009-10-20 18:26:30 +00001412 Name, Name, Name, Unit, LineNo,
Anders Carlsson4d6e8dd2008-11-26 17:40:42 +00001413 getOrCreateType(T, Unit),
Chris Lattner9c85ba32008-11-10 06:08:34 +00001414 Var->hasInternalLinkage(),
1415 true/*definition*/, Var);
Sanjiv Gupta686226b2008-06-05 08:59:10 +00001416}
1417
Devang Patel9ca36b62009-02-26 21:10:26 +00001418/// EmitGlobalVariable - Emit information about an objective-c interface.
Mike Stump1eb44332009-09-09 15:08:12 +00001419void CGDebugInfo::EmitGlobalVariable(llvm::GlobalVariable *Var,
Devang Patel9ca36b62009-02-26 21:10:26 +00001420 ObjCInterfaceDecl *Decl) {
1421 // Create global variable debug descriptor.
1422 llvm::DICompileUnit Unit = getOrCreateCompileUnit(Decl->getLocation());
1423 SourceManager &SM = M->getContext().getSourceManager();
Devang Patel4f6fa232009-04-17 21:35:15 +00001424 PresumedLoc PLoc = SM.getPresumedLoc(Decl->getLocation());
1425 unsigned LineNo = PLoc.isInvalid() ? 0 : PLoc.getLine();
Devang Patel9ca36b62009-02-26 21:10:26 +00001426
1427 std::string Name = Decl->getNameAsString();
1428
Chris Lattner03d9f342009-04-01 06:23:52 +00001429 QualType T = M->getContext().getObjCInterfaceType(Decl);
Devang Patel9ca36b62009-02-26 21:10:26 +00001430 if (T->isIncompleteArrayType()) {
Mike Stump1eb44332009-09-09 15:08:12 +00001431
Devang Patel9ca36b62009-02-26 21:10:26 +00001432 // CodeGen turns int[] into int[1] so we'll do the same here.
1433 llvm::APSInt ConstVal(32);
Mike Stump1eb44332009-09-09 15:08:12 +00001434
Devang Patel9ca36b62009-02-26 21:10:26 +00001435 ConstVal = 1;
1436 QualType ET = M->getContext().getAsArrayType(T)->getElementType();
Mike Stump1eb44332009-09-09 15:08:12 +00001437
1438 T = M->getContext().getConstantArrayType(ET, ConstVal,
Devang Patel9ca36b62009-02-26 21:10:26 +00001439 ArrayType::Normal, 0);
1440 }
1441
Devang Patelf6a39b72009-10-20 18:26:30 +00001442 DebugFactory.CreateGlobalVariable(Unit, Name, Name, Name, Unit, LineNo,
Devang Patel9ca36b62009-02-26 21:10:26 +00001443 getOrCreateType(T, Unit),
1444 Var->hasInternalLinkage(),
1445 true/*definition*/, Var);
1446}