36 #include "llvm/ADT/DenseSet.h" 37 #include "llvm/ADT/SmallVector.h" 38 #include "llvm/ADT/StringExtras.h" 39 #include "llvm/IR/Constants.h" 40 #include "llvm/IR/DataLayout.h" 41 #include "llvm/IR/DerivedTypes.h" 42 #include "llvm/IR/Instructions.h" 43 #include "llvm/IR/Intrinsics.h" 44 #include "llvm/IR/Metadata.h" 45 #include "llvm/IR/Module.h" 46 #include "llvm/Support/FileSystem.h" 47 #include "llvm/Support/MD5.h" 48 #include "llvm/Support/Path.h" 49 using namespace clang;
66 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
67 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
68 DBuilder(CGM.getModule()) {
70 DebugPrefixMap[KV.first] = KV.second;
75 assert(LexicalBlockStack.empty() &&
76 "Region stack mismatch, stack not empty!");
82 init(TemporaryLocation);
89 init(TemporaryLocation, DefaultToEmpty);
93 bool DefaultToEmpty) {
100 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
102 if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
105 if (TemporaryLocation.
isValid()) {
106 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
110 if (DefaultToEmpty) {
111 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
116 assert(!DI->LexicalBlockStack.empty());
117 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
118 0, 0, DI->LexicalBlockStack.back(), DI->getInlinedAt()));
132 OriginalLocation = CGF.
Builder.getCurrentDebugLocation();
134 CGF.
Builder.SetCurrentDebugLocation(std::move(Loc));
141 CGF->
Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
152 SavedLocation = DI.getLocation();
153 assert((DI.getInlinedAt() ==
154 CGF.
Builder.getCurrentDebugLocation()->getInlinedAt()) &&
155 "CGDebugInfo and IRBuilder are out of sync");
157 DI.EmitInlineFunctionStart(CGF.
Builder, InlinedFn);
165 DI.EmitLocation(CGF->
Builder, SavedLocation);
173 CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
178 if (LexicalBlockStack.empty())
182 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
184 if (PCLoc.isInvalid() ||
Scope->getFile() == getOrCreateFile(CurLoc))
187 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
188 LexicalBlockStack.pop_back();
189 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
190 LBF->getScope(), getOrCreateFile(CurLoc)));
191 }
else if (isa<llvm::DILexicalBlock>(
Scope) ||
192 isa<llvm::DISubprogram>(
Scope)) {
193 LexicalBlockStack.pop_back();
194 LexicalBlockStack.emplace_back(
195 DBuilder.createLexicalBlockFile(
Scope, getOrCreateFile(CurLoc)));
199 llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
200 llvm::DIScope *Mod = getParentModuleOrNull(D);
205 llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *Context,
210 auto I = RegionMap.find(Context);
211 if (I != RegionMap.end()) {
212 llvm::Metadata *
V = I->second;
213 return dyn_cast_or_null<llvm::DIScope>(
V);
217 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
218 return getOrCreateNamespace(NSDecl);
220 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
221 if (!RDecl->isDependentType())
222 return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
234 if (CGM.getCodeGenOpts().EmitCodeView)
239 PP.
remapPath = [
this](StringRef Path) {
return remapDIPath(Path); };
243 StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD) {
244 assert(FD &&
"Invalid FunctionDecl!");
256 CGM.getCodeGenOpts().EmitCodeView;
258 if (!Info && FII && !UseQualifiedName)
262 llvm::raw_svector_ostream OS(NS);
263 if (!UseQualifiedName)
275 return internString(OS.str());
278 StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
280 llvm::raw_svector_ostream OS(MethodName);
283 if (
const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
284 OS << OID->getName();
285 }
else if (
const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
286 OS << OID->getName();
287 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
288 if (OC->IsClassExtension()) {
289 OS << OC->getClassInterface()->getName();
291 OS << OC->getIdentifier()->getNameStart() <<
'(' 292 << OC->getIdentifier()->getNameStart() <<
')';
294 }
else if (
const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
295 OS << OCD->getClassInterface()->getName() <<
'(' << OCD->getName() <<
')';
296 }
else if (isa<ObjCProtocolDecl>(DC)) {
300 cast<ObjCObjectPointerType>(SelfDecl->getType())->getPointeeType();
306 return internString(OS.str());
309 StringRef CGDebugInfo::getSelectorName(
Selector S) {
313 StringRef CGDebugInfo::getClassName(
const RecordDecl *RD) {
314 if (isa<ClassTemplateSpecializationDecl>(RD)) {
316 llvm::raw_svector_ostream OS(Name);
323 return internString(Name);
329 return II->getName();
333 if (CGM.getCodeGenOpts().EmitCodeView) {
336 "Typedef should not be in another decl context!");
337 assert(D->getDeclName().getAsIdentifierInfo() &&
338 "Typedef was not named!");
339 return D->getDeclName().getAsIdentifierInfo()->getName();
342 if (CGM.getLangOpts().CPlusPlus) {
349 Name = DD->getName();
354 Name = TND->getName();
360 return internString(UnnamedType);
372 if (!CGM.getCodeGenOpts().EmitCodeView &&
373 CGM.getCodeGenOpts().DwarfVersion < 5)
378 const llvm::MemoryBuffer *MemBuffer = SM.
getBuffer(FID, &Invalid);
383 llvm::MD5::MD5Result Result;
385 Hash.update(MemBuffer->getBuffer());
388 Hash.stringifyResult(Result, Checksum);
389 return llvm::DIFile::CSK_MD5;
394 if (!CGM.getCodeGenOpts().EmbedSource)
397 bool SourceInvalid =
false;
409 return TheCU->getFile();
415 if (PLoc.
isInvalid() || FileName.empty())
417 return TheCU->getFile();
420 auto It = DIFileCache.find(FileName.data());
421 if (It != DIFileCache.end()) {
423 if (llvm::Metadata *
V = It->second)
424 return cast<llvm::DIFile>(
V);
433 computeChecksum(PLoc.
getFileID(), Checksum);
436 CSInfo.emplace(*CSKind, Checksum);
437 return createFile(FileName, CSInfo, getSource(SM, SM.
getFileID(Loc)));
441 CGDebugInfo::createFile(StringRef FileName,
442 Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
446 std::string RemappedFile = remapDIPath(FileName);
447 std::string CurDir = remapDIPath(getCurrentDirname());
450 if (llvm::sys::path::is_absolute(RemappedFile)) {
453 auto FileIt = llvm::sys::path::begin(RemappedFile);
454 auto FileE = llvm::sys::path::end(RemappedFile);
455 auto CurDirIt = llvm::sys::path::begin(CurDir);
456 auto CurDirE = llvm::sys::path::end(CurDir);
457 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
458 llvm::sys::path::append(DirBuf, *CurDirIt);
459 if (
std::distance(llvm::sys::path::begin(CurDir), CurDirIt) == 1) {
465 for (; FileIt != FileE; ++FileIt)
466 llvm::sys::path::append(FileBuf, *FileIt);
474 llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
475 DIFileCache[FileName.data()].reset(F);
480 for (
const auto &Entry : DebugPrefixMap)
481 if (Path.startswith(Entry.first))
482 return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
487 if (Loc.
isInvalid() && CurLoc.isInvalid())
494 unsigned CGDebugInfo::getColumnNumber(
SourceLocation Loc,
bool Force) {
496 if (!Force && !CGM.getCodeGenOpts().DebugColumnInfo)
500 if (Loc.
isInvalid() && CurLoc.isInvalid())
507 StringRef CGDebugInfo::getCurrentDirname() {
508 if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
509 return CGM.getCodeGenOpts().DebugCompilationDir;
511 if (!CWDName.empty())
514 llvm::sys::fs::current_path(CWD);
515 return CWDName = internString(CWD);
518 void CGDebugInfo::CreateCompileUnit() {
532 std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
533 if (MainFileName.empty())
534 MainFileName =
"<stdin>";
540 std::string MainFileDir;
542 MainFileDir = MainFile->getDir()->getName();
543 if (!llvm::sys::path::is_absolute(MainFileName)) {
545 llvm::sys::path::append(MainFileDirSS, MainFileName);
546 MainFileName = llvm::sys::path::remove_leading_dotslash(MainFileDirSS);
552 if (MainFile->getName() == MainFileName &&
554 MainFile->getName().rsplit(
'.').second)
556 MainFileName = CGM.getModule().getName().str();
561 llvm::dwarf::SourceLanguage LangTag;
565 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
566 else if (LO.CPlusPlus14)
567 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
568 else if (LO.CPlusPlus11)
569 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
571 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
572 }
else if (LO.ObjC) {
573 LangTag = llvm::dwarf::DW_LANG_ObjC;
574 }
else if (LO.RenderScript) {
575 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
577 LangTag = llvm::dwarf::DW_LANG_C99;
579 LangTag = llvm::dwarf::DW_LANG_C89;
585 unsigned RuntimeVers = 0;
589 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
593 EmissionKind = llvm::DICompileUnit::NoDebug;
596 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
603 EmissionKind = llvm::DICompileUnit::FullDebug;
608 auto &CGOpts = CGM.getCodeGenOpts();
614 CSInfo.emplace(*CSKind, Checksum);
615 llvm::DIFile *CUFile = DBuilder.createFile(
616 remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
620 TheCU = DBuilder.createCompileUnit(
621 LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer :
"",
622 LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
623 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
624 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
625 CGM.getTarget().getTriple().isNVPTX()
627 :
static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
628 CGOpts.DebugNameTable),
629 CGOpts.DebugRangesBaseAddress);
632 llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
636 #define BUILTIN_TYPE(Id, SingletonId) 637 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: 638 #include "clang/AST/BuiltinTypes.def" 639 case BuiltinType::Dependent:
640 llvm_unreachable(
"Unexpected builtin type");
641 case BuiltinType::NullPtr:
642 return DBuilder.createNullPtrType();
643 case BuiltinType::Void:
645 case BuiltinType::ObjCClass:
648 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
649 "objc_class", TheCU, TheCU->getFile(), 0);
651 case BuiltinType::ObjCId: {
662 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
663 "objc_class", TheCU, TheCU->getFile(), 0);
665 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
667 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
669 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
670 0, 0, llvm::DINode::FlagZero,
nullptr,
671 llvm::DINodeArray());
673 DBuilder.replaceArrays(
674 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
675 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
676 llvm::DINode::FlagZero, ISATy)));
679 case BuiltinType::ObjCSel: {
681 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
682 "objc_selector", TheCU,
683 TheCU->getFile(), 0);
687 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 688 case BuiltinType::Id: \ 689 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \ 691 #include "clang/Basic/OpenCLImageTypes.def" 692 case BuiltinType::OCLSampler:
693 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
694 case BuiltinType::OCLEvent:
695 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
696 case BuiltinType::OCLClkEvent:
697 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
698 case BuiltinType::OCLQueue:
699 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
700 case BuiltinType::OCLReserveID:
701 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
702 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 703 case BuiltinType::Id: \ 704 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty); 705 #include "clang/Basic/OpenCLExtensionTypes.def" 710 #define SVE_TYPE(Name, Id, SingletonId) \ 711 case BuiltinType::Id: 712 #include "clang/Basic/AArch64SVEACLETypes.def" 714 unsigned DiagID = CGM.getDiags().getCustomDiagID(
716 "cannot yet generate debug info for SVE type '%0'");
717 auto Name = BT->
getName(CGM.getContext().getPrintingPolicy());
718 CGM.getDiags().Report(DiagID) << Name;
720 return CreateType(cast<const BuiltinType>(CGM.getContext().IntTy));
723 case BuiltinType::UChar:
724 case BuiltinType::Char_U:
725 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
727 case BuiltinType::Char_S:
728 case BuiltinType::SChar:
729 Encoding = llvm::dwarf::DW_ATE_signed_char;
731 case BuiltinType::Char8:
732 case BuiltinType::Char16:
733 case BuiltinType::Char32:
734 Encoding = llvm::dwarf::DW_ATE_UTF;
736 case BuiltinType::UShort:
737 case BuiltinType::UInt:
738 case BuiltinType::UInt128:
739 case BuiltinType::ULong:
740 case BuiltinType::WChar_U:
741 case BuiltinType::ULongLong:
742 Encoding = llvm::dwarf::DW_ATE_unsigned;
744 case BuiltinType::Short:
745 case BuiltinType::Int:
746 case BuiltinType::Int128:
747 case BuiltinType::Long:
748 case BuiltinType::WChar_S:
749 case BuiltinType::LongLong:
750 Encoding = llvm::dwarf::DW_ATE_signed;
752 case BuiltinType::Bool:
753 Encoding = llvm::dwarf::DW_ATE_boolean;
755 case BuiltinType::Half:
756 case BuiltinType::Float:
757 case BuiltinType::LongDouble:
758 case BuiltinType::Float16:
759 case BuiltinType::Float128:
760 case BuiltinType::Double:
766 Encoding = llvm::dwarf::DW_ATE_float;
768 case BuiltinType::ShortAccum:
769 case BuiltinType::Accum:
770 case BuiltinType::LongAccum:
771 case BuiltinType::ShortFract:
772 case BuiltinType::Fract:
773 case BuiltinType::LongFract:
774 case BuiltinType::SatShortFract:
775 case BuiltinType::SatFract:
776 case BuiltinType::SatLongFract:
777 case BuiltinType::SatShortAccum:
778 case BuiltinType::SatAccum:
779 case BuiltinType::SatLongAccum:
780 Encoding = llvm::dwarf::DW_ATE_signed_fixed;
782 case BuiltinType::UShortAccum:
783 case BuiltinType::UAccum:
784 case BuiltinType::ULongAccum:
785 case BuiltinType::UShortFract:
786 case BuiltinType::UFract:
787 case BuiltinType::ULongFract:
788 case BuiltinType::SatUShortAccum:
789 case BuiltinType::SatUAccum:
790 case BuiltinType::SatULongAccum:
791 case BuiltinType::SatUShortFract:
792 case BuiltinType::SatUFract:
793 case BuiltinType::SatULongFract:
794 Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
799 case BuiltinType::Long:
802 case BuiltinType::LongLong:
803 BTName =
"long long int";
805 case BuiltinType::ULong:
806 BTName =
"long unsigned int";
808 case BuiltinType::ULongLong:
809 BTName =
"long long unsigned int";
812 BTName = BT->
getName(CGM.getLangOpts());
816 uint64_t Size = CGM.getContext().getTypeSize(BT);
817 return DBuilder.createBasicType(BTName, Size, Encoding);
820 llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
822 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
824 Encoding = llvm::dwarf::DW_ATE_lo_user;
826 uint64_t Size = CGM.getContext().getTypeSize(Ty);
827 return DBuilder.createBasicType(
"complex", Size, Encoding);
830 llvm::DIType *CGDebugInfo::CreateQualifiedType(
QualType Ty,
831 llvm::DIFile *Unit) {
842 llvm::dwarf::Tag Tag;
844 Tag = llvm::dwarf::DW_TAG_const_type;
847 Tag = llvm::dwarf::DW_TAG_volatile_type;
850 Tag = llvm::dwarf::DW_TAG_restrict_type;
853 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
854 return getOrCreateType(
QualType(T, 0), Unit);
857 auto *FromTy = getOrCreateType(Qc.
apply(CGM.getContext(), T), Unit);
861 return DBuilder.createQualifiedType(Tag, FromTy);
865 llvm::DIFile *Unit) {
871 return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
873 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
877 llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
878 llvm::DIFile *Unit) {
879 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
885 switch (TheCU->getSourceLanguage()) {
886 case llvm::dwarf::DW_LANG_C_plus_plus:
887 case llvm::dwarf::DW_LANG_C_plus_plus_11:
888 case llvm::dwarf::DW_LANG_C_plus_plus_14:
890 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
891 return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
919 llvm::DICompileUnit *TheCU) {
937 llvm::DICompileUnit *TheCU) {
943 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
945 if (RD->isDynamicClass() &&
951 llvm::raw_svector_ostream Out(Identifier);
958 llvm::dwarf::Tag Tag;
960 Tag = llvm::dwarf::DW_TAG_structure_type;
962 Tag = llvm::dwarf::DW_TAG_union_type;
967 Tag = llvm::dwarf::DW_TAG_class_type;
972 llvm::DICompositeType *
973 CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
974 llvm::DIScope *Ctx) {
976 if (llvm::DIType *T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
977 return cast<llvm::DICompositeType>(T);
978 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
980 StringRef RDName = getClassName(RD);
987 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
989 llvm::DINode::FlagFwdDecl, Identifier);
990 if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
991 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
992 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
993 CollectCXXTemplateParams(TSpecial, DefUnit));
994 ReplaceMap.emplace_back(
995 std::piecewise_construct, std::make_tuple(Ty),
996 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
1000 llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
1003 llvm::DIFile *Unit) {
1007 unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(PointeeTy);
1008 uint64_t Size = CGM.getTarget().getPointerWidth(AddressSpace);
1011 CGM.getTarget().getDWARFAddressSpace(AddressSpace);
1013 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1014 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
1015 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1016 Size, Align, DWARFAddressSpace);
1018 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1019 Align, DWARFAddressSpace);
1022 llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1023 llvm::DIType *&
Cache) {
1026 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1027 TheCU, TheCU->getFile(), 0);
1028 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1029 Cache = DBuilder.createPointerType(Cache, Size);
1033 uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1034 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1040 uint64_t FieldOffset = 0;
1045 if (CGM.getLangOpts().OpenCL) {
1046 FType = CGM.getContext().IntTy;
1047 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1048 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1050 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1051 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1052 FType = CGM.getContext().IntTy;
1053 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1054 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1056 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1057 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1058 uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
1059 uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
1060 EltTys.push_back(DBuilder.createMemberType(
1061 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1062 FieldOffset, llvm::DINode::FlagZero, DescTy));
1063 FieldOffset += FieldSize;
1070 llvm::DIFile *Unit) {
1073 uint64_t FieldOffset;
1074 llvm::DINodeArray Elements;
1077 FType = CGM.getContext().UnsignedLongTy;
1078 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1079 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1081 Elements = DBuilder.getOrCreateArray(EltTys);
1084 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1087 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1088 FieldOffset, 0, Flags,
nullptr, Elements);
1091 uint64_t Size = CGM.getContext().getTypeSize(Ty);
1093 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1095 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1098 Elements = DBuilder.getOrCreateArray(EltTys);
1104 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1105 Flags,
nullptr, Elements);
1107 return DBuilder.createPointerType(EltTy, Size);
1111 llvm::DIFile *Unit) {
1117 ->getTemplatedDecl();
1119 if (AliasDecl->hasAttr<NoDebugAttr>())
1123 llvm::raw_svector_ostream OS(NS);
1128 return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
1130 getDeclContextDescriptor(AliasDecl));
1133 llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1134 llvm::DIFile *Unit) {
1135 llvm::DIType *Underlying =
1146 return DBuilder.createTypedef(Underlying, Ty->
getDecl()->
getName(),
1147 getOrCreateFile(Loc), getLineNumber(Loc),
1148 getDeclContextDescriptor(Ty->
getDecl()));
1158 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1160 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1162 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1164 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1166 return llvm::dwarf::DW_CC_BORLAND_pascal;
1168 return llvm::dwarf::DW_CC_LLVM_Win64;
1170 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1173 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1175 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1177 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1179 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1181 return llvm::dwarf::DW_CC_LLVM_OpenCLKernel;
1183 return llvm::dwarf::DW_CC_LLVM_Swift;
1185 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1187 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1189 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1194 llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1195 llvm::DIFile *Unit) {
1199 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1203 if (isa<FunctionNoProtoType>(Ty))
1204 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1205 else if (
const auto *FPT = dyn_cast<FunctionProtoType>(Ty)) {
1206 for (
const QualType &ParamType : FPT->param_types())
1207 EltTys.push_back(getOrCreateType(ParamType, Unit));
1208 if (FPT->isVariadic())
1209 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1212 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1213 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
1228 if (Access == Default)
1229 return llvm::DINode::FlagZero;
1233 return llvm::DINode::FlagPrivate;
1235 return llvm::DINode::FlagProtected;
1237 return llvm::DINode::FlagPublic;
1239 return llvm::DINode::FlagZero;
1241 llvm_unreachable(
"unexpected access enumerator");
1244 llvm::DIType *CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1245 llvm::DIScope *RecordTy,
1247 StringRef Name = BitFieldDecl->
getName();
1250 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1251 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1254 llvm::DIFile *File = getOrCreateFile(Loc);
1255 unsigned Line = getLineNumber(Loc);
1258 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1259 uint64_t SizeInBits = BitFieldInfo.
Size;
1260 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1261 uint64_t StorageOffsetInBits =
1267 if (CGM.getDataLayout().isBigEndian())
1269 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1271 return DBuilder.createBitFieldMemberType(
1272 RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1279 uint32_t AlignInBits, llvm::DIFile *tunit,
1280 llvm::DIScope *scope,
const RecordDecl *RD) {
1281 llvm::DIType *debugType = getOrCreateType(type, tunit);
1284 llvm::DIFile *file = getOrCreateFile(loc);
1285 unsigned line = getLineNumber(loc);
1287 uint64_t SizeInBits = 0;
1288 auto Align = AlignInBits;
1290 TypeInfo TI = CGM.getContext().getTypeInfo(type);
1291 SizeInBits = TI.
Width;
1297 return DBuilder.createMemberType(scope,
name, file, line, SizeInBits, Align,
1298 offsetInBits, flags, debugType);
1301 void CGDebugInfo::CollectRecordLambdaFields(
1303 llvm::DIType *RecordTy) {
1307 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
1309 unsigned fieldno = 0;
1312 I != E; ++I, ++Field, ++fieldno) {
1316 assert(!Field->isBitField() &&
"lambdas don't have bitfield members!");
1318 StringRef VName = V->
getName();
1319 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1321 llvm::DIType *FieldType = createFieldType(
1322 VName, Field->getType(), Loc, Field->getAccess(),
1323 layout.
getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
1324 elements.push_back(FieldType);
1331 llvm::DIFile *VUnit = getOrCreateFile(f->
getLocation());
1333 llvm::DIType *fieldType = createFieldType(
1337 elements.push_back(fieldType);
1342 llvm::DIDerivedType *
1343 CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
1348 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
1349 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
1351 unsigned LineNumber = getLineNumber(Var->
getLocation());
1352 StringRef VName = Var->
getName();
1353 llvm::Constant *C =
nullptr;
1358 C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->
getInt());
1360 C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->
getFloat());
1366 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1367 RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
1372 void CGDebugInfo::CollectRecordNormalField(
1373 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
1383 llvm::DIType *FieldType;
1385 FieldType = createBitFieldType(field, RecordTy, RD);
1390 OffsetInBits, Align, tunit, RecordTy, RD);
1393 elements.push_back(FieldType);
1396 void CGDebugInfo::CollectRecordNestedType(
1398 QualType Ty = CGM.getContext().getTypeDeclType(TD);
1400 if (isa<InjectedClassNameType>(Ty))
1403 llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc));
1404 elements.push_back(nestedType);
1407 void CGDebugInfo::CollectRecordFields(
1408 const RecordDecl *record, llvm::DIFile *tunit,
1410 llvm::DICompositeType *RecordTy) {
1413 if (CXXDecl && CXXDecl->
isLambda())
1414 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
1416 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
1419 unsigned fieldNo = 0;
1423 for (
const auto *I : record->
decls())
1424 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
1425 if (
V->hasAttr<NoDebugAttr>())
1430 if (CGM.getCodeGenOpts().EmitCodeView &&
1431 isa<VarTemplateSpecializationDecl>(
V))
1434 if (isa<VarTemplatePartialSpecializationDecl>(
V))
1438 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
1439 if (MI != StaticDataMemberCache.end()) {
1440 assert(MI->second &&
1441 "Static data member declaration should still exist");
1442 elements.push_back(MI->second);
1444 auto Field = CreateRecordStaticField(
V, RecordTy, record);
1445 elements.push_back(Field);
1447 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
1448 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
1449 elements, RecordTy, record);
1453 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
1456 if (
const auto *nestedType = dyn_cast<TypeDecl>(I))
1457 if (!nestedType->isImplicit() &&
1458 nestedType->getDeclContext() == record)
1459 CollectRecordNestedType(nestedType, elements);
1464 llvm::DISubroutineType *
1465 CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *Method,
1466 llvm::DIFile *Unit) {
1469 return cast_or_null<llvm::DISubroutineType>(
1470 getOrCreateType(
QualType(Func, 0), Unit));
1471 return getOrCreateInstanceMethodType(Method->
getThisType(), Func, Unit);
1474 llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
1477 llvm::DITypeRefArray Args(
1478 cast<llvm::DISubroutineType>(getOrCreateType(
QualType(Func, 0), Unit))
1480 assert(Args.size() &&
"Invalid number of arguments!");
1485 Elts.push_back(Args[0]);
1489 if (isa<ClassTemplateSpecializationDecl>(RD)) {
1491 const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
1493 unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
1494 uint64_t Size = CGM.getTarget().getPointerWidth(AS);
1496 llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
1497 llvm::DIType *ThisPtrType =
1498 DBuilder.createPointerType(PointeeType, Size, Align);
1503 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1504 Elts.push_back(ThisPtrType);
1506 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
1508 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1509 Elts.push_back(ThisPtrType);
1513 for (
unsigned i = 1, e = Args.size(); i != e; ++i)
1514 Elts.push_back(Args[i]);
1516 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
1518 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1520 Flags |= llvm::DINode::FlagLValueReference;
1522 Flags |= llvm::DINode::FlagRValueReference;
1524 return DBuilder.createSubroutineType(EltTypeArray, Flags,
1531 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
1538 llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
1539 const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
1541 isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
1543 StringRef MethodName = getFunctionName(Method);
1544 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
1548 StringRef MethodLinkageName;
1555 MethodLinkageName = CGM.getMangledName(Method);
1558 llvm::DIFile *MethodDefUnit =
nullptr;
1559 unsigned MethodLine = 0;
1561 MethodDefUnit = getOrCreateFile(Method->
getLocation());
1562 MethodLine = getLineNumber(Method->
getLocation());
1566 llvm::DIType *ContainingType =
nullptr;
1567 unsigned VIndex = 0;
1568 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1569 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
1574 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
1576 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
1578 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
1581 if (!isa<CXXDestructorDecl>(Method))
1582 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(Method);
1589 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
1598 Flags |= llvm::DINode::FlagIntroducedVirtual;
1603 ThisAdjustment = CGM.getCXXABI()
1604 .getVirtualFunctionPrologueThisAdjustment(GD)
1607 ContainingType = RecordTy;
1611 Flags |= llvm::DINode::FlagNoReturn;
1613 Flags |= llvm::DINode::FlagStaticMember;
1615 Flags |= llvm::DINode::FlagArtificial;
1617 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
1618 if (CXXC->isExplicit())
1619 Flags |= llvm::DINode::FlagExplicit;
1620 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(Method)) {
1621 if (CXXC->isExplicit())
1622 Flags |= llvm::DINode::FlagExplicit;
1625 Flags |= llvm::DINode::FlagPrototyped;
1627 Flags |= llvm::DINode::FlagLValueReference;
1629 Flags |= llvm::DINode::FlagRValueReference;
1630 if (CGM.getLangOpts().Optimize)
1631 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
1633 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
1634 llvm::DISubprogram *SP = DBuilder.createMethod(
1635 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
1636 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
1637 TParamsArray.get());
1644 void CGDebugInfo::CollectCXXMemberFunctions(
1651 for (
const auto *I : RD->
decls()) {
1676 EltTys.push_back(MI == SPCache.end()
1677 ? CreateCXXMemberFunction(Method, Unit, RecordTy)
1678 :
static_cast<llvm::Metadata *
>(MI->second));
1682 void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1684 llvm::DIType *RecordTy) {
1686 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
1687 llvm::DINode::FlagZero);
1691 if (CGM.getCodeGenOpts().EmitCodeView) {
1692 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
1693 llvm::DINode::FlagIndirectVirtualBase);
1697 void CGDebugInfo::CollectCXXBasesAux(
1702 llvm::DINode::DIFlags StartingFlags) {
1704 for (
const auto &BI : Bases) {
1706 cast<CXXRecordDecl>(BI.getType()->castAs<
RecordType>()->getDecl());
1707 if (!SeenTypes.insert(
Base).second)
1709 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
1710 llvm::DINode::DIFlags BFlags = StartingFlags;
1711 uint64_t BaseOffset;
1712 uint32_t VBPtrOffset = 0;
1714 if (BI.isVirtual()) {
1715 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
1718 BaseOffset = 0 - CGM.getItaniumVTableContext()
1719 .getVirtualBaseOffsetOffset(RD,
Base)
1725 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD,
Base);
1726 VBPtrOffset = CGM.getContext()
1727 .getASTRecordLayout(RD)
1731 BFlags |= llvm::DINode::FlagVirtual;
1738 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
1739 VBPtrOffset, BFlags);
1740 EltTys.push_back(DTy);
1747 llvm::DIFile *Unit) {
1749 for (
unsigned i = 0, e = TAList.size(); i != e; ++i) {
1756 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
1757 TemplateParams.push_back(
1758 DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
1762 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1764 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
1769 llvm::DIType *TTy = getOrCreateType(T, Unit);
1770 llvm::Constant *
V =
nullptr;
1773 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
1774 !D->
hasAttr<CUDADeviceAttr>()) {
1778 if (
const auto *VD = dyn_cast<VarDecl>(D))
1779 V = CGM.GetAddrOfGlobalVar(VD);
1782 else if ((MD = dyn_cast<CXXMethodDecl>(D)) && MD->
isInstance())
1783 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
1784 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1785 V = CGM.GetAddrOfFunction(FD);
1788 else if (
const auto *MPT =
1789 dyn_cast<MemberPointerType>(T.
getTypePtr())) {
1793 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
1795 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
1796 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
1798 assert(V &&
"Failed to find template parameter pointer");
1799 V = V->stripPointerCasts();
1801 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1802 TheCU, Name, TTy, cast_or_null<llvm::Constant>(V)));
1806 llvm::DIType *TTy = getOrCreateType(T, Unit);
1807 llvm::Constant *
V =
nullptr;
1810 if (
const auto *MPT = dyn_cast<MemberPointerType>(T.
getTypePtr()))
1816 if (MPT->isMemberDataPointer())
1817 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
1819 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
1820 TemplateParams.push_back(
1821 DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V));
1824 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
1825 TheCU, Name,
nullptr,
1829 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
1830 TheCU, Name,
nullptr,
1837 T = CGM.getContext().getLValueReferenceType(T);
1839 assert(V &&
"Expression in template argument isn't constant");
1840 llvm::DIType *TTy = getOrCreateType(T, Unit);
1841 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1842 TheCU, Name, TTy, V->stripPointerCasts()));
1848 "These argument types shouldn't exist in concrete types");
1851 return DBuilder.getOrCreateArray(TemplateParams);
1855 CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
1856 llvm::DIFile *Unit) {
1862 return CollectTemplateParams(
1865 return llvm::DINodeArray();
1868 llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
1869 llvm::DIFile *Unit) {
1875 return llvm::DINodeArray();
1878 auto TA = TS->getTemplateArgs().
asArray();
1879 return CollectTemplateParams(TList, TA, Unit);
1882 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
1890 return CollectTemplateParams(TPList, TAList.
asArray(), Unit);
1893 llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
1895 return VTablePtrType;
1900 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
1901 llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
1902 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
1904 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
1906 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
1908 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
1909 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
1910 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
1911 return VTablePtrType;
1914 StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
1919 StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
1921 llvm::Function *InitFn) {
1924 if (!CGM.getCodeGenOpts().EmitCodeView)
1925 return InitFn->getName();
1935 llvm::raw_svector_ostream OS(QualifiedGV);
1937 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
1939 std::swap(Quals, GVName);
1943 llvm::raw_svector_ostream OS(InitName);
1945 OS << Quals <<
"::";
1949 llvm_unreachable(
"not an initializer");
1951 OS <<
"`dynamic initializer for '";
1954 OS <<
"`dynamic atexit destructor for '";
1961 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
1963 getPrintingPolicy());
1968 return internString(OS.str());
1971 void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1973 llvm::DICompositeType *RecordTy) {
1989 llvm::DIType *VPtrTy =
nullptr;
1990 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
1991 CGM.getTarget().getCXXABI().isMicrosoft();
1992 if (NeedVTableShape) {
1994 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1996 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
1997 unsigned VSlotCount =
1999 unsigned VTableWidth = PtrWidth * VSlotCount;
2000 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2002 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2005 llvm::DIType *VTableType = DBuilder.createPointerType(
2006 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2007 EltTys.push_back(VTableType);
2010 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
2018 VPtrTy = getOrCreateVTablePtrType(Unit);
2020 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
2021 llvm::DIType *VPtrMember =
2022 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
2023 llvm::DINode::FlagArtificial, VPtrTy);
2024 EltTys.push_back(VPtrMember);
2030 llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
2036 return getOrCreateStandaloneType(D, Loc);
2042 assert(!D.
isNull() &&
"null type");
2043 llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
2044 assert(T &&
"could not create debug info for type");
2055 node = llvm::MDNode::get(CGM.getLLVMContext(), None);
2058 node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
2061 CI->setMetadata(
"heapallocsite", node);
2067 QualType Ty = CGM.getContext().getEnumType(ED);
2069 auto I = TypeCache.find(TyPtr);
2070 if (I == TypeCache.end() || !cast<llvm::DIType>(I->second)->isForwardDecl())
2072 llvm::DIType *Res = CreateTypeDefinition(Ty->
castAs<
EnumType>());
2073 assert(!Res->isForwardDecl());
2074 TypeCache[TyPtr].reset(Res);
2079 !CGM.getLangOpts().CPlusPlus)
2080 completeRequiredType(RD);
2085 if (RD->
hasAttr<DLLImportAttr>())
2088 if (MD->hasAttr<DLLImportAttr>())
2101 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
2110 bool Explicit =
false;
2111 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
2112 Explicit = TD->isExplicitInstantiationOrSpecialization();
2126 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
2127 if (CXXRD->isDynamicClass() &&
2128 CGM.getVTableLinkage(CXXRD) ==
2129 llvm::GlobalValue::AvailableExternallyLinkage &&
2142 QualType Ty = CGM.getContext().getRecordType(RD);
2144 auto I = TypeCache.find(TyPtr);
2145 if (I != TypeCache.end() && !cast<llvm::DIType>(I->second)->isForwardDecl())
2148 assert(!Res->isForwardDecl());
2149 TypeCache[TyPtr].reset(Res);
2156 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
2157 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
2175 if (!LangOpts.CPlusPlus)
2197 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
2198 Spec = SD->getSpecializationKind();
2212 QualType Ty = CGM.getContext().getRecordType(RD);
2213 llvm::DIType *T = getTypeOrNull(Ty);
2214 if (T && T->isForwardDecl())
2215 completeClassData(RD);
2218 llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
2220 llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
2222 CGM.getLangOpts())) {
2224 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
2228 return CreateTypeDefinition(Ty);
2231 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
2235 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
2243 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
2249 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
2250 CollectContainingType(CXXDecl, FwdDecl);
2253 LexicalBlockStack.emplace_back(&*FwdDecl);
2254 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2266 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
2267 CollectVTableInfo(CXXDecl, DefUnit, EltTys, FwdDecl);
2271 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
2273 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
2275 LexicalBlockStack.pop_back();
2276 RegionMap.erase(Ty->
getDecl());
2278 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2279 DBuilder.replaceArrays(FwdDecl, Elements);
2281 if (FwdDecl->isTemporary())
2283 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
2285 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2290 llvm::DIFile *Unit) {
2296 llvm::DIFile *Unit) {
2301 return DBuilder.createTypedef(
2303 Ty->
getDecl()->
getName(), getOrCreateFile(Loc), getLineNumber(Loc),
2304 getDeclContextDescriptor(Ty->
getDecl()));
2332 llvm::DIFile *Unit) {
2342 return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
2344 getDeclContextDescriptor(ID), Unit, 0);
2347 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
2350 static_cast<llvm::dwarf::SourceLanguage
>(TheCU->getSourceLanguage());
2356 llvm::DIScope *Mod = getParentModuleOrNull(ID);
2357 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
2358 llvm::dwarf::DW_TAG_structure_type, ID->
getName(), Mod ? Mod : TheCU,
2359 DefUnit,
Line, RuntimeLang);
2360 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
2364 return CreateTypeDefinition(Ty, Unit);
2369 bool CreateSkeletonCU) {
2374 auto ModRef = ModuleCache.find(M);
2375 if (ModRef != ModuleCache.end())
2376 return cast<llvm::DIModule>(ModRef->second);
2381 llvm::raw_svector_ostream OS(ConfigMacros);
2382 const auto &PPOpts = CGM.getPreprocessorOpts();
2385 for (
auto &M : PPOpts.Macros) {
2388 const std::string &Macro = M.first;
2389 bool Undef = M.second;
2390 OS <<
"\"-" << (Undef ?
'U' :
'D');
2391 for (
char c : Macro)
2406 bool IsRootModule = M ? !M->
Parent :
true;
2410 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
2411 assert(StringRef(M->
Name).startswith(CGM.getLangOpts().ModuleName) &&
2412 "clang module without ASTFile must be specified by -fmodule-name");
2414 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
2418 uint64_t Signature =
2422 llvm::DIBuilder DIB(CGM.getModule());
2423 DIB.createCompileUnit(TheCU->getSourceLanguage(),
2426 TheCU->getProducer(),
true, StringRef(), 0,
2427 Mod.
getASTFile(), llvm::DICompileUnit::FullDebug,
2433 IsRootModule ? nullptr
2434 : getOrCreateModuleRef(
2437 llvm::DIModule *DIMod =
2438 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
2439 Mod.
getPath(), CGM.getHeaderSearchOpts().Sysroot);
2440 ModuleCache[M].reset(DIMod);
2445 llvm::DIFile *Unit) {
2447 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
2449 unsigned RuntimeLang = TheCU->getSourceLanguage();
2452 uint64_t Size = CGM.getContext().getTypeSize(Ty);
2455 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2457 Flags |= llvm::DINode::FlagObjcClassComplete;
2459 llvm::DIScope *Mod = getParentModuleOrNull(ID);
2460 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
2461 Mod ? Mod : Unit, ID->
getName(), DefUnit,
Line, Size, Align, Flags,
2462 nullptr, llvm::DINodeArray(), RuntimeLang);
2468 LexicalBlockStack.emplace_back(RealDecl);
2469 RegionMap[Ty->
getDecl()].reset(RealDecl);
2476 llvm::DIType *SClassTy =
2477 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
2481 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
2482 llvm::DINode::FlagZero);
2483 EltTys.push_back(InhTag);
2489 llvm::DIFile *PUnit = getOrCreateFile(Loc);
2490 unsigned PLine = getLineNumber(Loc);
2493 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
2494 PD->getName(), PUnit, PLine,
2496 : getSelectorName(PD->getGetterName()),
2498 : getSelectorName(PD->getSetterName()),
2499 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
2500 EltTys.push_back(PropertyNode);
2503 llvm::SmallPtrSet<const IdentifierInfo *, 16> PropertySet;
2505 for (
auto *PD : ClassExt->properties()) {
2506 PropertySet.insert(PD->getIdentifier());
2512 if (!PropertySet.insert(PD->getIdentifier()).second)
2518 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
2519 unsigned FieldNo = 0;
2521 Field = Field->getNextIvar(), ++FieldNo) {
2522 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
2526 StringRef FieldName = Field->getName();
2529 if (FieldName.empty())
2533 llvm::DIFile *FieldDefUnit = getOrCreateFile(Field->getLocation());
2534 unsigned FieldLine = getLineNumber(Field->getLocation());
2536 uint64_t FieldSize = 0;
2537 uint32_t FieldAlign = 0;
2539 if (!FType->isIncompleteArrayType()) {
2542 FieldSize = Field->isBitField()
2543 ? Field->getBitWidthValue(CGM.getContext())
2544 : CGM.getContext().getTypeSize(FType);
2548 uint64_t FieldOffset;
2549 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
2553 if (Field->isBitField()) {
2555 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
2556 FieldOffset %= CGM.getContext().getCharWidth();
2564 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2566 Flags = llvm::DINode::FlagProtected;
2568 Flags = llvm::DINode::FlagPrivate;
2570 Flags = llvm::DINode::FlagPublic;
2572 llvm::MDNode *PropertyNode =
nullptr;
2575 ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
2578 llvm::DIFile *PUnit = getOrCreateFile(Loc);
2579 unsigned PLine = getLineNumber(Loc);
2582 PropertyNode = DBuilder.createObjCProperty(
2583 PD->getName(), PUnit, PLine,
2586 : getSelectorName(PD->getGetterName()),
2589 : getSelectorName(PD->getSetterName()),
2590 PD->getPropertyAttributes(),
2591 getOrCreateType(PD->getType(), PUnit));
2595 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
2596 FieldSize, FieldAlign, FieldOffset, Flags,
2597 FieldTy, PropertyNode);
2598 EltTys.push_back(FieldTy);
2601 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2602 DBuilder.replaceArrays(RealDecl, Elements);
2604 LexicalBlockStack.pop_back();
2608 llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
2609 llvm::DIFile *Unit) {
2610 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
2613 llvm::Metadata *Subscript;
2615 auto SizeExpr = SizeExprCache.find(QTy);
2616 if (SizeExpr != SizeExprCache.end())
2617 Subscript = DBuilder.getOrCreateSubrange(0, SizeExpr->getSecond());
2619 Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
2620 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
2622 uint64_t Size = CGM.getContext().getTypeSize(Ty);
2625 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
2628 llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
2633 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2648 Size = CGM.getContext().getTypeSize(Ty);
2657 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
2666 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
2667 Count = CAT->getSize().getZExtValue();
2668 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2669 if (
Expr *Size = VAT->getSizeExpr()) {
2671 if (Size->EvaluateAsInt(Result, CGM.getContext()))
2672 Count = Result.
Val.
getInt().getExtValue();
2676 auto SizeNode = SizeExprCache.find(EltTy);
2677 if (SizeNode != SizeExprCache.end())
2678 Subscripts.push_back(
2679 DBuilder.getOrCreateSubrange(0, SizeNode->getSecond()));
2681 Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
2685 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
2687 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
2692 llvm::DIFile *Unit) {
2693 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
2698 llvm::DIFile *Unit) {
2699 return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
2705 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2709 Size = CGM.getContext().getTypeSize(Ty);
2712 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
2714 case MSInheritanceAttr::Keyword_single_inheritance:
2715 Flags |= llvm::DINode::FlagSingleInheritance;
2717 case MSInheritanceAttr::Keyword_multiple_inheritance:
2718 Flags |= llvm::DINode::FlagMultipleInheritance;
2720 case MSInheritanceAttr::Keyword_virtual_inheritance:
2721 Flags |= llvm::DINode::FlagVirtualInheritance;
2723 case MSInheritanceAttr::Keyword_unspecified_inheritance:
2725 case MSInheritanceAttr::SpellingNotCalculated:
2726 llvm_unreachable(
"Spelling not yet calculated");
2733 return DBuilder.createMemberPointerType(
2739 return DBuilder.createMemberPointerType(
2740 getOrCreateInstanceMethodType(
2743 ClassType, Size, 0, Flags);
2746 llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
2748 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
2751 llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
2755 llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
2767 bool isImportedFromModule =
2779 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
2780 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2781 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
2782 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
2785 StringRef EDName = ED->
getName();
2786 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
2787 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
2788 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
2790 ReplaceMap.emplace_back(
2791 std::piecewise_construct, std::make_tuple(Ty),
2792 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
2796 return CreateTypeDefinition(Ty);
2799 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
2815 const auto &InitVal = Enum->getInitVal();
2816 auto Value = IsSigned ? InitVal.getSExtValue() : InitVal.getZExtValue();
2817 Enumerators.push_back(
2818 DBuilder.createEnumerator(Enum->getName(),
Value, !IsSigned));
2822 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
2824 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2826 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
2827 llvm::DIType *ClassTy = getOrCreateType(ED->
getIntegerType(), DefUnit);
2828 return DBuilder.createEnumerationType(EnumContext, ED->
getName(), DefUnit,
2829 Line, Size, Align, EltArray, ClassTy,
2835 StringRef Name, StringRef
Value) {
2836 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
2837 return DBuilder.createMacro(Parent, Line, MType, Name, Value);
2843 llvm::DIFile *FName = getOrCreateFile(FileLoc);
2844 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
2845 return DBuilder.createTempMacroFile(Parent, Line, FName);
2855 Quals += InnerQuals;
2860 case Type::TemplateSpecialization: {
2861 const auto *Spec = cast<TemplateSpecializationType>(T);
2862 if (Spec->isTypeAlias())
2864 T = Spec->desugar();
2867 case Type::TypeOfExpr:
2868 T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
2873 case Type::Decltype:
2876 case Type::UnaryTransform:
2879 case Type::Attributed:
2880 T = cast<AttributedType>(T)->getEquivalentType();
2882 case Type::Elaborated:
2883 T = cast<ElaboratedType>(T)->getNamedType();
2886 T = cast<ParenType>(T)->getInnerType();
2888 case Type::MacroQualified:
2891 case Type::SubstTemplateTypeParm:
2892 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
2895 case Type::DeducedTemplateSpecialization: {
2896 QualType DT = cast<DeducedType>(T)->getDeducedType();
2897 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
2901 case Type::Adjusted:
2904 T = cast<AdjustedType>(T)->getAdjustedType();
2908 assert(T != LastT &&
"Type unwrapping failed to unwrap!");
2913 llvm::DIType *CGDebugInfo::getTypeOrNull(
QualType Ty) {
2919 if (It != TypeCache.end()) {
2921 if (llvm::Metadata *
V = It->second)
2922 return cast<llvm::DIType>(
V);
2932 completeUnusedClass(SD);
2939 completeClassData(&D);
2942 RetainedTypes.push_back(CGM.getContext().getRecordType(&D).getAsOpaquePtr());
2945 llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
2952 if (
auto *T = getTypeOrNull(Ty))
2955 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
2959 TypeCache[TyPtr].reset(Res);
2964 llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
2966 if (isa<RecordDecl>(D) && !cast<RecordDecl>(D)->
getDefinition())
2970 auto *Reader = CGM.getContext().getExternalSource();
2972 auto Info = Reader->getSourceDescriptor(Idx);
2974 return getOrCreateModuleRef(*Info,
true);
2975 }
else if (ClangModuleMap) {
2989 return getOrCreateModuleRef(Info,
false);
2992 return getOrCreateModuleRef(PCHDescriptor,
false);
2999 llvm::DIType *CGDebugInfo::CreateTypeNode(
QualType Ty, llvm::DIFile *Unit) {
3002 return CreateQualifiedType(Ty, Unit);
3006 #define TYPE(Class, Base) 3007 #define ABSTRACT_TYPE(Class, Base) 3008 #define NON_CANONICAL_TYPE(Class, Base) 3009 #define DEPENDENT_TYPE(Class, Base) case Type::Class: 3010 #include "clang/AST/TypeNodes.inc" 3011 llvm_unreachable(
"Dependent types cannot show up in debug information");
3013 case Type::ExtVector:
3015 return CreateType(cast<VectorType>(Ty), Unit);
3016 case Type::ObjCObjectPointer:
3017 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
3018 case Type::ObjCObject:
3019 return CreateType(cast<ObjCObjectType>(Ty), Unit);
3020 case Type::ObjCTypeParam:
3021 return CreateType(cast<ObjCTypeParamType>(Ty), Unit);
3022 case Type::ObjCInterface:
3023 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
3025 return CreateType(cast<BuiltinType>(Ty));
3027 return CreateType(cast<ComplexType>(Ty));
3029 return CreateType(cast<PointerType>(Ty), Unit);
3030 case Type::BlockPointer:
3031 return CreateType(cast<BlockPointerType>(Ty), Unit);
3033 return CreateType(cast<TypedefType>(Ty), Unit);
3035 return CreateType(cast<RecordType>(Ty));
3037 return CreateEnumType(cast<EnumType>(Ty));
3038 case Type::FunctionProto:
3039 case Type::FunctionNoProto:
3040 return CreateType(cast<FunctionType>(Ty), Unit);
3041 case Type::ConstantArray:
3042 case Type::VariableArray:
3043 case Type::IncompleteArray:
3044 return CreateType(cast<ArrayType>(Ty), Unit);
3046 case Type::LValueReference:
3047 return CreateType(cast<LValueReferenceType>(Ty), Unit);
3048 case Type::RValueReference:
3049 return CreateType(cast<RValueReferenceType>(Ty), Unit);
3051 case Type::MemberPointer:
3052 return CreateType(cast<MemberPointerType>(Ty), Unit);
3055 return CreateType(cast<AtomicType>(Ty), Unit);
3058 return CreateType(cast<PipeType>(Ty), Unit);
3060 case Type::TemplateSpecialization:
3061 return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
3064 case Type::Attributed:
3065 case Type::Adjusted:
3067 case Type::DeducedTemplateSpecialization:
3068 case Type::Elaborated:
3070 case Type::MacroQualified:
3071 case Type::SubstTemplateTypeParm:
3072 case Type::TypeOfExpr:
3074 case Type::Decltype:
3075 case Type::UnaryTransform:
3076 case Type::PackExpansion:
3080 llvm_unreachable(
"type should have been unwrapped!");
3083 llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty,
3084 llvm::DIFile *Unit) {
3087 auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
3092 if (T && !T->isForwardDecl())
3096 llvm::DICompositeType *Res = CreateLimitedType(Ty);
3101 DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
3109 llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
3113 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3115 StringRef RDName = getClassName(RD);
3117 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
3121 auto *T = cast_or_null<llvm::DICompositeType>(
3122 getTypeOrNull(CGM.getContext().getRecordType(RD)));
3130 return getOrCreateRecordFwdDecl(Ty, RDContext);
3132 uint64_t Size = CGM.getContext().getTypeSize(Ty);
3139 auto Flags = llvm::DINode::FlagZero;
3140 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3142 Flags |= llvm::DINode::FlagTypePassByReference;
3144 Flags |= llvm::DINode::FlagTypePassByValue;
3147 if (!CXXRD->isTrivial())
3148 Flags |= llvm::DINode::FlagNonTrivial;
3151 if (CXXRD->isAnonymousStructOrUnion())
3152 Flags |= llvm::DINode::FlagExportSymbols;
3155 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
3156 getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align,
3161 switch (RealDecl->getTag()) {
3163 llvm_unreachable(
"invalid composite type tag");
3165 case llvm::dwarf::DW_TAG_array_type:
3166 case llvm::dwarf::DW_TAG_enumeration_type:
3171 if (Identifier.empty())
3175 case llvm::dwarf::DW_TAG_structure_type:
3176 case llvm::dwarf::DW_TAG_union_type:
3177 case llvm::dwarf::DW_TAG_class_type:
3180 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
3184 RegionMap[Ty->
getDecl()].reset(RealDecl);
3187 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3188 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
3189 CollectCXXTemplateParams(TSpecial, DefUnit));
3193 void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
3194 llvm::DICompositeType *RealDecl) {
3196 llvm::DICompositeType *ContainingType =
nullptr;
3201 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
3208 ContainingType = cast<llvm::DICompositeType>(
3209 getOrCreateType(
QualType(PBase->getTypeForDecl(), 0),
3212 ContainingType = RealDecl;
3214 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
3217 llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit,
QualType FType,
3218 StringRef Name, uint64_t *
Offset) {
3219 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
3220 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
3223 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
3224 *Offset, llvm::DINode::FlagZero, FieldTy);
3225 *Offset += FieldSize;
3229 void CGDebugInfo::collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
3231 StringRef &LinkageName,
3232 llvm::DIScope *&FDContext,
3233 llvm::DINodeArray &TParamsArray,
3234 llvm::DINode::DIFlags &Flags) {
3235 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
3236 Name = getFunctionName(FD);
3239 LinkageName = CGM.getMangledName(GD);
3240 Flags |= llvm::DINode::FlagPrototyped;
3245 if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
3246 !CGM.getCodeGenOpts().EmitGcovNotes &&
3247 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
3249 LinkageName = StringRef();
3254 FDContext = getOrCreateNamespace(NSDecl);
3257 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
3258 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
3262 Flags |= llvm::DINode::FlagNoReturn;
3264 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
3268 void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
3270 StringRef &Name, StringRef &LinkageName,
3271 llvm::MDTuple *&TemplateParameters,
3272 llvm::DIScope *&VDContext) {
3279 if (T->isIncompleteArrayType()) {
3282 QualType ET = CGM.getContext().getAsArrayType(T)->getElementType();
3284 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
3291 LinkageName = CGM.getMangledName(VD);
3292 if (LinkageName == Name)
3293 LinkageName = StringRef();
3295 if (isa<VarTemplateSpecializationDecl>(VD)) {
3296 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
3297 TemplateParameters = parameterNodes.get();
3299 TemplateParameters =
nullptr;
3317 DC = CGM.getContext().getTranslationUnitDecl();
3319 llvm::DIScope *Mod = getParentModuleOrNull(VD);
3320 VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
3323 llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(
GlobalDecl GD,
3325 llvm::DINodeArray TParamsArray;
3326 StringRef Name, LinkageName;
3327 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3328 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3330 llvm::DIFile *Unit = getOrCreateFile(Loc);
3331 llvm::DIScope *DContext = Unit;
3332 unsigned Line = getLineNumber(Loc);
3333 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
3335 auto *FD = cast<FunctionDecl>(GD.
getDecl());
3340 ArgTypes.push_back(Parm->getType());
3343 QualType FnType = CGM.getContext().getFunctionType(
3346 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3347 if (CGM.getLangOpts().Optimize)
3348 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3351 Flags |= getCallSiteRelatedAttrs();
3352 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
3353 return DBuilder.createFunction(
3354 DContext, Name, LinkageName, Unit, Line,
3355 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
3356 TParamsArray.get(), getFunctionDeclaration(FD));
3359 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
3360 DContext, Name, LinkageName, Unit, Line,
3361 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
3362 TParamsArray.get(), getFunctionDeclaration(FD));
3364 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
3365 std::make_tuple(CanonDecl),
3366 std::make_tuple(SP));
3370 llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(
GlobalDecl GD) {
3371 return getFunctionFwdDeclOrStub(GD,
false);
3374 llvm::DISubprogram *CGDebugInfo::getFunctionStub(
GlobalDecl GD) {
3375 return getFunctionFwdDeclOrStub(GD,
true);
3378 llvm::DIGlobalVariable *
3379 CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
3381 StringRef Name, LinkageName;
3383 llvm::DIFile *Unit = getOrCreateFile(Loc);
3384 llvm::DIScope *DContext = Unit;
3385 unsigned Line = getLineNumber(Loc);
3386 llvm::MDTuple *TemplateParameters =
nullptr;
3388 collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, TemplateParameters,
3391 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
3392 DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
3394 FwdDeclReplaceMap.emplace_back(
3395 std::piecewise_construct,
3397 std::make_tuple(static_cast<llvm::Metadata *>(GV)));
3401 llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
3406 if (
const auto *TD = dyn_cast<TypeDecl>(D))
3407 return getOrCreateType(CGM.getContext().getTypeDeclType(TD),
3411 if (I != DeclCache.end()) {
3413 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
3414 return GVE->getVariable();
3415 return dyn_cast_or_null<llvm::DINode>(N);
3420 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
3421 return getFunctionForwardDeclaration(FD);
3422 else if (
const auto *VD = dyn_cast<VarDecl>(D))
3423 return getGlobalVariableForwardDeclaration(VD);
3428 llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
3437 auto *S = getDeclContextDescriptor(D);
3440 if (MI == SPCache.end()) {
3442 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
3443 cast<llvm::DICompositeType>(S));
3446 if (MI != SPCache.end()) {
3447 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
3448 if (SP && !SP->isDefinition())
3452 for (
auto NextFD : FD->
redecls()) {
3453 auto MI = SPCache.find(NextFD->getCanonicalDecl());
3454 if (MI != SPCache.end()) {
3455 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
3456 if (SP && !SP->isDefinition())
3465 llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
3471 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
3473 if (
const auto *Method = dyn_cast<CXXMethodDecl>(D))
3474 return getOrCreateMethodType(Method, F);
3479 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
3484 QualType ResultTy = OMethod->getReturnType();
3487 if (ResultTy == CGM.getContext().getObjCInstanceType())
3488 ResultTy = CGM.getContext().getPointerType(
3489 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
3491 Elts.push_back(getOrCreateType(ResultTy, F));
3494 if (
auto *SelfDecl = OMethod->getSelfDecl())
3495 SelfDeclTy = SelfDecl->getType();
3496 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
3497 if (FPT->getNumParams() > 1)
3498 SelfDeclTy = FPT->getParamType(0);
3499 if (!SelfDeclTy.
isNull())
3501 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
3503 Elts.push_back(DBuilder.createArtificialType(
3504 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
3506 for (
const auto *PI : OMethod->parameters())
3507 Elts.push_back(getOrCreateType(PI->getType(), F));
3509 if (OMethod->isVariadic())
3510 Elts.push_back(DBuilder.createUnspecifiedParameter());
3512 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
3513 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
3519 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
3523 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
3524 for (
QualType ParamType : FPT->param_types())
3525 EltTys.push_back(getOrCreateType(ParamType, F));
3526 EltTys.push_back(DBuilder.createUnspecifiedParameter());
3527 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
3528 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
3532 return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
3537 llvm::Function *Fn,
bool CurFuncIsThunk,
3541 StringRef LinkageName;
3543 FnBeginRegionCount.push_back(LexicalBlockStack.size());
3546 bool HasDecl = (D !=
nullptr);
3548 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3549 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3550 llvm::DIFile *Unit = getOrCreateFile(Loc);
3551 llvm::DIScope *FDContext = Unit;
3552 llvm::DINodeArray TParamsArray;
3555 LinkageName = Fn->getName();
3556 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3559 if (FI != SPCache.end()) {
3560 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
3561 if (SP && SP->isDefinition()) {
3562 LexicalBlockStack.emplace_back(SP);
3563 RegionMap[D].reset(SP);
3567 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
3568 TParamsArray, Flags);
3569 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
3570 Name = getObjCMethodName(OMD);
3571 Flags |= llvm::DINode::FlagPrototyped;
3572 }
else if (isa<VarDecl>(D) &&
3579 Name = Fn->getName();
3580 Flags |= llvm::DINode::FlagPrototyped;
3582 if (Name.startswith(
"\01"))
3583 Name = Name.substr(1);
3586 Flags |= llvm::DINode::FlagArtificial;
3592 Flags |= llvm::DINode::FlagThunk;
3594 if (Fn->hasLocalLinkage())
3595 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3596 if (CGM.getLangOpts().Optimize)
3597 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3599 llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
3600 llvm::DISubprogram::DISPFlags SPFlagsForDef =
3601 SPFlags | llvm::DISubprogram::SPFlagDefinition;
3603 unsigned LineNo = getLineNumber(Loc);
3604 unsigned ScopeLine = getLineNumber(ScopeLoc);
3611 llvm::DISubprogram *SP = DBuilder.createFunction(
3612 FDContext, Name, LinkageName, Unit, LineNo,
3613 getOrCreateFunctionType(D, FnType, Unit), ScopeLine, FlagsForDef,
3614 SPFlagsForDef, TParamsArray.get(), getFunctionDeclaration(D));
3615 Fn->setSubprogram(SP);
3619 if (HasDecl && isa<FunctionDecl>(D))
3626 if (CGM.getCodeGenOpts().EnableDebugEntryValues && HasDecl)
3627 if (
auto *FD = dyn_cast<FunctionDecl>(D))
3629 SPDefCache[FD].reset(SP);
3631 if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
3634 if (
const auto *OMD = dyn_cast_or_null<ObjCMethodDecl>(D)) {
3637 auto It = TypeCache.find(QTy.getAsOpaquePtr());
3638 if (It != TypeCache.end()) {
3639 llvm::DICompositeType *InterfaceDecl =
3640 cast<llvm::DICompositeType>(It->second);
3641 llvm::DISubprogram *FD = DBuilder.createFunction(
3642 InterfaceDecl, Name, LinkageName, Unit, LineNo,
3643 getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
3644 TParamsArray.get());
3645 DBuilder.finalizeSubprogram(FD);
3646 ObjCMethodCache[
ID].push_back(FD);
3652 LexicalBlockStack.emplace_back(SP);
3655 RegionMap[D].reset(SP);
3659 QualType FnType, llvm::Function *Fn) {
3661 StringRef LinkageName;
3667 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3668 llvm::DIFile *Unit = getOrCreateFile(Loc);
3669 bool IsDeclForCallSite = Fn ?
true :
false;
3670 llvm::DIScope *FDContext =
3671 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
3672 llvm::DINodeArray TParamsArray;
3673 if (isa<FunctionDecl>(D)) {
3675 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
3676 TParamsArray, Flags);
3677 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
3678 Name = getObjCMethodName(OMD);
3679 Flags |= llvm::DINode::FlagPrototyped;
3681 llvm_unreachable(
"not a function or ObjC method");
3683 if (!Name.empty() && Name[0] ==
'\01')
3684 Name = Name.substr(1);
3687 Flags |= llvm::DINode::FlagArtificial;
3692 unsigned LineNo = getLineNumber(Loc);
3693 unsigned ScopeLine = 0;
3694 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3695 if (CGM.getLangOpts().Optimize)
3696 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3698 llvm::DISubprogram *SP = DBuilder.createFunction(
3699 FDContext, Name, LinkageName, Unit, LineNo,
3700 getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
3701 TParamsArray.get(), getFunctionDeclaration(D));
3703 if (IsDeclForCallSite)
3704 Fn->setSubprogram(SP);
3706 DBuilder.retainType(SP);
3712 auto &CGOpts = CGM.getCodeGenOpts();
3713 if (!CGOpts.EnableDebugEntryValues || !CGM.getLangOpts().Optimize ||
3717 auto *Func = CallOrInvoke->getCalledFunction();
3724 if (Func->getSubprogram())
3728 EmitFunctionDecl(CalleeDecl, CalleeDecl->
getLocation(), CalleeType, Func);
3732 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
3735 llvm::DISubprogram *SP =
nullptr;
3736 if (FI != SPCache.end())
3737 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
3738 if (!SP || !SP->isDefinition())
3739 SP = getFunctionStub(GD);
3740 FnBeginRegionCount.push_back(LexicalBlockStack.size());
3741 LexicalBlockStack.emplace_back(SP);
3742 setInlinedAt(Builder.getCurrentDebugLocation());
3747 assert(CurInlinedAt &&
"unbalanced inline scope stack");
3748 EmitFunctionEnd(Builder,
nullptr);
3749 setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
3756 if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
3759 llvm::MDNode *
Scope = LexicalBlockStack.back();
3760 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
3761 getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt));
3765 llvm::MDNode *Back =
nullptr;
3766 if (!LexicalBlockStack.empty())
3767 Back = LexicalBlockStack.back().get();
3768 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
3769 cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
3770 getColumnNumber(CurLoc)));
3773 void CGDebugInfo::AppendAddressSpaceXDeref(
3776 CGM.getTarget().getDWARFAddressSpace(AddressSpace);
3777 if (!DWARFAddressSpace)
3780 Expr.push_back(llvm::dwarf::DW_OP_constu);
3781 Expr.push_back(DWARFAddressSpace.getValue());
3782 Expr.push_back(llvm::dwarf::DW_OP_swap);
3783 Expr.push_back(llvm::dwarf::DW_OP_xderef);
3792 Builder.SetCurrentDebugLocation(
3793 llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc),
3794 LexicalBlockStack.back(), CurInlinedAt));
3800 CreateLexicalBlock(Loc);
3805 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3813 LexicalBlockStack.pop_back();
3817 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3818 unsigned RCount = FnBeginRegionCount.back();
3819 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
3822 while (LexicalBlockStack.size() != RCount) {
3825 LexicalBlockStack.pop_back();
3827 FnBeginRegionCount.pop_back();
3829 if (Fn && Fn->getSubprogram())
3830 DBuilder.finalizeSubprogram(Fn->getSubprogram());
3833 CGDebugInfo::BlockByRefType
3834 CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
3835 uint64_t *XOffset) {
3838 uint64_t FieldSize, FieldOffset;
3839 uint32_t FieldAlign;
3841 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
3845 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3846 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
3847 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
3848 FType = CGM.getContext().IntTy;
3849 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
3850 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
3852 bool HasCopyAndDispose = CGM.getContext().BlockRequiresCopying(Type, VD);
3853 if (HasCopyAndDispose) {
3854 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3856 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
3858 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
3860 bool HasByrefExtendedLayout;
3862 if (CGM.getContext().getByrefLifetime(Type, Lifetime,
3863 HasByrefExtendedLayout) &&
3864 HasByrefExtendedLayout) {
3865 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3867 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
3870 CharUnits Align = CGM.getContext().getDeclAlign(VD);
3871 if (Align > CGM.getContext().toCharUnitsFromBits(
3872 CGM.getTarget().getPointerAlign(0))) {
3874 CGM.getContext().toCharUnitsFromBits(FieldOffset);
3876 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
3880 FType = CGM.getContext().getConstantArrayType(
3882 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
3887 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
3888 FieldSize = CGM.getContext().getTypeSize(FType);
3889 FieldAlign = CGM.getContext().toBits(Align);
3891 *XOffset = FieldOffset;
3892 llvm::DIType *FieldTy = DBuilder.createMemberType(
3893 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
3894 llvm::DINode::FlagZero, WrappedTy);
3895 EltTys.push_back(FieldTy);
3896 FieldOffset += FieldSize;
3898 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3899 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
3900 llvm::DINode::FlagZero,
nullptr, Elements),
3904 llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
3908 const bool UsePointerValue) {
3910 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3911 if (VD->
hasAttr<NoDebugAttr>())
3917 llvm::DIFile *Unit =
nullptr;
3921 uint64_t XOffset = 0;
3922 if (VD->
hasAttr<BlocksAttr>())
3923 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
3925 Ty = getOrCreateType(VD->
getType(), Unit);
3934 unsigned Column = 0;
3940 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3942 Flags |= llvm::DINode::FlagArtificial;
3946 unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(VD->
getType());
3947 AppendAddressSpaceXDeref(AddressSpace, Expr);
3951 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
3954 Flags |= llvm::DINode::FlagObjectPointer;
3961 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
3962 StringRef Name = VD->
getName();
3963 if (!Name.empty()) {
3964 if (VD->
hasAttr<BlocksAttr>()) {
3967 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
3969 offset = CGM.getContext().toCharUnitsFromBits(
3970 CGM.getTarget().getPointerWidth(0));
3972 Expr.push_back(llvm::dwarf::DW_OP_deref);
3973 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
3975 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
3978 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
3990 for (
const auto *Field : RD->
fields()) {
3991 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
3992 StringRef FieldName = Field->getName();
3995 if (FieldName.empty() && !isa<RecordType>(Field->getType()))
4000 auto *D = DBuilder.createAutoVariable(
4001 Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
4002 Flags | llvm::DINode::FlagArtificial, FieldAlign);
4005 DBuilder.insertDeclare(
4006 Storage, D, DBuilder.createExpression(Expr),
4007 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4008 Builder.GetInsertBlock());
4016 if (UsePointerValue) {
4017 assert(std::find(Expr.begin(), Expr.end(), llvm::dwarf::DW_OP_deref) ==
4019 "Debug info already contains DW_OP_deref.");
4020 Expr.push_back(llvm::dwarf::DW_OP_deref);
4024 auto *D = ArgNo ? DBuilder.createParameterVariable(
4025 Scope, Name, *ArgNo, Unit, Line, Ty,
4026 CGM.getLangOpts().Optimize, Flags)
4027 : DBuilder.createAutoVariable(
Scope, Name, Unit, Line, Ty,
4028 CGM.getLangOpts().Optimize,
4032 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
4033 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4034 Builder.GetInsertBlock());
4036 if (CGM.getCodeGenOpts().EnableDebugEntryValues && ArgNo) {
4037 if (
auto *PD = dyn_cast<ParmVarDecl>(VD))
4038 ParamCache[PD].reset(D);
4044 llvm::DILocalVariable *
4047 const bool UsePointerValue) {
4049 return EmitDeclare(VD, Storage,
llvm::None, Builder, UsePointerValue);
4054 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4056 if (D->
hasAttr<NoDebugAttr>())
4059 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
4060 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
4064 unsigned Column = getColumnNumber(D->
getLocation());
4066 StringRef Name = D->
getName();
4070 DBuilder.createLabel(
Scope, Name, Unit, Line, CGM.getLangOpts().Optimize);
4073 DBuilder.insertLabel(L,
4074 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4075 Builder.GetInsertBlock());
4078 llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
4080 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
4083 return DBuilder.createObjectPointerType(Ty);
4088 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
4090 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4092 if (Builder.GetInsertBlock() ==
nullptr)
4094 if (VD->
hasAttr<NoDebugAttr>())
4097 bool isByRef = VD->
hasAttr<BlocksAttr>();
4099 uint64_t XOffset = 0;
4100 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
4103 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
4105 Ty = getOrCreateType(VD->
getType(), Unit);
4109 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
4111 Ty = CreateSelfType(VD->
getType(), Ty);
4115 unsigned Column = getColumnNumber(VD->
getLocation());
4117 const llvm::DataLayout &target = CGM.getDataLayout();
4124 addr.push_back(llvm::dwarf::DW_OP_deref);
4125 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4128 addr.push_back(llvm::dwarf::DW_OP_deref);
4129 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4132 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
4134 addr.push_back(llvm::dwarf::DW_OP_deref);
4135 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4137 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
4143 auto *D = DBuilder.createAutoVariable(
4144 cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->
getName(), Unit,
4145 Line, Ty,
false, llvm::DINode::FlagZero, Align);
4149 llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt);
4150 auto *Expr = DBuilder.createExpression(addr);
4152 DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
4154 DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
4161 EmitDeclare(VD, AI, ArgNo, Builder);
4165 struct BlockLayoutChunk {
4166 uint64_t OffsetInBits;
4169 bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
4170 return l.OffsetInBits < r.OffsetInBits;
4174 void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
4176 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
4181 if (CGM.getLangOpts().OpenCL) {
4182 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
4183 BlockLayout.getElementOffsetInBits(0),
4185 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
4186 BlockLayout.getElementOffsetInBits(1),
4190 BlockLayout.getElementOffsetInBits(0),
4192 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
4193 BlockLayout.getElementOffsetInBits(1),
4197 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
4199 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
4200 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
4201 BlockLayout.getElementOffsetInBits(3),
4203 Fields.push_back(createFieldType(
4208 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
4215 llvm::AllocaInst *Alloca,
4223 llvm::DIFile *tunit = getOrCreateFile(loc);
4224 unsigned line = getLineNumber(loc);
4225 unsigned column = getColumnNumber(loc);
4228 getDeclContextDescriptor(blockDecl);
4230 const llvm::StructLayout *blockLayout =
4234 collectDefaultFieldsForBlockLiteralDeclare(block, C, loc, *blockLayout, tunit,
4243 BlockLayoutChunk chunk;
4244 chunk.OffsetInBits =
4245 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
4246 chunk.Capture =
nullptr;
4247 chunks.push_back(chunk);
4251 for (
const auto &capture : blockDecl->
captures()) {
4252 const VarDecl *variable = capture.getVariable();
4259 BlockLayoutChunk chunk;
4260 chunk.OffsetInBits =
4261 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
4262 chunk.Capture = &capture;
4263 chunks.push_back(chunk);
4267 llvm::array_pod_sort(chunks.begin(), chunks.end());
4269 for (
const BlockLayoutChunk &Chunk : chunks) {
4270 uint64_t offsetInBits = Chunk.OffsetInBits;
4279 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->
getParent()))
4280 type =
QualType(RDecl->getTypeForDecl(), 0);
4282 llvm_unreachable(
"unexpected block declcontext");
4284 fields.push_back(createFieldType(
"this", type, loc,
AS_public,
4285 offsetInBits, tunit, tunit));
4292 llvm::DIType *fieldType;
4299 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
4300 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
4301 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
4302 PtrInfo.
Width, Align, offsetInBits,
4303 llvm::DINode::FlagZero, fieldType);
4307 offsetInBits, Align, tunit, tunit);
4309 fields.push_back(fieldType);
4313 llvm::raw_svector_ostream(typeName)
4314 <<
"__block_literal_" << CGM.getUniqueBlockCount();
4316 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
4318 llvm::DIType *type =
4319 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
4320 CGM.getContext().toBits(block.
BlockSize), 0,
4321 llvm::DINode::FlagZero,
nullptr, fieldsArray);
4322 type = DBuilder.createPointerType(type, CGM.PointerWidthInBits);
4325 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
4326 auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
4329 auto *debugVar = DBuilder.createParameterVariable(
4330 scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags);
4333 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
4334 llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
4335 Builder.GetInsertBlock());
4338 llvm::DIDerivedType *
4339 CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
4344 if (MI != StaticDataMemberCache.end()) {
4345 assert(MI->second &&
"Static data member declaration should still exist");
4352 auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D));
4353 return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC));
4356 llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
4357 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
4358 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
4359 llvm::DIGlobalVariableExpression *GVE =
nullptr;
4361 for (
const auto *Field : RD->
fields()) {
4362 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
4363 StringRef FieldName = Field->getName();
4366 if (FieldName.empty()) {
4367 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
4368 GVE = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
4373 GVE = DBuilder.createGlobalVariableExpression(
4374 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
4375 Var->hasLocalLinkage());
4376 Var->addDebugInfo(GVE);
4384 if (D->
hasAttr<NoDebugAttr>())
4390 if (Cached != DeclCache.end())
4391 return Var->addDebugInfo(
4392 cast<llvm::DIGlobalVariableExpression>(Cached->second));
4395 llvm::DIFile *Unit =
nullptr;
4396 llvm::DIScope *DContext =
nullptr;
4398 StringRef DeclName, LinkageName;
4400 llvm::MDTuple *TemplateParameters =
nullptr;
4401 collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName,
4402 TemplateParameters, DContext);
4406 llvm::DIGlobalVariableExpression *GVE =
nullptr;
4414 "unnamed non-anonymous struct or union?");
4415 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
4420 unsigned AddressSpace =
4421 CGM.getContext().getTargetAddressSpace(D->
getType());
4422 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
4423 if (D->
hasAttr<CUDASharedAttr>())
4426 else if (D->
hasAttr<CUDAConstantAttr>())
4430 AppendAddressSpaceXDeref(AddressSpace, Expr);
4432 GVE = DBuilder.createGlobalVariableExpression(
4433 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
4434 Var->hasLocalLinkage(),
4435 Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
4436 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
4438 Var->addDebugInfo(GVE);
4445 if (VD->
hasAttr<NoDebugAttr>())
4449 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
4450 StringRef Name = VD->
getName();
4451 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
4453 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
4454 const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
4455 assert(isa<EnumType>(ED->getTypeForDecl()) &&
"Enum without EnumType?");
4457 if (CGM.getCodeGenOpts().EmitCodeView) {
4462 if (isa<RecordDecl>(ED->getDeclContext()))
4468 llvm::DIType *EDTy =
4469 getOrCreateType(
QualType(ED->getTypeForDecl(), 0), Unit);
4470 assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
4476 llvm::DIScope *DContext =
nullptr;
4484 auto *VarD = dyn_cast<
VarDecl>(VD);
4485 if (VarD && VarD->isStaticDataMember()) {
4486 auto *RD = cast<RecordDecl>(VarD->getDeclContext());
4487 getDeclContextDescriptor(VarD);
4492 RetainedTypes.push_back(
4493 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
4495 if (!CGM.getCodeGenOpts().EmitCodeView)
4499 DContext = getContextDescriptor(
4500 cast<Decl>(CGM.getContext().getTranslationUnitDecl()), TheCU);
4502 DContext = getDeclContextDescriptor(VD);
4505 auto &GV = DeclCache[VD];
4508 llvm::DIExpression *InitExpr =
nullptr;
4509 if (CGM.getContext().getTypeSize(VD->
getType()) <= 64) {
4513 DBuilder.createConstantValueExpression(Init.
getInt().getExtValue());
4515 InitExpr = DBuilder.createConstantValueExpression(
4516 Init.
getFloat().bitcastToAPInt().getZExtValue());
4519 llvm::MDTuple *TemplateParameters =
nullptr;
4521 if (isa<VarTemplateSpecializationDecl>(VD))
4523 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
4524 TemplateParameters = parameterNodes.get();
4527 GV.reset(DBuilder.createGlobalVariableExpression(
4528 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
4529 true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
4530 TemplateParameters, Align));
4533 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
4534 if (!LexicalBlockStack.empty())
4535 return LexicalBlockStack.back();
4536 llvm::DIScope *Mod = getParentModuleOrNull(D);
4537 return getContextDescriptor(D, Mod ? Mod : TheCU);
4545 CGM.getCodeGenOpts().DebugExplicitImport) {
4547 DBuilder.createImportedModule(
4549 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
4557 "We shouldn't be codegening an invalid UsingDecl containing no decls");
4566 if (
const auto *FD = dyn_cast<FunctionDecl>(USD.getUnderlyingDecl()))
4567 if (
const auto *AT =
4569 if (AT->getDeducedType().isNull())
4571 if (llvm::DINode *
Target =
4572 getDeclarationOrDefinition(USD.getUnderlyingDecl())) {
4573 auto Loc = USD.getLocation();
4574 DBuilder.createImportedDeclaration(
4575 getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())),
Target,
4576 getOrCreateFile(Loc), getLineNumber(Loc));
4581 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
4586 DBuilder.createImportedDeclaration(
4588 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
4589 getLineNumber(Loc));
4593 llvm::DIImportedEntity *
4597 auto &VH = NamespaceAliasCache[&NA];
4599 return cast<llvm::DIImportedEntity>(VH);
4600 llvm::DIImportedEntity *R;
4602 if (
const auto *Underlying =
4605 R = DBuilder.createImportedDeclaration(
4607 EmitNamespaceAlias(*Underlying), getOrCreateFile(Loc),
4608 getLineNumber(Loc), NA.
getName());
4610 R = DBuilder.createImportedDeclaration(
4613 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
4619 CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
4623 auto I = NamespaceCache.find(NSDecl);
4624 if (I != NamespaceCache.end())
4625 return cast<llvm::DINamespace>(I->second);
4627 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
4629 llvm::DINamespace *NS =
4630 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
4631 NamespaceCache[NSDecl].reset(NS);
4636 assert(TheCU &&
"no main compile unit");
4637 TheCU->setDWOId(Signature);
4644 llvm::DenseMap<const FunctionDecl *, llvm::TrackingMDRef> &SPDefCache,
4645 llvm::DenseMap<const ParmVarDecl *, llvm::TrackingMDRef> &ParamCache) {
4646 for (
auto &SP : SPDefCache) {
4647 auto *FD = SP.first;
4648 assert(FD->
hasBody() &&
"Functions must have body here");
4649 const Stmt *FuncBody = (*FD).getBody();
4655 auto I = ParamCache.find(Parm);
4656 assert(I != ParamCache.end() &&
"Parameters should be already cached");
4657 auto *DIParm = cast<llvm::DILocalVariable>(I->second);
4658 DIParm->setIsNotModified();
4666 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
4667 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
4668 llvm::DIType *Ty = E.
Type->getDecl()->getDefinition()
4669 ? CreateTypeDefinition(E.Type, E.Unit)
4671 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
4674 if (CGM.getCodeGenOpts().DwarfVersion >= 5) {
4676 for (
const auto &
P : ObjCMethodCache) {
4677 if (
P.second.empty())
4680 QualType QTy(
P.first->getTypeForDecl(), 0);
4681 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4682 assert(It != TypeCache.end());
4684 llvm::DICompositeType *InterfaceDecl =
4685 cast<llvm::DICompositeType>(It->second);
4688 auto CurrenetElts = InterfaceDecl->getElements();
4689 EltTys.append(CurrenetElts.begin(), CurrenetElts.end());
4690 for (
auto &MD :
P.second)
4691 EltTys.push_back(MD);
4692 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
4693 DBuilder.replaceArrays(InterfaceDecl, Elements);
4697 for (
const auto &
P : ReplaceMap) {
4699 auto *Ty = cast<llvm::DIType>(
P.second);
4700 assert(Ty->isForwardDecl());
4702 auto It = TypeCache.find(
P.first);
4703 assert(It != TypeCache.end());
4706 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
4707 cast<llvm::DIType>(It->second));
4710 for (
const auto &
P : FwdDeclReplaceMap) {
4712 llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(
P.second));
4713 llvm::Metadata *Repl;
4715 auto It = DeclCache.find(
P.first);
4719 if (It == DeclCache.end())
4724 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
4725 Repl = GVE->getVariable();
4726 DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
4731 for (
auto &RT : RetainedTypes)
4732 if (
auto MD = TypeCache[RT])
4733 DBuilder.retainType(cast<llvm::DIType>(MD));
4735 if (CGM.getCodeGenOpts().EnableDebugEntryValues)
4739 DBuilder.finalize();
4746 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
4748 DBuilder.retainType(DieTy);
4752 if (LexicalBlockStack.empty())
4753 return llvm::DebugLoc();
4755 llvm::MDNode *
Scope = LexicalBlockStack.back();
4756 return llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc), Scope);
4759 llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs()
const {
4764 return llvm::DINode::FlagZero;
4769 bool SupportsDWARFv4Ext =
4770 CGM.getCodeGenOpts().DwarfVersion == 4 &&
4771 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
4772 (CGM.getCodeGenOpts().EnableDebugEntryValues &&
4773 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB));
4775 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
4776 return llvm::DINode::FlagZero;
4778 return llvm::DINode::FlagAllCallsDescribed;
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
Defines the clang::ASTContext interface.
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
const Type * getTypeForDecl() const
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
const Capture & getCapture(const VarDecl *var) const
Represents a function declaration or definition.
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
std::string Name
The name of this module.
External linkage, which indicates that the entity can be referred to from other translation units...
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Setter)
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
Smart pointer class that efficiently represents Objective-C method names.
A class which contains all the information about a particular captured value.
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
StringRef getName(const PrintingPolicy &Policy) const
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getElementType() const
QualType getPointeeType() const
void EmitLocation(raw_ostream &o, const SourceManager &SM, SourceLocation L, const FIDMap &FM, unsigned indent)
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not...
static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx)
A (possibly-)qualified type.
const CodeGenOptions & getCodeGenOpts() const
ObjCInterfaceDecl * getClassInterface()
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Defines the clang::FileManager interface and associated types.
bool isMemberDataPointerType() const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder)
Emit call to llvm.dbg.label for an label.
TypePropertyCache< Private > Cache
Stmt - This represents one statement.
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
FunctionType - C99 6.7.5.3 - Function Declarators.
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the end of a new lexical block and pop the current block.
QualType getPointeeType() const
If this is a pointer, ObjC object pointer, or block pointer, this returns the respective pointee...
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
Defines the SourceManager interface.
QualType getThisType() const
Return the type of the this pointer.
static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
The template argument is an expression, and we've not resolved it to one of the other forms yet...
bool isRecordType() const
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
const Type * getTypeForDecl() const
Decl - This represents one declaration (or definition), e.g.
TagDecl * getDecl() const
ArrayRef< NamedDecl * > asArray()
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
Defines the C++ template declaration subclasses.
Parameter for C++ 'this' argument.
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C)
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Getter)
The base class of the type hierarchy.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
Declaration of a variable template.
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
Represent a C++ namespace.
NamedDecl * getParam(unsigned Idx)
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
RefQualifierKind RefQualifier
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
static bool needsTypeIdentifier(const TagDecl *TD, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
Describes the capture of a variable or of this, or of a C++1y init-capture.
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
MSInheritanceAttr::Spelling getMSInheritanceModel() const
Returns the inheritance model used for this record.
QualType getElementType() const
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
enumerator_range enumerators() const
Represents a variable declaration or definition.
void removeObjCLifetime()
QualType getReturnType() const
const T * getAs() const
Member-template getAs<specific type>'.
Analyzes whether any mutative operations are applied to an expression within a given statement...
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, QualType CalleeType, const FunctionDecl *CalleeDecl)
Emit debug info for an extern function being called.
A this pointer adjustment.
Represents a variable template specialization, which refers to a variable template with a given set o...
ObjCMethodDecl - Represents an instance or class method declaration.
Stores a list of template parameters for a TemplateDecl and its derived classes.
Describes how types, statements, expressions, and declarations should be printed. ...
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
bool hasDefinition() const
static const NamedDecl * getDefinition(const Decl *D)
Represents a parameter to a function.
QualType getIntegralType() const
Retrieve the type of the integral value.
static llvm::dwarf::Tag getTagForRecord(const RecordDecl *RD)
The collection of all-type qualifiers we support.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
void EmitInlineFunctionEnd(CGBuilderTy &Builder)
End an inlined function scope.
Represents a struct/union/class.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
std::map< std::string, std::string > DebugPrefixMap
void print(raw_ostream &OS, const PrintingPolicy &Policy, bool SuppressNNS=false) const
Print the template name.
void addHeapAllocSiteMetadata(llvm::Instruction *CallSite, QualType Ty, SourceLocation Loc)
Add heapallocsite metadata for MSAllocator calls.
Represents a class type in Objective C.
QualType getPointeeType() const
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
Expr * getAsExpr() const
Retrieve the template argument as an expression.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool isInline() const
Returns true if this is an inline namespace declaration.
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
static bool isFunctionLocalClass(const CXXRecordDecl *RD)
isFunctionLocalClass - Return true if CXXRecordDecl is defined inside a function. ...
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
void EmitImportDecl(const ImportDecl &ID)
Emit an declaration.
field_range fields() const
Represents a member of a struct/union/class.
StringRef getPath() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
prop_range properties() const
void completeClassData(const RecordDecl *RD)
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
llvm::DIMacro * CreateMacro(llvm::DIMacroFile *Parent, unsigned MType, SourceLocation LineLoc, StringRef Name, StringRef Value)
Create debug info for a macro defined by a #define directive or a macro undefined by a #undef directi...
method_iterator method_begin() const
Method begin iterator.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Describes a module or submodule.
QualType getParamTypeForDecl() const
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
ArrayRef< ParmVarDecl * > parameters() const
Provides information about a function template specialization, which is a FunctionDecl that has been ...
Represents a C++ using-declaration.
Type(TypeClass tc, QualType canon, bool Dependent, bool InstantiationDependent, bool VariablyModified, bool ContainsUnexpandedParameterPack)
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
ArrayRef< VTableComponent > vtable_components() const
unsigned Size
The total size of the bit-field, in bits.
An rvalue reference type, per C++11 [dcl.ref].
bool isBitField() const
Determines whether this field is a bitfield.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
An lvalue ref-qualifier was provided (&).
~ApplyInlineDebugLocation()
Restore everything back to the original state.
CharUnits - This is an opaque type for sizes expressed in character units.
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
APValue Val
Val - This is the value the expression can be folded to.
const BlockDecl * getBlockDecl() const
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
Emit location information but do not generate debug info in the output.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Represents a declaration of a type.
static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU)
Module * Parent
The parent of this module.
const Type * getClass() const
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
bool isLambda() const
Determine whether this class describes a lambda function object.
Scope - A scope is a transient data structure that is used while parsing the program.
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
field_iterator field_begin() const
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
static uint32_t getDeclAlignIfRequired(const Decl *D, const ASTContext &Ctx)
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn)
Constructs the debug code for exiting a function.
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
void * getAsOpaquePtr() const
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
Represents an ObjC class declaration.
shadow_iterator shadow_begin() const
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
unsigned PrintCanonicalTypes
Whether to print types as written or canonically.
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
const Module * getModuleOrNull() const
bool NeedsCopyDispose
True if the block has captures that would necessitate custom copy or dispose helper functions if the ...
unsigned getIndex() const
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
static unsigned getDwarfCC(CallingConv CC)
QualType getBaseType() const
Gets the base type of this object type.
Represents a prototype with parameter type info, e.g.
bool isDynamicClass() const
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
ASTFileSignature getSignature() const
CGBlockInfo - Information to generate a block literal.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
Represents a ValueDecl that came out of a declarator.
std::string getModuleName() const
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
ObjCTypeParamDecl * getDecl() const
void setDwoId(uint64_t Signature)
Module debugging: Support for building PCMs.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
capture_const_iterator captures_end() const
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file. ...
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn)
Set up the CodeGenFunction's DebugInfo to produce inline locations for the function InlinedFn...
Represents a block literal declaration, which is like an unnamed FunctionDecl.
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
This represents one expression.
QualType getPointeeType() const
known_extensions_range known_extensions() const
Emit only debug info necessary for generating line number tables (-gline-tables-only).
bool isPositive() const
isPositive - Test whether the quantity is greater than zero.
bool isVariadic() const
Whether this function is variadic.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
static void analyzeParametersModification(ASTContext &Ctx, llvm::DenseMap< const FunctionDecl *, llvm::TrackingMDRef > &SPDefCache, llvm::DenseMap< const ParmVarDecl *, llvm::TrackingMDRef > &ParamCache)
Analyzes each function parameter to determine whether it is constant throughout the function body...
void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD)
Start a new scope for an inlined function.
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
const AnnotatedLine * Line
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to...
const T * castAs() const
Member-template castAs<specific type>.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
unsigned getLine() const
Return the presumed line number of this location.
Represents a C++ destructor within a class.
Defines version macros and version-related utility functions for Clang.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
llvm::DIMacroFile * CreateTempMacroFile(llvm::DIMacroFile *Parent, SourceLocation LineLoc, SourceLocation FileLoc)
Create debug info for a file referenced by an #include directive.
field_iterator field_end() const
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
DeclContext * getDeclContext()
ObjCInterfaceDecl * getSuperClass() const
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
void completeUnusedClass(const CXXRecordDecl &D)
EnumDecl * getDefinition() const
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
bool isSignedIntegerType() const
Return true if this is an integer type that is signed, according to C99 6.2.5p4 [char, signed char, short, int, long..], or an enum decl which has a signed representation.
bool hasBody(const FunctionDecl *&Definition) const
Returns true if the function has a body.
clang::ObjCRuntime ObjCRuntime
bool hasExtendableVFPtr() const
hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl, 0 if there are none.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
method_iterator method_end() const
Method past-the-end iterator.
Represents an unpacked "presumed" location which can be presented to the user.
bool isInstanceMethod() const
QualType getBlockDescriptorType() const
Gets the struct used to keep track of the descriptor for pointer to blocks.
Represents a GCC generic vector type.
SourceLocation getCaretLocation() const
An lvalue reference type, per C++11 [dcl.ref].
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
Selector getSelector() const
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
ImplicitParamDecl * getSelfDecl() const
CallingConv
CallingConv - Specifies the calling convention that a function uses.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
GlobalDecl - represents a global declaration.
DynamicInitKind getDynamicInitKind() const
bool isVoidPointerType() const
bool isObjCOneArgSelector() const
The l-value was considered opaque, so the alignment was determined from a type.
RecordDecl * getDecl() const
const char * getFilename() const
Return the presumed filename of this location.
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an argument variable declaration.
bool capturesVariable() const
Determine whether this capture handles a variable.
Pass it as a pointer to temporary memory.
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
virtual void printName(raw_ostream &os) const
unsigned size_overridden_methods() const
StringRef getASTFile() const
static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access, const RecordDecl *RD)
Convert an AccessSpecifier into the corresponding DINode flag.
std::string getAsString() const
Derive the full selector name (e.g.
virtual void mangleCXXRTTIName(QualType T, raw_ostream &)=0
ExtProtoInfo getExtProtoInfo() const
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
unsigned getColumn() const
Return the presumed column number of this location.
Encodes a location in the source.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
QualType getReturnType() const
bool isPure() const
Whether this virtual function is pure, i.e.
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
Interfaces are the core concept in Objective-C for object oriented design.
llvm::StructType * StructureType
void completeRequiredType(const RecordDecl *RD)
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
Limit generated debug info to reduce size (-fno-standalone-debug).
Represents the declaration of a struct/union/class/enum.
ASTContext & getASTContext() const LLVM_READONLY
QualType getElementType() const
const Decl * getDecl() const
static QualType getUnderlyingType(const SubRegion *R)
Represents the declaration of a label.
Cached information about one file (either on disk or in the virtual file system). ...
Represents a static or instance method of a struct/union/class.
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
ObjCCategoryDecl - Represents a category declaration.
unsigned RemapFilePaths
Whether to apply -fdebug-prefix-map to any file paths.
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded...
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType, llvm::Function *Fn=nullptr)
Emit debug info for a function declaration.
Represents one property declaration in an Objective-C interface.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
llvm::DILocalVariable * EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder, const bool UsePointerValue=false)
Emit call to llvm.dbg.declare for an automatic variable declaration.
const BlockExpr * getBlockExpr() const
TypeClass getTypeClass() const
MangleContext & getMangleContext()
Gets the mangle context.
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
constexpr XRayInstrMask None
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
VarDecl * getVariable() const
The variable being captured.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
EnumDecl * getDecl() const
unsigned CXXThisIndex
The field index of 'this' within the block, if there is one.
An rvalue ref-qualifier was provided (&&).
ObjCImplementationDecl * getImplementation() const
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, CXXRecordDecl::method_iterator End)
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc)
Describes a module import declaration, which makes the contents of the named module visible in the cu...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
StringRef getName() const
Return the actual identifier string.
Base class for declarations which introduce a typedef-name.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
Represents a template argument.
const llvm::MemoryBuffer * getBuffer(FileID FID, SourceLocation Loc, bool *Invalid=nullptr) const
Return the buffer for the specified FileID.
void completeClass(const RecordDecl *RD)
This class organizes the cross-function state that is used while generating LLVM code.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Dataflow Directional Tag Classes.
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
bool isValid() const
Return true if this is a valid SourceLocation object.
A qualifier set is used to build a set of qualifiers.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
EvalResult is a struct with detailed info about an evaluated expression.
uint64_t Index
Method's index in the vftable.
ArrayRef< Capture > captures() const
static SmallString< 256 > getTypeIdentifier(const TagType *Ty, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
The template argument is a pack expansion of a template name that was provided for a template templat...
Parameter for Objective-C 'self' argument.
QualType getUnderlyingType() const
llvm::iterator_range< base_class_const_iterator > base_class_const_range
const Expr * getInit() const
AccessSpecifier getAccess() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
FileID getMainFileID() const
Returns the FileID of the main source file.
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
Emit only debug directives with the line numbers data.
This template specialization was instantiated from a template due to an explicit instantiation declar...
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined...
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
CGDebugInfo(CodeGenModule &CGM)
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
A pointer to member type per C++ 8.3.3 - Pointers to members.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
Represents a pointer to an Objective C object.
bool isMutated(const Expr *Exp)
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class...
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
bool isIncompleteArrayType() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
Don't generate debug info.
void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, SourceLocation ScopeLoc, QualType FnType, llvm::Function *Fn, bool CurFnIsThunk, CGBuilderTy &Builder)
Emit a call to llvm.dbg.function.start to indicate start of a new function.
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
std::string remapDIPath(StringRef) const
Remap a given path with the current debug prefix map.
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
void completeType(const EnumDecl *ED)
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
The template argument is a type.
The template argument is actually a parameter pack.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool capturesCXXThis() const
std::function< std::string(StringRef)> remapPath
When RemapFilePaths is true, this function performs the action.
A template argument list.
TypedefNameDecl * getDecl() const
void EmitUsingDecl(const UsingDecl &UD)
Emit C++ using declaration.
void EmitUsingDirective(const UsingDirectiveDecl &UD)
Emit C++ using directive.
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the beginning of a new lexical block and push the block onto the stack...
ArgKind getKind() const
Return the kind of stored template argument.
Represents a type parameter type in Objective C.
CallingConv getCallConv() const
QualType getAliasedType() const
Get the aliased type, if this is a specialization of a type alias template.
TypedefNameDecl * getTypedefNameForAnonDecl() const
true
A convenience builder class for complex constant initializers, especially for anonymous global struct...
Represents a C++ struct/union/class.
ArrayRef< TemplateArgument > template_arguments() const
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
The template argument is a template name that was provided for a template template parameter...
ObjCIvarDecl - Represents an ObjC instance variable.
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder, const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint=nullptr)
Emit call to llvm.dbg.declare for an imported variable declaration in a block.
This class is used for builtin types like 'int'.
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, StringRef Name, unsigned ArgNo, llvm::AllocaInst *LocalAddr, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for the block-literal argument to a block invocation function...
SourceLocation getLocation() const
Retrieve the source location of the capture.
bool isComplexIntegerType() const
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
void setLocation(SourceLocation Loc)
Update the current source location.
CGCXXABI & getCXXABI() const
std::string getQualifiedNameAsString() const
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
unsigned getNumElements() const
QualType getAsType() const
Retrieve the type for a type template argument.
Represents a type template specialization; the template must be a class template, a type alias templa...
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD)
Return true if the class or any of its methods are marked dllimport.
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
capture_const_iterator captures_begin() const
bool isStaticDataMember() const
Determines whether this is a static data member.
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
A wrapper class around a pointer that always points to its canonical declaration. ...
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
Represents a C++ namespace alias.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
static bool isDefinedInClangModule(const Reco