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 #include "llvm/Support/TimeProfiler.h" 50 using namespace clang;
67 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
68 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
69 DBuilder(CGM.getModule()) {
71 DebugPrefixMap[KV.first] = KV.second;
76 assert(LexicalBlockStack.empty() &&
77 "Region stack mismatch, stack not empty!");
83 init(TemporaryLocation);
90 init(TemporaryLocation, DefaultToEmpty);
94 bool DefaultToEmpty) {
101 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
103 if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
106 if (TemporaryLocation.
isValid()) {
107 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
111 if (DefaultToEmpty) {
112 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
117 assert(!DI->LexicalBlockStack.empty());
118 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
119 0, 0, DI->LexicalBlockStack.back(), DI->getInlinedAt()));
133 OriginalLocation = CGF.
Builder.getCurrentDebugLocation();
135 CGF.
Builder.SetCurrentDebugLocation(std::move(Loc));
142 CGF->
Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
153 SavedLocation = DI.getLocation();
154 assert((DI.getInlinedAt() ==
155 CGF.
Builder.getCurrentDebugLocation()->getInlinedAt()) &&
156 "CGDebugInfo and IRBuilder are out of sync");
158 DI.EmitInlineFunctionStart(CGF.
Builder, InlinedFn);
166 DI.EmitLocation(CGF->
Builder, SavedLocation);
174 CurLoc = CGM.getContext().getSourceManager().getExpansionLoc(Loc);
179 if (LexicalBlockStack.empty())
183 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
185 if (PCLoc.isInvalid() ||
Scope->getFile() == getOrCreateFile(CurLoc))
188 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
189 LexicalBlockStack.pop_back();
190 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
191 LBF->getScope(), getOrCreateFile(CurLoc)));
192 }
else if (isa<llvm::DILexicalBlock>(
Scope) ||
193 isa<llvm::DISubprogram>(
Scope)) {
194 LexicalBlockStack.pop_back();
195 LexicalBlockStack.emplace_back(
196 DBuilder.createLexicalBlockFile(
Scope, getOrCreateFile(CurLoc)));
200 llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
201 llvm::DIScope *Mod = getParentModuleOrNull(D);
206 llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *Context,
211 auto I = RegionMap.find(Context);
212 if (I != RegionMap.end()) {
213 llvm::Metadata *
V = I->second;
214 return dyn_cast_or_null<llvm::DIScope>(
V);
218 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
219 return getOrCreateNamespace(NSDecl);
221 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
222 if (!RDecl->isDependentType())
223 return getOrCreateType(CGM.getContext().getTypeDeclType(RDecl),
235 if (CGM.getCodeGenOpts().EmitCodeView)
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() <<
')';
299 return internString(OS.str());
302 StringRef CGDebugInfo::getSelectorName(
Selector S) {
306 StringRef CGDebugInfo::getClassName(
const RecordDecl *RD) {
307 if (isa<ClassTemplateSpecializationDecl>(RD)) {
309 llvm::raw_svector_ostream OS(Name);
316 return internString(Name);
322 return II->getName();
326 if (CGM.getCodeGenOpts().EmitCodeView) {
329 "Typedef should not be in another decl context!");
330 assert(D->getDeclName().getAsIdentifierInfo() &&
331 "Typedef was not named!");
332 return D->getDeclName().getAsIdentifierInfo()->getName();
335 if (CGM.getLangOpts().CPlusPlus) {
342 Name = DD->getName();
347 Name = TND->getName();
353 return internString(UnnamedType);
365 if (!CGM.getCodeGenOpts().EmitCodeView &&
366 CGM.getCodeGenOpts().DwarfVersion < 5)
371 const llvm::MemoryBuffer *MemBuffer = SM.
getBuffer(FID, &Invalid);
376 llvm::MD5::MD5Result Result;
378 Hash.update(MemBuffer->getBuffer());
381 Hash.stringifyResult(Result, Checksum);
382 return llvm::DIFile::CSK_MD5;
387 if (!CGM.getCodeGenOpts().EmbedSource)
390 bool SourceInvalid =
false;
402 return TheCU->getFile();
408 if (PLoc.
isInvalid() || FileName.empty())
410 return TheCU->getFile();
413 auto It = DIFileCache.find(FileName.data());
414 if (It != DIFileCache.end()) {
416 if (llvm::Metadata *
V = It->second)
417 return cast<llvm::DIFile>(
V);
426 computeChecksum(PLoc.
getFileID(), Checksum);
429 CSInfo.emplace(*CSKind, Checksum);
430 return createFile(FileName, CSInfo, getSource(SM, SM.
getFileID(Loc)));
434 CGDebugInfo::createFile(StringRef FileName,
435 Optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
439 std::string RemappedFile = remapDIPath(FileName);
440 std::string CurDir = remapDIPath(getCurrentDirname());
443 if (llvm::sys::path::is_absolute(RemappedFile)) {
446 auto FileIt = llvm::sys::path::begin(RemappedFile);
447 auto FileE = llvm::sys::path::end(RemappedFile);
448 auto CurDirIt = llvm::sys::path::begin(CurDir);
449 auto CurDirE = llvm::sys::path::end(CurDir);
450 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
451 llvm::sys::path::append(DirBuf, *CurDirIt);
452 if (
std::distance(llvm::sys::path::begin(CurDir), CurDirIt) == 1) {
458 for (; FileIt != FileE; ++FileIt)
459 llvm::sys::path::append(FileBuf, *FileIt);
467 llvm::DIFile *F = DBuilder.createFile(File, Dir, CSInfo, Source);
468 DIFileCache[FileName.data()].reset(F);
473 for (
const auto &Entry : DebugPrefixMap)
474 if (Path.startswith(Entry.first))
475 return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
480 if (Loc.
isInvalid() && CurLoc.isInvalid())
487 unsigned CGDebugInfo::getColumnNumber(
SourceLocation Loc,
bool Force) {
489 if (!Force && !CGM.getCodeGenOpts().DebugColumnInfo)
493 if (Loc.
isInvalid() && CurLoc.isInvalid())
500 StringRef CGDebugInfo::getCurrentDirname() {
501 if (!CGM.getCodeGenOpts().DebugCompilationDir.empty())
502 return CGM.getCodeGenOpts().DebugCompilationDir;
504 if (!CWDName.empty())
507 llvm::sys::fs::current_path(CWD);
508 return CWDName = internString(CWD);
511 void CGDebugInfo::CreateCompileUnit() {
525 std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
526 if (MainFileName.empty())
527 MainFileName =
"<stdin>";
533 std::string MainFileDir;
535 MainFileDir = MainFile->getDir()->getName();
536 if (!llvm::sys::path::is_absolute(MainFileName)) {
538 llvm::sys::path::append(MainFileDirSS, MainFileName);
539 MainFileName = llvm::sys::path::remove_leading_dotslash(MainFileDirSS);
545 if (MainFile->getName() == MainFileName &&
547 MainFile->getName().rsplit(
'.').second)
549 MainFileName = CGM.getModule().getName().str();
554 llvm::dwarf::SourceLanguage LangTag;
558 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
559 else if (LO.CPlusPlus14)
560 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
561 else if (LO.CPlusPlus11)
562 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
564 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
565 }
else if (LO.ObjC) {
566 LangTag = llvm::dwarf::DW_LANG_ObjC;
567 }
else if (LO.RenderScript) {
568 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
570 LangTag = llvm::dwarf::DW_LANG_C99;
572 LangTag = llvm::dwarf::DW_LANG_C89;
578 unsigned RuntimeVers = 0;
582 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
586 EmissionKind = llvm::DICompileUnit::NoDebug;
589 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
597 EmissionKind = llvm::DICompileUnit::FullDebug;
602 auto &CGOpts = CGM.getCodeGenOpts();
608 CSInfo.emplace(*CSKind, Checksum);
609 llvm::DIFile *CUFile = DBuilder.createFile(
610 remapDIPath(MainFileName), remapDIPath(getCurrentDirname()), CSInfo,
614 TheCU = DBuilder.createCompileUnit(
615 LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer :
"",
616 LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
617 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
618 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
619 CGM.getTarget().getTriple().isNVPTX()
621 :
static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
622 CGOpts.DebugNameTable),
623 CGOpts.DebugRangesBaseAddress);
626 llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
630 #define BUILTIN_TYPE(Id, SingletonId) 631 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id: 632 #include "clang/AST/BuiltinTypes.def" 633 case BuiltinType::Dependent:
634 llvm_unreachable(
"Unexpected builtin type");
635 case BuiltinType::NullPtr:
636 return DBuilder.createNullPtrType();
637 case BuiltinType::Void:
639 case BuiltinType::ObjCClass:
642 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
643 "objc_class", TheCU, TheCU->getFile(), 0);
645 case BuiltinType::ObjCId: {
656 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
657 "objc_class", TheCU, TheCU->getFile(), 0);
659 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
661 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
663 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
664 0, 0, llvm::DINode::FlagZero,
nullptr,
665 llvm::DINodeArray());
667 DBuilder.replaceArrays(
668 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
669 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
670 llvm::DINode::FlagZero, ISATy)));
673 case BuiltinType::ObjCSel: {
675 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
676 "objc_selector", TheCU,
677 TheCU->getFile(), 0);
681 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ 682 case BuiltinType::Id: \ 683 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \ 685 #include "clang/Basic/OpenCLImageTypes.def" 686 case BuiltinType::OCLSampler:
687 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
688 case BuiltinType::OCLEvent:
689 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
690 case BuiltinType::OCLClkEvent:
691 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
692 case BuiltinType::OCLQueue:
693 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
694 case BuiltinType::OCLReserveID:
695 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
696 #define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ 697 case BuiltinType::Id: \ 698 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty); 699 #include "clang/Basic/OpenCLExtensionTypes.def" 704 #define SVE_TYPE(Name, Id, SingletonId) \ 705 case BuiltinType::Id: 706 #include "clang/Basic/AArch64SVEACLETypes.def" 708 unsigned DiagID = CGM.getDiags().getCustomDiagID(
710 "cannot yet generate debug info for SVE type '%0'");
711 auto Name = BT->
getName(CGM.getContext().getPrintingPolicy());
712 CGM.getDiags().Report(DiagID) << Name;
714 return CreateType(cast<const BuiltinType>(CGM.getContext().IntTy));
717 case BuiltinType::UChar:
718 case BuiltinType::Char_U:
719 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
721 case BuiltinType::Char_S:
722 case BuiltinType::SChar:
723 Encoding = llvm::dwarf::DW_ATE_signed_char;
725 case BuiltinType::Char8:
726 case BuiltinType::Char16:
727 case BuiltinType::Char32:
728 Encoding = llvm::dwarf::DW_ATE_UTF;
730 case BuiltinType::UShort:
731 case BuiltinType::UInt:
732 case BuiltinType::UInt128:
733 case BuiltinType::ULong:
734 case BuiltinType::WChar_U:
735 case BuiltinType::ULongLong:
736 Encoding = llvm::dwarf::DW_ATE_unsigned;
738 case BuiltinType::Short:
739 case BuiltinType::Int:
740 case BuiltinType::Int128:
741 case BuiltinType::Long:
742 case BuiltinType::WChar_S:
743 case BuiltinType::LongLong:
744 Encoding = llvm::dwarf::DW_ATE_signed;
746 case BuiltinType::Bool:
747 Encoding = llvm::dwarf::DW_ATE_boolean;
749 case BuiltinType::Half:
750 case BuiltinType::Float:
751 case BuiltinType::LongDouble:
752 case BuiltinType::Float16:
753 case BuiltinType::Float128:
754 case BuiltinType::Double:
760 Encoding = llvm::dwarf::DW_ATE_float;
762 case BuiltinType::ShortAccum:
763 case BuiltinType::Accum:
764 case BuiltinType::LongAccum:
765 case BuiltinType::ShortFract:
766 case BuiltinType::Fract:
767 case BuiltinType::LongFract:
768 case BuiltinType::SatShortFract:
769 case BuiltinType::SatFract:
770 case BuiltinType::SatLongFract:
771 case BuiltinType::SatShortAccum:
772 case BuiltinType::SatAccum:
773 case BuiltinType::SatLongAccum:
774 Encoding = llvm::dwarf::DW_ATE_signed_fixed;
776 case BuiltinType::UShortAccum:
777 case BuiltinType::UAccum:
778 case BuiltinType::ULongAccum:
779 case BuiltinType::UShortFract:
780 case BuiltinType::UFract:
781 case BuiltinType::ULongFract:
782 case BuiltinType::SatUShortAccum:
783 case BuiltinType::SatUAccum:
784 case BuiltinType::SatULongAccum:
785 case BuiltinType::SatUShortFract:
786 case BuiltinType::SatUFract:
787 case BuiltinType::SatULongFract:
788 Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
793 case BuiltinType::Long:
796 case BuiltinType::LongLong:
797 BTName =
"long long int";
799 case BuiltinType::ULong:
800 BTName =
"long unsigned int";
802 case BuiltinType::ULongLong:
803 BTName =
"long long unsigned int";
806 BTName = BT->
getName(CGM.getLangOpts());
810 uint64_t Size = CGM.getContext().getTypeSize(BT);
811 return DBuilder.createBasicType(BTName, Size, Encoding);
814 llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
816 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
818 Encoding = llvm::dwarf::DW_ATE_lo_user;
820 uint64_t Size = CGM.getContext().getTypeSize(Ty);
821 return DBuilder.createBasicType(
"complex", Size, Encoding);
824 llvm::DIType *CGDebugInfo::CreateQualifiedType(
QualType Ty,
825 llvm::DIFile *Unit) {
836 llvm::dwarf::Tag Tag;
838 Tag = llvm::dwarf::DW_TAG_const_type;
841 Tag = llvm::dwarf::DW_TAG_volatile_type;
844 Tag = llvm::dwarf::DW_TAG_restrict_type;
847 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
848 return getOrCreateType(
QualType(T, 0), Unit);
851 auto *FromTy = getOrCreateType(Qc.
apply(CGM.getContext(), T), Unit);
855 return DBuilder.createQualifiedType(Tag, FromTy);
859 llvm::DIFile *Unit) {
865 return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
867 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
871 llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
872 llvm::DIFile *Unit) {
873 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
879 switch (TheCU->getSourceLanguage()) {
880 case llvm::dwarf::DW_LANG_C_plus_plus:
881 case llvm::dwarf::DW_LANG_C_plus_plus_11:
882 case llvm::dwarf::DW_LANG_C_plus_plus_14:
884 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
885 return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
913 llvm::DICompileUnit *TheCU) {
931 llvm::DICompileUnit *TheCU) {
937 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
939 if (RD->isDynamicClass() &&
945 llvm::raw_svector_ostream Out(Identifier);
952 llvm::dwarf::Tag Tag;
954 Tag = llvm::dwarf::DW_TAG_structure_type;
956 Tag = llvm::dwarf::DW_TAG_union_type;
961 Tag = llvm::dwarf::DW_TAG_class_type;
966 llvm::DICompositeType *
967 CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
968 llvm::DIScope *Ctx) {
970 if (llvm::DIType *T = getTypeOrNull(CGM.getContext().getRecordType(RD)))
971 return cast<llvm::DICompositeType>(T);
972 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
974 StringRef RDName = getClassName(RD);
981 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
983 llvm::DINode::FlagFwdDecl, Identifier);
984 if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
985 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
986 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
987 CollectCXXTemplateParams(TSpecial, DefUnit));
988 ReplaceMap.emplace_back(
989 std::piecewise_construct, std::make_tuple(Ty),
990 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
994 llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
997 llvm::DIFile *Unit) {
1001 unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(PointeeTy);
1002 uint64_t Size = CGM.getTarget().getPointerWidth(AddressSpace);
1005 CGM.getTarget().getDWARFAddressSpace(AddressSpace);
1007 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1008 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
1009 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1010 Size, Align, DWARFAddressSpace);
1012 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1013 Align, DWARFAddressSpace);
1016 llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1017 llvm::DIType *&
Cache) {
1020 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1021 TheCU, TheCU->getFile(), 0);
1022 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1023 Cache = DBuilder.createPointerType(Cache, Size);
1027 uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1028 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1034 uint64_t FieldOffset = 0;
1039 if (CGM.getLangOpts().OpenCL) {
1040 FType = CGM.getContext().IntTy;
1041 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1042 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1044 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1045 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1046 FType = CGM.getContext().IntTy;
1047 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1048 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1050 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1051 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1052 uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
1053 uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
1054 EltTys.push_back(DBuilder.createMemberType(
1055 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1056 FieldOffset, llvm::DINode::FlagZero, DescTy));
1057 FieldOffset += FieldSize;
1064 llvm::DIFile *Unit) {
1067 uint64_t FieldOffset;
1068 llvm::DINodeArray Elements;
1071 FType = CGM.getContext().UnsignedLongTy;
1072 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1073 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1075 Elements = DBuilder.getOrCreateArray(EltTys);
1078 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1081 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1082 FieldOffset, 0, Flags,
nullptr, Elements);
1085 uint64_t Size = CGM.getContext().getTypeSize(Ty);
1087 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1089 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1092 Elements = DBuilder.getOrCreateArray(EltTys);
1098 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1099 Flags,
nullptr, Elements);
1101 return DBuilder.createPointerType(EltTy, Size);
1105 llvm::DIFile *Unit) {
1111 ->getTemplatedDecl();
1113 if (AliasDecl->hasAttr<NoDebugAttr>())
1117 llvm::raw_svector_ostream OS(NS);
1122 return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
1124 getDeclContextDescriptor(AliasDecl));
1127 llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1128 llvm::DIFile *Unit) {
1129 llvm::DIType *Underlying =
1141 return DBuilder.createTypedef(Underlying, Ty->
getDecl()->
getName(),
1142 getOrCreateFile(Loc), getLineNumber(Loc),
1143 getDeclContextDescriptor(Ty->
getDecl()), Align);
1153 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1155 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1157 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1159 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1161 return llvm::dwarf::DW_CC_BORLAND_pascal;
1163 return llvm::dwarf::DW_CC_LLVM_Win64;
1165 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1168 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1170 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1172 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1174 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1176 return llvm::dwarf::DW_CC_LLVM_OpenCLKernel;
1178 return llvm::dwarf::DW_CC_LLVM_Swift;
1180 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1182 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1184 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1189 llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1190 llvm::DIFile *Unit) {
1194 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1198 if (isa<FunctionNoProtoType>(Ty))
1199 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1200 else if (
const auto *FPT = dyn_cast<FunctionProtoType>(Ty)) {
1201 for (
const QualType &ParamType : FPT->param_types())
1202 EltTys.push_back(getOrCreateType(ParamType, Unit));
1203 if (FPT->isVariadic())
1204 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1207 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1208 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
1223 if (Access == Default)
1224 return llvm::DINode::FlagZero;
1228 return llvm::DINode::FlagPrivate;
1230 return llvm::DINode::FlagProtected;
1232 return llvm::DINode::FlagPublic;
1234 return llvm::DINode::FlagZero;
1236 llvm_unreachable(
"unexpected access enumerator");
1239 llvm::DIType *CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1240 llvm::DIScope *RecordTy,
1242 StringRef Name = BitFieldDecl->
getName();
1245 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1246 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1249 llvm::DIFile *File = getOrCreateFile(Loc);
1250 unsigned Line = getLineNumber(Loc);
1253 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1254 uint64_t SizeInBits = BitFieldInfo.
Size;
1255 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1256 uint64_t StorageOffsetInBits =
1262 if (CGM.getDataLayout().isBigEndian())
1264 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1266 return DBuilder.createBitFieldMemberType(
1267 RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1274 uint32_t AlignInBits, llvm::DIFile *tunit,
1275 llvm::DIScope *scope,
const RecordDecl *RD) {
1276 llvm::DIType *debugType = getOrCreateType(type, tunit);
1279 llvm::DIFile *file = getOrCreateFile(loc);
1280 unsigned line = getLineNumber(loc);
1282 uint64_t SizeInBits = 0;
1283 auto Align = AlignInBits;
1285 TypeInfo TI = CGM.getContext().getTypeInfo(type);
1286 SizeInBits = TI.
Width;
1292 return DBuilder.createMemberType(scope,
name, file, line, SizeInBits, Align,
1293 offsetInBits, flags, debugType);
1296 void CGDebugInfo::CollectRecordLambdaFields(
1298 llvm::DIType *RecordTy) {
1302 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(CXXDecl);
1304 unsigned fieldno = 0;
1307 I != E; ++I, ++Field, ++fieldno) {
1311 assert(!Field->isBitField() &&
"lambdas don't have bitfield members!");
1313 StringRef VName = V->
getName();
1314 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1316 llvm::DIType *FieldType = createFieldType(
1317 VName, Field->getType(), Loc, Field->getAccess(),
1318 layout.
getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
1319 elements.push_back(FieldType);
1326 llvm::DIFile *VUnit = getOrCreateFile(f->
getLocation());
1328 llvm::DIType *fieldType = createFieldType(
1332 elements.push_back(fieldType);
1337 llvm::DIDerivedType *
1338 CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
1343 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
1344 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
1346 unsigned LineNumber = getLineNumber(Var->
getLocation());
1347 StringRef VName = Var->
getName();
1348 llvm::Constant *C =
nullptr;
1353 C = llvm::ConstantInt::get(CGM.getLLVMContext(), Value->
getInt());
1355 C = llvm::ConstantFP::get(CGM.getLLVMContext(), Value->
getFloat());
1361 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1362 RecordTy, VName, VUnit, LineNumber, VTy, Flags, C, Align);
1367 void CGDebugInfo::CollectRecordNormalField(
1368 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
1378 llvm::DIType *FieldType;
1380 FieldType = createBitFieldType(field, RecordTy, RD);
1385 OffsetInBits, Align, tunit, RecordTy, RD);
1388 elements.push_back(FieldType);
1391 void CGDebugInfo::CollectRecordNestedType(
1393 QualType Ty = CGM.getContext().getTypeDeclType(TD);
1395 if (isa<InjectedClassNameType>(Ty))
1398 llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc));
1399 elements.push_back(nestedType);
1402 void CGDebugInfo::CollectRecordFields(
1403 const RecordDecl *record, llvm::DIFile *tunit,
1405 llvm::DICompositeType *RecordTy) {
1408 if (CXXDecl && CXXDecl->
isLambda())
1409 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
1411 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
1414 unsigned fieldNo = 0;
1418 for (
const auto *I : record->
decls())
1419 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
1420 if (
V->hasAttr<NoDebugAttr>())
1425 if (CGM.getCodeGenOpts().EmitCodeView &&
1426 isa<VarTemplateSpecializationDecl>(
V))
1429 if (isa<VarTemplatePartialSpecializationDecl>(
V))
1433 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
1434 if (MI != StaticDataMemberCache.end()) {
1435 assert(MI->second &&
1436 "Static data member declaration should still exist");
1437 elements.push_back(MI->second);
1439 auto Field = CreateRecordStaticField(
V, RecordTy, record);
1440 elements.push_back(Field);
1442 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
1443 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
1444 elements, RecordTy, record);
1448 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
1451 if (
const auto *nestedType = dyn_cast<TypeDecl>(I))
1452 if (!nestedType->isImplicit() &&
1453 nestedType->getDeclContext() == record)
1454 CollectRecordNestedType(nestedType, elements);
1459 llvm::DISubroutineType *
1460 CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *Method,
1461 llvm::DIFile *Unit) {
1464 return cast_or_null<llvm::DISubroutineType>(
1465 getOrCreateType(
QualType(Func, 0), Unit));
1466 return getOrCreateInstanceMethodType(Method->
getThisType(), Func, Unit);
1469 llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
1472 llvm::DITypeRefArray Args(
1473 cast<llvm::DISubroutineType>(getOrCreateType(
QualType(Func, 0), Unit))
1475 assert(Args.size() &&
"Invalid number of arguments!");
1480 Elts.push_back(Args[0]);
1484 if (isa<ClassTemplateSpecializationDecl>(RD)) {
1486 const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
1488 unsigned AS = CGM.getContext().getTargetAddressSpace(PointeeTy);
1489 uint64_t Size = CGM.getTarget().getPointerWidth(AS);
1491 llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
1492 llvm::DIType *ThisPtrType =
1493 DBuilder.createPointerType(PointeeType, Size, Align);
1498 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1499 Elts.push_back(ThisPtrType);
1501 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
1503 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1504 Elts.push_back(ThisPtrType);
1508 for (
unsigned i = 1, e = Args.size(); i != e; ++i)
1509 Elts.push_back(Args[i]);
1511 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
1513 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1515 Flags |= llvm::DINode::FlagLValueReference;
1517 Flags |= llvm::DINode::FlagRValueReference;
1519 return DBuilder.createSubroutineType(EltTypeArray, Flags,
1526 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
1533 llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
1534 const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
1536 isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
1538 StringRef MethodName = getFunctionName(Method);
1539 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
1543 StringRef MethodLinkageName;
1550 MethodLinkageName = CGM.getMangledName(Method);
1553 llvm::DIFile *MethodDefUnit =
nullptr;
1554 unsigned MethodLine = 0;
1556 MethodDefUnit = getOrCreateFile(Method->
getLocation());
1557 MethodLine = getLineNumber(Method->
getLocation());
1561 llvm::DIType *ContainingType =
nullptr;
1562 unsigned VIndex = 0;
1563 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1564 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
1569 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
1571 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
1573 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
1576 if (!isa<CXXDestructorDecl>(Method))
1577 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(Method);
1584 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
1593 Flags |= llvm::DINode::FlagIntroducedVirtual;
1598 ThisAdjustment = CGM.getCXXABI()
1599 .getVirtualFunctionPrologueThisAdjustment(GD)
1602 ContainingType = RecordTy;
1607 auto checkAttrDeleted = [&](
const auto *Method) {
1609 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
1614 case Decl::CXXConstructor:
1615 case Decl::CXXDestructor:
1616 checkAttrDeleted(Method);
1618 case Decl::CXXMethod:
1621 checkAttrDeleted(Method);
1628 Flags |= llvm::DINode::FlagNoReturn;
1631 Flags |= llvm::DINode::FlagStaticMember;
1633 Flags |= llvm::DINode::FlagArtificial;
1635 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
1636 if (CXXC->isExplicit())
1637 Flags |= llvm::DINode::FlagExplicit;
1638 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(Method)) {
1639 if (CXXC->isExplicit())
1640 Flags |= llvm::DINode::FlagExplicit;
1643 Flags |= llvm::DINode::FlagPrototyped;
1645 Flags |= llvm::DINode::FlagLValueReference;
1647 Flags |= llvm::DINode::FlagRValueReference;
1648 if (CGM.getLangOpts().Optimize)
1649 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
1655 completeClass(CD->getParent());
1657 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
1658 llvm::DISubprogram *SP = DBuilder.createMethod(
1659 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
1660 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
1661 TParamsArray.get());
1668 void CGDebugInfo::CollectCXXMemberFunctions(
1675 for (
const auto *I : RD->
decls()) {
1700 EltTys.push_back(MI == SPCache.end()
1701 ? CreateCXXMemberFunction(Method, Unit, RecordTy)
1702 :
static_cast<llvm::Metadata *
>(MI->second));
1706 void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1708 llvm::DIType *RecordTy) {
1710 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
1711 llvm::DINode::FlagZero);
1715 if (CGM.getCodeGenOpts().EmitCodeView) {
1716 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
1717 llvm::DINode::FlagIndirectVirtualBase);
1721 void CGDebugInfo::CollectCXXBasesAux(
1726 llvm::DINode::DIFlags StartingFlags) {
1728 for (
const auto &BI : Bases) {
1730 cast<CXXRecordDecl>(BI.getType()->castAs<
RecordType>()->getDecl());
1731 if (!SeenTypes.insert(
Base).second)
1733 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
1734 llvm::DINode::DIFlags BFlags = StartingFlags;
1735 uint64_t BaseOffset;
1736 uint32_t VBPtrOffset = 0;
1738 if (BI.isVirtual()) {
1739 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
1742 BaseOffset = 0 - CGM.getItaniumVTableContext()
1743 .getVirtualBaseOffsetOffset(RD,
Base)
1749 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD,
Base);
1750 VBPtrOffset = CGM.getContext()
1751 .getASTRecordLayout(RD)
1755 BFlags |= llvm::DINode::FlagVirtual;
1762 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
1763 VBPtrOffset, BFlags);
1764 EltTys.push_back(DTy);
1771 llvm::DIFile *Unit) {
1773 for (
unsigned i = 0, e = TAList.size(); i != e; ++i) {
1780 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
1781 TemplateParams.push_back(
1782 DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
1786 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1788 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
1793 llvm::DIType *TTy = getOrCreateType(T, Unit);
1794 llvm::Constant *
V =
nullptr;
1797 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
1798 !D->
hasAttr<CUDADeviceAttr>()) {
1802 if (
const auto *VD = dyn_cast<VarDecl>(D))
1803 V = CGM.GetAddrOfGlobalVar(VD);
1806 else if ((MD = dyn_cast<CXXMethodDecl>(D)) && MD->
isInstance())
1807 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
1808 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1809 V = CGM.GetAddrOfFunction(FD);
1812 else if (
const auto *MPT =
1813 dyn_cast<MemberPointerType>(T.
getTypePtr())) {
1817 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
1819 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
1820 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
1822 assert(V &&
"Failed to find template parameter pointer");
1823 V = V->stripPointerCasts();
1825 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1826 TheCU, Name, TTy, cast_or_null<llvm::Constant>(V)));
1830 llvm::DIType *TTy = getOrCreateType(T, Unit);
1831 llvm::Constant *
V =
nullptr;
1834 if (
const auto *MPT = dyn_cast<MemberPointerType>(T.
getTypePtr()))
1840 if (MPT->isMemberDataPointer())
1841 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
1843 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
1844 TemplateParams.push_back(
1845 DBuilder.createTemplateValueParameter(TheCU, Name, TTy, V));
1848 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
1849 TheCU, Name,
nullptr,
1853 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
1854 TheCU, Name,
nullptr,
1861 T = CGM.getContext().getLValueReferenceType(T);
1863 assert(V &&
"Expression in template argument isn't constant");
1864 llvm::DIType *TTy = getOrCreateType(T, Unit);
1865 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1866 TheCU, Name, TTy, V->stripPointerCasts()));
1872 "These argument types shouldn't exist in concrete types");
1875 return DBuilder.getOrCreateArray(TemplateParams);
1879 CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
1880 llvm::DIFile *Unit) {
1886 return CollectTemplateParams(
1889 return llvm::DINodeArray();
1892 llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
1893 llvm::DIFile *Unit) {
1899 return llvm::DINodeArray();
1902 auto TA = TS->getTemplateArgs().
asArray();
1903 return CollectTemplateParams(TList, TA, Unit);
1906 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
1914 return CollectTemplateParams(TPList, TAList.
asArray(), Unit);
1917 llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
1919 return VTablePtrType;
1924 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
1925 llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
1926 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
1928 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
1930 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
1932 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
1933 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
1934 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
1935 return VTablePtrType;
1938 StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
1943 StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
1945 llvm::Function *InitFn) {
1948 if (!CGM.getCodeGenOpts().EmitCodeView)
1949 return InitFn->getName();
1959 llvm::raw_svector_ostream OS(QualifiedGV);
1961 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
1963 std::swap(Quals, GVName);
1967 llvm::raw_svector_ostream OS(InitName);
1969 OS << Quals <<
"::";
1973 llvm_unreachable(
"not an initializer");
1975 OS <<
"`dynamic initializer for '";
1978 OS <<
"`dynamic atexit destructor for '";
1985 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
1987 getPrintingPolicy());
1992 return internString(OS.str());
1995 void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1997 llvm::DICompositeType *RecordTy) {
2013 llvm::DIType *VPtrTy =
nullptr;
2014 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
2015 CGM.getTarget().getCXXABI().isMicrosoft();
2016 if (NeedVTableShape) {
2018 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
2020 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
2021 unsigned VSlotCount =
2023 unsigned VTableWidth = PtrWidth * VSlotCount;
2024 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2026 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2029 llvm::DIType *VTableType = DBuilder.createPointerType(
2030 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2031 EltTys.push_back(VTableType);
2034 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
2042 VPtrTy = getOrCreateVTablePtrType(Unit);
2044 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
2045 llvm::DIType *VPtrMember =
2046 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
2047 llvm::DINode::FlagArtificial, VPtrTy);
2048 EltTys.push_back(VPtrMember);
2053 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
2054 llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
2060 return getOrCreateStandaloneType(D, Loc);
2065 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
2066 assert(!D.
isNull() &&
"null type");
2067 llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
2068 assert(T &&
"could not create debug info for type");
2079 node = llvm::MDNode::get(CGM.getLLVMContext(), None);
2082 node = getOrCreateType(PointeeTy, getOrCreateFile(Loc));
2085 CI->setMetadata(
"heapallocsite", node);
2091 QualType Ty = CGM.getContext().getEnumType(ED);
2093 auto I = TypeCache.find(TyPtr);
2094 if (I == TypeCache.end() || !cast<llvm::DIType>(I->second)->isForwardDecl())
2096 llvm::DIType *Res = CreateTypeDefinition(Ty->
castAs<
EnumType>());
2097 assert(!Res->isForwardDecl());
2098 TypeCache[TyPtr].reset(Res);
2103 !CGM.getLangOpts().CPlusPlus)
2104 completeRequiredType(RD);
2109 if (RD->
hasAttr<DLLImportAttr>())
2112 if (MD->hasAttr<DLLImportAttr>())
2125 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
2134 bool Explicit =
false;
2135 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
2136 Explicit = TD->isExplicitInstantiationOrSpecialization();
2150 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
2151 if (CXXRD->isDynamicClass() &&
2152 CGM.getVTableLinkage(CXXRD) ==
2153 llvm::GlobalValue::AvailableExternallyLinkage &&
2166 QualType Ty = CGM.getContext().getRecordType(RD);
2168 auto I = TypeCache.find(TyPtr);
2169 if (I != TypeCache.end() && !cast<llvm::DIType>(I->second)->isForwardDecl())
2172 assert(!Res->isForwardDecl());
2173 TypeCache[TyPtr].reset(Res);
2180 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
2181 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
2199 if (!LangOpts.CPlusPlus)
2225 for (
const auto *Ctor : CXXDecl->
ctors()) {
2226 if (Ctor->isUserProvided())
2232 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
2233 Spec = SD->getSpecializationKind();
2247 QualType Ty = CGM.getContext().getRecordType(RD);
2248 llvm::DIType *T = getTypeOrNull(Ty);
2249 if (T && T->isForwardDecl())
2250 completeClassData(RD);
2253 llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
2255 llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
2257 CGM.getLangOpts())) {
2259 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
2263 return CreateTypeDefinition(Ty);
2266 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
2270 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
2278 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
2284 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
2285 CollectContainingType(CXXDecl, FwdDecl);
2288 LexicalBlockStack.emplace_back(&*FwdDecl);
2289 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2301 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
2302 CollectVTableInfo(CXXDecl, DefUnit, EltTys, FwdDecl);
2306 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
2308 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
2310 LexicalBlockStack.pop_back();
2311 RegionMap.erase(Ty->
getDecl());
2313 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2314 DBuilder.replaceArrays(FwdDecl, Elements);
2316 if (FwdDecl->isTemporary())
2318 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
2320 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2325 llvm::DIFile *Unit) {
2331 llvm::DIFile *Unit) {
2336 return DBuilder.createTypedef(
2338 Ty->
getDecl()->
getName(), getOrCreateFile(Loc), getLineNumber(Loc),
2339 getDeclContextDescriptor(Ty->
getDecl()));
2367 llvm::DIFile *Unit) {
2377 return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
2379 getDeclContextDescriptor(ID), Unit, 0);
2382 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
2385 static_cast<llvm::dwarf::SourceLanguage
>(TheCU->getSourceLanguage());
2391 llvm::DIScope *Mod = getParentModuleOrNull(ID);
2392 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
2393 llvm::dwarf::DW_TAG_structure_type, ID->
getName(), Mod ? Mod : TheCU,
2394 DefUnit,
Line, RuntimeLang);
2395 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
2399 return CreateTypeDefinition(Ty, Unit);
2404 bool CreateSkeletonCU) {
2409 auto ModRef = ModuleCache.find(M);
2410 if (ModRef != ModuleCache.end())
2411 return cast<llvm::DIModule>(ModRef->second);
2416 llvm::raw_svector_ostream OS(ConfigMacros);
2417 const auto &PPOpts = CGM.getPreprocessorOpts();
2420 for (
auto &M : PPOpts.Macros) {
2423 const std::string &Macro = M.first;
2424 bool Undef = M.second;
2425 OS <<
"\"-" << (Undef ?
'U' :
'D');
2426 for (
char c : Macro)
2441 bool IsRootModule = M ? !M->
Parent :
true;
2445 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
2446 assert(StringRef(M->
Name).startswith(CGM.getLangOpts().ModuleName) &&
2447 "clang module without ASTFile must be specified by -fmodule-name");
2449 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
2453 uint64_t Signature =
2457 llvm::DIBuilder DIB(CGM.getModule());
2458 DIB.createCompileUnit(TheCU->getSourceLanguage(),
2461 TheCU->getProducer(),
true, StringRef(), 0,
2462 Mod.
getASTFile(), llvm::DICompileUnit::FullDebug,
2468 IsRootModule ? nullptr
2469 : getOrCreateModuleRef(
2472 llvm::DIModule *DIMod =
2473 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
2474 Mod.
getPath(), CGM.getHeaderSearchOpts().Sysroot);
2475 ModuleCache[M].reset(DIMod);
2480 llvm::DIFile *Unit) {
2482 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
2484 unsigned RuntimeLang = TheCU->getSourceLanguage();
2487 uint64_t Size = CGM.getContext().getTypeSize(Ty);
2490 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2492 Flags |= llvm::DINode::FlagObjcClassComplete;
2494 llvm::DIScope *Mod = getParentModuleOrNull(ID);
2495 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
2496 Mod ? Mod : Unit, ID->
getName(), DefUnit,
Line, Size, Align, Flags,
2497 nullptr, llvm::DINodeArray(), RuntimeLang);
2503 LexicalBlockStack.emplace_back(RealDecl);
2504 RegionMap[Ty->
getDecl()].reset(RealDecl);
2511 llvm::DIType *SClassTy =
2512 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
2516 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
2517 llvm::DINode::FlagZero);
2518 EltTys.push_back(InhTag);
2524 llvm::DIFile *PUnit = getOrCreateFile(Loc);
2525 unsigned PLine = getLineNumber(Loc);
2528 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
2529 PD->getName(), PUnit, PLine,
2531 : getSelectorName(PD->getGetterName()),
2533 : getSelectorName(PD->getSetterName()),
2534 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
2535 EltTys.push_back(PropertyNode);
2538 llvm::SmallPtrSet<const IdentifierInfo *, 16> PropertySet;
2540 for (
auto *PD : ClassExt->properties()) {
2541 PropertySet.insert(PD->getIdentifier());
2547 if (!PropertySet.insert(PD->getIdentifier()).second)
2553 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
2554 unsigned FieldNo = 0;
2556 Field = Field->getNextIvar(), ++FieldNo) {
2557 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
2561 StringRef FieldName = Field->getName();
2564 if (FieldName.empty())
2568 llvm::DIFile *FieldDefUnit = getOrCreateFile(Field->getLocation());
2569 unsigned FieldLine = getLineNumber(Field->getLocation());
2571 uint64_t FieldSize = 0;
2572 uint32_t FieldAlign = 0;
2574 if (!FType->isIncompleteArrayType()) {
2577 FieldSize = Field->isBitField()
2578 ? Field->getBitWidthValue(CGM.getContext())
2579 : CGM.getContext().getTypeSize(FType);
2583 uint64_t FieldOffset;
2584 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
2588 if (Field->isBitField()) {
2590 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
2591 FieldOffset %= CGM.getContext().getCharWidth();
2599 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2601 Flags = llvm::DINode::FlagProtected;
2603 Flags = llvm::DINode::FlagPrivate;
2605 Flags = llvm::DINode::FlagPublic;
2607 llvm::MDNode *PropertyNode =
nullptr;
2610 ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
2613 llvm::DIFile *PUnit = getOrCreateFile(Loc);
2614 unsigned PLine = getLineNumber(Loc);
2617 PropertyNode = DBuilder.createObjCProperty(
2618 PD->getName(), PUnit, PLine,
2621 : getSelectorName(PD->getGetterName()),
2624 : getSelectorName(PD->getSetterName()),
2625 PD->getPropertyAttributes(),
2626 getOrCreateType(PD->getType(), PUnit));
2630 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
2631 FieldSize, FieldAlign, FieldOffset, Flags,
2632 FieldTy, PropertyNode);
2633 EltTys.push_back(FieldTy);
2636 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2637 DBuilder.replaceArrays(RealDecl, Elements);
2639 LexicalBlockStack.pop_back();
2643 llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
2644 llvm::DIFile *Unit) {
2645 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
2648 llvm::Metadata *Subscript;
2650 auto SizeExpr = SizeExprCache.find(QTy);
2651 if (SizeExpr != SizeExprCache.end())
2652 Subscript = DBuilder.getOrCreateSubrange(0, SizeExpr->getSecond());
2654 Subscript = DBuilder.getOrCreateSubrange(0, Count ? Count : -1);
2655 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
2657 uint64_t Size = CGM.getContext().getTypeSize(Ty);
2660 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
2663 llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
2668 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2683 Size = CGM.getContext().getTypeSize(Ty);
2692 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
2701 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
2702 Count = CAT->getSize().getZExtValue();
2703 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2704 if (
Expr *Size = VAT->getSizeExpr()) {
2706 if (Size->EvaluateAsInt(Result, CGM.getContext()))
2707 Count = Result.
Val.
getInt().getExtValue();
2711 auto SizeNode = SizeExprCache.find(EltTy);
2712 if (SizeNode != SizeExprCache.end())
2713 Subscripts.push_back(
2714 DBuilder.getOrCreateSubrange(0, SizeNode->getSecond()));
2716 Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
2720 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
2722 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
2727 llvm::DIFile *Unit) {
2728 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
2733 llvm::DIFile *Unit) {
2734 return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
2740 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2744 Size = CGM.getContext().getTypeSize(Ty);
2747 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
2750 Flags |= llvm::DINode::FlagSingleInheritance;
2753 Flags |= llvm::DINode::FlagMultipleInheritance;
2756 Flags |= llvm::DINode::FlagVirtualInheritance;
2766 return DBuilder.createMemberPointerType(
2772 return DBuilder.createMemberPointerType(
2773 getOrCreateInstanceMethodType(
2776 ClassType, Size, 0, Flags);
2779 llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
2781 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
2784 llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
2788 llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
2800 bool isImportedFromModule =
2812 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
2813 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2814 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
2815 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
2818 StringRef EDName = ED->
getName();
2819 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
2820 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
2821 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
2823 ReplaceMap.emplace_back(
2824 std::piecewise_construct, std::make_tuple(Ty),
2825 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
2829 return CreateTypeDefinition(Ty);
2832 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
2848 const auto &InitVal = Enum->getInitVal();
2849 auto Value = IsSigned ? InitVal.getSExtValue() : InitVal.getZExtValue();
2850 Enumerators.push_back(
2851 DBuilder.createEnumerator(Enum->getName(),
Value, !IsSigned));
2855 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
2857 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2859 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
2860 llvm::DIType *ClassTy = getOrCreateType(ED->
getIntegerType(), DefUnit);
2861 return DBuilder.createEnumerationType(EnumContext, ED->
getName(), DefUnit,
2862 Line, Size, Align, EltArray, ClassTy,
2868 StringRef Name, StringRef
Value) {
2869 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
2870 return DBuilder.createMacro(Parent, Line, MType, Name, Value);
2876 llvm::DIFile *FName = getOrCreateFile(FileLoc);
2877 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
2878 return DBuilder.createTempMacroFile(Parent, Line, FName);
2888 Quals += InnerQuals;
2893 case Type::TemplateSpecialization: {
2894 const auto *Spec = cast<TemplateSpecializationType>(T);
2895 if (Spec->isTypeAlias())
2897 T = Spec->desugar();
2900 case Type::TypeOfExpr:
2901 T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
2906 case Type::Decltype:
2909 case Type::UnaryTransform:
2912 case Type::Attributed:
2913 T = cast<AttributedType>(T)->getEquivalentType();
2915 case Type::Elaborated:
2916 T = cast<ElaboratedType>(T)->getNamedType();
2919 T = cast<ParenType>(T)->getInnerType();
2921 case Type::MacroQualified:
2924 case Type::SubstTemplateTypeParm:
2925 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
2928 case Type::DeducedTemplateSpecialization: {
2929 QualType DT = cast<DeducedType>(T)->getDeducedType();
2930 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
2934 case Type::Adjusted:
2937 T = cast<AdjustedType>(T)->getAdjustedType();
2941 assert(T != LastT &&
"Type unwrapping failed to unwrap!");
2946 llvm::DIType *CGDebugInfo::getTypeOrNull(
QualType Ty) {
2952 if (It != TypeCache.end()) {
2954 if (llvm::Metadata *
V = It->second)
2955 return cast<llvm::DIType>(
V);
2965 completeUnusedClass(SD);
2972 completeClassData(&D);
2975 RetainedTypes.push_back(CGM.getContext().getRecordType(&D).getAsOpaquePtr());
2978 llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
2982 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
2984 llvm::raw_string_ostream OS(Name);
2985 Ty.
print(OS, getPrintingPolicy());
2992 if (
auto *T = getTypeOrNull(Ty))
2995 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
2996 void *TyPtr = Ty.getAsOpaquePtr();
2999 TypeCache[TyPtr].reset(Res);
3004 llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
3006 if (isa<RecordDecl>(D) && !cast<RecordDecl>(D)->
getDefinition())
3010 auto *Reader = CGM.getContext().getExternalSource();
3012 auto Info = Reader->getSourceDescriptor(Idx);
3014 return getOrCreateModuleRef(*Info,
true);
3015 }
else if (ClangModuleMap) {
3029 return getOrCreateModuleRef(Info,
false);
3032 return getOrCreateModuleRef(PCHDescriptor,
false);
3039 llvm::DIType *CGDebugInfo::CreateTypeNode(
QualType Ty, llvm::DIFile *Unit) {
3042 return CreateQualifiedType(Ty, Unit);
3046 #define TYPE(Class, Base) 3047 #define ABSTRACT_TYPE(Class, Base) 3048 #define NON_CANONICAL_TYPE(Class, Base) 3049 #define DEPENDENT_TYPE(Class, Base) case Type::Class: 3050 #include "clang/AST/TypeNodes.inc" 3051 llvm_unreachable(
"Dependent types cannot show up in debug information");
3053 case Type::ExtVector:
3055 return CreateType(cast<VectorType>(Ty), Unit);
3056 case Type::ObjCObjectPointer:
3057 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
3058 case Type::ObjCObject:
3059 return CreateType(cast<ObjCObjectType>(Ty), Unit);
3060 case Type::ObjCTypeParam:
3061 return CreateType(cast<ObjCTypeParamType>(Ty), Unit);
3062 case Type::ObjCInterface:
3063 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
3065 return CreateType(cast<BuiltinType>(Ty));
3067 return CreateType(cast<ComplexType>(Ty));
3069 return CreateType(cast<PointerType>(Ty), Unit);
3070 case Type::BlockPointer:
3071 return CreateType(cast<BlockPointerType>(Ty), Unit);
3073 return CreateType(cast<TypedefType>(Ty), Unit);
3075 return CreateType(cast<RecordType>(Ty));
3077 return CreateEnumType(cast<EnumType>(Ty));
3078 case Type::FunctionProto:
3079 case Type::FunctionNoProto:
3080 return CreateType(cast<FunctionType>(Ty), Unit);
3081 case Type::ConstantArray:
3082 case Type::VariableArray:
3083 case Type::IncompleteArray:
3084 return CreateType(cast<ArrayType>(Ty), Unit);
3086 case Type::LValueReference:
3087 return CreateType(cast<LValueReferenceType>(Ty), Unit);
3088 case Type::RValueReference:
3089 return CreateType(cast<RValueReferenceType>(Ty), Unit);
3091 case Type::MemberPointer:
3092 return CreateType(cast<MemberPointerType>(Ty), Unit);
3095 return CreateType(cast<AtomicType>(Ty), Unit);
3098 return CreateType(cast<PipeType>(Ty), Unit);
3100 case Type::TemplateSpecialization:
3101 return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
3104 case Type::Attributed:
3105 case Type::Adjusted:
3107 case Type::DeducedTemplateSpecialization:
3108 case Type::Elaborated:
3110 case Type::MacroQualified:
3111 case Type::SubstTemplateTypeParm:
3112 case Type::TypeOfExpr:
3114 case Type::Decltype:
3115 case Type::UnaryTransform:
3116 case Type::PackExpansion:
3120 llvm_unreachable(
"type should have been unwrapped!");
3123 llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty,
3124 llvm::DIFile *Unit) {
3127 auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
3132 if (T && !T->isForwardDecl())
3136 llvm::DICompositeType *Res = CreateLimitedType(Ty);
3141 DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
3149 llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
3153 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3155 StringRef RDName = getClassName(RD);
3157 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
3161 auto *T = cast_or_null<llvm::DICompositeType>(
3162 getTypeOrNull(CGM.getContext().getRecordType(RD)));
3170 return getOrCreateRecordFwdDecl(Ty, RDContext);
3172 uint64_t Size = CGM.getContext().getTypeSize(Ty);
3179 auto Flags = llvm::DINode::FlagZero;
3180 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3182 Flags |= llvm::DINode::FlagTypePassByReference;
3184 Flags |= llvm::DINode::FlagTypePassByValue;
3187 if (!CXXRD->isTrivial())
3188 Flags |= llvm::DINode::FlagNonTrivial;
3191 if (CXXRD->isAnonymousStructOrUnion())
3192 Flags |= llvm::DINode::FlagExportSymbols;
3195 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
3196 getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align,
3201 switch (RealDecl->getTag()) {
3203 llvm_unreachable(
"invalid composite type tag");
3205 case llvm::dwarf::DW_TAG_array_type:
3206 case llvm::dwarf::DW_TAG_enumeration_type:
3211 if (Identifier.empty())
3215 case llvm::dwarf::DW_TAG_structure_type:
3216 case llvm::dwarf::DW_TAG_union_type:
3217 case llvm::dwarf::DW_TAG_class_type:
3220 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
3224 RegionMap[Ty->
getDecl()].reset(RealDecl);
3227 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3228 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
3229 CollectCXXTemplateParams(TSpecial, DefUnit));
3233 void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
3234 llvm::DICompositeType *RealDecl) {
3236 llvm::DICompositeType *ContainingType =
nullptr;
3241 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
3248 ContainingType = cast<llvm::DICompositeType>(
3249 getOrCreateType(
QualType(PBase->getTypeForDecl(), 0),
3252 ContainingType = RealDecl;
3254 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
3257 llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit,
QualType FType,
3258 StringRef Name, uint64_t *
Offset) {
3259 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
3260 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
3263 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
3264 *Offset, llvm::DINode::FlagZero, FieldTy);
3265 *Offset += FieldSize;
3269 void CGDebugInfo::collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
3271 StringRef &LinkageName,
3272 llvm::DIScope *&FDContext,
3273 llvm::DINodeArray &TParamsArray,
3274 llvm::DINode::DIFlags &Flags) {
3275 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
3276 Name = getFunctionName(FD);
3279 LinkageName = CGM.getMangledName(GD);
3280 Flags |= llvm::DINode::FlagPrototyped;
3285 if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
3286 !CGM.getCodeGenOpts().EmitGcovNotes &&
3287 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
3289 LinkageName = StringRef();
3291 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
3294 FDContext = getOrCreateNamespace(NSDecl);
3297 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
3298 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
3302 Flags |= llvm::DINode::FlagNoReturn;
3304 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
3308 void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
3310 StringRef &Name, StringRef &LinkageName,
3311 llvm::MDTuple *&TemplateParameters,
3312 llvm::DIScope *&VDContext) {
3319 if (T->isIncompleteArrayType()) {
3322 QualType ET = CGM.getContext().getAsArrayType(T)->getElementType();
3324 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
3331 LinkageName = CGM.getMangledName(VD);
3332 if (LinkageName == Name)
3333 LinkageName = StringRef();
3335 if (isa<VarTemplateSpecializationDecl>(VD)) {
3336 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
3337 TemplateParameters = parameterNodes.get();
3339 TemplateParameters =
nullptr;
3357 DC = CGM.getContext().getTranslationUnitDecl();
3359 llvm::DIScope *Mod = getParentModuleOrNull(VD);
3360 VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
3363 llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(
GlobalDecl GD,
3365 llvm::DINodeArray TParamsArray;
3366 StringRef Name, LinkageName;
3367 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3368 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3370 llvm::DIFile *Unit = getOrCreateFile(Loc);
3371 llvm::DIScope *DContext = Unit;
3372 unsigned Line = getLineNumber(Loc);
3373 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
3375 auto *FD = cast<FunctionDecl>(GD.
getDecl());
3380 ArgTypes.push_back(Parm->getType());
3383 QualType FnType = CGM.getContext().getFunctionType(
3386 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3387 if (CGM.getLangOpts().Optimize)
3388 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3391 Flags |= getCallSiteRelatedAttrs();
3392 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
3393 return DBuilder.createFunction(
3394 DContext, Name, LinkageName, Unit, Line,
3395 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
3396 TParamsArray.get(), getFunctionDeclaration(FD));
3399 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
3400 DContext, Name, LinkageName, Unit, Line,
3401 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
3402 TParamsArray.get(), getFunctionDeclaration(FD));
3404 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
3405 std::make_tuple(CanonDecl),
3406 std::make_tuple(SP));
3410 llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(
GlobalDecl GD) {
3411 return getFunctionFwdDeclOrStub(GD,
false);
3414 llvm::DISubprogram *CGDebugInfo::getFunctionStub(
GlobalDecl GD) {
3415 return getFunctionFwdDeclOrStub(GD,
true);
3418 llvm::DIGlobalVariable *
3419 CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
3421 StringRef Name, LinkageName;
3423 llvm::DIFile *Unit = getOrCreateFile(Loc);
3424 llvm::DIScope *DContext = Unit;
3425 unsigned Line = getLineNumber(Loc);
3426 llvm::MDTuple *TemplateParameters =
nullptr;
3428 collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, TemplateParameters,
3431 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
3432 DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
3434 FwdDeclReplaceMap.emplace_back(
3435 std::piecewise_construct,
3437 std::make_tuple(static_cast<llvm::Metadata *>(GV)));
3441 llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
3446 if (
const auto *TD = dyn_cast<TypeDecl>(D))
3447 return getOrCreateType(CGM.getContext().getTypeDeclType(TD),
3451 if (I != DeclCache.end()) {
3453 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
3454 return GVE->getVariable();
3455 return dyn_cast_or_null<llvm::DINode>(N);
3460 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
3461 return getFunctionForwardDeclaration(FD);
3462 else if (
const auto *VD = dyn_cast<VarDecl>(D))
3463 return getGlobalVariableForwardDeclaration(VD);
3468 llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
3477 auto *S = getDeclContextDescriptor(D);
3480 if (MI == SPCache.end()) {
3482 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
3483 cast<llvm::DICompositeType>(S));
3486 if (MI != SPCache.end()) {
3487 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
3488 if (SP && !SP->isDefinition())
3492 for (
auto NextFD : FD->
redecls()) {
3493 auto MI = SPCache.find(NextFD->getCanonicalDecl());
3494 if (MI != SPCache.end()) {
3495 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
3496 if (SP && !SP->isDefinition())
3503 llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
3504 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
3505 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
3513 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
3517 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
3527 auto It = TypeCache.find(QTy.getAsOpaquePtr());
3528 if (It == TypeCache.end())
3530 auto *InterfaceType = cast<llvm::DICompositeType>(It->second);
3531 llvm::DISubprogram *FD = DBuilder.createFunction(
3532 InterfaceType, getObjCMethodName(OMD), StringRef(),
3533 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
3534 DBuilder.finalizeSubprogram(FD);
3541 llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
3547 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
3549 if (
const auto *Method = dyn_cast<CXXMethodDecl>(D))
3550 return getOrCreateMethodType(Method, F);
3555 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
3560 QualType ResultTy = OMethod->getReturnType();
3563 if (ResultTy == CGM.getContext().getObjCInstanceType())
3564 ResultTy = CGM.getContext().getPointerType(
3565 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
3567 Elts.push_back(getOrCreateType(ResultTy, F));
3570 if (
auto *SelfDecl = OMethod->getSelfDecl())
3571 SelfDeclTy = SelfDecl->getType();
3572 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
3573 if (FPT->getNumParams() > 1)
3574 SelfDeclTy = FPT->getParamType(0);
3575 if (!SelfDeclTy.
isNull())
3577 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
3579 Elts.push_back(DBuilder.createArtificialType(
3580 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
3582 for (
const auto *PI : OMethod->parameters())
3583 Elts.push_back(getOrCreateType(PI->getType(), F));
3585 if (OMethod->isVariadic())
3586 Elts.push_back(DBuilder.createUnspecifiedParameter());
3588 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
3589 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
3595 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
3599 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
3600 for (
QualType ParamType : FPT->param_types())
3601 EltTys.push_back(getOrCreateType(ParamType, F));
3602 EltTys.push_back(DBuilder.createUnspecifiedParameter());
3603 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
3604 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
3608 return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
3613 llvm::Function *Fn,
bool CurFuncIsThunk,
3617 StringRef LinkageName;
3619 FnBeginRegionCount.push_back(LexicalBlockStack.size());
3622 bool HasDecl = (D !=
nullptr);
3624 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3625 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3626 llvm::DIFile *Unit = getOrCreateFile(Loc);
3627 llvm::DIScope *FDContext = Unit;
3628 llvm::DINodeArray TParamsArray;
3631 LinkageName = Fn->getName();
3632 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
3635 if (FI != SPCache.end()) {
3636 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
3637 if (SP && SP->isDefinition()) {
3638 LexicalBlockStack.emplace_back(SP);
3639 RegionMap[D].reset(SP);
3643 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
3644 TParamsArray, Flags);
3645 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
3646 Name = getObjCMethodName(OMD);
3647 Flags |= llvm::DINode::FlagPrototyped;
3648 }
else if (isa<VarDecl>(D) &&
3655 Name = Fn->getName();
3656 Flags |= llvm::DINode::FlagPrototyped;
3658 if (Name.startswith(
"\01"))
3659 Name = Name.substr(1);
3662 Flags |= llvm::DINode::FlagArtificial;
3668 Flags |= llvm::DINode::FlagThunk;
3670 if (Fn->hasLocalLinkage())
3671 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
3672 if (CGM.getLangOpts().Optimize)
3673 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3675 llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
3676 llvm::DISubprogram::DISPFlags SPFlagsForDef =
3677 SPFlags | llvm::DISubprogram::SPFlagDefinition;
3679 unsigned LineNo = getLineNumber(Loc);
3680 unsigned ScopeLine = getLineNumber(ScopeLoc);
3681 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
3682 llvm::DISubprogram *
Decl =
nullptr;
3684 Decl = isa<ObjCMethodDecl>(D)
3685 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
3686 : getFunctionDeclaration(D);
3693 llvm::DISubprogram *SP = DBuilder.createFunction(
3694 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
3695 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl);
3696 Fn->setSubprogram(SP);
3700 if (HasDecl && isa<FunctionDecl>(D))
3704 LexicalBlockStack.emplace_back(SP);
3707 RegionMap[D].reset(SP);
3711 QualType FnType, llvm::Function *Fn) {
3713 StringRef LinkageName;
3719 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
3721 llvm::raw_string_ostream OS(Name);
3722 if (
const NamedDecl *ND = dyn_cast<NamedDecl>(D))
3723 ND->getNameForDiagnostic(OS, getPrintingPolicy(),
3728 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3729 llvm::DIFile *Unit = getOrCreateFile(Loc);
3730 bool IsDeclForCallSite = Fn ?
true :
false;
3731 llvm::DIScope *FDContext =
3732 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
3733 llvm::DINodeArray TParamsArray;
3734 if (isa<FunctionDecl>(D)) {
3736 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
3737 TParamsArray, Flags);
3738 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
3739 Name = getObjCMethodName(OMD);
3740 Flags |= llvm::DINode::FlagPrototyped;
3742 llvm_unreachable(
"not a function or ObjC method");
3744 if (!Name.empty() && Name[0] ==
'\01')
3745 Name = Name.substr(1);
3748 Flags |= llvm::DINode::FlagArtificial;
3753 unsigned LineNo = getLineNumber(Loc);
3754 unsigned ScopeLine = 0;
3755 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
3756 if (CGM.getLangOpts().Optimize)
3757 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
3759 llvm::DISubprogram *SP = DBuilder.createFunction(
3760 FDContext, Name, LinkageName, Unit, LineNo,
3761 getOrCreateFunctionType(D, FnType, Unit), ScopeLine, Flags, SPFlags,
3762 TParamsArray.get(), getFunctionDeclaration(D));
3764 if (IsDeclForCallSite)
3765 Fn->setSubprogram(SP);
3767 DBuilder.retainType(SP);
3775 auto *Func = CallOrInvoke->getCalledFunction();
3778 if (Func->getSubprogram())
3787 getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
3790 if (
Id->isReservedName())
3797 EmitFunctionDecl(CalleeDecl, CalleeDecl->
getLocation(), CalleeType, Func);
3801 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
3804 llvm::DISubprogram *SP =
nullptr;
3805 if (FI != SPCache.end())
3806 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
3807 if (!SP || !SP->isDefinition())
3808 SP = getFunctionStub(GD);
3809 FnBeginRegionCount.push_back(LexicalBlockStack.size());
3810 LexicalBlockStack.emplace_back(SP);
3811 setInlinedAt(Builder.getCurrentDebugLocation());
3816 assert(CurInlinedAt &&
"unbalanced inline scope stack");
3817 EmitFunctionEnd(Builder,
nullptr);
3818 setInlinedAt(llvm::DebugLoc(CurInlinedAt).getInlinedAt());
3825 if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
3828 llvm::MDNode *
Scope = LexicalBlockStack.back();
3829 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
3830 getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope, CurInlinedAt));
3834 llvm::MDNode *Back =
nullptr;
3835 if (!LexicalBlockStack.empty())
3836 Back = LexicalBlockStack.back().get();
3837 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
3838 cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
3839 getColumnNumber(CurLoc)));
3842 void CGDebugInfo::AppendAddressSpaceXDeref(
3845 CGM.getTarget().getDWARFAddressSpace(AddressSpace);
3846 if (!DWARFAddressSpace)
3849 Expr.push_back(llvm::dwarf::DW_OP_constu);
3850 Expr.push_back(DWARFAddressSpace.getValue());
3851 Expr.push_back(llvm::dwarf::DW_OP_swap);
3852 Expr.push_back(llvm::dwarf::DW_OP_xderef);
3861 Builder.SetCurrentDebugLocation(
3862 llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc),
3863 LexicalBlockStack.back(), CurInlinedAt));
3869 CreateLexicalBlock(Loc);
3874 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3882 LexicalBlockStack.pop_back();
3886 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3887 unsigned RCount = FnBeginRegionCount.back();
3888 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
3891 while (LexicalBlockStack.size() != RCount) {
3894 LexicalBlockStack.pop_back();
3896 FnBeginRegionCount.pop_back();
3898 if (Fn && Fn->getSubprogram())
3899 DBuilder.finalizeSubprogram(Fn->getSubprogram());
3902 CGDebugInfo::BlockByRefType
3903 CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
3904 uint64_t *XOffset) {
3907 uint64_t FieldSize, FieldOffset;
3908 uint32_t FieldAlign;
3910 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
3914 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3915 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
3916 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
3917 FType = CGM.getContext().IntTy;
3918 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
3919 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
3921 bool HasCopyAndDispose = CGM.getContext().BlockRequiresCopying(Type, VD);
3922 if (HasCopyAndDispose) {
3923 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3925 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
3927 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
3929 bool HasByrefExtendedLayout;
3931 if (CGM.getContext().getByrefLifetime(Type, Lifetime,
3932 HasByrefExtendedLayout) &&
3933 HasByrefExtendedLayout) {
3934 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
3936 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
3939 CharUnits Align = CGM.getContext().getDeclAlign(VD);
3940 if (Align > CGM.getContext().toCharUnitsFromBits(
3941 CGM.getTarget().getPointerAlign(0))) {
3943 CGM.getContext().toCharUnitsFromBits(FieldOffset);
3945 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
3949 FType = CGM.getContext().getConstantArrayType(
3951 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
3956 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
3957 FieldSize = CGM.getContext().getTypeSize(FType);
3958 FieldAlign = CGM.getContext().toBits(Align);
3960 *XOffset = FieldOffset;
3961 llvm::DIType *FieldTy = DBuilder.createMemberType(
3962 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
3963 llvm::DINode::FlagZero, WrappedTy);
3964 EltTys.push_back(FieldTy);
3965 FieldOffset += FieldSize;
3967 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3968 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
3969 llvm::DINode::FlagZero,
nullptr, Elements),
3973 llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
3977 const bool UsePointerValue) {
3978 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3979 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3980 if (VD->
hasAttr<NoDebugAttr>())
3986 llvm::DIFile *Unit =
nullptr;
3990 uint64_t XOffset = 0;
3991 if (VD->
hasAttr<BlocksAttr>())
3992 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
3994 Ty = getOrCreateType(VD->
getType(), Unit);
4003 unsigned Column = 0;
4009 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4011 Flags |= llvm::DINode::FlagArtificial;
4015 unsigned AddressSpace = CGM.getContext().getTargetAddressSpace(VD->
getType());
4016 AppendAddressSpaceXDeref(AddressSpace, Expr);
4020 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
4023 Flags |= llvm::DINode::FlagObjectPointer;
4030 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
4031 StringRef Name = VD->
getName();
4032 if (!Name.empty()) {
4033 if (VD->
hasAttr<BlocksAttr>()) {
4036 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4038 offset = CGM.getContext().toCharUnitsFromBits(
4039 CGM.getTarget().getPointerWidth(0));
4041 Expr.push_back(llvm::dwarf::DW_OP_deref);
4042 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4044 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
4047 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
4059 for (
const auto *Field : RD->
fields()) {
4060 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
4061 StringRef FieldName = Field->getName();
4064 if (FieldName.empty() && !isa<RecordType>(Field->getType()))
4069 auto *D = DBuilder.createAutoVariable(
4070 Scope, FieldName, Unit, Line, FieldTy, CGM.getLangOpts().Optimize,
4071 Flags | llvm::DINode::FlagArtificial, FieldAlign);
4074 DBuilder.insertDeclare(
4075 Storage, D, DBuilder.createExpression(Expr),
4076 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4077 Builder.GetInsertBlock());
4085 if (UsePointerValue) {
4086 assert(std::find(Expr.begin(), Expr.end(), llvm::dwarf::DW_OP_deref) ==
4088 "Debug info already contains DW_OP_deref.");
4089 Expr.push_back(llvm::dwarf::DW_OP_deref);
4093 auto *D = ArgNo ? DBuilder.createParameterVariable(
4094 Scope, Name, *ArgNo, Unit, Line, Ty,
4095 CGM.getLangOpts().Optimize, Flags)
4096 : DBuilder.createAutoVariable(
Scope, Name, Unit, Line, Ty,
4097 CGM.getLangOpts().Optimize,
4101 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
4102 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4103 Builder.GetInsertBlock());
4108 llvm::DILocalVariable *
4111 const bool UsePointerValue) {
4112 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4113 return EmitDeclare(VD, Storage,
llvm::None, Builder, UsePointerValue);
4117 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4118 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4120 if (D->
hasAttr<NoDebugAttr>())
4123 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
4124 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
4128 unsigned Column = getColumnNumber(D->
getLocation());
4130 StringRef Name = D->
getName();
4134 DBuilder.createLabel(
Scope, Name, Unit, Line, CGM.getLangOpts().Optimize);
4137 DBuilder.insertLabel(L,
4138 llvm::DebugLoc::get(Line, Column,
Scope, CurInlinedAt),
4139 Builder.GetInsertBlock());
4142 llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
4144 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
4147 return DBuilder.createObjectPointerType(Ty);
4152 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
4153 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4154 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4156 if (Builder.GetInsertBlock() ==
nullptr)
4158 if (VD->
hasAttr<NoDebugAttr>())
4161 bool isByRef = VD->
hasAttr<BlocksAttr>();
4163 uint64_t XOffset = 0;
4164 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
4167 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
4169 Ty = getOrCreateType(VD->
getType(), Unit);
4173 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
4175 Ty = CreateSelfType(VD->
getType(), Ty);
4179 unsigned Column = getColumnNumber(VD->
getLocation());
4181 const llvm::DataLayout &target = CGM.getDataLayout();
4188 addr.push_back(llvm::dwarf::DW_OP_deref);
4189 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4192 addr.push_back(llvm::dwarf::DW_OP_deref);
4193 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4196 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
4198 addr.push_back(llvm::dwarf::DW_OP_deref);
4199 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4201 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
4207 auto *D = DBuilder.createAutoVariable(
4208 cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->
getName(), Unit,
4209 Line, Ty,
false, llvm::DINode::FlagZero, Align);
4213 llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back(), CurInlinedAt);
4214 auto *Expr = DBuilder.createExpression(addr);
4216 DBuilder.insertDeclare(Storage, D, Expr, DL, InsertPoint);
4218 DBuilder.insertDeclare(Storage, D, Expr, DL, Builder.GetInsertBlock());
4224 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4225 EmitDeclare(VD, AI, ArgNo, Builder);
4229 struct BlockLayoutChunk {
4230 uint64_t OffsetInBits;
4233 bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
4234 return l.OffsetInBits < r.OffsetInBits;
4238 void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
4240 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
4245 if (CGM.getLangOpts().OpenCL) {
4246 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
4247 BlockLayout.getElementOffsetInBits(0),
4249 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
4250 BlockLayout.getElementOffsetInBits(1),
4254 BlockLayout.getElementOffsetInBits(0),
4256 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
4257 BlockLayout.getElementOffsetInBits(1),
4261 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
4263 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
4264 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
4265 BlockLayout.getElementOffsetInBits(3),
4267 Fields.push_back(createFieldType(
4272 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
4279 llvm::AllocaInst *Alloca,
4281 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4287 llvm::DIFile *tunit = getOrCreateFile(loc);
4288 unsigned line = getLineNumber(loc);
4289 unsigned column = getColumnNumber(loc);
4292 getDeclContextDescriptor(blockDecl);
4294 const llvm::StructLayout *blockLayout =
4298 collectDefaultFieldsForBlockLiteralDeclare(block, C, loc, *blockLayout, tunit,
4307 BlockLayoutChunk chunk;
4308 chunk.OffsetInBits =
4309 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
4310 chunk.Capture =
nullptr;
4311 chunks.push_back(chunk);
4315 for (
const auto &capture : blockDecl->
captures()) {
4316 const VarDecl *variable = capture.getVariable();
4323 BlockLayoutChunk chunk;
4324 chunk.OffsetInBits =
4325 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
4326 chunk.Capture = &capture;
4327 chunks.push_back(chunk);
4331 llvm::array_pod_sort(chunks.begin(), chunks.end());
4333 for (
const BlockLayoutChunk &Chunk : chunks) {
4334 uint64_t offsetInBits = Chunk.OffsetInBits;
4343 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->
getParent()))
4344 type =
QualType(RDecl->getTypeForDecl(), 0);
4346 llvm_unreachable(
"unexpected block declcontext");
4348 fields.push_back(createFieldType(
"this", type, loc,
AS_public,
4349 offsetInBits, tunit, tunit));
4356 llvm::DIType *fieldType;
4358 TypeInfo PtrInfo = C.getTypeInfo(C.VoidPtrTy);
4363 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
4364 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
4365 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
4366 PtrInfo.
Width, Align, offsetInBits,
4367 llvm::DINode::FlagZero, fieldType);
4371 offsetInBits, Align, tunit, tunit);
4373 fields.push_back(fieldType);
4377 llvm::raw_svector_ostream(typeName)
4378 <<
"__block_literal_" << CGM.getUniqueBlockCount();
4380 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
4382 llvm::DIType *type =
4383 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
4384 CGM.getContext().toBits(block.
BlockSize), 0,
4385 llvm::DINode::FlagZero,
nullptr, fieldsArray);
4386 type = DBuilder.createPointerType(type, CGM.PointerWidthInBits);
4389 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
4390 auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
4393 auto *debugVar = DBuilder.createParameterVariable(
4394 scope, Name, ArgNo, tunit, line, type, CGM.getLangOpts().Optimize, flags);
4397 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
4398 llvm::DebugLoc::get(line, column, scope, CurInlinedAt),
4399 Builder.GetInsertBlock());
4402 llvm::DIDerivedType *
4403 CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
4408 if (MI != StaticDataMemberCache.end()) {
4409 assert(MI->second &&
"Static data member declaration should still exist");
4416 auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D));
4417 return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC));
4420 llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
4421 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
4422 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
4423 llvm::DIGlobalVariableExpression *GVE =
nullptr;
4425 for (
const auto *Field : RD->
fields()) {
4426 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
4427 StringRef FieldName = Field->getName();
4430 if (FieldName.empty()) {
4431 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
4432 GVE = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
4437 GVE = DBuilder.createGlobalVariableExpression(
4438 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
4439 Var->hasLocalLinkage());
4440 Var->addDebugInfo(GVE);
4447 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4448 if (D->
hasAttr<NoDebugAttr>())
4451 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
4453 llvm::raw_string_ostream OS(Name);
4462 if (Cached != DeclCache.end())
4463 return Var->addDebugInfo(
4464 cast<llvm::DIGlobalVariableExpression>(Cached->second));
4467 llvm::DIFile *Unit =
nullptr;
4468 llvm::DIScope *DContext =
nullptr;
4470 StringRef DeclName, LinkageName;
4472 llvm::MDTuple *TemplateParameters =
nullptr;
4473 collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName,
4474 TemplateParameters, DContext);
4478 llvm::DIGlobalVariableExpression *GVE =
nullptr;
4486 "unnamed non-anonymous struct or union?");
4487 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
4492 unsigned AddressSpace =
4493 CGM.getContext().getTargetAddressSpace(D->
getType());
4494 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
4495 if (D->
hasAttr<CUDASharedAttr>())
4498 else if (D->
hasAttr<CUDAConstantAttr>())
4502 AppendAddressSpaceXDeref(AddressSpace, Expr);
4504 GVE = DBuilder.createGlobalVariableExpression(
4505 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
4506 Var->hasLocalLinkage(),
true,
4507 Expr.empty() ? nullptr : DBuilder.createExpression(Expr),
4508 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
4510 Var->addDebugInfo(GVE);
4516 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4517 if (VD->
hasAttr<NoDebugAttr>())
4519 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
4521 llvm::raw_string_ostream OS(Name);
4529 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
4530 StringRef Name = VD->
getName();
4531 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
4533 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
4534 const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
4535 assert(isa<EnumType>(ED->getTypeForDecl()) &&
"Enum without EnumType?");
4537 if (CGM.getCodeGenOpts().EmitCodeView) {
4542 if (isa<RecordDecl>(ED->getDeclContext()))
4548 llvm::DIType *EDTy =
4549 getOrCreateType(
QualType(ED->getTypeForDecl(), 0), Unit);
4550 assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
4556 llvm::DIScope *DContext =
nullptr;
4564 auto *VarD = dyn_cast<
VarDecl>(VD);
4565 if (VarD && VarD->isStaticDataMember()) {
4566 auto *RD = cast<RecordDecl>(VarD->getDeclContext());
4567 getDeclContextDescriptor(VarD);
4572 RetainedTypes.push_back(
4573 CGM.getContext().getRecordType(RD).getAsOpaquePtr());
4575 if (!CGM.getCodeGenOpts().EmitCodeView)
4579 DContext = getContextDescriptor(
4580 cast<Decl>(CGM.getContext().getTranslationUnitDecl()), TheCU);
4582 DContext = getDeclContextDescriptor(VD);
4585 auto &GV = DeclCache[VD];
4588 llvm::DIExpression *InitExpr =
nullptr;
4589 if (CGM.getContext().getTypeSize(VD->
getType()) <= 64) {
4593 DBuilder.createConstantValueExpression(Init.
getInt().getExtValue());
4595 InitExpr = DBuilder.createConstantValueExpression(
4596 Init.
getFloat().bitcastToAPInt().getZExtValue());
4599 llvm::MDTuple *TemplateParameters =
nullptr;
4601 if (isa<VarTemplateSpecializationDecl>(VD))
4603 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
4604 TemplateParameters = parameterNodes.get();
4607 GV.reset(DBuilder.createGlobalVariableExpression(
4608 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
4609 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
4610 TemplateParameters, Align));
4615 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
4616 if (D->
hasAttr<NoDebugAttr>())
4620 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
4621 StringRef Name = D->
getName();
4622 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
4624 llvm::DIScope *DContext = getDeclContextDescriptor(D);
4625 llvm::DIGlobalVariableExpression *GVE =
4626 DBuilder.createGlobalVariableExpression(
4627 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
4628 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
4629 Var->addDebugInfo(GVE);
4632 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
4633 if (!LexicalBlockStack.empty())
4634 return LexicalBlockStack.back();
4635 llvm::DIScope *Mod = getParentModuleOrNull(D);
4636 return getContextDescriptor(D, Mod ? Mod : TheCU);
4640 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
4644 CGM.getCodeGenOpts().DebugExplicitImport) {
4646 DBuilder.createImportedModule(
4648 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
4653 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
4656 "We shouldn't be codegening an invalid UsingDecl containing no decls");
4665 if (
const auto *FD = dyn_cast<FunctionDecl>(USD.getUnderlyingDecl()))
4666 if (
const auto *AT =
4668 if (AT->getDeducedType().isNull())
4670 if (llvm::DINode *
Target =
4671 getDeclarationOrDefinition(USD.getUnderlyingDecl())) {
4672 auto Loc = USD.getLocation();
4673 DBuilder.createImportedDeclaration(
4674 getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())),
Target,
4675 getOrCreateFile(Loc), getLineNumber(Loc));
4680 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
4685 DBuilder.createImportedDeclaration(
4687 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
4688 getLineNumber(Loc));
4692 llvm::DIImportedEntity *
4694 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
4696 auto &VH = NamespaceAliasCache[&NA];
4698 return cast<llvm::DIImportedEntity>(VH);
4699 llvm::DIImportedEntity *R;
4701 if (
const auto *Underlying =
4704 R = DBuilder.createImportedDeclaration(
4706 EmitNamespaceAlias(*Underlying), getOrCreateFile(Loc),
4707 getLineNumber(Loc), NA.
getName());
4709 R = DBuilder.createImportedDeclaration(
4712 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
4718 CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
4722 auto I = NamespaceCache.find(NSDecl);
4723 if (I != NamespaceCache.end())
4724 return cast<llvm::DINamespace>(I->second);
4726 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
4728 llvm::DINamespace *NS =
4729 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
4730 NamespaceCache[NSDecl].reset(NS);
4735 assert(TheCU &&
"no main compile unit");
4736 TheCU->setDWOId(Signature);
4742 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
4743 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
4744 llvm::DIType *Ty = E.
Type->getDecl()->getDefinition()
4745 ? CreateTypeDefinition(E.Type, E.Unit)
4747 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
4751 for (
const auto &
P : ObjCMethodCache) {
4752 if (
P.second.empty())
4755 QualType QTy(
P.first->getTypeForDecl(), 0);
4756 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4757 assert(It != TypeCache.end());
4759 llvm::DICompositeType *InterfaceDecl =
4760 cast<llvm::DICompositeType>(It->second);
4762 auto CurElts = InterfaceDecl->getElements();
4766 for (
auto &SubprogramDirect :
P.second)
4767 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
4768 EltTys.push_back(SubprogramDirect.getPointer());
4770 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
4771 DBuilder.replaceArrays(InterfaceDecl, Elements);
4774 for (
const auto &
P : ReplaceMap) {
4776 auto *Ty = cast<llvm::DIType>(
P.second);
4777 assert(Ty->isForwardDecl());
4779 auto It = TypeCache.find(
P.first);
4780 assert(It != TypeCache.end());
4783 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
4784 cast<llvm::DIType>(It->second));
4787 for (
const auto &
P : FwdDeclReplaceMap) {
4789 llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(
P.second));
4790 llvm::Metadata *Repl;
4792 auto It = DeclCache.find(
P.first);
4796 if (It == DeclCache.end())
4801 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
4802 Repl = GVE->getVariable();
4803 DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
4808 for (
auto &RT : RetainedTypes)
4809 if (
auto MD = TypeCache[RT])
4810 DBuilder.retainType(cast<llvm::DIType>(MD));
4812 DBuilder.finalize();
4816 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
4819 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
4821 DBuilder.retainType(DieTy);
4825 if (LexicalBlockStack.empty())
4826 return llvm::DebugLoc();
4828 llvm::MDNode *
Scope = LexicalBlockStack.back();
4829 return llvm::DebugLoc::get(getLineNumber(Loc), getColumnNumber(Loc), Scope);
4832 llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs()
const {
4837 return llvm::DINode::FlagZero;
4842 bool SupportsDWARFv4Ext =
4843 CGM.getCodeGenOpts().DwarfVersion == 4 &&
4844 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
4845 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
4847 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5 &&
4848 !CGM.getCodeGenOpts().EnableDebugEntryValues)
4849 return llvm::DINode::FlagZero;
4851 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 ...
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
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...
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
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.
Represents a C++ constructor within a class.
float __ovld __cnfn distance(float p0, float p1)
Returns the distance between p0 and p1.
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>'.
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
Don't generate debug info.
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.
bool isMoveAssignmentOperator() const
Determine whether this is a move assignment operator.
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.
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about an external variable.
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.
bool isDirectMethod() const
True if the method is tagged as objc_direct.
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 only debug directives with the line numbers data.
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.
unsigned getBuiltinID(bool ConsiderWrapperFunctions=false) const
Returns a value indicating whether this function corresponds to a builtin function.
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
Limit generated debug info to reduce size (-fno-standalone-debug).
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.
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.
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.
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...
Generate complete debug info.
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.
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.
Limit generated debug info for classes to reduce size.
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 info necessary for generating line number tables (-gline-tables-only).
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.
bool isCopyAssignmentOperator() const
Determine whether this is a copy-assignment operator, regardless of whether it was declared implicitl...
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.
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.
Emit location information but do not generate debug info in the output.
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
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...
bool isDeleted() const
Whether this function has been deleted.
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.
This represents a decl that may have a name.
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 RecordDecl *RD)
Does a type definition exist in an imported clang module?
Represents C++ using-directive.
void removeAddressSpace()
MSInheritanceModel getMSInheritanceModel() const
Returns the inheritance model used for this record.
bool isObjCZeroArgSelector() const
base_class_range vbases()
This class handles loading and caching of source files into memory.
SourceLocation getLocation() const
QualType getPointeeType() const
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
bool isExternallyVisible() const
Structure with information about how a bitfield should be accessed.
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
method_range methods() const