41#include "llvm/ADT/DenseSet.h"
42#include "llvm/ADT/SmallVector.h"
43#include "llvm/ADT/StringExtras.h"
44#include "llvm/IR/Constants.h"
45#include "llvm/IR/DataLayout.h"
46#include "llvm/IR/DerivedTypes.h"
47#include "llvm/IR/Instructions.h"
48#include "llvm/IR/Intrinsics.h"
49#include "llvm/IR/Metadata.h"
50#include "llvm/IR/Module.h"
51#include "llvm/Support/FileSystem.h"
52#include "llvm/Support/MD5.h"
53#include "llvm/Support/Path.h"
54#include "llvm/Support/SHA1.h"
55#include "llvm/Support/SHA256.h"
56#include "llvm/Support/TimeProfiler.h"
63 if (TI.isAlignRequired())
91 llvm::dyn_cast_or_null<DeclRefExpr>(
Init->IgnoreUnlessSpelledInSource());
95 return llvm::dyn_cast_or_null<DecompositionDecl>(RefExpr->getDecl());
113 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
114 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
115 DBuilder(CGM.getModule()) {
120 assert(LexicalBlockStack.empty() &&
121 "Region stack mismatch, stack not empty!");
127 init(TemporaryLocation);
134 init(TemporaryLocation, DefaultToEmpty);
138 bool DefaultToEmpty) {
145 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
147 if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
150 if (TemporaryLocation.
isValid()) {
151 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
155 if (DefaultToEmpty) {
156 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
161 assert(!DI->LexicalBlockStack.empty());
162 CGF->
Builder.SetCurrentDebugLocation(
163 llvm::DILocation::get(DI->LexicalBlockStack.back()->getContext(), 0, 0,
164 DI->LexicalBlockStack.back(), DI->getInlinedAt()));
178 OriginalLocation = CGF.
Builder.getCurrentDebugLocation();
180 CGF.
Builder.SetCurrentDebugLocation(std::move(
Loc));
187 CGF->
Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
198 SavedLocation = DI.getLocation();
199 assert((DI.getInlinedAt() ==
200 CGF.
Builder.getCurrentDebugLocation()->getInlinedAt()) &&
201 "CGDebugInfo and IRBuilder are out of sync");
203 DI.EmitInlineFunctionStart(CGF.
Builder, InlinedFn);
211 DI.EmitLocation(CGF->
Builder, SavedLocation);
224 if (LexicalBlockStack.empty())
228 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
230 if (PCLoc.
isInvalid() ||
Scope->getFile() == getOrCreateFile(CurLoc))
233 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
234 LexicalBlockStack.pop_back();
235 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
236 LBF->getScope(), getOrCreateFile(CurLoc)));
237 }
else if (isa<llvm::DILexicalBlock>(
Scope) ||
238 isa<llvm::DISubprogram>(
Scope)) {
239 LexicalBlockStack.pop_back();
240 LexicalBlockStack.emplace_back(
241 DBuilder.createLexicalBlockFile(
Scope, getOrCreateFile(CurLoc)));
245llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *
D) {
246 llvm::DIScope *Mod = getParentModuleOrNull(
D);
251llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *Context,
256 auto I = RegionMap.find(Context);
257 if (I != RegionMap.end()) {
258 llvm::Metadata *
V = I->second;
259 return dyn_cast_or_null<llvm::DIScope>(
V);
263 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
264 return getOrCreateNamespace(NSDecl);
266 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
267 if (!RDecl->isDependentType())
301StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD) {
302 return internString(GetName(FD));
305StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
307 llvm::raw_svector_ostream OS(MethodName);
310 if (
const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
311 OS << OID->getName();
312 }
else if (
const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
313 OS << OID->getName();
314 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
315 if (OC->IsClassExtension()) {
316 OS << OC->getClassInterface()->getName();
318 OS << OC->getIdentifier()->getNameStart() <<
'('
319 << OC->getIdentifier()->getNameStart() <<
')';
321 }
else if (
const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
322 OS << OCD->getClassInterface()->getName() <<
'(' << OCD->getName() <<
')';
326 return internString(OS.str());
329StringRef CGDebugInfo::getSelectorName(
Selector S) {
330 return internString(S.getAsString());
333StringRef CGDebugInfo::getClassName(
const RecordDecl *RD) {
334 if (isa<ClassTemplateSpecializationDecl>(RD)) {
336 return internString(GetName(RD));
342 return II->getName();
350 "Typedef should not be in another decl context!");
351 assert(
D->getDeclName().getAsIdentifierInfo() &&
352 "Typedef was not named!");
353 return D->getDeclName().getAsIdentifierInfo()->getName();
363 Name = DD->getName();
368 Name = TND->getName();
371 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
372 if (CXXRD->isLambda())
380 return internString(UnnamedType);
388std::optional<llvm::DIFile::ChecksumKind>
397 std::optional<llvm::MemoryBufferRef> MemBuffer =
SM.getBufferOrNone(FID);
401 auto Data = llvm::arrayRefFromStringRef(MemBuffer->getBuffer());
404 llvm::toHex(llvm::MD5::hash(
Data),
true, Checksum);
405 return llvm::DIFile::CSK_MD5;
407 llvm::toHex(llvm::SHA1::hash(
Data),
true, Checksum);
408 return llvm::DIFile::CSK_SHA1;
410 llvm::toHex(llvm::SHA256::hash(
Data),
true, Checksum);
411 return llvm::DIFile::CSK_SHA256;
413 llvm_unreachable(
"Unhandled DebugSrcHashKind enum");
416std::optional<StringRef> CGDebugInfo::getSource(
const SourceManager &
SM,
421 bool SourceInvalid =
false;
422 StringRef Source =
SM.getBufferData(FID, &SourceInvalid);
434 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
440 FileName = TheCU->getFile()->getFilename();
441 CSInfo = TheCU->getFile()->getChecksum();
447 FileName = TheCU->getFile()->getFilename();
455 auto It = DIFileCache.find(
FileName.data());
456 if (It != DIFileCache.end()) {
458 if (llvm::Metadata *
V = It->second)
459 return cast<llvm::DIFile>(
V);
465 std::optional<llvm::DIFile::ChecksumKind> CSKind =
466 computeChecksum(FID, Checksum);
468 CSInfo.emplace(*CSKind, Checksum);
473llvm::DIFile *CGDebugInfo::createFile(
475 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
476 std::optional<StringRef> Source) {
480 std::string CurDir =
remapDIPath(getCurrentDirname());
483 if (llvm::sys::path::is_absolute(RemappedFile)) {
486 auto FileIt = llvm::sys::path::begin(RemappedFile);
487 auto FileE = llvm::sys::path::end(RemappedFile);
488 auto CurDirIt = llvm::sys::path::begin(CurDir);
489 auto CurDirE = llvm::sys::path::end(CurDir);
490 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
491 llvm::sys::path::append(DirBuf, *CurDirIt);
492 if (llvm::sys::path::root_path(DirBuf) == DirBuf) {
498 for (; FileIt != FileE; ++FileIt)
499 llvm::sys::path::append(FileBuf, *FileIt);
504 if (!llvm::sys::path::is_absolute(
FileName))
508 llvm::DIFile *F = DBuilder.createFile(
File, Dir, CSInfo, Source);
509 DIFileCache[
FileName.data()].reset(F);
516 if (llvm::sys::path::replace_path_prefix(
P, From, To))
518 return P.str().str();
525 return SM.getPresumedLoc(
Loc).getLine();
541StringRef CGDebugInfo::getCurrentDirname() {
545 if (!CWDName.empty())
547 llvm::ErrorOr<std::string> CWD =
551 return CWDName = internString(*CWD);
554void CGDebugInfo::CreateCompileUnit() {
556 std::optional<llvm::DIFile::ChecksumKind> CSKind;
557 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
570 std::string MainFileName = CGO.MainFileName;
571 if (MainFileName.empty())
572 MainFileName =
"<stdin>";
578 std::string MainFileDir;
580 SM.getFileEntryRefForID(
SM.getMainFileID())) {
581 MainFileDir = std::string(MainFile->getDir().getName());
582 if (!llvm::sys::path::is_absolute(MainFileName)) {
584 llvm::sys::path::Style Style =
587 ? llvm::sys::path::Style::windows_backslash
588 : llvm::sys::path::Style::posix)
589 : llvm::sys::path::Style::native;
590 llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
591 MainFileName = std::string(
592 llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
599 if (MainFile->getName() == MainFileName &&
601 MainFile->getName().rsplit(
'.').second)
603 MainFileName = CGM.
getModule().getName().str();
605 CSKind = computeChecksum(
SM.getMainFileID(), Checksum);
609 llvm::dwarf::SourceLanguage LangTag;
612 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
613 else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
614 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
615 else if (LO.CPlusPlus14)
616 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
617 else if (LO.CPlusPlus11)
618 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
620 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
621 }
else if (LO.ObjC) {
622 LangTag = llvm::dwarf::DW_LANG_ObjC;
623 }
else if (LO.OpenCL && (!CGM.
getCodeGenOpts().DebugStrictDwarf ||
625 LangTag = llvm::dwarf::DW_LANG_OpenCL;
626 }
else if (LO.RenderScript) {
627 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
628 }
else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
629 LangTag = llvm::dwarf::DW_LANG_C11;
631 LangTag = llvm::dwarf::DW_LANG_C99;
633 LangTag = llvm::dwarf::DW_LANG_C89;
639 unsigned RuntimeVers = 0;
643 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
645 case llvm::codegenoptions::NoDebugInfo:
646 case llvm::codegenoptions::LocTrackingOnly:
647 EmissionKind = llvm::DICompileUnit::NoDebug;
649 case llvm::codegenoptions::DebugLineTablesOnly:
650 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
652 case llvm::codegenoptions::DebugDirectivesOnly:
653 EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
655 case llvm::codegenoptions::DebugInfoConstructor:
656 case llvm::codegenoptions::LimitedDebugInfo:
657 case llvm::codegenoptions::FullDebugInfo:
658 case llvm::codegenoptions::UnusedTypeInfo:
659 EmissionKind = llvm::DICompileUnit::FullDebug;
670 CSInfo.emplace(*CSKind, Checksum);
671 llvm::DIFile *CUFile = DBuilder.createFile(
673 getSource(
SM,
SM.getMainFileID()));
675 StringRef Sysroot, SDK;
676 if (CGM.
getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
678 auto B = llvm::sys::path::rbegin(Sysroot);
679 auto E = llvm::sys::path::rend(Sysroot);
681 std::find_if(B,
E, [](
auto SDK) {
return SDK.ends_with(
".sdk"); });
686 llvm::DICompileUnit::DebugNameTableKind NameTableKind =
687 static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
688 CGOpts.DebugNameTable);
690 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
692 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
695 TheCU = DBuilder.createCompileUnit(
696 LangTag, CUFile, CGOpts.EmitVersionIdentMetadata ? Producer :
"",
697 LO.Optimize || CGOpts.PrepareForLTO || CGOpts.PrepareForThinLTO,
698 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
699 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
700 NameTableKind, CGOpts.DebugRangesBaseAddress,
remapDIPath(Sysroot), SDK);
703llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
707#define BUILTIN_TYPE(Id, SingletonId)
708#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
709#include "clang/AST/BuiltinTypes.def"
710 case BuiltinType::Dependent:
711 llvm_unreachable(
"Unexpected builtin type");
712 case BuiltinType::NullPtr:
713 return DBuilder.createNullPtrType();
714 case BuiltinType::Void:
716 case BuiltinType::ObjCClass:
719 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
720 "objc_class", TheCU, TheCU->getFile(), 0);
722 case BuiltinType::ObjCId: {
733 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
734 "objc_class", TheCU, TheCU->getFile(), 0);
738 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
740 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
741 0, 0, llvm::DINode::FlagZero,
nullptr,
742 llvm::DINodeArray());
744 DBuilder.replaceArrays(
745 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
746 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
747 llvm::DINode::FlagZero, ISATy)));
750 case BuiltinType::ObjCSel: {
752 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
753 "objc_selector", TheCU,
754 TheCU->getFile(), 0);
758#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
759 case BuiltinType::Id: \
760 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
762#include "clang/Basic/OpenCLImageTypes.def"
763 case BuiltinType::OCLSampler:
764 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
765 case BuiltinType::OCLEvent:
766 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
767 case BuiltinType::OCLClkEvent:
768 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
769 case BuiltinType::OCLQueue:
770 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
771 case BuiltinType::OCLReserveID:
772 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
773#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
774 case BuiltinType::Id: \
775 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
776#include "clang/Basic/OpenCLExtensionTypes.def"
777#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
778 case BuiltinType::Id: \
779 return getOrCreateStructPtrType(#Name, SingletonId);
780#include "clang/Basic/HLSLIntangibleTypes.def"
782#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
783#include "clang/Basic/AArch64SVEACLETypes.def"
787 BT->
getKind() == BuiltinType::SveCount
791 : CGM.getContext().getBuiltinVectorTypeInfo(BT);
798 "Unsupported number of vectors for svcount_t");
802 unsigned NumElems = Info.
EC.getKnownMinValue() * Info.
NumVectors;
808 llvm::Metadata *LowerBound, *UpperBound;
809 LowerBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
811 if (Info.
EC.isScalable()) {
812 unsigned NumElemsPerVG = NumElems / 2;
814 {llvm::dwarf::DW_OP_constu, NumElemsPerVG, llvm::dwarf::DW_OP_bregx,
815 46, 0, llvm::dwarf::DW_OP_mul,
816 llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
817 UpperBound = DBuilder.createExpression(
Expr);
819 UpperBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
822 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
823 nullptr, LowerBound, UpperBound,
nullptr);
824 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
825 llvm::DIType *ElemTy =
826 getOrCreateType(Info.
ElementType, TheCU->getFile());
828 return DBuilder.createVectorType( 0, Align, ElemTy,
833#define PPC_VECTOR_TYPE(Name, Id, size) \
834 case BuiltinType::Id:
835#include "clang/Basic/PPCTypes.def"
838#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
839#include "clang/Basic/RISCVVTypes.def"
844 unsigned ElementCount = Info.
EC.getKnownMinValue();
847 bool Fractional =
false;
849 unsigned FixedSize = ElementCount * SEW;
853 }
else if (FixedSize < 64) {
856 LMUL = 64 / FixedSize;
858 LMUL = FixedSize / 64;
866 {llvm::dwarf::DW_OP_bregx,
869 llvm::dwarf::DW_OP_constu,
871 llvm::dwarf::DW_OP_div, llvm::dwarf::DW_OP_constu, LMUL});
873 Expr.push_back(llvm::dwarf::DW_OP_div);
875 Expr.push_back(llvm::dwarf::DW_OP_mul);
877 Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
880 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
882 auto *UpperBound = DBuilder.createExpression(
Expr);
883 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
884 nullptr, LowerBound, UpperBound,
nullptr);
885 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
886 llvm::DIType *ElemTy =
887 getOrCreateType(Info.
ElementType, TheCU->getFile());
890 return DBuilder.createVectorType(0, Align, ElemTy,
894#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
895 case BuiltinType::Id: { \
898 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, \
899 MangledName, TheCU, TheCU->getFile(), 0); \
900 return SingletonId; \
902#include "clang/Basic/WebAssemblyReferenceTypes.def"
903#define AMDGPU_OPAQUE_PTR_TYPE(Name, MangledName, AS, Width, Align, Id, \
905 case BuiltinType::Id: { \
908 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, \
909 MangledName, TheCU, TheCU->getFile(), 0); \
910 return SingletonId; \
912#include "clang/Basic/AMDGPUTypes.def"
913 case BuiltinType::UChar:
914 case BuiltinType::Char_U:
915 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
917 case BuiltinType::Char_S:
918 case BuiltinType::SChar:
919 Encoding = llvm::dwarf::DW_ATE_signed_char;
921 case BuiltinType::Char8:
922 case BuiltinType::Char16:
923 case BuiltinType::Char32:
926 case BuiltinType::UShort:
927 case BuiltinType::UInt:
928 case BuiltinType::UInt128:
929 case BuiltinType::ULong:
930 case BuiltinType::WChar_U:
931 case BuiltinType::ULongLong:
932 Encoding = llvm::dwarf::DW_ATE_unsigned;
934 case BuiltinType::Short:
935 case BuiltinType::Int:
936 case BuiltinType::Int128:
937 case BuiltinType::Long:
938 case BuiltinType::WChar_S:
939 case BuiltinType::LongLong:
940 Encoding = llvm::dwarf::DW_ATE_signed;
942 case BuiltinType::Bool:
943 Encoding = llvm::dwarf::DW_ATE_boolean;
945 case BuiltinType::Half:
946 case BuiltinType::Float:
947 case BuiltinType::LongDouble:
948 case BuiltinType::Float16:
949 case BuiltinType::BFloat16:
950 case BuiltinType::Float128:
951 case BuiltinType::Double:
952 case BuiltinType::Ibm128:
958 Encoding = llvm::dwarf::DW_ATE_float;
960 case BuiltinType::ShortAccum:
961 case BuiltinType::Accum:
962 case BuiltinType::LongAccum:
963 case BuiltinType::ShortFract:
964 case BuiltinType::Fract:
965 case BuiltinType::LongFract:
966 case BuiltinType::SatShortFract:
967 case BuiltinType::SatFract:
968 case BuiltinType::SatLongFract:
969 case BuiltinType::SatShortAccum:
970 case BuiltinType::SatAccum:
971 case BuiltinType::SatLongAccum:
972 Encoding = llvm::dwarf::DW_ATE_signed_fixed;
974 case BuiltinType::UShortAccum:
975 case BuiltinType::UAccum:
976 case BuiltinType::ULongAccum:
977 case BuiltinType::UShortFract:
978 case BuiltinType::UFract:
979 case BuiltinType::ULongFract:
980 case BuiltinType::SatUShortAccum:
981 case BuiltinType::SatUAccum:
982 case BuiltinType::SatULongAccum:
983 case BuiltinType::SatUShortFract:
984 case BuiltinType::SatUFract:
985 case BuiltinType::SatULongFract:
986 Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
993 return DBuilder.createBasicType(BTName, Size, Encoding);
996llvm::DIType *CGDebugInfo::CreateType(
const BitIntType *Ty) {
998 StringRef Name = Ty->
isUnsigned() ?
"unsigned _BitInt" :
"_BitInt";
1000 ? llvm::dwarf::DW_ATE_unsigned
1001 : llvm::dwarf::DW_ATE_signed;
1007llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
1009 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
1011 Encoding = llvm::dwarf::DW_ATE_lo_user;
1014 return DBuilder.createBasicType(
"complex", Size, Encoding);
1028 return llvm::dwarf::DW_TAG_const_type;
1032 return llvm::dwarf::DW_TAG_volatile_type;
1036 return llvm::dwarf::DW_TAG_restrict_type;
1038 return (llvm::dwarf::Tag)0;
1041llvm::DIType *CGDebugInfo::CreateQualifiedType(
QualType Ty,
1042 llvm::DIFile *Unit) {
1052 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1053 return getOrCreateType(
QualType(
T, 0), Unit);
1060 return DBuilder.createQualifiedType(Tag, FromTy);
1064 llvm::DIFile *Unit) {
1073 assert(Q.
empty() &&
"Unknown type qualifier for debug info");
1084 return DBuilder.createQualifiedType(Tag, FromTy);
1088 llvm::DIFile *Unit) {
1096 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1100llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
1101 llvm::DIFile *Unit) {
1102 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1108 switch (TheCU->getSourceLanguage()) {
1109 case llvm::dwarf::DW_LANG_C_plus_plus:
1110 case llvm::dwarf::DW_LANG_C_plus_plus_11:
1111 case llvm::dwarf::DW_LANG_C_plus_plus_14:
1113 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
1114 return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
1142 llvm::DICompileUnit *TheCU) {
1160 llvm::DICompileUnit *TheCU) {
1166 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
1168 if (RD->isDynamicClass() &&
1181 llvm::dwarf::Tag Tag;
1183 Tag = llvm::dwarf::DW_TAG_structure_type;
1185 Tag = llvm::dwarf::DW_TAG_union_type;
1190 Tag = llvm::dwarf::DW_TAG_class_type;
1195llvm::DICompositeType *
1196CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
1197 llvm::DIScope *Ctx) {
1200 return cast<llvm::DICompositeType>(
T);
1201 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
1202 const unsigned Line =
1204 StringRef RDName = getClassName(RD);
1210 if (
D &&
D->isCompleteDefinition())
1213 llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
1218 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1219 if (!CXXRD->hasDefinition() ||
1220 (CXXRD->hasDefinition() && !CXXRD->isTrivial()))
1221 Flags |= llvm::DINode::FlagNonTrivial;
1228 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
1232 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
1233 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
1234 CollectCXXTemplateParams(TSpecial, DefUnit));
1235 ReplaceMap.emplace_back(
1236 std::piecewise_construct, std::make_tuple(Ty),
1237 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
1241llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
1244 llvm::DIFile *Unit) {
1249 std::optional<unsigned> DWARFAddressSpace =
1254 auto *BTFAttrTy = dyn_cast<BTFTagAttributedType>(PointeeTy);
1256 StringRef
Tag = BTFAttrTy->getAttr()->getBTFTypeTag();
1258 llvm::Metadata *Ops[2] = {
1259 llvm::MDString::get(CGM.
getLLVMContext(), StringRef(
"btf_type_tag")),
1261 Annots.insert(Annots.begin(),
1264 BTFAttrTy = dyn_cast<BTFTagAttributedType>(BTFAttrTy->getWrappedType());
1267 llvm::DINodeArray Annotations =
nullptr;
1268 if (Annots.size() > 0)
1269 Annotations = DBuilder.getOrCreateArray(Annots);
1271 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1272 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
1273 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1274 Size, Align, DWARFAddressSpace);
1276 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1277 Align, DWARFAddressSpace, StringRef(),
1281llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1282 llvm::DIType *&
Cache) {
1285 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1286 TheCU, TheCU->getFile(), 0);
1288 Cache = DBuilder.createPointerType(
Cache, Size);
1292uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1293 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1306 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1307 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1310 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1312 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1313 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1315 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1319 EltTys.push_back(DBuilder.createMemberType(
1320 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1321 FieldOffset, llvm::DINode::FlagZero, DescTy));
1322 FieldOffset += FieldSize;
1329 llvm::DIFile *Unit) {
1333 llvm::DINodeArray Elements;
1337 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1338 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1340 Elements = DBuilder.getOrCreateArray(EltTys);
1343 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1346 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1347 FieldOffset, 0, Flags,
nullptr, Elements);
1352 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1354 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1357 Elements = DBuilder.getOrCreateArray(EltTys);
1363 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1364 Flags,
nullptr, Elements);
1366 return DBuilder.createPointerType(EltTy, Size);
1383 if (Param->isParameterPack()) {
1392 if (SubstArgs.empty()) {
1401 SpecArgs.push_back(SubstArgs.front());
1402 SubstArgs = SubstArgs.drop_front();
1408 llvm::DIFile *Unit) {
1413 if (isa<BuiltinTemplateDecl>(TD))
1416 const auto *
AliasDecl = cast<TypeAliasTemplateDecl>(TD)->getTemplatedDecl();
1421 llvm::raw_svector_ostream OS(NS);
1423 auto PP = getPrintingPolicy();
1450 auto ArgVector = ::GetTemplateArgs(TD, Ty);
1459 llvm::raw_string_ostream OS(Name);
1462 llvm::codegenoptions::DebugTemplateNamesKind::Simple ||
1463 !HasReconstitutableArgs(Args.Args))
1466 llvm::DIDerivedType *AliasTy = DBuilder.createTemplateAlias(
1467 Src, Name, getOrCreateFile(
Loc), getLineNumber(
Loc),
1468 getDeclContextDescriptor(
AliasDecl), CollectTemplateParams(Args, Unit));
1483 return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(
Loc),
1500 return llvm::DINode::FlagZero;
1504 return llvm::DINode::FlagPrivate;
1506 return llvm::DINode::FlagProtected;
1508 return llvm::DINode::FlagPublic;
1510 return llvm::DINode::FlagZero;
1512 llvm_unreachable(
"unexpected access enumerator");
1515llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1516 llvm::DIFile *Unit) {
1517 llvm::DIType *Underlying =
1529 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(Ty->
getDecl());
1531 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1533 if (isa<RecordDecl>(DC))
1536 return DBuilder.createTypedef(Underlying, Ty->
getDecl()->
getName(),
1537 getOrCreateFile(
Loc), getLineNumber(
Loc),
1538 getDeclContextDescriptor(Ty->
getDecl()), Align,
1539 Flags, Annotations);
1549 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1551 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1553 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1555 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1557 return llvm::dwarf::DW_CC_BORLAND_pascal;
1559 return llvm::dwarf::DW_CC_LLVM_Win64;
1561 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1565 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1567 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1569 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1571 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1574 return llvm::dwarf::DW_CC_LLVM_OpenCLKernel;
1576 return llvm::dwarf::DW_CC_LLVM_Swift;
1578 return llvm::dwarf::DW_CC_LLVM_SwiftTail;
1580 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1582 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1584 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1586 return llvm::dwarf::DW_CC_LLVM_M68kRTD;
1588 return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1590 return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
1596 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1598 Flags |= llvm::DINode::FlagLValueReference;
1600 Flags |= llvm::DINode::FlagRValueReference;
1604llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1605 llvm::DIFile *Unit) {
1606 const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
1608 if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
1617 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1619 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1623 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1626 for (
const QualType &ParamType : FPT->param_types())
1627 EltTys.push_back(getOrCreateType(ParamType, Unit));
1628 if (FPT->isVariadic())
1629 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1632 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1633 llvm::DIType *F = DBuilder.createSubroutineType(
1638llvm::DIDerivedType *
1639CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1640 llvm::DIScope *RecordTy,
const RecordDecl *RD) {
1641 StringRef Name = BitFieldDecl->
getName();
1643 if (BitFieldDecl->
hasAttr<PreferredTypeAttr>())
1644 Ty = BitFieldDecl->
getAttr<PreferredTypeAttr>()->getType();
1646 llvm::DIFile *VUnit = getOrCreateFile(
Loc);
1647 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1650 llvm::DIFile *
File = getOrCreateFile(
Loc);
1651 unsigned Line = getLineNumber(
Loc);
1656 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1665 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1667 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(BitFieldDecl);
1668 return DBuilder.createBitFieldMemberType(
1669 RecordTy, Name,
File,
Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1670 Flags, DebugType, Annotations);
1673llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
1674 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
1702 if (PreviousFieldsDI.empty())
1706 auto *PreviousMDEntry =
1707 PreviousFieldsDI.empty() ? nullptr : PreviousFieldsDI.back();
1708 auto *PreviousMDField =
1709 dyn_cast_or_null<llvm::DIDerivedType>(PreviousMDEntry);
1710 if (!PreviousMDField || !PreviousMDField->isBitField() ||
1711 PreviousMDField->getSizeInBits() == 0)
1715 std::advance(PreviousBitfield, BitFieldDecl->
getFieldIndex() - 1);
1717 assert(PreviousBitfield->isBitField());
1720 if (!PreviousBitfield->isZeroLengthBitField(Context))
1723 QualType Ty = PreviousBitfield->getType();
1725 llvm::DIFile *VUnit = getOrCreateFile(
Loc);
1726 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1727 llvm::DIScope *RecordTy = BitFieldDI->getScope();
1729 llvm::DIFile *
File = getOrCreateFile(
Loc);
1730 unsigned Line = getLineNumber(
Loc);
1733 cast<llvm::ConstantInt>(BitFieldDI->getStorageOffsetInBits())
1736 llvm::DINode::DIFlags Flags =
1738 llvm::DINodeArray Annotations =
1739 CollectBTFDeclTagAnnotations(*PreviousBitfield);
1740 return DBuilder.createBitFieldMemberType(
1741 RecordTy,
"",
File,
Line, 0, StorageOffsetInBits, StorageOffsetInBits,
1742 Flags, DebugType, Annotations);
1745llvm::DIType *CGDebugInfo::createFieldType(
1747 uint64_t offsetInBits, uint32_t AlignInBits, llvm::DIFile *tunit,
1748 llvm::DIScope *scope,
const RecordDecl *RD, llvm::DINodeArray Annotations) {
1749 llvm::DIType *debugType = getOrCreateType(
type, tunit);
1752 llvm::DIFile *file = getOrCreateFile(loc);
1753 const unsigned line = getLineNumber(loc.
isValid() ? loc : CurLoc);
1756 auto Align = AlignInBits;
1757 if (!
type->isIncompleteArrayType()) {
1759 SizeInBits = TI.
Width;
1765 return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
1766 offsetInBits, flags, debugType, Annotations);
1770CGDebugInfo::createInlinedTrapSubprogram(StringRef FuncName,
1771 llvm::DIFile *FileScope) {
1775 llvm::DISubprogram *&SP = InlinedTrapFuncMap[FuncName];
1778 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(
nullptr);
1779 SP = DBuilder.createFunction(
1780 FileScope, FuncName, StringRef(),
1781 FileScope, 0, DIFnTy,
1783 llvm::DINode::FlagArtificial,
1784 llvm::DISubprogram::SPFlagDefinition,
1785 nullptr,
nullptr,
nullptr);
1791void CGDebugInfo::CollectRecordLambdaFields(
1793 llvm::DIType *RecordTy) {
1799 unsigned fieldno = 0;
1802 I !=
E; ++I, ++Field, ++fieldno) {
1804 if (
C.capturesVariable()) {
1806 assert(!
Field->isBitField() &&
"lambdas don't have bitfield members!");
1808 StringRef VName =
V->getName();
1809 llvm::DIFile *VUnit = getOrCreateFile(
Loc);
1811 llvm::DIType *FieldType = createFieldType(
1813 layout.
getFieldOffset(fieldno), Align, VUnit, RecordTy, CXXDecl);
1814 elements.push_back(FieldType);
1815 }
else if (
C.capturesThis()) {
1821 llvm::DIFile *VUnit = getOrCreateFile(f->
getLocation());
1823 StringRef ThisName =
1825 llvm::DIType *fieldType = createFieldType(
1829 elements.push_back(fieldType);
1834llvm::DIDerivedType *
1835CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
1840 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
1841 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
1843 unsigned LineNumber = getLineNumber(Var->
getLocation());
1844 StringRef VName = Var->
getName();
1848 llvm::Constant *
C =
nullptr;
1854 if (
Value->isFloat())
1861 ? llvm::dwarf::DW_TAG_variable
1862 : llvm::dwarf::DW_TAG_member;
1864 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1865 RecordTy, VName, VUnit, LineNumber, VTy, Flags,
C, Tag, Align);
1870void CGDebugInfo::CollectRecordNormalField(
1871 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
1878 if (
name.empty() && !
type->isRecordType())
1881 llvm::DIType *FieldType;
1883 llvm::DIDerivedType *BitFieldType;
1884 FieldType = BitFieldType = createBitFieldType(field, RecordTy, RD);
1885 if (llvm::DIType *Separator =
1886 createBitFieldSeparatorIfNeeded(field, BitFieldType, elements, RD))
1887 elements.push_back(Separator);
1890 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
1893 OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
1896 elements.push_back(FieldType);
1899void CGDebugInfo::CollectRecordNestedType(
1903 if (isa<InjectedClassNameType>(Ty))
1906 llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(
Loc));
1907 elements.push_back(nestedType);
1910void CGDebugInfo::CollectRecordFields(
1911 const RecordDecl *record, llvm::DIFile *tunit,
1913 llvm::DICompositeType *RecordTy) {
1914 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
1916 if (CXXDecl && CXXDecl->
isLambda())
1917 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
1922 unsigned fieldNo = 0;
1926 for (
const auto *I : record->
decls())
1927 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
1928 if (
V->hasAttr<NoDebugAttr>())
1934 isa<VarTemplateSpecializationDecl>(
V))
1937 if (isa<VarTemplatePartialSpecializationDecl>(
V))
1941 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
1942 if (MI != StaticDataMemberCache.end()) {
1943 assert(MI->second &&
1944 "Static data member declaration should still exist");
1945 elements.push_back(MI->second);
1947 auto Field = CreateRecordStaticField(
V, RecordTy, record);
1948 elements.push_back(Field);
1950 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
1951 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
1952 elements, RecordTy, record);
1959 if (
const auto *nestedType = dyn_cast<TypeDecl>(I)) {
1961 if (isa<RecordDecl>(I) &&
1962 cast<RecordDecl>(I)->isAnonymousStructOrUnion())
1964 if (!nestedType->isImplicit() &&
1965 nestedType->getDeclContext() == record)
1966 CollectRecordNestedType(nestedType, elements);
1972llvm::DISubroutineType *
1973CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *Method,
1974 llvm::DIFile *Unit) {
1977 return cast_or_null<llvm::DISubroutineType>(
1984 return getOrCreateInstanceMethodType(ThisType,
Func, Unit);
1987llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
2003 const auto *OriginalFunc = cast<llvm::DISubroutineType>(
2005 Func->getReturnType(),
Func->getParamTypes(), EPI),
2007 llvm::DITypeRefArray Args = OriginalFunc->getTypeArray();
2008 assert(Args.size() &&
"Invalid number of arguments!");
2013 Elts.push_back(Args[0]);
2020 if (isa<ClassTemplateSpecializationDecl>(RD)) {
2022 const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
2025 llvm::DIType *PointeeType =
2027 llvm::DIType *ThisPtrType =
2028 DBuilder.createPointerType(PointeeType, Size, Align);
2033 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2034 Elts.push_back(ThisPtrType);
2036 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2038 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
2039 Elts.push_back(ThisPtrType);
2044 for (
unsigned i = 1, e = Args.size(); i != e; ++i)
2045 Elts.push_back(Args[i]);
2047 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2049 return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
2056 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
2063llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
2064 const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
2066 isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
2068 StringRef MethodName = getFunctionName(Method);
2069 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
2073 StringRef MethodLinkageName;
2083 llvm::DIFile *MethodDefUnit =
nullptr;
2084 unsigned MethodLine = 0;
2086 MethodDefUnit = getOrCreateFile(Method->
getLocation());
2087 MethodLine = getLineNumber(Method->
getLocation());
2091 llvm::DIType *ContainingType =
nullptr;
2092 unsigned VIndex = 0;
2093 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2094 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
2099 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
2101 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
2106 if (!isa<CXXDestructorDecl>(Method))
2111 const auto *DD = dyn_cast<CXXDestructorDecl>(Method);
2123 Flags |= llvm::DINode::FlagIntroducedVirtual;
2132 ContainingType = RecordTy;
2136 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
2139 Flags |= llvm::DINode::FlagNoReturn;
2142 Flags |= llvm::DINode::FlagStaticMember;
2144 Flags |= llvm::DINode::FlagArtificial;
2146 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
2147 if (CXXC->isExplicit())
2148 Flags |= llvm::DINode::FlagExplicit;
2149 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(Method)) {
2150 if (CXXC->isExplicit())
2151 Flags |= llvm::DINode::FlagExplicit;
2154 Flags |= llvm::DINode::FlagPrototyped;
2156 Flags |= llvm::DINode::FlagLValueReference;
2158 Flags |= llvm::DINode::FlagRValueReference;
2160 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2162 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
2166 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor)
2170 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
2171 llvm::DISubprogram *SP = DBuilder.createMethod(
2172 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
2173 MethodTy, VIndex,
ThisAdjustment, ContainingType, Flags, SPFlags,
2174 TParamsArray.get());
2181void CGDebugInfo::CollectCXXMemberFunctions(
2188 for (
const auto *I : RD->
decls()) {
2189 const auto *Method = dyn_cast<CXXMethodDecl>(I);
2213 EltTys.push_back(MI == SPCache.end()
2214 ? CreateCXXMemberFunction(Method, Unit, RecordTy)
2215 :
static_cast<llvm::Metadata *
>(MI->second));
2219void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2221 llvm::DIType *RecordTy) {
2222 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
2223 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
2224 llvm::DINode::FlagZero);
2229 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
2230 llvm::DINode::FlagIndirectVirtualBase);
2234void CGDebugInfo::CollectCXXBasesAux(
2239 llvm::DINode::DIFlags StartingFlags) {
2241 for (
const auto &BI : Bases) {
2244 if (!SeenTypes.insert(
Base).second)
2246 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
2247 llvm::DINode::DIFlags BFlags = StartingFlags;
2251 if (BI.isVirtual()) {
2268 BFlags |= llvm::DINode::FlagVirtual;
2275 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
2276 VBPtrOffset, BFlags);
2277 EltTys.push_back(DTy);
2282CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
2283 llvm::DIFile *Unit) {
2285 return llvm::DINodeArray();
2286 TemplateArgs &Args = *OArgs;
2288 for (
unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
2293 Name = Args.TList->getParam(i)->getName();
2297 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
2298 TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
2299 TheCU, Name, TTy, defaultParameter));
2304 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2305 TheCU, Name, TTy, defaultParameter,
2311 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2312 llvm::Constant *
V =
nullptr;
2319 if (
const auto *VD = dyn_cast<VarDecl>(
D))
2323 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(
D);
2324 MD && MD->isImplicitObjectMemberFunction())
2326 else if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
2330 else if (
const auto *MPT =
2331 dyn_cast<MemberPointerType>(
T.getTypePtr())) {
2339 }
else if (
const auto *GD = dyn_cast<MSGuidDecl>(
D)) {
2341 }
else if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(
D)) {
2348 assert(
V &&
"Failed to find template parameter pointer");
2349 V =
V->stripPointerCasts();
2351 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2352 TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(
V)));
2356 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2357 llvm::Constant *
V =
nullptr;
2360 if (
const auto *MPT = dyn_cast<MemberPointerType>(
T.getTypePtr()))
2366 if (MPT->isMemberDataPointer())
2369 V = llvm::ConstantInt::get(CGM.
Int8Ty, 0);
2370 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2371 TheCU, Name, TTy, defaultParameter,
V));
2375 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2378 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2379 TheCU, Name, TTy, defaultParameter,
V));
2382 std::string QualName;
2383 llvm::raw_string_ostream OS(QualName);
2385 OS, getPrintingPolicy());
2386 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2387 TheCU, Name,
nullptr, OS.str(), defaultParameter));
2391 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
2392 TheCU, Name,
nullptr,
2401 assert(
V &&
"Expression in template argument isn't constant");
2402 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2403 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2404 TheCU, Name, TTy, defaultParameter,
V->stripPointerCasts()));
2410 "These argument types shouldn't exist in concrete types");
2413 return DBuilder.getOrCreateArray(TemplateParams);
2416std::optional<CGDebugInfo::TemplateArgs>
2417CGDebugInfo::GetTemplateArgs(
const FunctionDecl *FD)
const {
2425 return std::nullopt;
2427std::optional<CGDebugInfo::TemplateArgs>
2428CGDebugInfo::GetTemplateArgs(
const VarDecl *VD)
const {
2432 auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VD);
2434 return std::nullopt;
2437 auto TA = TS->getTemplateArgs().asArray();
2438 return {{TList, TA}};
2440std::optional<CGDebugInfo::TemplateArgs>
2441CGDebugInfo::GetTemplateArgs(
const RecordDecl *RD)
const {
2442 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2447 TSpecial->getSpecializedTemplate()->getTemplateParameters();
2449 return {{TPList, TAList.
asArray()}};
2451 return std::nullopt;
2455CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
2456 llvm::DIFile *Unit) {
2457 return CollectTemplateParams(GetTemplateArgs(FD), Unit);
2460llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
2461 llvm::DIFile *Unit) {
2462 return CollectTemplateParams(GetTemplateArgs(VL), Unit);
2465llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
const RecordDecl *RD,
2466 llvm::DIFile *Unit) {
2467 return CollectTemplateParams(GetTemplateArgs(RD), Unit);
2470llvm::DINodeArray CGDebugInfo::CollectBTFDeclTagAnnotations(
const Decl *
D) {
2476 llvm::Metadata *Ops[2] = {
2477 llvm::MDString::get(CGM.
getLLVMContext(), StringRef(
"btf_decl_tag")),
2479 Annotations.push_back(llvm::MDNode::get(CGM.
getLLVMContext(), Ops));
2481 return DBuilder.getOrCreateArray(Annotations);
2484llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
2486 return VTablePtrType;
2491 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
2492 llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
2493 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
2496 std::optional<unsigned> DWARFAddressSpace =
2499 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
2500 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2501 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
2502 return VTablePtrType;
2505StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
2510StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
2512 llvm::Function *InitFn) {
2517 return InitFn->getName();
2527 llvm::raw_svector_ostream OS(QualifiedGV);
2529 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
2531 std::swap(Quals, GVName);
2535 llvm::raw_svector_ostream OS(InitName);
2537 OS << Quals <<
"::";
2542 llvm_unreachable(
"not an initializer");
2544 OS <<
"`dynamic initializer for '";
2547 OS <<
"`dynamic atexit destructor for '";
2554 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
2556 getPrintingPolicy());
2561 return internString(OS.str());
2564void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2581 llvm::DIType *VPtrTy =
nullptr;
2584 if (NeedVTableShape) {
2589 unsigned VSlotCount =
2591 unsigned VTableWidth = PtrWidth * VSlotCount;
2593 std::optional<unsigned> DWARFAddressSpace =
2597 llvm::DIType *VTableType = DBuilder.createPointerType(
2598 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2599 EltTys.push_back(VTableType);
2602 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
2610 VPtrTy = getOrCreateVTablePtrType(Unit);
2613 llvm::DIType *VPtrMember =
2614 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
2615 llvm::DINode::FlagArtificial, VPtrTy);
2616 EltTys.push_back(VPtrMember);
2622 llvm::DIType *
T = getOrCreateType(RTy, getOrCreateFile(
Loc));
2634 assert(!
D.isNull() &&
"null type");
2635 llvm::DIType *
T = getOrCreateType(
D, getOrCreateFile(
Loc));
2636 assert(
T &&
"could not create debug info for type");
2638 RetainedTypes.push_back(
D.getAsOpaquePtr());
2646 llvm::codegenoptions::DebugLineTablesOnly)
2652 node = getOrCreateType(AllocatedTy, getOrCreateFile(
Loc));
2654 CI->setMetadata(
"heapallocsite", node);
2658 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
2662 auto I = TypeCache.find(TyPtr);
2663 if (I == TypeCache.end() || !cast<llvm::DIType>(I->second)->isForwardDecl())
2665 llvm::DIType *Res = CreateTypeDefinition(Ty->
castAs<
EnumType>());
2666 assert(!Res->isForwardDecl());
2667 TypeCache[TyPtr].reset(Res);
2671 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
2678 if (RD->
hasAttr<DLLImportAttr>())
2681 if (MD->hasAttr<DLLImportAttr>())
2694 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
2703 bool Explicit =
false;
2704 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
2705 Explicit = TD->isExplicitInstantiationOrSpecialization();
2719 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
2720 if (CXXRD->isDynamicClass() &&
2722 llvm::GlobalValue::AvailableExternallyLinkage &&
2733 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
2737 auto I = TypeCache.find(TyPtr);
2738 if (I != TypeCache.end() && !cast<llvm::DIType>(I->second)->isForwardDecl())
2745 assert(!Res->isForwardDecl());
2746 TypeCache[TyPtr].reset(Res);
2753 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
2754 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
2777 if (Ctor->isCopyOrMoveConstructor())
2779 if (!Ctor->isDeleted())
2798 if (DebugKind == llvm::codegenoptions::DebugLineTablesOnly)
2801 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
2802 RD->
hasAttr<StandaloneDebugAttr>())
2805 if (!LangOpts.CPlusPlus)
2811 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
2827 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
2828 Spec = SD->getSpecializationKind();
2837 if ((DebugKind == llvm::codegenoptions::DebugInfoConstructor) &&
2849 llvm::DIType *
T = getTypeOrNull(Ty);
2850 if (
T &&
T->isForwardDecl())
2854llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
2856 llvm::DIType *
T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
2860 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
2864 auto [Def, Pref] = CreateTypeDefinition(Ty);
2866 return Pref ? Pref : Def;
2869llvm::DIType *CGDebugInfo::GetPreferredNameType(
const CXXRecordDecl *RD,
2870 llvm::DIFile *Unit) {
2874 auto const *PNA = RD->
getAttr<PreferredNameAttr>();
2878 return getOrCreateType(PNA->getTypedefType(), Unit);
2881std::pair<llvm::DIType *, llvm::DIType *>
2882CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
2886 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
2894 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
2897 if (!
D || !
D->isCompleteDefinition())
2898 return {FwdDecl,
nullptr};
2900 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
2901 CollectContainingType(CXXDecl, FwdDecl);
2904 LexicalBlockStack.emplace_back(&*FwdDecl);
2905 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2915 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
2917 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
2918 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
2922 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
2923 if (CXXDecl && !CGM.
getCodeGenOpts().DebugOmitUnreferencedMethods)
2924 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
2926 LexicalBlockStack.pop_back();
2927 RegionMap.erase(Ty->
getDecl());
2929 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2930 DBuilder.replaceArrays(FwdDecl, Elements);
2932 if (FwdDecl->isTemporary())
2934 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
2936 RegionMap[Ty->
getDecl()].reset(FwdDecl);
2938 if (CGM.
getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
2939 if (
auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
2940 return {FwdDecl, PrefDI};
2942 return {FwdDecl,
nullptr};
2946 llvm::DIFile *Unit) {
2952 llvm::DIFile *Unit) {
2957 return DBuilder.createTypedef(
2960 getDeclContextDescriptor(Ty->
getDecl()));
2988 llvm::DIFile *Unit) {
2996 if (DebugTypeExtRefs &&
ID->isFromASTFile() &&
ID->getDefinition() &&
2997 !
ID->getImplementation())
2998 return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
3000 getDeclContextDescriptor(ID), Unit, 0);
3003 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3004 unsigned Line = getLineNumber(
ID->getLocation());
3006 static_cast<llvm::dwarf::SourceLanguage
>(TheCU->getSourceLanguage());
3012 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3013 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
3014 llvm::dwarf::DW_TAG_structure_type,
ID->getName(), Mod ? Mod : TheCU,
3015 DefUnit,
Line, RuntimeLang);
3016 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
3020 return CreateTypeDefinition(Ty, Unit);
3024 bool CreateSkeletonCU) {
3029 auto ModRef = ModuleCache.find(M);
3030 if (ModRef != ModuleCache.end())
3031 return cast<llvm::DIModule>(ModRef->second);
3036 llvm::raw_svector_ostream OS(ConfigMacros);
3040 for (
auto &M : PPOpts.Macros) {
3043 const std::string &
Macro = M.first;
3044 bool Undef = M.second;
3045 OS <<
"\"-" << (Undef ?
'U' :
'D');
3046 for (
char c : Macro)
3061 bool IsRootModule = M ? !M->
Parent :
true;
3065 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
3067 "clang module without ASTFile must be specified by -fmodule-name");
3070 auto RemapPath = [
this](StringRef
Path) -> std::string {
3072 StringRef Relative(Remapped);
3073 StringRef CompDir = TheCU->getDirectory();
3074 if (Relative.consume_front(CompDir))
3075 Relative.consume_front(llvm::sys::path::get_separator());
3077 return Relative.str();
3080 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
3087 Signature = ModSig.truncatedValue();
3093 if (!llvm::sys::path::is_absolute(Mod.
getASTFile())) {
3095 PCM = getCurrentDirname();
3099 llvm::sys::path::append(PCM, Mod.
getASTFile());
3100 DIB.createCompileUnit(
3101 TheCU->getSourceLanguage(),
3104 TheCU->getProducer(),
false, StringRef(), 0, RemapPath(PCM),
3105 llvm::DICompileUnit::FullDebug, Signature);
3110 IsRootModule ? nullptr
3113 std::string IncludePath = Mod.
getPath().str();
3114 llvm::DIModule *DIMod =
3116 RemapPath(IncludePath));
3117 ModuleCache[M].reset(DIMod);
3122 llvm::DIFile *Unit) {
3124 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3125 unsigned Line = getLineNumber(
ID->getLocation());
3126 unsigned RuntimeLang = TheCU->getSourceLanguage();
3132 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3133 if (
ID->getImplementation())
3134 Flags |= llvm::DINode::FlagObjcClassComplete;
3136 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3137 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
3138 Mod ? Mod : Unit,
ID->getName(), DefUnit,
Line, Size, Align, Flags,
3139 nullptr, llvm::DINodeArray(), RuntimeLang);
3142 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
3145 LexicalBlockStack.emplace_back(RealDecl);
3146 RegionMap[Ty->
getDecl()].reset(RealDecl);
3153 llvm::DIType *SClassTy =
3158 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
3159 llvm::DINode::FlagZero);
3160 EltTys.push_back(InhTag);
3166 llvm::DIFile *PUnit = getOrCreateFile(
Loc);
3167 unsigned PLine = getLineNumber(
Loc);
3170 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
3171 PD->getName(), PUnit, PLine,
3173 : getSelectorName(PD->getGetterName()),
3175 : getSelectorName(PD->getSetterName()),
3176 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
3177 EltTys.push_back(PropertyNode);
3182 typedef std::pair<char, const IdentifierInfo *> IsClassAndIdent;
3186 llvm::DenseSet<IsClassAndIdent> PropertySet;
3189 return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
3192 for (
auto *PD : ClassExt->properties()) {
3193 PropertySet.insert(GetIsClassAndIdent(PD));
3196 for (
const auto *PD :
ID->properties()) {
3199 if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
3206 unsigned FieldNo = 0;
3208 Field =
Field->getNextIvar(), ++FieldNo) {
3209 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
3213 StringRef FieldName =
Field->getName();
3216 if (FieldName.empty())
3220 llvm::DIFile *FieldDefUnit = getOrCreateFile(
Field->getLocation());
3221 unsigned FieldLine = getLineNumber(
Field->getLocation());
3229 FieldSize =
Field->isBitField()
3240 if (
Field->isBitField()) {
3251 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3253 Flags = llvm::DINode::FlagProtected;
3255 Flags = llvm::DINode::FlagPrivate;
3257 Flags = llvm::DINode::FlagPublic;
3259 if (
Field->isBitField())
3260 Flags |= llvm::DINode::FlagBitField;
3262 llvm::MDNode *PropertyNode =
nullptr;
3265 ImpD->FindPropertyImplIvarDecl(
Field->getIdentifier())) {
3268 llvm::DIFile *PUnit = getOrCreateFile(
Loc);
3269 unsigned PLine = getLineNumber(
Loc);
3272 PropertyNode = DBuilder.createObjCProperty(
3273 PD->getName(), PUnit, PLine,
3276 : getSelectorName(PD->getGetterName()),
3279 : getSelectorName(PD->getSetterName()),
3280 PD->getPropertyAttributes(),
3281 getOrCreateType(PD->getType(), PUnit));
3285 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
3286 FieldSize, FieldAlign, FieldOffset, Flags,
3287 FieldTy, PropertyNode);
3288 EltTys.push_back(FieldTy);
3291 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3292 DBuilder.replaceArrays(RealDecl, Elements);
3294 LexicalBlockStack.pop_back();
3298llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
3299 llvm::DIFile *Unit) {
3317 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3320 llvm::Metadata *Subscript;
3322 auto SizeExpr = SizeExprCache.find(QTy);
3323 if (SizeExpr != SizeExprCache.end())
3324 Subscript = DBuilder.getOrCreateSubrange(
3325 SizeExpr->getSecond() ,
nullptr ,
3326 nullptr ,
nullptr );
3329 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3330 llvm::Type::getInt64Ty(CGM.
getLLVMContext()), Count ? Count : -1));
3331 Subscript = DBuilder.getOrCreateSubrange(
3332 CountNode ,
nullptr ,
nullptr ,
3335 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
3340 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
3344 llvm::DIFile *Unit) {
3348 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3354 auto *ColumnCountNode =
3355 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3357 auto *RowCountNode =
3358 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3360 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3361 ColumnCountNode ,
nullptr ,
nullptr ,
3363 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3364 RowCountNode ,
nullptr ,
nullptr ,
3366 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3367 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
3370llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
3375 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3399 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
3408 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
3409 Count = CAT->getZExtSize();
3410 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3411 if (
Expr *Size = VAT->getSizeExpr()) {
3414 Count =
Result.Val.getInt().getExtValue();
3418 auto SizeNode = SizeExprCache.find(EltTy);
3419 if (SizeNode != SizeExprCache.end())
3420 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3421 SizeNode->getSecond() ,
nullptr ,
3422 nullptr ,
nullptr ));
3425 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3427 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3428 CountNode ,
nullptr ,
nullptr ,
3434 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3436 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
3441 llvm::DIFile *Unit) {
3442 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
3447 llvm::DIFile *Unit) {
3448 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
3452 Tag = llvm::dwarf::DW_TAG_reference_type;
3454 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
3459 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3469 Flags |= llvm::DINode::FlagSingleInheritance;
3472 Flags |= llvm::DINode::FlagMultipleInheritance;
3475 Flags |= llvm::DINode::FlagVirtualInheritance;
3485 return DBuilder.createMemberPointerType(
3491 return DBuilder.createMemberPointerType(
3492 getOrCreateInstanceMethodType(
3495 ClassType,
Size, 0, Flags);
3498llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *
U) {
3500 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
3503llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *
U) {
3507llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
3519 bool isImportedFromModule =
3531 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
3532 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
3533 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
3534 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
3537 StringRef EDName = ED->
getName();
3538 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
3539 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
3540 0, Size, Align, llvm::DINode::FlagFwdDecl,
Identifier);
3542 ReplaceMap.emplace_back(
3543 std::piecewise_construct, std::make_tuple(Ty),
3544 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
3548 return CreateTypeDefinition(Ty);
3551llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
3565 Enumerators.push_back(
3566 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
3570 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
3572 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
3574 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
3575 llvm::DIType *ClassTy = getOrCreateType(ED->
getIntegerType(), DefUnit);
3576 return DBuilder.createEnumerationType(
3577 EnumContext, ED->
getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
3583 StringRef Name, StringRef
Value) {
3584 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
3591 llvm::DIFile *FName = getOrCreateFile(FileLoc);
3592 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
3593 return DBuilder.createTempMacroFile(
Parent,
Line, FName);
3597 llvm::DebugLoc TrapLocation, StringRef
Category, StringRef FailureMsg) {
3605 FuncName += FailureMsg;
3607 llvm::DISubprogram *TrapSP =
3608 createInlinedTrapSubprogram(FuncName, TrapLocation->getFile());
3610 TrapSP, TrapLocation);
3620 Quals += InnerQuals;
3624 return C.getQualifiedType(
T.getTypePtr(), Quals);
3625 case Type::TemplateSpecialization: {
3626 const auto *Spec = cast<TemplateSpecializationType>(
T);
3627 if (Spec->isTypeAlias())
3628 return C.getQualifiedType(
T.getTypePtr(), Quals);
3632 case Type::TypeOfExpr:
3633 T = cast<TypeOfExprType>(
T)->getUnderlyingExpr()->getType();
3636 T = cast<TypeOfType>(
T)->getUnmodifiedType();
3638 case Type::Decltype:
3639 T = cast<DecltypeType>(
T)->getUnderlyingType();
3641 case Type::UnaryTransform:
3642 T = cast<UnaryTransformType>(
T)->getUnderlyingType();
3644 case Type::Attributed:
3645 T = cast<AttributedType>(
T)->getEquivalentType();
3647 case Type::BTFTagAttributed:
3648 T = cast<BTFTagAttributedType>(
T)->getWrappedType();
3650 case Type::CountAttributed:
3651 T = cast<CountAttributedType>(
T)->
desugar();
3653 case Type::Elaborated:
3654 T = cast<ElaboratedType>(
T)->getNamedType();
3657 T = cast<UsingType>(
T)->getUnderlyingType();
3660 T = cast<ParenType>(
T)->getInnerType();
3662 case Type::MacroQualified:
3663 T = cast<MacroQualifiedType>(
T)->getUnderlyingType();
3665 case Type::SubstTemplateTypeParm:
3666 T = cast<SubstTemplateTypeParmType>(
T)->getReplacementType();
3669 case Type::DeducedTemplateSpecialization: {
3670 QualType DT = cast<DeducedType>(
T)->getDeducedType();
3671 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
3675 case Type::PackIndexing: {
3676 T = cast<PackIndexingType>(
T)->getSelectedType();
3679 case Type::Adjusted:
3682 T = cast<AdjustedType>(
T)->getAdjustedType();
3686 assert(
T != LastT &&
"Type unwrapping failed to unwrap!");
3691llvm::DIType *CGDebugInfo::getTypeOrNull(
QualType Ty) {
3694 if (It != TypeCache.end()) {
3696 if (llvm::Metadata *
V = It->second)
3697 return cast<llvm::DIType>(
V);
3709 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
3719llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
3723 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
3725 llvm::raw_string_ostream OS(Name);
3726 Ty.
print(OS, getPrintingPolicy());
3733 if (
auto *
T = getTypeOrNull(Ty))
3736 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
3737 void *TyPtr = Ty.getAsOpaquePtr();
3740 TypeCache[TyPtr].reset(Res);
3745llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *
D) {
3753 auto Info = Reader->getSourceDescriptor(Idx);
3755 return getOrCreateModuleRef(*Info,
true);
3756 }
else if (ClangModuleMap) {
3770 return getOrCreateModuleRef(Info,
false);
3773 return getOrCreateModuleRef(PCHDescriptor,
false);
3780llvm::DIType *CGDebugInfo::CreateTypeNode(
QualType Ty, llvm::DIFile *Unit) {
3783 return CreateQualifiedType(Ty, Unit);
3787#define TYPE(Class, Base)
3788#define ABSTRACT_TYPE(Class, Base)
3789#define NON_CANONICAL_TYPE(Class, Base)
3790#define DEPENDENT_TYPE(Class, Base) case Type::Class:
3791#include "clang/AST/TypeNodes.inc"
3792 llvm_unreachable(
"Dependent types cannot show up in debug information");
3794 case Type::ExtVector:
3796 return CreateType(cast<VectorType>(Ty), Unit);
3797 case Type::ConstantMatrix:
3798 return CreateType(cast<ConstantMatrixType>(Ty), Unit);
3799 case Type::ObjCObjectPointer:
3800 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
3801 case Type::ObjCObject:
3802 return CreateType(cast<ObjCObjectType>(Ty), Unit);
3803 case Type::ObjCTypeParam:
3804 return CreateType(cast<ObjCTypeParamType>(Ty), Unit);
3805 case Type::ObjCInterface:
3806 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
3808 return CreateType(cast<BuiltinType>(Ty));
3810 return CreateType(cast<ComplexType>(Ty));
3812 return CreateType(cast<PointerType>(Ty), Unit);
3813 case Type::BlockPointer:
3814 return CreateType(cast<BlockPointerType>(Ty), Unit);
3816 return CreateType(cast<TypedefType>(Ty), Unit);
3818 return CreateType(cast<RecordType>(Ty));
3820 return CreateEnumType(cast<EnumType>(Ty));
3821 case Type::FunctionProto:
3822 case Type::FunctionNoProto:
3823 return CreateType(cast<FunctionType>(Ty), Unit);
3824 case Type::ConstantArray:
3825 case Type::VariableArray:
3826 case Type::IncompleteArray:
3827 case Type::ArrayParameter:
3828 return CreateType(cast<ArrayType>(Ty), Unit);
3830 case Type::LValueReference:
3831 return CreateType(cast<LValueReferenceType>(Ty), Unit);
3832 case Type::RValueReference:
3833 return CreateType(cast<RValueReferenceType>(Ty), Unit);
3835 case Type::MemberPointer:
3836 return CreateType(cast<MemberPointerType>(Ty), Unit);
3839 return CreateType(cast<AtomicType>(Ty), Unit);
3842 return CreateType(cast<BitIntType>(Ty));
3844 return CreateType(cast<PipeType>(Ty), Unit);
3846 case Type::TemplateSpecialization:
3847 return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
3849 case Type::CountAttributed:
3851 case Type::Attributed:
3852 case Type::BTFTagAttributed:
3853 case Type::Adjusted:
3855 case Type::DeducedTemplateSpecialization:
3856 case Type::Elaborated:
3859 case Type::MacroQualified:
3860 case Type::SubstTemplateTypeParm:
3861 case Type::TypeOfExpr:
3863 case Type::Decltype:
3864 case Type::PackIndexing:
3865 case Type::UnaryTransform:
3869 llvm_unreachable(
"type should have been unwrapped!");
3872llvm::DICompositeType *
3873CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
3876 auto *
T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
3881 if (
T && !
T->isForwardDecl())
3885 llvm::DICompositeType *Res = CreateLimitedType(Ty);
3890 DBuilder.replaceArrays(Res,
T ?
T->getElements() : llvm::DINodeArray());
3893 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
3898llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
3902 StringRef RDName = getClassName(RD);
3904 llvm::DIFile *DefUnit =
nullptr;
3907 DefUnit = getOrCreateFile(
Loc);
3911 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
3915 auto *
T = cast_or_null<llvm::DICompositeType>(
3923 if (!
D || !
D->isCompleteDefinition())
3924 return getOrCreateRecordFwdDecl(Ty, RDContext);
3937 auto Flags = llvm::DINode::FlagZero;
3938 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
3940 Flags |= llvm::DINode::FlagTypePassByReference;
3942 Flags |= llvm::DINode::FlagTypePassByValue;
3945 if (!CXXRD->isTrivial())
3946 Flags |= llvm::DINode::FlagNonTrivial;
3949 if (CXXRD->isAnonymousStructOrUnion())
3950 Flags |= llvm::DINode::FlagExportSymbols;
3953 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
3956 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(
D);
3957 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
3963 switch (RealDecl->getTag()) {
3965 llvm_unreachable(
"invalid composite type tag");
3967 case llvm::dwarf::DW_TAG_array_type:
3968 case llvm::dwarf::DW_TAG_enumeration_type:
3977 case llvm::dwarf::DW_TAG_structure_type:
3978 case llvm::dwarf::DW_TAG_union_type:
3979 case llvm::dwarf::DW_TAG_class_type:
3982 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
3986 RegionMap[Ty->
getDecl()].reset(RealDecl);
3989 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3990 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
3991 CollectCXXTemplateParams(TSpecial, DefUnit));
3995void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
3996 llvm::DICompositeType *RealDecl) {
3998 llvm::DIType *ContainingType =
nullptr;
4010 ContainingType = getOrCreateType(
QualType(PBase->getTypeForDecl(), 0),
4013 ContainingType = RealDecl;
4015 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4018llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit,
QualType FType,
4019 StringRef Name, uint64_t *Offset) {
4020 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4024 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4025 *Offset, llvm::DINode::FlagZero, FieldTy);
4026 *Offset += FieldSize;
4030void CGDebugInfo::collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
4032 StringRef &LinkageName,
4033 llvm::DIScope *&FDContext,
4034 llvm::DINodeArray &TParamsArray,
4035 llvm::DINode::DIFlags &Flags) {
4037 Name = getFunctionName(FD);
4042 Flags |= llvm::DINode::FlagPrototyped;
4046 if (LinkageName == Name ||
4051 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4052 LinkageName = StringRef();
4057 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4061 FDContext = getOrCreateNamespace(NSDecl);
4064 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4065 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4071 Flags |= llvm::DINode::FlagNoReturn;
4073 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4077void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4079 StringRef &Name, StringRef &LinkageName,
4080 llvm::MDTuple *&TemplateParameters,
4081 llvm::DIScope *&VDContext) {
4090 llvm::APInt ConstVal(32, 1);
4101 if (LinkageName == Name)
4102 LinkageName = StringRef();
4104 if (isa<VarTemplateSpecializationDecl>(VD)) {
4105 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4106 TemplateParameters = parameterNodes.get();
4108 TemplateParameters =
nullptr;
4128 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4129 VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
4132llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(
GlobalDecl GD,
4134 llvm::DINodeArray TParamsArray;
4135 StringRef Name, LinkageName;
4136 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4137 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4139 llvm::DIFile *Unit = getOrCreateFile(
Loc);
4140 llvm::DIScope *DContext = Unit;
4141 unsigned Line = getLineNumber(
Loc);
4142 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4144 auto *FD = cast<FunctionDecl>(GD.
getDecl());
4149 ArgTypes.push_back(Parm->getType());
4155 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4157 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4160 Flags |= getCallSiteRelatedAttrs();
4161 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4162 return DBuilder.createFunction(
4163 DContext, Name, LinkageName, Unit,
Line,
4164 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4165 TParamsArray.get(), getFunctionDeclaration(FD));
4168 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4169 DContext, Name, LinkageName, Unit,
Line,
4170 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4171 TParamsArray.get(), getFunctionDeclaration(FD));
4173 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4174 std::make_tuple(CanonDecl),
4175 std::make_tuple(SP));
4179llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(
GlobalDecl GD) {
4180 return getFunctionFwdDeclOrStub(GD,
false);
4183llvm::DISubprogram *CGDebugInfo::getFunctionStub(
GlobalDecl GD) {
4184 return getFunctionFwdDeclOrStub(GD,
true);
4187llvm::DIGlobalVariable *
4188CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4190 StringRef Name, LinkageName;
4192 llvm::DIFile *Unit = getOrCreateFile(
Loc);
4193 llvm::DIScope *DContext = Unit;
4194 unsigned Line = getLineNumber(
Loc);
4195 llvm::MDTuple *TemplateParameters =
nullptr;
4197 collectVarDeclProps(VD, Unit,
Line,
T, Name, LinkageName, TemplateParameters,
4200 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4201 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(
T, Unit),
4203 FwdDeclReplaceMap.emplace_back(
4204 std::piecewise_construct,
4206 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4210llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *
D) {
4215 if (
const auto *TD = dyn_cast<TypeDecl>(
D))
4220 if (I != DeclCache.end()) {
4222 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4223 return GVE->getVariable();
4224 return cast<llvm::DINode>(N);
4231 if (IE != ImportedDeclCache.end()) {
4232 auto N = IE->second;
4233 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4234 return cast<llvm::DINode>(GVE);
4235 return dyn_cast_or_null<llvm::DINode>(N);
4240 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
4241 return getFunctionForwardDeclaration(FD);
4242 else if (
const auto *VD = dyn_cast<VarDecl>(
D))
4243 return getGlobalVariableForwardDeclaration(VD);
4248llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *
D) {
4249 if (!
D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4252 const auto *FD = dyn_cast<FunctionDecl>(
D);
4257 auto *S = getDeclContextDescriptor(
D);
4260 if (MI == SPCache.end()) {
4262 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
4263 cast<llvm::DICompositeType>(S));
4266 if (MI != SPCache.end()) {
4267 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4268 if (SP && !SP->isDefinition())
4272 for (
auto *NextFD : FD->
redecls()) {
4273 auto MI = SPCache.find(NextFD->getCanonicalDecl());
4274 if (MI != SPCache.end()) {
4275 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4276 if (SP && !SP->isDefinition())
4283llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
4284 const Decl *
D, llvm::DISubroutineType *FnType,
unsigned LineNo,
4285 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
4286 if (!
D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4289 const auto *OMD = dyn_cast<ObjCMethodDecl>(
D);
4297 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
4307 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4308 if (It == TypeCache.end())
4310 auto *InterfaceType = cast<llvm::DICompositeType>(It->second);
4311 llvm::DISubprogram *FD = DBuilder.createFunction(
4312 InterfaceType, getObjCMethodName(OMD), StringRef(),
4313 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
4314 DBuilder.finalizeSubprogram(FD);
4321llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *
D,
4326 if (!
D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
4330 return DBuilder.createSubroutineType(
4331 DBuilder.getOrCreateTypeArray(std::nullopt));
4333 if (
const auto *Method = dyn_cast<CXXMethodDecl>(
D))
4334 return getOrCreateMethodType(Method, F);
4339 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(
D)) {
4344 QualType ResultTy = OMethod->getReturnType();
4349 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
4351 Elts.push_back(getOrCreateType(ResultTy, F));
4354 if (
auto *SelfDecl = OMethod->getSelfDecl())
4355 SelfDeclTy = SelfDecl->getType();
4356 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4359 if (!SelfDeclTy.
isNull())
4361 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
4363 Elts.push_back(DBuilder.createArtificialType(
4366 for (
const auto *PI : OMethod->parameters())
4367 Elts.push_back(getOrCreateType(PI->getType(), F));
4369 if (OMethod->isVariadic())
4370 Elts.push_back(DBuilder.createUnspecifiedParameter());
4372 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
4373 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
4379 if (
const auto *FD = dyn_cast<FunctionDecl>(
D))
4380 if (FD->isVariadic()) {
4382 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
4383 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4385 EltTys.push_back(getOrCreateType(ParamType, F));
4386 EltTys.push_back(DBuilder.createUnspecifiedParameter());
4387 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
4388 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
4392 return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
4401 CC = SrcFnTy->getCallConv();
4403 for (
const VarDecl *VD : Args)
4404 ArgTypes.push_back(VD->
getType());
4411 llvm::Function *Fn,
bool CurFuncIsThunk) {
4413 StringRef LinkageName;
4415 FnBeginRegionCount.push_back(LexicalBlockStack.size());
4418 bool HasDecl = (
D !=
nullptr);
4420 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4421 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4422 llvm::DIFile *Unit = getOrCreateFile(
Loc);
4423 llvm::DIScope *FDContext = Unit;
4424 llvm::DINodeArray TParamsArray;
4427 LinkageName = Fn->getName();
4428 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(
D)) {
4430 auto FI = SPCache.find(FD->getCanonicalDecl());
4431 if (FI != SPCache.end()) {
4432 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
4433 if (SP && SP->isDefinition()) {
4434 LexicalBlockStack.emplace_back(SP);
4435 RegionMap[
D].reset(SP);
4439 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
4440 TParamsArray, Flags);
4441 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(
D)) {
4442 Name = getObjCMethodName(OMD);
4443 Flags |= llvm::DINode::FlagPrototyped;
4444 }
else if (isa<VarDecl>(
D) &&
4450 Name = Fn->getName();
4452 if (isa<BlockDecl>(
D))
4455 Flags |= llvm::DINode::FlagPrototyped;
4457 if (Name.starts_with(
"\01"))
4458 Name = Name.substr(1);
4460 assert((!
D || !isa<VarDecl>(
D) ||
4462 "Unexpected DynamicInitKind !");
4465 isa<VarDecl>(
D) || isa<CapturedDecl>(
D)) {
4466 Flags |= llvm::DINode::FlagArtificial;
4472 Flags |= llvm::DINode::FlagThunk;
4474 if (Fn->hasLocalLinkage())
4475 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4477 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4479 llvm::DINode::DIFlags FlagsForDef = Flags | getCallSiteRelatedAttrs();
4480 llvm::DISubprogram::DISPFlags SPFlagsForDef =
4481 SPFlags | llvm::DISubprogram::SPFlagDefinition;
4483 const unsigned LineNo = getLineNumber(
Loc.
isValid() ?
Loc : CurLoc);
4484 unsigned ScopeLine = getLineNumber(ScopeLoc);
4485 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(
D, FnType, Unit);
4486 llvm::DISubprogram *
Decl =
nullptr;
4487 llvm::DINodeArray Annotations =
nullptr;
4489 Decl = isa<ObjCMethodDecl>(
D)
4490 ? getObjCMethodDeclaration(
D, DIFnType, LineNo, Flags, SPFlags)
4491 : getFunctionDeclaration(
D);
4492 Annotations = CollectBTFDeclTagAnnotations(
D);
4500 llvm::DISubprogram *SP = DBuilder.createFunction(
4501 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
4502 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
4504 Fn->setSubprogram(SP);
4508 if (HasDecl && isa<FunctionDecl>(
D))
4512 LexicalBlockStack.emplace_back(SP);
4515 RegionMap[
D].reset(SP);
4519 QualType FnType, llvm::Function *Fn) {
4521 StringRef LinkageName;
4527 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
4528 return GetName(
D,
true);
4531 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4532 llvm::DIFile *Unit = getOrCreateFile(
Loc);
4533 bool IsDeclForCallSite = Fn ?
true :
false;
4534 llvm::DIScope *FDContext =
4535 IsDeclForCallSite ? Unit : getDeclContextDescriptor(
D);
4536 llvm::DINodeArray TParamsArray;
4537 if (isa<FunctionDecl>(
D)) {
4539 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
4540 TParamsArray, Flags);
4541 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(
D)) {
4542 Name = getObjCMethodName(OMD);
4543 Flags |= llvm::DINode::FlagPrototyped;
4545 llvm_unreachable(
"not a function or ObjC method");
4547 if (!Name.empty() && Name[0] ==
'\01')
4548 Name = Name.substr(1);
4551 Flags |= llvm::DINode::FlagArtificial;
4556 unsigned LineNo = getLineNumber(
Loc);
4557 unsigned ScopeLine = 0;
4558 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4560 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4562 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(
D);
4563 llvm::DISubroutineType *STy = getOrCreateFunctionType(
D, FnType, Unit);
4564 llvm::DISubprogram *SP = DBuilder.createFunction(
4565 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
4566 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations);
4572 if (
auto *FD = dyn_cast<FunctionDecl>(
D)) {
4573 llvm::DITypeRefArray ParamTypes = STy->getTypeArray();
4576 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
4577 DBuilder.createParameterVariable(
4578 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
4579 llvm::DINode::FlagZero, ParamAnnotations);
4585 if (IsDeclForCallSite)
4586 Fn->setSubprogram(SP);
4588 DBuilder.finalizeSubprogram(SP);
4596 auto *
Func = CallOrInvoke->getCalledFunction();
4599 if (
Func->getSubprogram())
4604 if (CalleeDecl->
hasAttr<NoDebugAttr>() ||
4605 getCallSiteRelatedAttrs() == llvm::DINode::FlagZero)
4616 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
4618 auto FI = SPCache.find(FD->getCanonicalDecl());
4619 llvm::DISubprogram *SP =
nullptr;
4620 if (FI != SPCache.end())
4621 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
4622 if (!SP || !SP->isDefinition())
4623 SP = getFunctionStub(GD);
4624 FnBeginRegionCount.push_back(LexicalBlockStack.size());
4625 LexicalBlockStack.emplace_back(SP);
4631 assert(CurInlinedAt &&
"unbalanced inline scope stack");
4640 if (CurLoc.isInvalid() || CurLoc.isMacroID() || LexicalBlockStack.empty())
4643 llvm::MDNode *
Scope = LexicalBlockStack.back();
4644 Builder.SetCurrentDebugLocation(
4645 llvm::DILocation::get(CGM.
getLLVMContext(), getLineNumber(CurLoc),
4646 getColumnNumber(CurLoc),
Scope, CurInlinedAt));
4650 llvm::MDNode *Back =
nullptr;
4651 if (!LexicalBlockStack.empty())
4652 Back = LexicalBlockStack.back().get();
4653 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
4654 cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
4655 getColumnNumber(CurLoc)));
4658void CGDebugInfo::AppendAddressSpaceXDeref(
4660 std::optional<unsigned> DWARFAddressSpace =
4662 if (!DWARFAddressSpace)
4665 Expr.push_back(llvm::dwarf::DW_OP_constu);
4666 Expr.push_back(*DWARFAddressSpace);
4667 Expr.push_back(llvm::dwarf::DW_OP_swap);
4668 Expr.push_back(llvm::dwarf::DW_OP_xderef);
4677 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
4679 LexicalBlockStack.back(), CurInlinedAt));
4681 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4685 CreateLexicalBlock(
Loc);
4690 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4695 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4698 LexicalBlockStack.pop_back();
4702 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4703 unsigned RCount = FnBeginRegionCount.back();
4704 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
4707 while (LexicalBlockStack.size() != RCount) {
4710 LexicalBlockStack.pop_back();
4712 FnBeginRegionCount.pop_back();
4714 if (Fn && Fn->getSubprogram())
4715 DBuilder.finalizeSubprogram(Fn->getSubprogram());
4718CGDebugInfo::BlockByRefType
4719CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
4720 uint64_t *XOffset) {
4723 uint64_t FieldSize, FieldOffset;
4724 uint32_t FieldAlign;
4726 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
4731 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
4732 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
4734 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
4735 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
4738 if (HasCopyAndDispose) {
4741 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
4743 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
4745 bool HasByrefExtendedLayout;
4748 HasByrefExtendedLayout) &&
4749 HasByrefExtendedLayout) {
4752 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
4761 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
4764 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
4767 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
4772 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
4776 *XOffset = FieldOffset;
4777 llvm::DIType *FieldTy = DBuilder.createMemberType(
4778 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
4779 llvm::DINode::FlagZero, WrappedTy);
4780 EltTys.push_back(FieldTy);
4781 FieldOffset += FieldSize;
4783 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
4784 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
4785 llvm::DINode::FlagZero,
nullptr, Elements),
4789llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
4790 llvm::Value *Storage,
4791 std::optional<unsigned> ArgNo,
4793 const bool UsePointerValue) {
4795 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4796 if (VD->
hasAttr<NoDebugAttr>())
4801 llvm::DIFile *Unit =
nullptr;
4802 if (!VarIsArtificial)
4806 if (VD->
hasAttr<BlocksAttr>())
4807 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
4809 Ty = getOrCreateType(VD->
getType(), Unit);
4819 if (!VarIsArtificial) {
4824 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4825 if (VarIsArtificial)
4826 Flags |= llvm::DINode::FlagArtificial;
4831 AppendAddressSpaceXDeref(AddressSpace,
Expr);
4835 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
4838 Flags |= llvm::DINode::FlagObjectPointer;
4845 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
4846 StringRef Name = VD->
getName();
4847 if (!Name.empty()) {
4853 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4858 Expr.push_back(llvm::dwarf::DW_OP_deref);
4859 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
4864 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
4876 for (
const auto *Field : RD->
fields()) {
4877 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
4878 StringRef FieldName =
Field->getName();
4881 if (FieldName.empty() && !isa<RecordType>(
Field->getType()))
4886 auto *
D = DBuilder.createAutoVariable(
4888 Flags | llvm::DINode::FlagArtificial, FieldAlign);
4891 DBuilder.insertDeclare(Storage,
D, DBuilder.createExpression(
Expr),
4895 Builder.GetInsertBlock());
4903 if (UsePointerValue) {
4904 assert(!llvm::is_contained(
Expr, llvm::dwarf::DW_OP_deref) &&
4905 "Debug info already contains DW_OP_deref.");
4906 Expr.push_back(llvm::dwarf::DW_OP_deref);
4910 llvm::DILocalVariable *
D =
nullptr;
4912 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
4913 D = DBuilder.createParameterVariable(
Scope, Name, *ArgNo, Unit,
Line, Ty,
4924 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
4927 if (!isa<llvm::DISubprogram>(
Scope) || !
Scope->isDistinct())
4930 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
4931 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
4932 if (
DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
4935 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
4941 if (
Iter != CoroutineParameterMappings.end()) {
4943 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
4944 return DbgPair.first == PD && DbgPair.second->getScope() ==
Scope;
4946 if (Iter2 != ParamDbgMappings.end())
4947 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
4953 D = RemapCoroArgToLocalVar();
4956 D = DBuilder.createAutoVariable(
Scope, Name, Unit,
Line, Ty,
4960 DBuilder.insertDeclare(Storage,
D, DBuilder.createExpression(
Expr),
4963 Builder.GetInsertBlock());
4968llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
4969 llvm::Value *Storage,
4970 std::optional<unsigned> ArgNo,
4972 const bool UsePointerValue) {
4974 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4975 if (BD->
hasAttr<NoDebugAttr>())
4982 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
4983 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
4994 AppendAddressSpaceXDeref(AddressSpace,
Expr);
4999 if (UsePointerValue) {
5000 assert(!llvm::is_contained(
Expr, llvm::dwarf::DW_OP_deref) &&
5001 "Debug info already contains DW_OP_deref.");
5002 Expr.push_back(llvm::dwarf::DW_OP_deref);
5007 StringRef Name = BD->
getName();
5008 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
5010 llvm::DILocalVariable *
D = DBuilder.createAutoVariable(
5012 llvm::DINode::FlagZero, Align);
5015 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5016 const unsigned fieldIndex = FD->getFieldIndex();
5022 if (FD->isBitField()) {
5029 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5035 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5036 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5041 Expr.push_back(std::min((uint64_t)Info.
Size, TypeSize));
5042 }
else if (fieldOffset != 0) {
5044 "Unexpected non-bitfield with non-byte-aligned offset");
5045 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5051 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5052 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5053 const uint64_t value = IL->getValue().getZExtValue();
5057 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5066 DBuilder.insertDeclare(Storage,
D, DBuilder.createExpression(
Expr),
5069 Builder.GetInsertBlock());
5074llvm::DILocalVariable *
5077 const bool UsePointerValue) {
5080 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5081 for (
auto *B : DD->bindings()) {
5082 EmitDeclare(B, Storage, std::nullopt, Builder,
5090 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5095 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5100 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
5101 llvm::DIFile *Unit = getOrCreateFile(
D->
getLocation());
5107 StringRef Name =
D->getName();
5114 DBuilder.insertLabel(L,
5116 Scope, CurInlinedAt),
5117 Builder.GetInsertBlock());
5120llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5122 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5125 return DBuilder.createObjectPointerType(Ty);
5130 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5132 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5134 if (Builder.GetInsertBlock() ==
nullptr)
5136 if (VD->
hasAttr<NoDebugAttr>())
5139 bool isByRef = VD->
hasAttr<BlocksAttr>();
5141 uint64_t XOffset = 0;
5142 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5145 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5147 Ty = getOrCreateType(VD->
getType(), Unit);
5151 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5153 Ty = CreateSelfType(VD->
getType(), Ty);
5156 const unsigned Line =
5167 addr.push_back(llvm::dwarf::DW_OP_deref);
5168 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5171 addr.push_back(llvm::dwarf::DW_OP_deref);
5172 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5177 addr.push_back(llvm::dwarf::DW_OP_deref);
5178 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5186 auto *
D = DBuilder.createAutoVariable(
5187 cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->
getName(), Unit,
5188 Line, Ty,
false, llvm::DINode::FlagZero, Align);
5192 LexicalBlockStack.back(), CurInlinedAt);
5193 auto *
Expr = DBuilder.createExpression(addr);
5195 DBuilder.insertDeclare(Storage,
D,
Expr, DL, InsertPoint);
5197 DBuilder.insertDeclare(Storage,
D,
Expr, DL, Builder.GetInsertBlock());
5200llvm::DILocalVariable *
5203 bool UsePointerValue) {
5205 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
5209struct BlockLayoutChunk {
5210 uint64_t OffsetInBits;
5213bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
5214 return l.OffsetInBits < r.OffsetInBits;
5218void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
5220 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
5227 BlockLayout.getElementOffsetInBits(0),
5230 BlockLayout.getElementOffsetInBits(1),
5234 BlockLayout.getElementOffsetInBits(0),
5237 BlockLayout.getElementOffsetInBits(1),
5241 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
5242 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
5244 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType,
Loc,
AS_public,
5245 BlockLayout.getElementOffsetInBits(3),
5247 Fields.push_back(createFieldType(
5252 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
5259 llvm::AllocaInst *Alloca,
5267 llvm::DIFile *tunit = getOrCreateFile(loc);
5268 unsigned line = getLineNumber(loc);
5269 unsigned column = getColumnNumber(loc);
5274 const llvm::StructLayout *blockLayout =
5278 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
5287 BlockLayoutChunk chunk;
5288 chunk.OffsetInBits =
5289 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
5290 chunk.Capture =
nullptr;
5291 chunks.push_back(chunk);
5295 for (
const auto &capture :
blockDecl->captures()) {
5296 const VarDecl *variable = capture.getVariable();
5303 BlockLayoutChunk chunk;
5304 chunk.OffsetInBits =
5305 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
5306 chunk.Capture = &capture;
5307 chunks.push_back(chunk);
5311 llvm::array_pod_sort(chunks.begin(), chunks.end());
5313 for (
const BlockLayoutChunk &Chunk : chunks) {
5314 uint64_t offsetInBits = Chunk.OffsetInBits;
5321 cast_or_null<CXXMethodDecl>(
blockDecl->getNonClosureContext()))
5323 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(
blockDecl->getParent()))
5326 llvm_unreachable(
"unexpected block declcontext");
5328 fields.push_back(createFieldType(
"this",
type, loc,
AS_public,
5329 offsetInBits, tunit, tunit));
5334 StringRef name = variable->
getName();
5336 llvm::DIType *fieldType;
5338 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
5343 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
5344 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
5345 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
5346 PtrInfo.
Width, Align, offsetInBits,
5347 llvm::DINode::FlagZero, fieldType);
5351 offsetInBits, Align, tunit, tunit);
5353 fields.push_back(fieldType);
5357 llvm::raw_svector_ostream(typeName)
5360 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
5362 llvm::DIType *
type =
5363 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
5365 llvm::DINode::FlagZero,
nullptr, fieldsArray);
5369 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
5370 auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
5373 auto *debugVar = DBuilder.createParameterVariable(
5374 scope, Name, ArgNo, tunit, line,
type, CGM.
getLangOpts().Optimize, flags);
5377 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
5379 column, scope, CurInlinedAt),
5380 Builder.GetInsertBlock());
5383llvm::DIDerivedType *
5384CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *
D) {
5385 if (!
D || !
D->isStaticDataMember())
5389 if (MI != StaticDataMemberCache.end()) {
5390 assert(MI->second &&
"Static data member declaration should still exist");
5397 auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(
D));
5398 return CreateRecordStaticField(
D, Ctxt, cast<RecordDecl>(DC));
5401llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
5402 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
5403 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5404 llvm::DIGlobalVariableExpression *GVE =
nullptr;
5406 for (
const auto *Field : RD->
fields()) {
5407 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
5408 StringRef FieldName = Field->getName();
5411 if (FieldName.empty()) {
5412 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
5413 GVE = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
5418 GVE = DBuilder.createGlobalVariableExpression(
5419 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
5420 Var->hasLocalLinkage());
5421 Var->addDebugInfo(GVE);
5433 const auto *RD = dyn_cast<CXXRecordDecl>(RT->
getDecl());
5438 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
5446 case TemplateArgument::Pack:
5447 return ReferencesAnonymousEntity(TA.getPackAsArray());
5448 case TemplateArgument::Type: {
5449 struct ReferencesAnonymous
5450 : public RecursiveASTVisitor<ReferencesAnonymous> {
5451 bool RefAnon = false;
5452 bool VisitRecordType(RecordType *RT) {
5453 if (ReferencesAnonymousEntity(RT)) {
5460 ReferencesAnonymous RT;
5461 RT.TraverseType(TA.getAsType());
5474 bool Reconstitutable =
true;
5476 Reconstitutable =
false;
5480 Reconstitutable =
false;
5483 bool VisitType(
Type *
T) {
5487 Reconstitutable =
false;
5492 bool TraverseEnumType(
EnumType *ET) {
5495 if (
const auto *ED = dyn_cast<EnumDecl>(ET->
getDecl())) {
5497 Reconstitutable =
false;
5501 Reconstitutable =
false;
5511 return Reconstitutable;
5515 Reconstitutable =
false;
5525 ReconstitutableType
T;
5527 return T.Reconstitutable;
5530bool CGDebugInfo::HasReconstitutableArgs(
5534 case TemplateArgument::Template:
5541 case TemplateArgument::Declaration:
5550 case TemplateArgument::NullPtr:
5554 case TemplateArgument::Pack:
5557 return HasReconstitutableArgs(TA.getPackAsArray());
5558 case TemplateArgument::Integral:
5563 return TA.getAsIntegral().getBitWidth() <= 64 &&
5564 IsReconstitutableType(TA.getIntegralType());
5565 case TemplateArgument::StructuralValue:
5567 case TemplateArgument::Type:
5568 return IsReconstitutableType(TA.getAsType());
5569 case TemplateArgument::Expression:
5570 return IsReconstitutableType(TA.getAsExpr()->getType());
5572 llvm_unreachable(
"Other, unresolved, template arguments should "
5573 "not be seen here");
5578std::string CGDebugInfo::GetName(
const Decl *
D,
bool Qualified)
const {
5580 llvm::raw_string_ostream OS(Name);
5581 const NamedDecl *ND = dyn_cast<NamedDecl>(
D);
5584 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
5588 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
5590 std::optional<TemplateArgs> Args;
5592 bool IsOperatorOverload =
false;
5593 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
5594 Args = GetTemplateArgs(RD);
5595 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
5596 Args = GetTemplateArgs(FD);
5598 IsOperatorOverload |=
5601 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
5602 Args = GetTemplateArgs(VD);
5626 bool Reconstitutable =
5627 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
5631 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
5635 bool Mangled = TemplateNamesKind ==
5636 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
5642 std::string EncodedOriginalName;
5643 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
5651 std::string CanonicalOriginalName;
5652 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
5654 assert(EncodedOriginalNameOS.str() == OriginalOS.str());
5667 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
5668 return GetName(
D,
true);
5674 if (Cached != DeclCache.end())
5675 return Var->addDebugInfo(
5676 cast<llvm::DIGlobalVariableExpression>(Cached->second));
5679 llvm::DIFile *Unit =
nullptr;
5680 llvm::DIScope *DContext =
nullptr;
5682 StringRef DeclName, LinkageName;
5684 llvm::MDTuple *TemplateParameters =
nullptr;
5685 collectVarDeclProps(
D, Unit, LineNo,
T, DeclName, LinkageName,
5686 TemplateParameters, DContext);
5690 llvm::DIGlobalVariableExpression *GVE =
nullptr;
5698 "unnamed non-anonymous struct or union?");
5699 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
5709 else if (
D->
hasAttr<CUDAConstantAttr>())
5713 AppendAddressSpaceXDeref(AddressSpace,
Expr);
5715 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(
D);
5716 GVE = DBuilder.createGlobalVariableExpression(
5717 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(
T, Unit),
5718 Var->hasLocalLinkage(),
true,
5719 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
5720 getOrCreateStaticDataMemberDeclarationOrNull(
D), TemplateParameters,
5721 Align, Annotations);
5722 Var->addDebugInfo(GVE);
5729 if (VD->
hasAttr<NoDebugAttr>())
5731 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
5732 return GetName(VD,
true);
5737 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5738 StringRef Name = VD->
getName();
5739 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
5741 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
5742 const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
5743 assert(isa<EnumType>(ED->
getTypeForDecl()) &&
"Enum without EnumType?");
5756 llvm::DIType *EDTy =
5758 assert (EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
5769 auto *VarD = dyn_cast<VarDecl>(VD);
5770 if (VarD && VarD->isStaticDataMember()) {
5771 auto *RD = cast<RecordDecl>(VarD->getDeclContext());
5772 getDeclContextDescriptor(VarD);
5777 RetainedTypes.push_back(
5782 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
5784 auto &GV = DeclCache[VD];
5788 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
5789 llvm::MDTuple *TemplateParameters =
nullptr;
5791 if (isa<VarTemplateSpecializationDecl>(VD))
5793 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
5794 TemplateParameters = parameterNodes.get();
5797 GV.reset(DBuilder.createGlobalVariableExpression(
5798 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
5799 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
5800 TemplateParameters, Align));
5810 llvm::DIFile *Unit = getOrCreateFile(
D->
getLocation());
5811 StringRef Name =
D->getName();
5812 llvm::DIType *Ty = getOrCreateType(
D->getType(), Unit);
5814 llvm::DIScope *DContext = getDeclContextDescriptor(
D);
5815 llvm::DIGlobalVariableExpression *GVE =
5816 DBuilder.createGlobalVariableExpression(
5817 DContext, Name, StringRef(), Unit, getLineNumber(
D->
getLocation()),
5818 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
5819 Var->addDebugInfo(GVE);
5827 llvm::codegenoptions::DebugLineTablesOnly)
5830 llvm::DILocation *DIL =
Value->getDebugLoc().get();
5834 llvm::DIFile *Unit = DIL->getFile();
5835 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
5840 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
5841 llvm::Value *Var = Load->getPointerOperand();
5846 auto DeclareTypeMatches = [&](
auto *DbgDeclare) {
5847 return DbgDeclare->getVariable()->getType() ==
Type;
5849 if (any_of(llvm::findDbgDeclares(Var), DeclareTypeMatches) ||
5850 any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
5854 llvm::DILocalVariable *
D =
5855 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
5856 Type,
false, llvm::DINode::FlagArtificial);
5858 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
5859 DBuilder.insertDbgValueIntrinsic(
Value,
D, DBuilder.createExpression(), DIL,
5872 const auto *
D = cast<ValueDecl>(GD.
getDecl());
5891 if (!(DI = getDeclarationOrDefinition(
5892 AliaseeDecl.getCanonicalDecl().getDecl())))
5895 llvm::DIScope *DContext = getDeclContextDescriptor(
D);
5898 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
5899 DContext, DI, getOrCreateFile(
Loc), getLineNumber(
Loc),
D->getName());
5912 llvm::DIFile *
File = getOrCreateFile(
Loc);
5913 llvm::DIGlobalVariableExpression *Debug =
5914 DBuilder.createGlobalVariableExpression(
5915 nullptr, StringRef(), StringRef(), getOrCreateFile(
Loc),
5916 getLineNumber(
Loc), getOrCreateType(S->getType(),
File),
true);
5917 GV->addDebugInfo(Debug);
5920llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *
D) {
5921 if (!LexicalBlockStack.empty())
5922 return LexicalBlockStack.back();
5923 llvm::DIScope *Mod = getParentModuleOrNull(
D);
5924 return getContextDescriptor(
D, Mod ? Mod : TheCU);
5936 DBuilder.createImportedModule(
5938 getOrCreateNamespace(NSDecl), getOrCreateFile(
Loc), getLineNumber(
Loc));
5943 if (llvm::DINode *
Target =
5946 DBuilder.createImportedDeclaration(
5948 getOrCreateFile(
Loc), getLineNumber(
Loc));
5956 "We shouldn't be codegening an invalid UsingDecl containing no decls");
5958 for (
const auto *USD : UD.
shadows()) {
5963 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
5964 if (
const auto *AT = FD->getType()
5967 if (AT->getDeducedType().isNull())
5981 "We shouldn't be codegening an invalid UsingEnumDecl"
5982 " containing no decls");
5984 for (
const auto *USD : UD.
shadows())
5989 if (CGM.
getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
5991 if (
Module *M = ID.getImportedModule()) {
5993 auto Loc = ID.getLocation();
5994 DBuilder.createImportedDeclaration(
5995 getCurrentContextDescriptor(cast<Decl>(ID.getDeclContext())),
5996 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(
Loc),
5997 getLineNumber(
Loc));
6001llvm::DIImportedEntity *
6005 auto &VH = NamespaceAliasCache[&NA];
6007 return cast<llvm::DIImportedEntity>(VH);
6008 llvm::DIImportedEntity *R;
6010 if (
const auto *Underlying =
6013 R = DBuilder.createImportedDeclaration(
6018 R = DBuilder.createImportedDeclaration(
6027CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6031 auto I = NamespaceCache.find(NSDecl);
6032 if (I != NamespaceCache.end())
6033 return cast<llvm::DINamespace>(I->second);
6035 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6037 llvm::DINamespace *NS =
6038 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6039 NamespaceCache[NSDecl].reset(NS);
6044 assert(TheCU &&
"no main compile unit");
6045 TheCU->setDWOId(Signature);
6051 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6052 ObjCInterfaceCacheEntry
E = ObjCInterfaceCache[i];
6053 llvm::DIType *Ty =
E.Type->getDecl()->getDefinition()
6054 ? CreateTypeDefinition(
E.Type,
E.Unit)
6056 DBuilder.replaceTemporary(llvm::TempDIType(
E.Decl), Ty);
6060 for (
const auto &
P : ObjCMethodCache) {
6061 if (
P.second.empty())
6064 QualType QTy(
P.first->getTypeForDecl(), 0);
6066 assert(It != TypeCache.end());
6068 llvm::DICompositeType *InterfaceDecl =
6069 cast<llvm::DICompositeType>(It->second);
6071 auto CurElts = InterfaceDecl->getElements();
6075 for (
auto &SubprogramDirect :
P.second)
6076 if (CGM.
getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6077 EltTys.push_back(SubprogramDirect.getPointer());
6079 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6080 DBuilder.replaceArrays(InterfaceDecl, Elements);
6083 for (
const auto &
P : ReplaceMap) {
6085 auto *Ty = cast<llvm::DIType>(
P.second);
6086 assert(Ty->isForwardDecl());
6088 auto It = TypeCache.find(
P.first);
6089 assert(It != TypeCache.end());
6092 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6093 cast<llvm::DIType>(It->second));
6096 for (
const auto &
P : FwdDeclReplaceMap) {
6098 llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(
P.second));
6099 llvm::Metadata *Repl;
6101 auto It = DeclCache.find(
P.first);
6105 if (It == DeclCache.end())
6110 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6111 Repl = GVE->getVariable();
6112 DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
6117 for (
auto &RT : RetainedTypes)
6118 if (
auto MD = TypeCache[RT])
6119 DBuilder.retainType(cast<llvm::DIType>(MD));
6121 DBuilder.finalize();
6127 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6128 DBuilder.retainType(DieTy);
6133 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6134 DBuilder.retainType(DieTy);
6138 if (LexicalBlockStack.empty())
6139 return llvm::DebugLoc();
6141 llvm::MDNode *
Scope = LexicalBlockStack.back();
6146llvm::DINode::DIFlags CGDebugInfo::getCallSiteRelatedAttrs()
const {
6150 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6151 DebugKind == llvm::codegenoptions::LocTrackingOnly)
6152 return llvm::DINode::FlagZero;
6157 bool SupportsDWARFv4Ext =
6159 (CGM.
getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6160 CGM.
getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6162 if (!SupportsDWARFv4Ext && CGM.
getCodeGenOpts().DwarfVersion < 5)
6163 return llvm::DINode::FlagZero;
6165 return llvm::DINode::FlagAllCallsDescribed;
6176 return DBuilder.createConstantValueExpression(
6177 Val.
getFloat().bitcastToAPInt().getZExtValue());
6182 llvm::APSInt
const &ValInt = Val.
getInt();
6183 std::optional<uint64_t> ValIntOpt;
6184 if (ValInt.isUnsigned())
6185 ValIntOpt = ValInt.tryZExtValue();
6186 else if (
auto tmp = ValInt.trySExtValue())
6189 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6192 return DBuilder.createConstantValueExpression(ValIntOpt.value());
Defines the clang::ASTContext interface.
static bool IsReconstitutableType(QualType QT)
static void stripUnusedQualifiers(Qualifiers &Q)
static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU)
static bool IsArtificial(VarDecl const *VD)
Returns true if VD is a compiler-generated variable and should be treated as artificial for the purpo...
static bool needsTypeIdentifier(const TagDecl *TD, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static bool shouldOmitDefinition(llvm::codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access, const RecordDecl *RD)
Convert an AccessSpecifier into the corresponding DINode flag.
static llvm::DINode::DIFlags getRefFlags(const FunctionProtoType *Func)
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C)
static llvm::dwarf::Tag getTagForRecord(const RecordDecl *RD)
static llvm::SmallVector< TemplateArgument > GetTemplateArgs(const TemplateDecl *TD, const TemplateSpecializationType *Ty)
static bool isFunctionLocalClass(const CXXRecordDecl *RD)
isFunctionLocalClass - Return true if CXXRecordDecl is defined inside a function.
static uint32_t getDeclAlignIfRequired(const Decl *D, const ASTContext &Ctx)
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, CXXRecordDecl::method_iterator End)
static bool canUseCtorHoming(const CXXRecordDecl *RD)
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Getter)
static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD)
Return true if the class or any of its methods are marked dllimport.
static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx)
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Setter)
static bool isDefinedInClangModule(const RecordDecl *RD)
Does a type definition exist in an imported clang module?
static llvm::dwarf::Tag getNextQualifier(Qualifiers &Q)
static bool IsDecomposedVarDecl(VarDecl const *VD)
Returns true if VD is a a holding variable (aka a VarDecl retrieved using BindingDecl::getHoldingVar)...
static SmallString< 256 > getTypeIdentifier(const TagType *Ty, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static unsigned getDwarfCC(CallingConv CC)
static bool ReferencesAnonymousEntity(ArrayRef< TemplateArgument > Args)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
Defines the clang::FileManager interface and associated types.
llvm::MachO::Target Target
constexpr llvm::StringRef ClangTrapPrefix
static const NamedDecl * getDefinition(const Decl *D)
Defines the SourceManager interface.
Defines version macros and version-related utility functions for Clang.
__device__ __2f16 float c
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool getByrefLifetime(QualType Ty, Qualifiers::ObjCLifetime &Lifetime, bool &HasByrefExtendedLayout) const
Returns true, if given type has a known lifetime.
BuiltinVectorTypeInfo getBuiltinVectorTypeInfo(const BuiltinType *VecTy) const
Returns the element type, element count and number of vectors (in case of tuple) for a builtin vector...
SourceManager & getSourceManager()
TranslationUnitDecl * getTranslationUnitDecl() const
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl.
QualType getRecordType(const RecordDecl *Decl) const
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D,...
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getEnumType(const EnumDecl *Decl) const
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type.
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;.
const ASTRecordLayout & getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const
Get or compute information about the layout of the specified Objective-C interface.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
CanQualType UnsignedLongTy
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
QualType getBlockDescriptorType() const
Gets the struct used to keep track of the descriptor for pointer to blocks.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
const clang::PrintingPolicy & getPrintingPolicy() const
QualType getObjCIdType() const
Represents the Objective-CC id type.
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
CanQualType UnsignedCharTy
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
unsigned getTargetAddressSpace(LangAS AS) const
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
uint64_t getCharWidth() const
Return the size of the character type, in bits.
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getVBPtrOffset() const
getVBPtrOffset - Get the offset for virtual base table pointer.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
bool hasExtendableVFPtr() const
hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
Module * getModuleOrNull() const
ASTFileSignature getSignature() const
StringRef getASTFile() const
StringRef getPath() const
std::string getModuleName() const
ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
QualType getElementType() const
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
shadow_range shadows() const
A binding in a decomposition declaration.
Expr * getBinding() const
Get the expression to which this declaration is bound.
A fixed int type of a specified bitwidth.
A class which contains all the information about a particular captured value.
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
VarDecl * getVariable() const
The variable being captured.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
QualType getPointeeType() const
This class is used for builtin types like 'int'.
StringRef getName(const PrintingPolicy &Policy) const
Represents a C++ constructor within a class.
Represents a static or instance method of a struct/union/class.
unsigned size_overridden_methods() const
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
const CXXRecordDecl * getParent() const
Return the parent of this method declaration, which is the class in which this method is defined.
QualType getThisType() const
Return the type of the this pointer.
CXXMethodDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
Represents a C++ struct/union/class.
bool isAggregate() const
Determine whether this class is an aggregate (C++ [dcl.init.aggr]), which is a class with no user-dec...
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isLambda() const
Determine whether this class describes a lambda function object.
capture_const_iterator captures_end() const
method_range methods() const
bool hasConstexprNonCopyMoveConstructor() const
Determine whether this class has at least one constexpr constructor other than the copy or move const...
method_iterator method_begin() const
Method begin iterator.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
base_class_range vbases()
bool isDynamicClass() const
MSInheritanceModel getMSInheritanceModel() const
Returns the inheritance model used for this record.
bool hasDefinition() const
method_iterator method_end() const
Method past-the-end iterator.
capture_const_iterator captures_begin() const
llvm::iterator_range< base_class_const_iterator > base_class_const_range
A wrapper class around a pointer that always points to its canonical declaration.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isPositive() const
isPositive - Test whether the quantity is greater than zero.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
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 ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
llvm::SmallVector< std::pair< std::string, std::string >, 0 > DebugPrefixMap
std::string CoverageNotesFile
The filename with path we use for coverage notes files.
std::string CoverageDataFile
The filename with path we use for coverage data files.
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
bool hasReducedDebugInfo() const
Check if type and variable info should be emitted.
bool hasMaybeUnusedDebugInfo() const
Check if maybe unused type info should be emitted.
ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn)
Set up the CodeGenFunction's DebugInfo to produce inline locations for the function InlinedFn.
~ApplyInlineDebugLocation()
Restore everything back to the original state.
unsigned getIndex() const
CGBlockInfo - Information to generate a block literal.
unsigned CXXThisIndex
The field index of 'this' within the block, if there is one.
const BlockDecl * getBlockDecl() const
llvm::StructType * StructureType
const Capture & getCapture(const VarDecl *var) const
virtual CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD)
Get the ABI-specific "this" parameter adjustment to apply in the prologue of a virtual function.
@ RAA_Indirect
Pass it as a pointer to temporary memory.
virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)
Create a null member pointer of the given type.
virtual RecordArgABI getRecordArgABI(const CXXRecordDecl *RD) const =0
Returns how an argument of the given record type should be passed.
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
MangleContext & getMangleContext()
Gets the mangle context.
llvm::MDNode * getInlinedAt() const
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file.
void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl)
Emit information about global variable alias.
void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder)
Emit call to llvm.dbg.label for an label.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
void setInlinedAt(llvm::MDNode *InlinedAt)
Update the current inline scope.
void completeUnusedClass(const CXXRecordDecl &D)
void EmitUsingShadowDecl(const UsingShadowDecl &USD)
Emit a shadow decl brought in by a using or using-enum.
void EmitUsingEnumDecl(const UsingEnumDecl &UD)
Emit C++ using-enum declaration.
void EmitFunctionEnd(CGBuilderTy &Builder, llvm::Function *Fn)
Constructs the debug code for exiting a function.
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, QualType CalleeType, const FunctionDecl *CalleeDecl)
Emit debug info for an extern function being called.
void EmitUsingDecl(const UsingDecl &UD)
Emit C++ using declaration.
llvm::DIMacroFile * CreateTempMacroFile(llvm::DIMacroFile *Parent, SourceLocation LineLoc, SourceLocation FileLoc)
Create debug info for a file referenced by an #include directive.
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
void EmitExternalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about an external variable.
void emitFunctionStart(GlobalDecl GD, SourceLocation Loc, SourceLocation ScopeLoc, QualType FnType, llvm::Function *Fn, bool CurFnIsThunk)
Emit a call to llvm.dbg.function.start to indicate start of a new function.
llvm::DILocalVariable * EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder, bool UsePointerValue=false)
Emit call to llvm.dbg.declare for an argument variable declaration.
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the end of a new lexical block and pop the current block.
void EmitUsingDirective(const UsingDirectiveDecl &UD)
Emit C++ using directive.
void completeRequiredType(const RecordDecl *RD)
void EmitAndRetainType(QualType Ty)
Emit the type even if it might not be used.
void EmitInlineFunctionEnd(CGBuilderTy &Builder)
End an inlined function scope.
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType, llvm::Function *Fn=nullptr)
Emit debug info for a function declaration.
void AddStringLiteralDebugInfo(llvm::GlobalVariable *GV, const StringLiteral *S)
DebugInfo isn't attached to string literals by default.
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.
void completeClassData(const RecordDecl *RD)
void EmitInlineFunctionStart(CGBuilderTy &Builder, GlobalDecl GD)
Start a new scope for an inlined function.
void EmitImportDecl(const ImportDecl &ID)
Emit an @import declaration.
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.
llvm::DebugLoc SourceLocToDebugLoc(SourceLocation Loc)
CGDebugInfo(CodeGenModule &CGM)
void completeClass(const RecordDecl *RD)
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the beginning of a new lexical block and push the block onto the stack.
void setLocation(SourceLocation Loc)
Update the current source location.
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...
llvm::DILocation * CreateTrapFailureMessageFor(llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg)
Create a debug location from TrapLocation that adds an artificial inline frame where the frame name i...
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value, QualType Ty)
Emit a pseudo variable and debug info for an intermediate value if it does not correspond to a variab...
std::string remapDIPath(StringRef) const
Remap a given path with the current debug prefix map.
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy, SourceLocation Loc)
Add heapallocsite metadata for MSAllocator calls.
void setDwoId(uint64_t Signature)
Module debugging: Support for building PCMs.
QualType getFunctionType(const FunctionDecl *FD, QualType RetTy, const SmallVectorImpl< const VarDecl * > &Args)
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
void completeType(const EnumDecl *ED)
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.
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *ID, const ObjCIvarDecl *Ivar)
CGRecordLayout - This class handles struct and union layout info while lowering AST types to LLVM typ...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CGDebugInfo * getDebugInfo()
This class organizes the cross-function state that is used while generating LLVM code.
const PreprocessorOptions & getPreprocessorOpts() const
ConstantAddress GetAddrOfMSGuidDecl(const MSGuidDecl *GD)
Get the address of a GUID.
llvm::Module & getModule() const
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, ForDefinition_t IsForDefinition=NotForDefinition)
Return the address of the given function.
const IntrusiveRefCntPtr< llvm::vfs::FileSystem > & getFileSystem() const
const LangOptions & getLangOpts() const
int getUniqueBlockCount()
Fetches the global unique block count.
CodeGenTypes & getTypes()
const TargetInfo & getTarget() const
const llvm::DataLayout & getDataLayout() const
CGCXXABI & getCXXABI() const
ItaniumVTableContext & getItaniumVTableContext()
ASTContext & getContext() const
ConstantAddress GetAddrOfTemplateParamObject(const TemplateParamObjectDecl *TPO)
Get the address of a template parameter object.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, ForDefinition_t IsForDefinition=NotForDefinition)
Return the llvm::Constant for the address of the given global variable.
MicrosoftVTableContext & getMicrosoftVTableContext()
const HeaderSearchOptions & getHeaderSearchOpts() const
const TargetCodeGenInfo & getTargetCodeGenInfo()
const CodeGenOptions & getCodeGenOpts() const
StringRef getMangledName(GlobalDecl GD)
llvm::LLVMContext & getLLVMContext()
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
const GlobalDecl getMangledNameDecl(StringRef)
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
unsigned getTargetAddressSpace(QualType T) const
llvm::Constant * getPointer() const
llvm::Constant * emitAbstract(const Expr *E, QualType T)
Emit the result of the given expression as an abstract constant, asserting that it succeeded.
virtual bool shouldEmitDWARFBitFieldSeparators() const
Complex values, per C99 6.2.5p11.
Represents a concrete matrix type with constant number of rows and columns.
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext,...
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
DeclContext * getParent()
getParent - Returns the containing DeclContext.
DeclContext * getEnclosingNamespaceContext()
Retrieve the nearest enclosing namespace context.
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
Decl - This represents one declaration (or definition), e.g.
ASTContext & getASTContext() const LLVM_READONLY
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
unsigned getMaxAlignment() const
getMaxAlignment - return the maximum alignment specified by attributes on this decl,...
Module * getOwningModule() const
Get the module that owns this declaration (for visibility purposes).
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
bool isObjCZeroArgSelector() const
@ CXXConversionFunctionName
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
bool isObjCOneArgSelector() const
NameKind getNameKind() const
Determine what kind of name this is.
Represents a ValueDecl that came out of a declarator.
enumerator_range enumerators() const
bool isScoped() const
Returns true if this is a C++11 scoped enumeration.
QualType getIntegerType() const
Return the integer type this enum decl corresponds to.
EnumDecl * getDefinition() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums.
EnumDecl * getDecl() const
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
An opaque identifier used by SourceManager which refers to a source file (MemoryBuffer) along with it...
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
Represents a function declaration or definition.
bool hasCXXExplicitFunctionObjectParameter() const
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isDeleted() const
Whether this function has been deleted.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
@ TK_FunctionTemplateSpecialization
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
bool isPureVirtual() const
Whether this virtual function is pure, i.e.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
QualType getParamType(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > getParamTypes() const
ArrayRef< QualType > param_types() const
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
FunctionType - C99 6.7.5.3 - Function Declarators.
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
CallingConv getCallConv() const
QualType getReturnType() const
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
DynamicInitKind getDynamicInitKind() const
const Decl * getDecl() const
One of these records is kept for each identifier that is lexed.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
An lvalue reference type, per C++11 [dcl.ref].
Represents the declaration of a label.
Describes the capture of a variable or of this, or of a C++1y init-capture.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::string ModuleName
The module currently being compiled as specified by -fmodule-name.
clang::ObjCRuntime ObjCRuntime
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
virtual std::string getLambdaString(const CXXRecordDecl *Lambda)=0
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
QualType getElementType() const
Returns type of the elements being stored in the matrix.
MemberExpr - [C99 6.5.2.3] Structure and Union Members.
A pointer to member type per C++ 8.3.3 - Pointers to members.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
QualType getPointeeType() const
const Type * getClass() const
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
MethodVFTableLocation getMethodVFTableLocation(GlobalDecl GD)
const VTableLayout & getVFTableLayout(const CXXRecordDecl *RD, CharUnits VFPtrOffset)
Describes a module or submodule.
Module * Parent
The parent of this module.
std::string Name
The name of this module.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
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...
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
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 isExternallyVisible() const
Represents a C++ namespace alias.
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
bool isInline() const
Returns true if this is an inline namespace declaration.
ObjCCategoryDecl - Represents a category declaration.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
Represents an ObjC class declaration.
ObjCImplementationDecl * getImplementation() const
Interfaces are the core concept in Objective-C for object oriented design.
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
ObjCIvarDecl - Represents an ObjC instance variable.
ObjCMethodDecl - Represents an instance or class method declaration.
bool isDirectMethod() const
True if the method is tagged as objc_direct.
Selector getSelector() const
bool isInstanceMethod() const
ObjCInterfaceDecl * getClassInterface()
Represents a pointer to an Objective C object.
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Represents a class type in Objective C.
QualType getBaseType() const
Gets the base type of this object type.
Represents one property declaration in an Objective-C interface.
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Represents a type parameter type in Objective C.
ObjCTypeParamDecl * getDecl() const
Represents a parameter to a function.
QualType getElementType() const
PointerType - C99 6.7.5.1 - Pointer Declarators.
QualType getPointeeType() const
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
A (possibly-)qualified type.
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void * getAsOpaquePtr() const
A qualifier set is used to build a set of qualifiers.
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
The collection of all-type qualifiers we support.
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
void removeObjCLifetime()
void removeAddressSpace()
An rvalue reference type, per C++11 [dcl.ref].
Represents a struct/union/class.
field_iterator field_end() const
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
field_iterator field_begin() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
RecordDecl * getDecl() const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
QualType getPointeeType() const
Scope - A scope is a transient data structure that is used while parsing the program.
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
Smart pointer class that efficiently represents Objective-C method names.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
std::string getAsString() const
Derive the full selector name (e.g.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
Stmt - This represents one statement.
StringLiteral - This represents a string literal expression, e.g.
Represents the declaration of a struct/union/class/enum.
bool isCompleteDefinition() const
Return true if this decl has its body fully specified.
TypedefNameDecl * getTypedefNameForAnonDecl() const
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
TagDecl * getDecl() const
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
bool isItaniumFamily() const
Does this ABI generally fall into the Itanium family of ABIs?
virtual std::optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
uint64_t getPointerWidth(LangAS AddrSpace) const
Return the width of pointers on this target, for the specified address space.
virtual unsigned getVtblPtrAddressSpace() const
uint64_t getPointerAlign(LangAS AddrSpace) const
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
A template argument list.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
Represents a template argument.
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
QualType getStructuralValueType() const
Get the type of a StructuralValue.
QualType getParamTypeForDecl() const
Expr * getAsExpr() const
Retrieve the template argument as an expression.
QualType getAsType() const
Retrieve the type for a type template argument.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
QualType getIntegralType() const
Retrieve the type of the integral value.
bool getIsDefaulted() const
If returns 'true', this TemplateArgument corresponds to a default template parameter.
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
@ Declaration
The template argument is a declaration that was provided for a pointer, reference,...
@ Template
The template argument is a template name that was provided for a template template parameter.
@ StructuralValue
The template argument is a non-type template argument that can't be represented by the special-case D...
@ Pack
The template argument is actually a parameter pack.
@ TemplateExpansion
The template argument is a pack expansion of a template name that was provided for a template templat...
@ NullPtr
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
@ Type
The template argument is a type.
@ Null
Represents an empty template argument, e.g., one that has not been deduced.
@ Integral
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
@ Expression
The template argument is an expression, and we've not resolved it to one of the other forms yet,...
ArgKind getKind() const
Return the kind of stored template argument.
const APValue & getAsStructuralValue() const
Get the value of a StructuralValue.
The base class of all kinds of template declarations (e.g., class, function, etc.).
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known.
void print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual=Qualified::AsWritten) const
Print the template name.
Stores a list of template parameters for a TemplateDecl and its derived classes.
ArrayRef< NamedDecl * > asArray()
Represents a type template specialization; the template must be a class template, a type alias templa...
QualType getAliasedType() const
Get the aliased type, if this is a specialization of a type alias template.
ArrayRef< TemplateArgument > template_arguments() const
TemplateName getTemplateName() const
Retrieve the name of the template that we are specializing.
bool isTypeAlias() const
Determine if this template specialization type is for a type alias template that has been substituted...
Represents a declaration of a type.
const Type * getTypeForDecl() const
The base class of the type hierarchy.
bool isIncompleteArrayType() const
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that the type refers to.
bool isExtVectorBoolType() const
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isInstantiationDependentType() const
Determine whether this type is an instantiation-dependent type, meaning that the type involves a temp...
bool isMemberDataPointerType() const
bool isBitIntType() const
bool isComplexIntegerType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
Base class for declarations which introduce a typedef-name.
QualType getUnderlyingType() const
TypedefNameDecl * getDecl() const
Represents a C++ using-declaration.
Represents C++ using-directive.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Represents a C++ using-enum-declaration.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
static bool hasVtableSlot(const CXXMethodDecl *MD)
Determine whether this function should be assigned a vtable slot.
ArrayRef< VTableComponent > vtable_components() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isStaticDataMember() const
Determines whether this is a static data member.
const Expr * getInit() const
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
Declaration of a variable template.
Represents a GCC generic vector type.
unsigned getNumElements() const
QualType getElementType() const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
The JSON file list parser is used to communicate input to InstallAPI.
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Result
The result type of a method or function.
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Dtor_Deleting
Deleting dtor.
const FunctionProtoType * T
void printTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, const TemplateParameterList *TPL=nullptr)
Print a template argument list, including the '<' and '>' enclosing the template arguments.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ Generic
not a target-specific vector type
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ CXXThis
Parameter for C++ 'this' argument.
@ ObjCSelf
Parameter for Objective-C 'self' argument.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
Structure with information about how a bitfield should be accessed.
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
unsigned Size
The total size of the bit-field, in bits.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
unsigned IsSigned
Whether the bit-field is signed.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
EvalResult is a struct with detailed info about an evaluated expression.
Extra information about a function prototype.
uint64_t Index
Method's index in the vftable.
Describes how types, statements, expressions, and declarations should be printed.
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
unsigned SplitTemplateClosers
Whether nested templates must be closed like 'a<b<c> >' rather than 'a<b<c>>'.
unsigned PrintCanonicalTypes
Whether to print types as written or canonically.
unsigned AlwaysIncludeTypeForTemplateArgument
Whether to use type suffixes (eg: 1U) on integral non-type template parameters.
unsigned UsePreferredNames
Whether to use C++ template preferred_name attributes when printing templates.
unsigned UseEnumerators
Whether to print enumerator non-type template parameters with a matching enumerator name or via cast ...
unsigned SuppressInlineNamespace
Suppress printing parts of scope specifiers that correspond to inline namespaces, where the name is u...
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.
A this pointer adjustment.