1 //===--- DIBuilder.cpp - Debug Information Builder ------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file implements the DIBuilder. 10 // 11 //===----------------------------------------------------------------------===// 12 13 #include "llvm/IR/DIBuilder.h" 14 #include "LLVMContextImpl.h" 15 #include "llvm/ADT/Optional.h" 16 #include "llvm/ADT/STLExtras.h" 17 #include "llvm/BinaryFormat/Dwarf.h" 18 #include "llvm/IR/Constants.h" 19 #include "llvm/IR/DebugInfo.h" 20 #include "llvm/IR/IRBuilder.h" 21 #include "llvm/IR/IntrinsicInst.h" 22 #include "llvm/IR/Module.h" 23 #include "llvm/Support/CommandLine.h" 24 #include "llvm/Support/Debug.h" 25 26 using namespace llvm; 27 using namespace llvm::dwarf; 28 29 static cl::opt<bool> 30 UseDbgAddr("use-dbg-addr", 31 llvm::cl::desc("Use llvm.dbg.addr for all local variables"), 32 cl::init(false), cl::Hidden); 33 34 DIBuilder::DIBuilder(Module &m, bool AllowUnresolvedNodes, DICompileUnit *CU) 35 : M(m), VMContext(M.getContext()), CUNode(CU), 36 DeclareFn(nullptr), ValueFn(nullptr), LabelFn(nullptr), 37 AllowUnresolvedNodes(AllowUnresolvedNodes) {} 38 39 void DIBuilder::trackIfUnresolved(MDNode *N) { 40 if (!N) 41 return; 42 if (N->isResolved()) 43 return; 44 45 assert(AllowUnresolvedNodes && "Cannot handle unresolved nodes"); 46 UnresolvedNodes.emplace_back(N); 47 } 48 49 void DIBuilder::finalizeSubprogram(DISubprogram *SP) { 50 MDTuple *Temp = SP->getRetainedNodes().get(); 51 if (!Temp || !Temp->isTemporary()) 52 return; 53 54 SmallVector<Metadata *, 16> RetainedNodes; 55 56 auto PV = PreservedVariables.find(SP); 57 if (PV != PreservedVariables.end()) 58 RetainedNodes.append(PV->second.begin(), PV->second.end()); 59 60 auto PL = PreservedLabels.find(SP); 61 if (PL != PreservedLabels.end()) 62 RetainedNodes.append(PL->second.begin(), PL->second.end()); 63 64 DINodeArray Node = getOrCreateArray(RetainedNodes); 65 66 TempMDTuple(Temp)->replaceAllUsesWith(Node.get()); 67 } 68 69 void DIBuilder::finalize() { 70 if (!CUNode) { 71 assert(!AllowUnresolvedNodes && 72 "creating type nodes without a CU is not supported"); 73 return; 74 } 75 76 CUNode->replaceEnumTypes(MDTuple::get(VMContext, AllEnumTypes)); 77 78 SmallVector<Metadata *, 16> RetainValues; 79 // Declarations and definitions of the same type may be retained. Some 80 // clients RAUW these pairs, leaving duplicates in the retained types 81 // list. Use a set to remove the duplicates while we transform the 82 // TrackingVHs back into Values. 83 SmallPtrSet<Metadata *, 16> RetainSet; 84 for (unsigned I = 0, E = AllRetainTypes.size(); I < E; I++) 85 if (RetainSet.insert(AllRetainTypes[I]).second) 86 RetainValues.push_back(AllRetainTypes[I]); 87 88 if (!RetainValues.empty()) 89 CUNode->replaceRetainedTypes(MDTuple::get(VMContext, RetainValues)); 90 91 DISubprogramArray SPs = MDTuple::get(VMContext, AllSubprograms); 92 for (auto *SP : SPs) 93 finalizeSubprogram(SP); 94 for (auto *N : RetainValues) 95 if (auto *SP = dyn_cast<DISubprogram>(N)) 96 finalizeSubprogram(SP); 97 98 if (!AllGVs.empty()) 99 CUNode->replaceGlobalVariables(MDTuple::get(VMContext, AllGVs)); 100 101 if (!AllImportedModules.empty()) 102 CUNode->replaceImportedEntities(MDTuple::get( 103 VMContext, SmallVector<Metadata *, 16>(AllImportedModules.begin(), 104 AllImportedModules.end()))); 105 106 for (const auto &I : AllMacrosPerParent) { 107 // DIMacroNode's with nullptr parent are DICompileUnit direct children. 108 if (!I.first) { 109 CUNode->replaceMacros(MDTuple::get(VMContext, I.second.getArrayRef())); 110 continue; 111 } 112 // Otherwise, it must be a temporary DIMacroFile that need to be resolved. 113 auto *TMF = cast<DIMacroFile>(I.first); 114 auto *MF = DIMacroFile::get(VMContext, dwarf::DW_MACINFO_start_file, 115 TMF->getLine(), TMF->getFile(), 116 getOrCreateMacroArray(I.second.getArrayRef())); 117 replaceTemporary(llvm::TempDIMacroNode(TMF), MF); 118 } 119 120 // Now that all temp nodes have been replaced or deleted, resolve remaining 121 // cycles. 122 for (const auto &N : UnresolvedNodes) 123 if (N && !N->isResolved()) 124 N->resolveCycles(); 125 UnresolvedNodes.clear(); 126 127 // Can't handle unresolved nodes anymore. 128 AllowUnresolvedNodes = false; 129 } 130 131 /// If N is compile unit return NULL otherwise return N. 132 static DIScope *getNonCompileUnitScope(DIScope *N) { 133 if (!N || isa<DICompileUnit>(N)) 134 return nullptr; 135 return cast<DIScope>(N); 136 } 137 138 DICompileUnit *DIBuilder::createCompileUnit( 139 unsigned Lang, DIFile *File, StringRef Producer, bool isOptimized, 140 StringRef Flags, unsigned RunTimeVer, StringRef SplitName, 141 DICompileUnit::DebugEmissionKind Kind, uint64_t DWOId, 142 bool SplitDebugInlining, bool DebugInfoForProfiling, 143 DICompileUnit::DebugNameTableKind NameTableKind, bool RangesBaseAddress) { 144 145 assert(((Lang <= dwarf::DW_LANG_Fortran08 && Lang >= dwarf::DW_LANG_C89) || 146 (Lang <= dwarf::DW_LANG_hi_user && Lang >= dwarf::DW_LANG_lo_user)) && 147 "Invalid Language tag"); 148 149 assert(!CUNode && "Can only make one compile unit per DIBuilder instance"); 150 CUNode = DICompileUnit::getDistinct( 151 VMContext, Lang, File, Producer, isOptimized, Flags, RunTimeVer, 152 SplitName, Kind, nullptr, nullptr, nullptr, nullptr, nullptr, DWOId, 153 SplitDebugInlining, DebugInfoForProfiling, NameTableKind, 154 RangesBaseAddress); 155 156 // Create a named metadata so that it is easier to find cu in a module. 157 NamedMDNode *NMD = M.getOrInsertNamedMetadata("llvm.dbg.cu"); 158 NMD->addOperand(CUNode); 159 trackIfUnresolved(CUNode); 160 return CUNode; 161 } 162 163 static DIImportedEntity * 164 createImportedModule(LLVMContext &C, dwarf::Tag Tag, DIScope *Context, 165 Metadata *NS, DIFile *File, unsigned Line, StringRef Name, 166 SmallVectorImpl<TrackingMDNodeRef> &AllImportedModules) { 167 if (Line) 168 assert(File && "Source location has line number but no file"); 169 unsigned EntitiesCount = C.pImpl->DIImportedEntitys.size(); 170 auto *M = DIImportedEntity::get(C, Tag, Context, cast_or_null<DINode>(NS), 171 File, Line, Name); 172 if (EntitiesCount < C.pImpl->DIImportedEntitys.size()) 173 // A new Imported Entity was just added to the context. 174 // Add it to the Imported Modules list. 175 AllImportedModules.emplace_back(M); 176 return M; 177 } 178 179 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, 180 DINamespace *NS, DIFile *File, 181 unsigned Line) { 182 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, 183 Context, NS, File, Line, StringRef(), 184 AllImportedModules); 185 } 186 187 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, 188 DIImportedEntity *NS, 189 DIFile *File, unsigned Line) { 190 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, 191 Context, NS, File, Line, StringRef(), 192 AllImportedModules); 193 } 194 195 DIImportedEntity *DIBuilder::createImportedModule(DIScope *Context, DIModule *M, 196 DIFile *File, unsigned Line) { 197 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_module, 198 Context, M, File, Line, StringRef(), 199 AllImportedModules); 200 } 201 202 DIImportedEntity *DIBuilder::createImportedDeclaration(DIScope *Context, 203 DINode *Decl, 204 DIFile *File, 205 unsigned Line, 206 StringRef Name) { 207 // Make sure to use the unique identifier based metadata reference for 208 // types that have one. 209 return ::createImportedModule(VMContext, dwarf::DW_TAG_imported_declaration, 210 Context, Decl, File, Line, Name, 211 AllImportedModules); 212 } 213 214 DIFile *DIBuilder::createFile(StringRef Filename, StringRef Directory, 215 Optional<DIFile::ChecksumInfo<StringRef>> CS, 216 Optional<StringRef> Source) { 217 return DIFile::get(VMContext, Filename, Directory, CS, Source); 218 } 219 220 DIMacro *DIBuilder::createMacro(DIMacroFile *Parent, unsigned LineNumber, 221 unsigned MacroType, StringRef Name, 222 StringRef Value) { 223 assert(!Name.empty() && "Unable to create macro without name"); 224 assert((MacroType == dwarf::DW_MACINFO_undef || 225 MacroType == dwarf::DW_MACINFO_define) && 226 "Unexpected macro type"); 227 auto *M = DIMacro::get(VMContext, MacroType, LineNumber, Name, Value); 228 AllMacrosPerParent[Parent].insert(M); 229 return M; 230 } 231 232 DIMacroFile *DIBuilder::createTempMacroFile(DIMacroFile *Parent, 233 unsigned LineNumber, DIFile *File) { 234 auto *MF = DIMacroFile::getTemporary(VMContext, dwarf::DW_MACINFO_start_file, 235 LineNumber, File, DIMacroNodeArray()) 236 .release(); 237 AllMacrosPerParent[Parent].insert(MF); 238 // Add the new temporary DIMacroFile to the macro per parent map as a parent. 239 // This is needed to assure DIMacroFile with no children to have an entry in 240 // the map. Otherwise, it will not be resolved in DIBuilder::finalize(). 241 AllMacrosPerParent.insert({MF, {}}); 242 return MF; 243 } 244 245 DIEnumerator *DIBuilder::createEnumerator(StringRef Name, int64_t Val, 246 bool IsUnsigned) { 247 assert(!Name.empty() && "Unable to create enumerator without name"); 248 return DIEnumerator::get(VMContext, Val, IsUnsigned, Name); 249 } 250 251 DIBasicType *DIBuilder::createUnspecifiedType(StringRef Name) { 252 assert(!Name.empty() && "Unable to create type without name"); 253 return DIBasicType::get(VMContext, dwarf::DW_TAG_unspecified_type, Name); 254 } 255 256 DIBasicType *DIBuilder::createNullPtrType() { 257 return createUnspecifiedType("decltype(nullptr)"); 258 } 259 260 DIBasicType *DIBuilder::createBasicType(StringRef Name, uint64_t SizeInBits, 261 unsigned Encoding, 262 DINode::DIFlags Flags) { 263 assert(!Name.empty() && "Unable to create type without name"); 264 return DIBasicType::get(VMContext, dwarf::DW_TAG_base_type, Name, SizeInBits, 265 0, Encoding, Flags); 266 } 267 268 DIDerivedType *DIBuilder::createQualifiedType(unsigned Tag, DIType *FromTy) { 269 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, FromTy, 0, 270 0, 0, None, DINode::FlagZero); 271 } 272 273 DIDerivedType *DIBuilder::createPointerType( 274 DIType *PointeeTy, 275 uint64_t SizeInBits, 276 uint32_t AlignInBits, 277 Optional<unsigned> DWARFAddressSpace, 278 StringRef Name) { 279 // FIXME: Why is there a name here? 280 return DIDerivedType::get(VMContext, dwarf::DW_TAG_pointer_type, Name, 281 nullptr, 0, nullptr, PointeeTy, SizeInBits, 282 AlignInBits, 0, DWARFAddressSpace, 283 DINode::FlagZero); 284 } 285 286 DIDerivedType *DIBuilder::createMemberPointerType(DIType *PointeeTy, 287 DIType *Base, 288 uint64_t SizeInBits, 289 uint32_t AlignInBits, 290 DINode::DIFlags Flags) { 291 return DIDerivedType::get(VMContext, dwarf::DW_TAG_ptr_to_member_type, "", 292 nullptr, 0, nullptr, PointeeTy, SizeInBits, 293 AlignInBits, 0, None, Flags, Base); 294 } 295 296 DIDerivedType *DIBuilder::createReferenceType( 297 unsigned Tag, DIType *RTy, 298 uint64_t SizeInBits, 299 uint32_t AlignInBits, 300 Optional<unsigned> DWARFAddressSpace) { 301 assert(RTy && "Unable to create reference type"); 302 return DIDerivedType::get(VMContext, Tag, "", nullptr, 0, nullptr, RTy, 303 SizeInBits, AlignInBits, 0, DWARFAddressSpace, 304 DINode::FlagZero); 305 } 306 307 DIDerivedType *DIBuilder::createTypedef(DIType *Ty, StringRef Name, 308 DIFile *File, unsigned LineNo, 309 DIScope *Context, 310 uint32_t AlignInBits) { 311 return DIDerivedType::get(VMContext, dwarf::DW_TAG_typedef, Name, File, 312 LineNo, getNonCompileUnitScope(Context), Ty, 0, 313 AlignInBits, 0, None, DINode::FlagZero); 314 } 315 316 DIDerivedType *DIBuilder::createFriend(DIType *Ty, DIType *FriendTy) { 317 assert(Ty && "Invalid type!"); 318 assert(FriendTy && "Invalid friend type!"); 319 return DIDerivedType::get(VMContext, dwarf::DW_TAG_friend, "", nullptr, 0, Ty, 320 FriendTy, 0, 0, 0, None, DINode::FlagZero); 321 } 322 323 DIDerivedType *DIBuilder::createInheritance(DIType *Ty, DIType *BaseTy, 324 uint64_t BaseOffset, 325 uint32_t VBPtrOffset, 326 DINode::DIFlags Flags) { 327 assert(Ty && "Unable to create inheritance"); 328 Metadata *ExtraData = ConstantAsMetadata::get( 329 ConstantInt::get(IntegerType::get(VMContext, 32), VBPtrOffset)); 330 return DIDerivedType::get(VMContext, dwarf::DW_TAG_inheritance, "", nullptr, 331 0, Ty, BaseTy, 0, 0, BaseOffset, None, 332 Flags, ExtraData); 333 } 334 335 DIDerivedType *DIBuilder::createMemberType(DIScope *Scope, StringRef Name, 336 DIFile *File, unsigned LineNumber, 337 uint64_t SizeInBits, 338 uint32_t AlignInBits, 339 uint64_t OffsetInBits, 340 DINode::DIFlags Flags, DIType *Ty) { 341 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, 342 LineNumber, getNonCompileUnitScope(Scope), Ty, 343 SizeInBits, AlignInBits, OffsetInBits, None, Flags); 344 } 345 346 static ConstantAsMetadata *getConstantOrNull(Constant *C) { 347 if (C) 348 return ConstantAsMetadata::get(C); 349 return nullptr; 350 } 351 352 DIDerivedType *DIBuilder::createVariantMemberType( 353 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 354 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, 355 Constant *Discriminant, DINode::DIFlags Flags, DIType *Ty) { 356 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, 357 LineNumber, getNonCompileUnitScope(Scope), Ty, 358 SizeInBits, AlignInBits, OffsetInBits, None, Flags, 359 getConstantOrNull(Discriminant)); 360 } 361 362 DIDerivedType *DIBuilder::createBitFieldMemberType( 363 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 364 uint64_t SizeInBits, uint64_t OffsetInBits, uint64_t StorageOffsetInBits, 365 DINode::DIFlags Flags, DIType *Ty) { 366 Flags |= DINode::FlagBitField; 367 return DIDerivedType::get( 368 VMContext, dwarf::DW_TAG_member, Name, File, LineNumber, 369 getNonCompileUnitScope(Scope), Ty, SizeInBits, /* AlignInBits */ 0, 370 OffsetInBits, None, Flags, 371 ConstantAsMetadata::get(ConstantInt::get(IntegerType::get(VMContext, 64), 372 StorageOffsetInBits))); 373 } 374 375 DIDerivedType * 376 DIBuilder::createStaticMemberType(DIScope *Scope, StringRef Name, DIFile *File, 377 unsigned LineNumber, DIType *Ty, 378 DINode::DIFlags Flags, llvm::Constant *Val, 379 uint32_t AlignInBits) { 380 Flags |= DINode::FlagStaticMember; 381 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, 382 LineNumber, getNonCompileUnitScope(Scope), Ty, 0, 383 AlignInBits, 0, None, Flags, 384 getConstantOrNull(Val)); 385 } 386 387 DIDerivedType * 388 DIBuilder::createObjCIVar(StringRef Name, DIFile *File, unsigned LineNumber, 389 uint64_t SizeInBits, uint32_t AlignInBits, 390 uint64_t OffsetInBits, DINode::DIFlags Flags, 391 DIType *Ty, MDNode *PropertyNode) { 392 return DIDerivedType::get(VMContext, dwarf::DW_TAG_member, Name, File, 393 LineNumber, getNonCompileUnitScope(File), Ty, 394 SizeInBits, AlignInBits, OffsetInBits, None, Flags, 395 PropertyNode); 396 } 397 398 DIObjCProperty * 399 DIBuilder::createObjCProperty(StringRef Name, DIFile *File, unsigned LineNumber, 400 StringRef GetterName, StringRef SetterName, 401 unsigned PropertyAttributes, DIType *Ty) { 402 return DIObjCProperty::get(VMContext, Name, File, LineNumber, GetterName, 403 SetterName, PropertyAttributes, Ty); 404 } 405 406 DITemplateTypeParameter * 407 DIBuilder::createTemplateTypeParameter(DIScope *Context, StringRef Name, 408 DIType *Ty) { 409 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); 410 return DITemplateTypeParameter::get(VMContext, Name, Ty); 411 } 412 413 static DITemplateValueParameter * 414 createTemplateValueParameterHelper(LLVMContext &VMContext, unsigned Tag, 415 DIScope *Context, StringRef Name, DIType *Ty, 416 Metadata *MD) { 417 assert((!Context || isa<DICompileUnit>(Context)) && "Expected compile unit"); 418 return DITemplateValueParameter::get(VMContext, Tag, Name, Ty, MD); 419 } 420 421 DITemplateValueParameter * 422 DIBuilder::createTemplateValueParameter(DIScope *Context, StringRef Name, 423 DIType *Ty, Constant *Val) { 424 return createTemplateValueParameterHelper( 425 VMContext, dwarf::DW_TAG_template_value_parameter, Context, Name, Ty, 426 getConstantOrNull(Val)); 427 } 428 429 DITemplateValueParameter * 430 DIBuilder::createTemplateTemplateParameter(DIScope *Context, StringRef Name, 431 DIType *Ty, StringRef Val) { 432 return createTemplateValueParameterHelper( 433 VMContext, dwarf::DW_TAG_GNU_template_template_param, Context, Name, Ty, 434 MDString::get(VMContext, Val)); 435 } 436 437 DITemplateValueParameter * 438 DIBuilder::createTemplateParameterPack(DIScope *Context, StringRef Name, 439 DIType *Ty, DINodeArray Val) { 440 return createTemplateValueParameterHelper( 441 VMContext, dwarf::DW_TAG_GNU_template_parameter_pack, Context, Name, Ty, 442 Val.get()); 443 } 444 445 DICompositeType *DIBuilder::createClassType( 446 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, 447 uint64_t SizeInBits, uint32_t AlignInBits, uint64_t OffsetInBits, 448 DINode::DIFlags Flags, DIType *DerivedFrom, DINodeArray Elements, 449 DIType *VTableHolder, MDNode *TemplateParams, StringRef UniqueIdentifier) { 450 assert((!Context || isa<DIScope>(Context)) && 451 "createClassType should be called with a valid Context"); 452 453 auto *R = DICompositeType::get( 454 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, 455 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 456 OffsetInBits, Flags, Elements, 0, VTableHolder, 457 cast_or_null<MDTuple>(TemplateParams), UniqueIdentifier); 458 trackIfUnresolved(R); 459 return R; 460 } 461 462 DICompositeType *DIBuilder::createStructType( 463 DIScope *Context, StringRef Name, DIFile *File, unsigned LineNumber, 464 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, 465 DIType *DerivedFrom, DINodeArray Elements, unsigned RunTimeLang, 466 DIType *VTableHolder, StringRef UniqueIdentifier) { 467 auto *R = DICompositeType::get( 468 VMContext, dwarf::DW_TAG_structure_type, Name, File, LineNumber, 469 getNonCompileUnitScope(Context), DerivedFrom, SizeInBits, AlignInBits, 0, 470 Flags, Elements, RunTimeLang, VTableHolder, nullptr, UniqueIdentifier); 471 trackIfUnresolved(R); 472 return R; 473 } 474 475 DICompositeType *DIBuilder::createUnionType( 476 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 477 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, 478 DINodeArray Elements, unsigned RunTimeLang, StringRef UniqueIdentifier) { 479 auto *R = DICompositeType::get( 480 VMContext, dwarf::DW_TAG_union_type, Name, File, LineNumber, 481 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, 482 Elements, RunTimeLang, nullptr, nullptr, UniqueIdentifier); 483 trackIfUnresolved(R); 484 return R; 485 } 486 487 DICompositeType *DIBuilder::createVariantPart( 488 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 489 uint64_t SizeInBits, uint32_t AlignInBits, DINode::DIFlags Flags, 490 DIDerivedType *Discriminator, DINodeArray Elements, StringRef UniqueIdentifier) { 491 auto *R = DICompositeType::get( 492 VMContext, dwarf::DW_TAG_variant_part, Name, File, LineNumber, 493 getNonCompileUnitScope(Scope), nullptr, SizeInBits, AlignInBits, 0, Flags, 494 Elements, 0, nullptr, nullptr, UniqueIdentifier, Discriminator); 495 trackIfUnresolved(R); 496 return R; 497 } 498 499 DISubroutineType *DIBuilder::createSubroutineType(DITypeRefArray ParameterTypes, 500 DINode::DIFlags Flags, 501 unsigned CC) { 502 return DISubroutineType::get(VMContext, Flags, CC, ParameterTypes); 503 } 504 505 DICompositeType *DIBuilder::createEnumerationType( 506 DIScope *Scope, StringRef Name, DIFile *File, unsigned LineNumber, 507 uint64_t SizeInBits, uint32_t AlignInBits, DINodeArray Elements, 508 DIType *UnderlyingType, StringRef UniqueIdentifier, bool IsScoped) { 509 auto *CTy = DICompositeType::get( 510 VMContext, dwarf::DW_TAG_enumeration_type, Name, File, LineNumber, 511 getNonCompileUnitScope(Scope), UnderlyingType, SizeInBits, AlignInBits, 0, 512 IsScoped ? DINode::FlagEnumClass : DINode::FlagZero, Elements, 0, nullptr, 513 nullptr, UniqueIdentifier); 514 AllEnumTypes.push_back(CTy); 515 trackIfUnresolved(CTy); 516 return CTy; 517 } 518 519 DICompositeType *DIBuilder::createArrayType(uint64_t Size, 520 uint32_t AlignInBits, DIType *Ty, 521 DINodeArray Subscripts) { 522 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", 523 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, 524 DINode::FlagZero, Subscripts, 0, nullptr); 525 trackIfUnresolved(R); 526 return R; 527 } 528 529 DICompositeType *DIBuilder::createVectorType(uint64_t Size, 530 uint32_t AlignInBits, DIType *Ty, 531 DINodeArray Subscripts) { 532 auto *R = DICompositeType::get(VMContext, dwarf::DW_TAG_array_type, "", 533 nullptr, 0, nullptr, Ty, Size, AlignInBits, 0, 534 DINode::FlagVector, Subscripts, 0, nullptr); 535 trackIfUnresolved(R); 536 return R; 537 } 538 539 DISubprogram *DIBuilder::createArtificialSubprogram(DISubprogram *SP) { 540 auto NewSP = SP->cloneWithFlags(SP->getFlags() | DINode::FlagArtificial); 541 return MDNode::replaceWithDistinct(std::move(NewSP)); 542 } 543 544 static DIType *createTypeWithFlags(const DIType *Ty, 545 DINode::DIFlags FlagsToSet) { 546 auto NewTy = Ty->cloneWithFlags(Ty->getFlags() | FlagsToSet); 547 return MDNode::replaceWithUniqued(std::move(NewTy)); 548 } 549 550 DIType *DIBuilder::createArtificialType(DIType *Ty) { 551 // FIXME: Restrict this to the nodes where it's valid. 552 if (Ty->isArtificial()) 553 return Ty; 554 return createTypeWithFlags(Ty, DINode::FlagArtificial); 555 } 556 557 DIType *DIBuilder::createObjectPointerType(DIType *Ty) { 558 // FIXME: Restrict this to the nodes where it's valid. 559 if (Ty->isObjectPointer()) 560 return Ty; 561 DINode::DIFlags Flags = DINode::FlagObjectPointer | DINode::FlagArtificial; 562 return createTypeWithFlags(Ty, Flags); 563 } 564 565 void DIBuilder::retainType(DIScope *T) { 566 assert(T && "Expected non-null type"); 567 assert((isa<DIType>(T) || (isa<DISubprogram>(T) && 568 cast<DISubprogram>(T)->isDefinition() == false)) && 569 "Expected type or subprogram declaration"); 570 AllRetainTypes.emplace_back(T); 571 } 572 573 DIBasicType *DIBuilder::createUnspecifiedParameter() { return nullptr; } 574 575 DICompositeType * 576 DIBuilder::createForwardDecl(unsigned Tag, StringRef Name, DIScope *Scope, 577 DIFile *F, unsigned Line, unsigned RuntimeLang, 578 uint64_t SizeInBits, uint32_t AlignInBits, 579 StringRef UniqueIdentifier) { 580 // FIXME: Define in terms of createReplaceableForwardDecl() by calling 581 // replaceWithUniqued(). 582 auto *RetTy = DICompositeType::get( 583 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, 584 SizeInBits, AlignInBits, 0, DINode::FlagFwdDecl, nullptr, RuntimeLang, 585 nullptr, nullptr, UniqueIdentifier); 586 trackIfUnresolved(RetTy); 587 return RetTy; 588 } 589 590 DICompositeType *DIBuilder::createReplaceableCompositeType( 591 unsigned Tag, StringRef Name, DIScope *Scope, DIFile *F, unsigned Line, 592 unsigned RuntimeLang, uint64_t SizeInBits, uint32_t AlignInBits, 593 DINode::DIFlags Flags, StringRef UniqueIdentifier) { 594 auto *RetTy = 595 DICompositeType::getTemporary( 596 VMContext, Tag, Name, F, Line, getNonCompileUnitScope(Scope), nullptr, 597 SizeInBits, AlignInBits, 0, Flags, nullptr, RuntimeLang, nullptr, 598 nullptr, UniqueIdentifier) 599 .release(); 600 trackIfUnresolved(RetTy); 601 return RetTy; 602 } 603 604 DINodeArray DIBuilder::getOrCreateArray(ArrayRef<Metadata *> Elements) { 605 return MDTuple::get(VMContext, Elements); 606 } 607 608 DIMacroNodeArray 609 DIBuilder::getOrCreateMacroArray(ArrayRef<Metadata *> Elements) { 610 return MDTuple::get(VMContext, Elements); 611 } 612 613 DITypeRefArray DIBuilder::getOrCreateTypeArray(ArrayRef<Metadata *> Elements) { 614 SmallVector<llvm::Metadata *, 16> Elts; 615 for (unsigned i = 0, e = Elements.size(); i != e; ++i) { 616 if (Elements[i] && isa<MDNode>(Elements[i])) 617 Elts.push_back(cast<DIType>(Elements[i])); 618 else 619 Elts.push_back(Elements[i]); 620 } 621 return DITypeRefArray(MDNode::get(VMContext, Elts)); 622 } 623 624 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, int64_t Count) { 625 return DISubrange::get(VMContext, Count, Lo); 626 } 627 628 DISubrange *DIBuilder::getOrCreateSubrange(int64_t Lo, Metadata *CountNode) { 629 return DISubrange::get(VMContext, CountNode, Lo); 630 } 631 632 static void checkGlobalVariableScope(DIScope *Context) { 633 #ifndef NDEBUG 634 if (auto *CT = 635 dyn_cast_or_null<DICompositeType>(getNonCompileUnitScope(Context))) 636 assert(CT->getIdentifier().empty() && 637 "Context of a global variable should not be a type with identifier"); 638 #endif 639 } 640 641 DIGlobalVariableExpression *DIBuilder::createGlobalVariableExpression( 642 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, 643 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, DIExpression *Expr, 644 MDNode *Decl, MDTuple *templateParams, uint32_t AlignInBits) { 645 checkGlobalVariableScope(Context); 646 647 auto *GV = DIGlobalVariable::getDistinct( 648 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, 649 LineNumber, Ty, isLocalToUnit, true, cast_or_null<DIDerivedType>(Decl), 650 templateParams, AlignInBits); 651 if (!Expr) 652 Expr = createExpression(); 653 auto *N = DIGlobalVariableExpression::get(VMContext, GV, Expr); 654 AllGVs.push_back(N); 655 return N; 656 } 657 658 DIGlobalVariable *DIBuilder::createTempGlobalVariableFwdDecl( 659 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, 660 unsigned LineNumber, DIType *Ty, bool isLocalToUnit, MDNode *Decl, 661 MDTuple *templateParams, uint32_t AlignInBits) { 662 checkGlobalVariableScope(Context); 663 664 return DIGlobalVariable::getTemporary( 665 VMContext, cast_or_null<DIScope>(Context), Name, LinkageName, F, 666 LineNumber, Ty, isLocalToUnit, false, 667 cast_or_null<DIDerivedType>(Decl), templateParams, AlignInBits) 668 .release(); 669 } 670 671 static DILocalVariable *createLocalVariable( 672 LLVMContext &VMContext, 673 DenseMap<MDNode *, SmallVector<TrackingMDNodeRef, 1>> &PreservedVariables, 674 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, 675 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags, 676 uint32_t AlignInBits) { 677 // FIXME: Why getNonCompileUnitScope()? 678 // FIXME: Why is "!Context" okay here? 679 // FIXME: Why doesn't this check for a subprogram or lexical block (AFAICT 680 // the only valid scopes)? 681 DIScope *Context = getNonCompileUnitScope(Scope); 682 683 auto *Node = 684 DILocalVariable::get(VMContext, cast_or_null<DILocalScope>(Context), Name, 685 File, LineNo, Ty, ArgNo, Flags, AlignInBits); 686 if (AlwaysPreserve) { 687 // The optimizer may remove local variables. If there is an interest 688 // to preserve variable info in such situation then stash it in a 689 // named mdnode. 690 DISubprogram *Fn = getDISubprogram(Scope); 691 assert(Fn && "Missing subprogram for local variable"); 692 PreservedVariables[Fn].emplace_back(Node); 693 } 694 return Node; 695 } 696 697 DILocalVariable *DIBuilder::createAutoVariable(DIScope *Scope, StringRef Name, 698 DIFile *File, unsigned LineNo, 699 DIType *Ty, bool AlwaysPreserve, 700 DINode::DIFlags Flags, 701 uint32_t AlignInBits) { 702 return createLocalVariable(VMContext, PreservedVariables, Scope, Name, 703 /* ArgNo */ 0, File, LineNo, Ty, AlwaysPreserve, 704 Flags, AlignInBits); 705 } 706 707 DILocalVariable *DIBuilder::createParameterVariable( 708 DIScope *Scope, StringRef Name, unsigned ArgNo, DIFile *File, 709 unsigned LineNo, DIType *Ty, bool AlwaysPreserve, DINode::DIFlags Flags) { 710 assert(ArgNo && "Expected non-zero argument number for parameter"); 711 return createLocalVariable(VMContext, PreservedVariables, Scope, Name, ArgNo, 712 File, LineNo, Ty, AlwaysPreserve, Flags, 713 /* AlignInBits */0); 714 } 715 716 DILabel *DIBuilder::createLabel( 717 DIScope *Scope, StringRef Name, DIFile *File, 718 unsigned LineNo, bool AlwaysPreserve) { 719 DIScope *Context = getNonCompileUnitScope(Scope); 720 721 auto *Node = 722 DILabel::get(VMContext, cast_or_null<DILocalScope>(Context), Name, 723 File, LineNo); 724 725 if (AlwaysPreserve) { 726 /// The optimizer may remove labels. If there is an interest 727 /// to preserve label info in such situation then append it to 728 /// the list of retained nodes of the DISubprogram. 729 DISubprogram *Fn = getDISubprogram(Scope); 730 assert(Fn && "Missing subprogram for label"); 731 PreservedLabels[Fn].emplace_back(Node); 732 } 733 return Node; 734 } 735 736 DIExpression *DIBuilder::createExpression(ArrayRef<uint64_t> Addr) { 737 return DIExpression::get(VMContext, Addr); 738 } 739 740 DIExpression *DIBuilder::createExpression(ArrayRef<int64_t> Signed) { 741 // TODO: Remove the callers of this signed version and delete. 742 SmallVector<uint64_t, 8> Addr(Signed.begin(), Signed.end()); 743 return createExpression(Addr); 744 } 745 746 template <class... Ts> 747 static DISubprogram *getSubprogram(bool IsDistinct, Ts &&... Args) { 748 if (IsDistinct) 749 return DISubprogram::getDistinct(std::forward<Ts>(Args)...); 750 return DISubprogram::get(std::forward<Ts>(Args)...); 751 } 752 753 DISubprogram *DIBuilder::createFunction( 754 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, 755 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, 756 DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags, 757 DITemplateParameterArray TParams, DISubprogram *Decl, 758 DITypeArray ThrownTypes) { 759 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; 760 auto *Node = getSubprogram( 761 /*IsDistinct=*/IsDefinition, VMContext, getNonCompileUnitScope(Context), 762 Name, LinkageName, File, LineNo, Ty, ScopeLine, nullptr, 0, 0, Flags, 763 SPFlags, IsDefinition ? CUNode : nullptr, TParams, Decl, 764 MDTuple::getTemporary(VMContext, None).release(), ThrownTypes); 765 766 if (IsDefinition) 767 AllSubprograms.push_back(Node); 768 trackIfUnresolved(Node); 769 return Node; 770 } 771 772 DISubprogram *DIBuilder::createTempFunctionFwdDecl( 773 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *File, 774 unsigned LineNo, DISubroutineType *Ty, unsigned ScopeLine, 775 DINode::DIFlags Flags, DISubprogram::DISPFlags SPFlags, 776 DITemplateParameterArray TParams, DISubprogram *Decl, 777 DITypeArray ThrownTypes) { 778 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; 779 return DISubprogram::getTemporary(VMContext, getNonCompileUnitScope(Context), 780 Name, LinkageName, File, LineNo, Ty, 781 ScopeLine, nullptr, 0, 0, Flags, SPFlags, 782 IsDefinition ? CUNode : nullptr, TParams, 783 Decl, nullptr, ThrownTypes) 784 .release(); 785 } 786 787 DISubprogram *DIBuilder::createMethod( 788 DIScope *Context, StringRef Name, StringRef LinkageName, DIFile *F, 789 unsigned LineNo, DISubroutineType *Ty, unsigned VIndex, int ThisAdjustment, 790 DIType *VTableHolder, DINode::DIFlags Flags, 791 DISubprogram::DISPFlags SPFlags, DITemplateParameterArray TParams, 792 DITypeArray ThrownTypes) { 793 assert(getNonCompileUnitScope(Context) && 794 "Methods should have both a Context and a context that isn't " 795 "the compile unit."); 796 // FIXME: Do we want to use different scope/lines? 797 bool IsDefinition = SPFlags & DISubprogram::SPFlagDefinition; 798 auto *SP = getSubprogram( 799 /*IsDistinct=*/IsDefinition, VMContext, cast<DIScope>(Context), Name, 800 LinkageName, F, LineNo, Ty, LineNo, VTableHolder, VIndex, ThisAdjustment, 801 Flags, SPFlags, IsDefinition ? CUNode : nullptr, TParams, nullptr, 802 nullptr, ThrownTypes); 803 804 if (IsDefinition) 805 AllSubprograms.push_back(SP); 806 trackIfUnresolved(SP); 807 return SP; 808 } 809 810 DICommonBlock *DIBuilder::createCommonBlock( 811 DIScope *Scope, DIGlobalVariable *Decl, StringRef Name, DIFile *File, 812 unsigned LineNo) { 813 return DICommonBlock::get( 814 VMContext, Scope, Decl, Name, File, LineNo); 815 } 816 817 DINamespace *DIBuilder::createNameSpace(DIScope *Scope, StringRef Name, 818 bool ExportSymbols) { 819 820 // It is okay to *not* make anonymous top-level namespaces distinct, because 821 // all nodes that have an anonymous namespace as their parent scope are 822 // guaranteed to be unique and/or are linked to their containing 823 // DICompileUnit. This decision is an explicit tradeoff of link time versus 824 // memory usage versus code simplicity and may get revisited in the future. 825 return DINamespace::get(VMContext, getNonCompileUnitScope(Scope), Name, 826 ExportSymbols); 827 } 828 829 DIModule *DIBuilder::createModule(DIScope *Scope, StringRef Name, 830 StringRef ConfigurationMacros, 831 StringRef IncludePath, 832 StringRef ISysRoot) { 833 return DIModule::get(VMContext, getNonCompileUnitScope(Scope), Name, 834 ConfigurationMacros, IncludePath, ISysRoot); 835 } 836 837 DILexicalBlockFile *DIBuilder::createLexicalBlockFile(DIScope *Scope, 838 DIFile *File, 839 unsigned Discriminator) { 840 return DILexicalBlockFile::get(VMContext, Scope, File, Discriminator); 841 } 842 843 DILexicalBlock *DIBuilder::createLexicalBlock(DIScope *Scope, DIFile *File, 844 unsigned Line, unsigned Col) { 845 // Make these distinct, to avoid merging two lexical blocks on the same 846 // file/line/column. 847 return DILexicalBlock::getDistinct(VMContext, getNonCompileUnitScope(Scope), 848 File, Line, Col); 849 } 850 851 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, 852 DIExpression *Expr, const DILocation *DL, 853 Instruction *InsertBefore) { 854 return insertDeclare(Storage, VarInfo, Expr, DL, InsertBefore->getParent(), 855 InsertBefore); 856 } 857 858 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, 859 DIExpression *Expr, const DILocation *DL, 860 BasicBlock *InsertAtEnd) { 861 // If this block already has a terminator then insert this intrinsic before 862 // the terminator. Otherwise, put it at the end of the block. 863 Instruction *InsertBefore = InsertAtEnd->getTerminator(); 864 return insertDeclare(Storage, VarInfo, Expr, DL, InsertAtEnd, InsertBefore); 865 } 866 867 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, 868 Instruction *InsertBefore) { 869 return insertLabel( 870 LabelInfo, DL, InsertBefore ? InsertBefore->getParent() : nullptr, 871 InsertBefore); 872 } 873 874 Instruction *DIBuilder::insertLabel(DILabel *LabelInfo, const DILocation *DL, 875 BasicBlock *InsertAtEnd) { 876 return insertLabel(LabelInfo, DL, InsertAtEnd, nullptr); 877 } 878 879 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, 880 DILocalVariable *VarInfo, 881 DIExpression *Expr, 882 const DILocation *DL, 883 Instruction *InsertBefore) { 884 return insertDbgValueIntrinsic( 885 V, VarInfo, Expr, DL, InsertBefore ? InsertBefore->getParent() : nullptr, 886 InsertBefore); 887 } 888 889 Instruction *DIBuilder::insertDbgValueIntrinsic(Value *V, 890 DILocalVariable *VarInfo, 891 DIExpression *Expr, 892 const DILocation *DL, 893 BasicBlock *InsertAtEnd) { 894 return insertDbgValueIntrinsic(V, VarInfo, Expr, DL, InsertAtEnd, nullptr); 895 } 896 897 /// Return an IRBuilder for inserting dbg.declare and dbg.value intrinsics. This 898 /// abstracts over the various ways to specify an insert position. 899 static IRBuilder<> getIRBForDbgInsertion(const DILocation *DL, 900 BasicBlock *InsertBB, 901 Instruction *InsertBefore) { 902 IRBuilder<> B(DL->getContext()); 903 if (InsertBefore) 904 B.SetInsertPoint(InsertBefore); 905 else if (InsertBB) 906 B.SetInsertPoint(InsertBB); 907 B.SetCurrentDebugLocation(DL); 908 return B; 909 } 910 911 static Value *getDbgIntrinsicValueImpl(LLVMContext &VMContext, Value *V) { 912 assert(V && "no value passed to dbg intrinsic"); 913 return MetadataAsValue::get(VMContext, ValueAsMetadata::get(V)); 914 } 915 916 static Function *getDeclareIntrin(Module &M) { 917 return Intrinsic::getDeclaration(&M, UseDbgAddr ? Intrinsic::dbg_addr 918 : Intrinsic::dbg_declare); 919 } 920 921 Instruction *DIBuilder::insertDeclare(Value *Storage, DILocalVariable *VarInfo, 922 DIExpression *Expr, const DILocation *DL, 923 BasicBlock *InsertBB, Instruction *InsertBefore) { 924 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.declare"); 925 assert(DL && "Expected debug loc"); 926 assert(DL->getScope()->getSubprogram() == 927 VarInfo->getScope()->getSubprogram() && 928 "Expected matching subprograms"); 929 if (!DeclareFn) 930 DeclareFn = getDeclareIntrin(M); 931 932 trackIfUnresolved(VarInfo); 933 trackIfUnresolved(Expr); 934 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, Storage), 935 MetadataAsValue::get(VMContext, VarInfo), 936 MetadataAsValue::get(VMContext, Expr)}; 937 938 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); 939 return B.CreateCall(DeclareFn, Args); 940 } 941 942 Instruction *DIBuilder::insertDbgValueIntrinsic( 943 Value *V, DILocalVariable *VarInfo, DIExpression *Expr, 944 const DILocation *DL, BasicBlock *InsertBB, Instruction *InsertBefore) { 945 assert(V && "no value passed to dbg.value"); 946 assert(VarInfo && "empty or invalid DILocalVariable* passed to dbg.value"); 947 assert(DL && "Expected debug loc"); 948 assert(DL->getScope()->getSubprogram() == 949 VarInfo->getScope()->getSubprogram() && 950 "Expected matching subprograms"); 951 if (!ValueFn) 952 ValueFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_value); 953 954 trackIfUnresolved(VarInfo); 955 trackIfUnresolved(Expr); 956 Value *Args[] = {getDbgIntrinsicValueImpl(VMContext, V), 957 MetadataAsValue::get(VMContext, VarInfo), 958 MetadataAsValue::get(VMContext, Expr)}; 959 960 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); 961 return B.CreateCall(ValueFn, Args); 962 } 963 964 Instruction *DIBuilder::insertLabel( 965 DILabel *LabelInfo, const DILocation *DL, 966 BasicBlock *InsertBB, Instruction *InsertBefore) { 967 assert(LabelInfo && "empty or invalid DILabel* passed to dbg.label"); 968 assert(DL && "Expected debug loc"); 969 assert(DL->getScope()->getSubprogram() == 970 LabelInfo->getScope()->getSubprogram() && 971 "Expected matching subprograms"); 972 if (!LabelFn) 973 LabelFn = Intrinsic::getDeclaration(&M, Intrinsic::dbg_label); 974 975 trackIfUnresolved(LabelInfo); 976 Value *Args[] = {MetadataAsValue::get(VMContext, LabelInfo)}; 977 978 IRBuilder<> B = getIRBForDbgInsertion(DL, InsertBB, InsertBefore); 979 return B.CreateCall(LabelFn, Args); 980 } 981 982 void DIBuilder::replaceVTableHolder(DICompositeType *&T, 983 DIType *VTableHolder) { 984 { 985 TypedTrackingMDRef<DICompositeType> N(T); 986 N->replaceVTableHolder(VTableHolder); 987 T = N.get(); 988 } 989 990 // If this didn't create a self-reference, just return. 991 if (T != VTableHolder) 992 return; 993 994 // Look for unresolved operands. T will drop RAUW support, orphaning any 995 // cycles underneath it. 996 if (T->isResolved()) 997 for (const MDOperand &O : T->operands()) 998 if (auto *N = dyn_cast_or_null<MDNode>(O)) 999 trackIfUnresolved(N); 1000 } 1001 1002 void DIBuilder::replaceArrays(DICompositeType *&T, DINodeArray Elements, 1003 DINodeArray TParams) { 1004 { 1005 TypedTrackingMDRef<DICompositeType> N(T); 1006 if (Elements) 1007 N->replaceElements(Elements); 1008 if (TParams) 1009 N->replaceTemplateParams(DITemplateParameterArray(TParams)); 1010 T = N.get(); 1011 } 1012 1013 // If T isn't resolved, there's no problem. 1014 if (!T->isResolved()) 1015 return; 1016 1017 // If T is resolved, it may be due to a self-reference cycle. Track the 1018 // arrays explicitly if they're unresolved, or else the cycles will be 1019 // orphaned. 1020 if (Elements) 1021 trackIfUnresolved(Elements.get()); 1022 if (TParams) 1023 trackIfUnresolved(TParams.get()); 1024 } 1025