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/Instruction.h"
48#include "llvm/IR/Instructions.h"
49#include "llvm/IR/Intrinsics.h"
50#include "llvm/IR/Metadata.h"
51#include "llvm/IR/Module.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"
76 if (TI.isAlignRequired())
103 auto const *RefExpr =
104 llvm::dyn_cast_or_null<DeclRefExpr>(
Init->IgnoreUnlessSpelledInSource());
108 return llvm::dyn_cast_or_null<DecompositionDecl>(RefExpr->getDecl());
132 if (!llvm::isa<ParmVarDecl>(VD))
142 if (!Method->isImplicit() || !Method->isPropertyAccessor())
153 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
154 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
155 DBuilder(CGM.getModule()) {
160 assert(LexicalBlockStack.empty() &&
161 "Region stack mismatch, stack not empty!");
164void CGDebugInfo::addInstSourceAtomMetadata(llvm::Instruction *I,
165 uint64_t Group, uint8_t Rank) {
166 if (!I->getDebugLoc() || Group == 0 || !I->getDebugLoc()->getLine())
170 Rank = std::min<uint8_t>(Rank, 7);
172 const llvm::DebugLoc &DL = I->getDebugLoc();
177 if (DL->getAtomGroup() && DL->getAtomRank() && DL->getAtomRank() < Rank) {
178 Group = DL->getAtomGroup();
179 Rank = DL->getAtomRank();
184 KeyInstructionsInfo.HighestEmittedAtom =
185 std::max(Group, KeyInstructionsInfo.HighestEmittedAtom);
188 llvm::DILocation *NewDL = llvm::DILocation::get(
189 I->getContext(), DL.getLine(), DL.getCol(), DL.getScope(),
190 DL.getInlinedAt(), DL.isImplicitCode(), Group, Rank);
191 I->setDebugLoc(NewDL);
195 llvm::Value *Backup) {
197 KeyInstructionsInfo.CurrentAtom);
203 if (!Group || !CGM.getCodeGenOpts().DebugKeyInstructions)
206 llvm::DISubprogram *SP = KeyInstruction->getFunction()->getSubprogram();
207 if (!SP || !SP->getKeyInstructionsEnabled())
210 addInstSourceAtomMetadata(KeyInstruction, Group, 1);
212 llvm::Instruction *BackupI =
213 llvm::dyn_cast_or_null<llvm::Instruction>(Backup);
218 addInstSourceAtomMetadata(BackupI, Group, 2);
224 while (
auto *Cast = dyn_cast<llvm::CastInst>(BackupI)) {
225 BackupI = dyn_cast<llvm::Instruction>(Cast->getOperand(0));
228 addInstSourceAtomMetadata(BackupI, Group, Rank++);
234 KeyInstructionsInfo.NextAtom = 1;
235 KeyInstructionsInfo.HighestEmittedAtom = 0;
236 KeyInstructionsInfo.CurrentAtom = 0;
242 OriginalAtom = DI->KeyInstructionsInfo.CurrentAtom;
243 DI->KeyInstructionsInfo.CurrentAtom = DI->KeyInstructionsInfo.NextAtom++;
251 DI->KeyInstructionsInfo.NextAtom =
252 std::min(DI->KeyInstructionsInfo.HighestEmittedAtom + 1,
253 DI->KeyInstructionsInfo.NextAtom);
255 DI->KeyInstructionsInfo.CurrentAtom = OriginalAtom;
261 init(TemporaryLocation);
268 init(TemporaryLocation, DefaultToEmpty);
272 bool DefaultToEmpty) {
279 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
281 if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
284 if (TemporaryLocation.
isValid()) {
285 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
289 if (DefaultToEmpty) {
290 CGF->Builder.SetCurrentDebugLocation(llvm::DebugLoc());
295 assert(!DI->LexicalBlockStack.empty());
296 CGF->Builder.SetCurrentDebugLocation(
297 llvm::DILocation::get(DI->LexicalBlockStack.back()->getContext(), 0, 0,
298 DI->LexicalBlockStack.back(), DI->getInlinedAt()));
308 if (!CGF.getDebugInfo()) {
312 OriginalLocation = CGF.Builder.getCurrentDebugLocation();
316 if (Loc->getAtomGroup())
317 Loc = llvm::DILocation::get(Loc->getContext(), Loc.getLine(),
318 Loc->getColumn(), Loc->getScope(),
319 Loc->getInlinedAt(), Loc.isImplicitCode());
320 CGF.Builder.SetCurrentDebugLocation(std::move(Loc));
328 CGF->Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
334 if (!CGF.getDebugInfo()) {
338 auto &DI = *CGF.getDebugInfo();
339 SavedLocation = DI.getLocation();
340 assert((DI.getInlinedAt() ==
341 CGF.Builder.getCurrentDebugLocation()->getInlinedAt()) &&
342 "CGDebugInfo and IRBuilder are out of sync");
344 DI.EmitInlineFunctionStart(CGF.Builder, InlinedFn);
350 auto &DI = *CGF->getDebugInfo();
351 DI.EmitInlineFunctionEnd(CGF->Builder);
352 DI.EmitLocation(CGF->Builder, SavedLocation);
362 if (CurLoc != NewLoc) {
364 CurLocFile =
nullptr;
373 if (CGM.getCodeGenOpts().DebugColumnInfo)
375 CurLocFile = getOrCreateFile(CurLoc);
381 if (LexicalBlockStack.empty())
385 if (!CurLocFile ||
Scope->getFile() == CurLocFile)
388 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
389 LexicalBlockStack.pop_back();
390 LexicalBlockStack.emplace_back(
391 DBuilder.createLexicalBlockFile(LBF->getScope(), CurLocFile));
394 LexicalBlockStack.pop_back();
395 LexicalBlockStack.emplace_back(
396 DBuilder.createLexicalBlockFile(
Scope, CurLocFile));
400llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
401 llvm::DIScope *Mod = getParentModuleOrNull(D);
406llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *Context,
411 auto I = RegionMap.find(Context);
412 if (I != RegionMap.end()) {
413 llvm::Metadata *
V = I->second;
414 return dyn_cast_or_null<llvm::DIScope>(
V);
418 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
419 return getOrCreateNamespace(NSDecl);
421 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
422 if (!RDecl->isDependentType())
429 if (LexicalBlockStack.empty())
435 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB) {
437 if (llvm::DIScope *S = LexicalBlockMap.lookup(D))
440 return getDeclContextDescriptor(
cast<Decl>(D));
452 PP.MSVCFormatting =
true;
462 PP.PrintAsCanonical =
true;
463 PP.UsePreferredNames =
false;
464 PP.AlwaysIncludeTypeForTemplateArgument =
true;
473StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD,
474 bool *NameIsSimplified) {
475 return internString(GetName(FD,
false, NameIsSimplified));
478StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
479 SmallString<256> MethodName;
480 llvm::raw_svector_ostream
OS(MethodName);
483 if (
const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
484 OS << OID->getName();
485 }
else if (
const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
486 OS << OID->getName();
487 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
488 if (OC->IsClassExtension()) {
489 OS << OC->getClassInterface()->getName();
491 OS << OC->getIdentifier()->getNameStart() <<
'('
492 << OC->getIdentifier()->getNameStart() <<
')';
494 }
else if (
const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
495 OS << OCD->getClassInterface()->getName() <<
'(' << OCD->getName() <<
')';
499 return internString(
OS.str());
502StringRef CGDebugInfo::getSelectorName(Selector S) {
506StringRef CGDebugInfo::getClassName(
const RecordDecl *RD,
507 bool *NameIsSimplified) {
510 return internString(GetName(RD,
false, NameIsSimplified));
516 return II->getName();
521 if (CGM.getCodeGenOpts().EmitCodeView) {
524 "Typedef should not be in another decl context!");
525 assert(D->getDeclName().getAsIdentifierInfo() &&
526 "Typedef was not named!");
527 return D->getDeclName().getAsIdentifierInfo()->getName();
530 if (CGM.getLangOpts().CPlusPlus) {
533 ASTContext &Context = CGM.getContext();
537 Name = DD->getName();
538 else if (
const TypedefNameDecl *TND =
542 Name = TND->getName();
545 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
546 if (CXXRD->isLambda())
548 CGM.getCXXABI().getMangleContext().getLambdaString(CXXRD));
551 SmallString<256> UnnamedType(
"<unnamed-type-");
554 return internString(UnnamedType);
562std::optional<llvm::DIFile::ChecksumKind>
563CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum)
const {
566 if (!CGM.getCodeGenOpts().EmitCodeView &&
567 CGM.getCodeGenOpts().DwarfVersion < 5)
570 SourceManager &SM = CGM.getContext().getSourceManager();
571 std::optional<llvm::MemoryBufferRef> MemBuffer = SM.
getBufferOrNone(FID);
575 auto Data = llvm::arrayRefFromStringRef(MemBuffer->getBuffer());
576 switch (CGM.getCodeGenOpts().getDebugSrcHash()) {
578 llvm::toHex(llvm::MD5::hash(
Data),
true, Checksum);
579 return llvm::DIFile::CSK_MD5;
581 llvm::toHex(llvm::SHA1::hash(
Data),
true, Checksum);
582 return llvm::DIFile::CSK_SHA1;
584 llvm::toHex(llvm::SHA256::hash(
Data),
true, Checksum);
585 return llvm::DIFile::CSK_SHA256;
589 llvm_unreachable(
"Unhandled DebugSrcHashKind enum");
592std::optional<StringRef> CGDebugInfo::getSource(
const SourceManager &SM,
594 if (!CGM.getCodeGenOpts().EmbedSource)
597 bool SourceInvalid =
false;
606llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
607 SourceManager &SM = CGM.getContext().getSourceManager();
610 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
616 FileName = TheCU->getFile()->getFilename();
617 CSInfo = TheCU->getFile()->getChecksum();
620 if (Loc == CurLoc && CurLocFile)
627 FileName = TheCU->getFile()->getFilename();
635 auto It = DIFileCache.find(
FileName.data());
636 if (It != DIFileCache.end()) {
638 if (llvm::Metadata *
V = It->second)
643 SmallString<64> Checksum;
646 CSInfo = TheCU->getFile()->getChecksum();
648 std::optional<llvm::DIFile::ChecksumKind> CSKind =
649 computeChecksum(FID, Checksum);
651 CSInfo.emplace(*CSKind, Checksum);
657 recordDIFileSource(F, FID);
661void CGDebugInfo::recordDIFileSource(
const llvm::DIFile *F, FileID FID) {
662 SourceManager &SM = CGM.getContext().getSourceManager();
665 auto [It, Inserted] = DIFileSources.try_emplace(F, DIFileSource{FID});
666 DIFileSource &Source = It->second;
667 if (Inserted || !Source.FID.isValid() || Source.FID == FID)
673 Source.FID = FileID();
675 Source.Shared =
true;
678llvm::DenseMap<const llvm::DIFile *, OptionalFileEntryRef>
681 llvm::DenseMap<const llvm::DIFile *, OptionalFileEntryRef> Sources;
682 for (
const auto &[F, Source] : DIFileSources) {
683 if (!Source.FID.isValid() ||
692llvm::DIFile *CGDebugInfo::createFile(
694 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
695 std::optional<StringRef> Source) {
699 std::string CurDir =
remapDIPath(getCurrentDirname());
702 if (llvm::sys::path::is_absolute(RemappedFile)) {
705 auto FileIt = llvm::sys::path::begin(RemappedFile);
706 auto FileE = llvm::sys::path::end(RemappedFile);
707 auto CurDirIt = llvm::sys::path::begin(CurDir);
708 auto CurDirE = llvm::sys::path::end(CurDir);
709 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
710 llvm::sys::path::append(DirBuf, *CurDirIt);
711 if (llvm::sys::path::root_path(DirBuf) == DirBuf) {
717 for (; FileIt != FileE; ++FileIt)
718 llvm::sys::path::append(FileBuf, *FileIt);
723 if (!llvm::sys::path::is_absolute(
FileName))
727 llvm::DIFile *F = DBuilder.createFile(
File, Dir, CSInfo, Source);
728 DIFileCache[
FileName.data()].reset(F);
733 return CGM.getCodeGenOpts().remapDebugPathPrefix(Path);
741 if (DebugLoc == CurLoc)
756 if (DebugLoc == CurLoc)
762StringRef CGDebugInfo::getCurrentDirname() {
770 assert(CGO.DwarfVersion <= 5);
772 llvm::dwarf::SourceLanguage LangTag;
775 LangTag = llvm::dwarf::DW_LANG_HLSL;
777 LangTag = llvm::dwarf::DW_LANG_HIP;
779 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
780 else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
781 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
782 else if (LO.CPlusPlus14)
783 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
784 else if (LO.CPlusPlus11)
785 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
787 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
788 }
else if (LO.ObjC) {
789 LangTag = llvm::dwarf::DW_LANG_ObjC;
790 }
else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
791 LangTag = llvm::dwarf::DW_LANG_OpenCL;
792 }
else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
793 LangTag = llvm::dwarf::DW_LANG_C11;
795 LangTag = llvm::dwarf::DW_LANG_C99;
797 LangTag = llvm::dwarf::DW_LANG_C89;
803static llvm::DISourceLanguageName
812 llvm::dwarf::SourceLanguageName LangTag;
815 LangTag = llvm::dwarf::DW_LNAME_HLSL;
817 LangTag = llvm::dwarf::DW_LNAME_HIP;
818 }
else if (LO.ObjC) {
819 LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
821 LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
824 }
else if (LO.ObjC) {
825 LangTag = llvm::dwarf::DW_LNAME_ObjC;
826 }
else if (LO.OpenCL) {
827 LangTag = llvm::dwarf::DW_LNAME_OpenCL_C;
829 LangTag = llvm::dwarf::DW_LNAME_C;
833 return llvm::DISourceLanguageName(LangTag, LangVersion);
836void CGDebugInfo::CreateCompileUnit() {
837 SmallString<64> Checksum;
838 std::optional<llvm::DIFile::ChecksumKind> CSKind;
839 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
849 SourceManager &SM = CGM.getContext().getSourceManager();
850 auto &CGO = CGM.getCodeGenOpts();
851 const LangOptions &LO = CGM.getLangOpts();
852 std::string MainFileName = CGO.MainFileName;
853 if (MainFileName.empty())
854 MainFileName =
"<stdin>";
860 std::string MainFileDir;
863 MainFileDir = std::string(MainFile->getDir().getName());
864 if (!llvm::sys::path::is_absolute(MainFileName)) {
865 llvm::SmallString<1024> MainFileDirSS(MainFileDir);
866 llvm::sys::path::Style Style =
868 ? (CGM.getTarget().
getTriple().isOSWindows()
869 ? llvm::sys::path::Style::windows_backslash
870 : llvm::sys::path::Style::posix)
871 : llvm::sys::path::Style::native;
872 llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
873 MainFileName = std::string(
874 llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
881 if (MainFile->getName() == MainFileName &&
883 MainFile->getName().rsplit(
'.').second)
885 MainFileName = CGM.getModule().getName().str();
894 unsigned RuntimeVers = 0;
898 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
900 case llvm::codegenoptions::NoDebugInfo:
901 case llvm::codegenoptions::LocTrackingOnly:
902 EmissionKind = llvm::DICompileUnit::NoDebug;
904 case llvm::codegenoptions::DebugLineTablesOnly:
905 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
907 case llvm::codegenoptions::DebugDirectivesOnly:
908 EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
910 case llvm::codegenoptions::DebugInfoConstructor:
911 case llvm::codegenoptions::LimitedDebugInfo:
912 case llvm::codegenoptions::FullDebugInfo:
913 case llvm::codegenoptions::UnusedTypeInfo:
914 EmissionKind = llvm::DICompileUnit::FullDebug;
919 auto &CGOpts = CGM.getCodeGenOpts();
925 CSInfo.emplace(*CSKind, Checksum);
926 const llvm::StringRef cwd =
927 !CGOpts.EmitCodeView ||
928 (CGOpts.EmitCodeView && CGOpts.CodeViewEmitCurrentWorkdir)
929 ? getCurrentDirname()
930 : llvm::StringRef(
"");
931 llvm::DIFile *CUFile =
935 StringRef Sysroot, SDK;
936 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
937 StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
938 if (CGM.getCodeGenOpts().DebugRecordSysroot)
939 Sysroot = FullSysroot;
940 auto B = llvm::sys::path::rbegin(FullSysroot);
941 auto E = llvm::sys::path::rend(FullSysroot);
943 std::find_if(B, E, [](
auto SDK) {
return SDK.ends_with(
".sdk"); });
948 llvm::DICompileUnit::DebugNameTableKind NameTableKind =
949 static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
950 CGOpts.DebugNameTable);
951 if (CGM.getTarget().getTriple().isNVPTX())
952 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
953 else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
954 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
957 TheCU = DBuilder.createCompileUnit(
959 CGOpts.EmitVersionIdentMetadata ? Producer :
"",
960 CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
961 CGOpts.PrepareForThinLTO,
962 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
963 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
964 NameTableKind, CGOpts.DebugRangesBaseAddress,
remapDIPath(Sysroot), SDK);
967llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
971#define BUILTIN_TYPE(Id, SingletonId)
972#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
973#include "clang/AST/BuiltinTypes.def"
974 case BuiltinType::Dependent:
975 llvm_unreachable(
"Unexpected builtin type");
976 case BuiltinType::NullPtr:
977 return DBuilder.createNullPtrType();
978 case BuiltinType::Void:
980 case BuiltinType::ObjCClass:
983 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
984 "objc_class", TheCU, TheCU->getFile(), 0);
986 case BuiltinType::ObjCId: {
997 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
998 "objc_class", TheCU, TheCU->getFile(), 0);
1000 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1002 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
1004 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
1005 (
uint64_t)0, 0, llvm::DINode::FlagZero,
1006 nullptr, llvm::DINodeArray());
1008 DBuilder.replaceArrays(
1009 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
1010 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
1011 llvm::DINode::FlagZero, ISATy)));
1014 case BuiltinType::ObjCSel: {
1016 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
1017 "objc_selector", TheCU,
1018 TheCU->getFile(), 0);
1022#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
1023 case BuiltinType::Id: \
1024 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
1026#include "clang/Basic/OpenCLImageTypes.def"
1027 case BuiltinType::OCLSampler:
1028 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
1029 case BuiltinType::OCLEvent:
1030 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
1031 case BuiltinType::OCLClkEvent:
1032 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
1033 case BuiltinType::OCLQueue:
1034 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
1035 case BuiltinType::OCLReserveID:
1036 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
1037#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
1038 case BuiltinType::Id: \
1039 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
1040#include "clang/Basic/OpenCLExtensionTypes.def"
1041#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
1042 case BuiltinType::Id: \
1043 return getOrCreateStructPtrType(#Name, SingletonId);
1044#include "clang/Basic/HLSLIntangibleTypes.def"
1045#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
1046 case BuiltinType::Id: \
1047 return DBuilder.createBasicType(#Name, 32, llvm::dwarf::DW_ATE_unsigned);
1048#include "clang/Basic/HLSLPackedTypes.def"
1050#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1051#include "clang/Basic/AArch64ACLETypes.def"
1053 if (BT->
getKind() == BuiltinType::MFloat8) {
1054 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
1055 BTName = BT->
getName(CGM.getLangOpts());
1058 return DBuilder.createBasicType(BTName, Size, Encoding);
1060 ASTContext::BuiltinVectorTypeInfo Info =
1062 BT->
getKind() == BuiltinType::SveCount
1063 ? ASTContext::BuiltinVectorTypeInfo(
1064 CGM.getContext().BoolTy, llvm::ElementCount::getFixed(16),
1066 : CGM.getContext().getBuiltinVectorTypeInfo(BT);
1073 "Unsupported number of vectors for svcount_t");
1075 unsigned NumElems = Info.
EC.getKnownMinValue() * Info.
NumVectors;
1076 llvm::Metadata *BitStride =
nullptr;
1077 if (BT->
getKind() == BuiltinType::SveBool) {
1078 Info.
ElementType = CGM.getContext().UnsignedCharTy;
1079 BitStride = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1080 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 1));
1081 }
else if (BT->
getKind() == BuiltinType::SveCount) {
1083 Info.
ElementType = CGM.getContext().UnsignedCharTy;
1086 llvm::Metadata *LowerBound, *UpperBound;
1087 LowerBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1088 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 0));
1089 if (Info.
EC.isScalable()) {
1090 unsigned NumElemsPerVG = NumElems / 2;
1091 SmallVector<uint64_t, 9> Expr(
1092 {llvm::dwarf::DW_OP_constu, NumElemsPerVG, llvm::dwarf::DW_OP_bregx,
1093 46, 0, llvm::dwarf::DW_OP_mul,
1094 llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
1095 UpperBound = DBuilder.createExpression(Expr);
1097 UpperBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1098 llvm::Type::getInt64Ty(CGM.getLLVMContext()), NumElems - 1));
1100 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
1101 nullptr, LowerBound, UpperBound,
nullptr);
1102 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
1103 llvm::DIType *ElemTy =
1104 getOrCreateType(Info.
ElementType, TheCU->getFile());
1106 return DBuilder.createVectorType( 0, Align, ElemTy,
1107 SubscriptArray, BitStride);
1111#define PPC_VECTOR_TYPE(Name, Id, size) \
1112 case BuiltinType::Id:
1113#include "clang/Basic/PPCTypes.def"
1116#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1117#include "clang/Basic/RISCVVTypes.def"
1119 ASTContext::BuiltinVectorTypeInfo Info =
1120 CGM.getContext().getBuiltinVectorTypeInfo(BT);
1122 unsigned ElementCount = Info.
EC.getKnownMinValue();
1123 unsigned SEW = CGM.getContext().getTypeSize(Info.
ElementType);
1125 bool Fractional =
false;
1128 unsigned FixedSize = ElementCount * SEW;
1129 if (Info.
ElementType == CGM.getContext().BoolTy) {
1132 }
else if (FixedSize < 64) {
1135 LMUL = 64 / FixedSize;
1137 LMUL = FixedSize / 64;
1141 SmallVector<uint64_t, 12> Expr(
1145 {llvm::dwarf::DW_OP_bregx,
1148 llvm::dwarf::DW_OP_constu,
1150 llvm::dwarf::DW_OP_div, llvm::dwarf::DW_OP_constu, LMUL});
1152 Expr.push_back(llvm::dwarf::DW_OP_div);
1154 Expr.push_back(llvm::dwarf::DW_OP_mul);
1157 Expr.append({llvm::dwarf::DW_OP_constu, NFIELDS, llvm::dwarf::DW_OP_mul});
1159 Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
1162 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1163 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 0));
1164 auto *UpperBound = DBuilder.createExpression(Expr);
1165 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
1166 nullptr, LowerBound, UpperBound,
nullptr);
1167 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
1168 llvm::DIType *ElemTy =
1169 getOrCreateType(Info.
ElementType, TheCU->getFile());
1172 return DBuilder.createVectorType(0, Align, ElemTy,
1176#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
1177 case BuiltinType::Id: { \
1180 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, \
1181 MangledName, TheCU, TheCU->getFile(), 0); \
1182 return SingletonId; \
1184#include "clang/Basic/WebAssemblyReferenceTypes.def"
1185#define AMDGPU_OPAQUE_PTR_TYPE(Name, Id, SingletonId, Width, Align, AS) \
1186 case BuiltinType::Id: { \
1189 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, \
1190 TheCU, TheCU->getFile(), 0); \
1191 return SingletonId; \
1193#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope) \
1194 case BuiltinType::Id: { \
1197 DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); \
1198 return SingletonId; \
1200#define AMDGPU_FEATURE_PREDICATE_TYPE(Name, Id, SingletonId, Width, Align) \
1201 case BuiltinType::Id: { \
1204 DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_boolean); \
1205 return SingletonId; \
1207#include "clang/Basic/AMDGPUTypes.def"
1208#define SPIRV_TYPE(Name, Id, SingletonId) \
1209 case BuiltinType::Id: \
1210 return getOrCreateStructPtrType(Name, SingletonId);
1211#include "clang/Basic/SPIRVTypes.def"
1212 case BuiltinType::UChar:
1213 case BuiltinType::Char_U:
1214 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
1216 case BuiltinType::Char_S:
1217 case BuiltinType::SChar:
1218 Encoding = llvm::dwarf::DW_ATE_signed_char;
1220 case BuiltinType::Char8:
1221 case BuiltinType::Char16:
1222 case BuiltinType::Char32:
1223 Encoding = llvm::dwarf::DW_ATE_UTF;
1225 case BuiltinType::UShort:
1226 case BuiltinType::UInt:
1227 case BuiltinType::UInt128:
1228 case BuiltinType::ULong:
1229 case BuiltinType::WChar_U:
1230 case BuiltinType::ULongLong:
1231 Encoding = llvm::dwarf::DW_ATE_unsigned;
1233 case BuiltinType::Short:
1234 case BuiltinType::Int:
1235 case BuiltinType::Int128:
1236 case BuiltinType::Long:
1237 case BuiltinType::WChar_S:
1238 case BuiltinType::LongLong:
1239 Encoding = llvm::dwarf::DW_ATE_signed;
1241 case BuiltinType::Bool:
1242 Encoding = llvm::dwarf::DW_ATE_boolean;
1244 case BuiltinType::Half:
1245 case BuiltinType::Float:
1246 case BuiltinType::LongDouble:
1247 case BuiltinType::Float16:
1248 case BuiltinType::BFloat16:
1249 case BuiltinType::Float128:
1250 case BuiltinType::Double:
1251 case BuiltinType::Ibm128:
1257 Encoding = llvm::dwarf::DW_ATE_float;
1259 case BuiltinType::ShortAccum:
1260 case BuiltinType::Accum:
1261 case BuiltinType::LongAccum:
1262 case BuiltinType::ShortFract:
1263 case BuiltinType::Fract:
1264 case BuiltinType::LongFract:
1265 case BuiltinType::SatShortFract:
1266 case BuiltinType::SatFract:
1267 case BuiltinType::SatLongFract:
1268 case BuiltinType::SatShortAccum:
1269 case BuiltinType::SatAccum:
1270 case BuiltinType::SatLongAccum:
1271 Encoding = llvm::dwarf::DW_ATE_signed_fixed;
1273 case BuiltinType::UShortAccum:
1274 case BuiltinType::UAccum:
1275 case BuiltinType::ULongAccum:
1276 case BuiltinType::UShortFract:
1277 case BuiltinType::UFract:
1278 case BuiltinType::ULongFract:
1279 case BuiltinType::SatUShortAccum:
1280 case BuiltinType::SatUAccum:
1281 case BuiltinType::SatULongAccum:
1282 case BuiltinType::SatUShortFract:
1283 case BuiltinType::SatUFract:
1284 case BuiltinType::SatULongFract:
1285 Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
1287 case BuiltinType::MetaInfo:
1288 llvm_unreachable(
"std::meta::info is consteval-only type");
1291 BTName = BT->
getName(CGM.getLangOpts());
1294 return DBuilder.createBasicType(BTName, Size, Encoding);
1297llvm::DIType *CGDebugInfo::CreateType(
const BitIntType *Ty) {
1298 SmallString<32> Name;
1299 llvm::raw_svector_ostream
OS(Name);
1300 OS << (Ty->
isUnsigned() ?
"unsigned _BitInt(" :
"_BitInt(")
1303 ? llvm::dwarf::DW_ATE_unsigned
1304 : llvm::dwarf::DW_ATE_signed;
1305 return DBuilder.createBasicType(Name, CGM.getContext().getTypeSize(Ty),
1306 Encoding, llvm::DINode::FlagZero, 0,
1310llvm::DIType *CGDebugInfo::CreateType(
const OverflowBehaviorType *Ty,
1312 return getOrCreateType(Ty->getUnderlyingType(), U);
1315llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
1317 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
1319 Encoding = llvm::dwarf::DW_ATE_lo_user;
1322 return DBuilder.createBasicType(
"complex", Size, Encoding);
1336 return llvm::dwarf::DW_TAG_const_type;
1340 return llvm::dwarf::DW_TAG_volatile_type;
1344 return llvm::dwarf::DW_TAG_restrict_type;
1346 return (llvm::dwarf::Tag)0;
1349llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty,
1350 llvm::DIFile *Unit) {
1351 QualifierCollector Qc;
1365 bool AuthenticatesNullValues =
1368 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1369 llvm::DIType *FromTy = getOrCreateType(QualType(
T, 0), Unit);
1370 return DBuilder.createPtrAuthQualifiedType(FromTy, Key, IsDiscr,
1371 ExtraDiscr, IsaPointer,
1372 AuthenticatesNullValues);
1374 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1375 return getOrCreateType(QualType(
T, 0), Unit);
1379 auto *FromTy = getOrCreateType(Qc.
apply(CGM.getContext(),
T), Unit);
1383 return DBuilder.createQualifiedType(Tag, FromTy);
1386llvm::DIType *CGDebugInfo::CreateQualifiedType(
const FunctionProtoType *F,
1387 llvm::DIFile *Unit) {
1396 assert(Q.
empty() &&
"Unknown type qualifier for debug info");
1401 getOrCreateType(CGM.getContext().getFunctionType(F->
getReturnType(),
1407 return DBuilder.createQualifiedType(Tag, FromTy);
1410llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectPointerType *Ty,
1411 llvm::DIFile *Unit) {
1417 return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
1419 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1423llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
1424 llvm::DIFile *Unit) {
1425 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1431 case llvm::dwarf::DW_LANG_C_plus_plus:
1432 case llvm::dwarf::DW_LANG_C_plus_plus_11:
1433 case llvm::dwarf::DW_LANG_C_plus_plus_14:
1434 case llvm::dwarf::DW_LANG_HIP:
1436 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
1446 case llvm::dwarf::DW_LNAME_C_plus_plus:
1447 case llvm::dwarf::DW_LNAME_HIP:
1449 case llvm::dwarf::DW_LNAME_ObjC_plus_plus:
1460 if (llvm::DISourceLanguageName SourceLang = TheCU->getSourceLanguage();
1461 SourceLang.hasVersionedName())
1463 static_cast<llvm::dwarf::SourceLanguageName
>(SourceLang.getName()),
1467 static_cast<llvm::dwarf::SourceLanguage
>(SourceLang.getName()),
1493 llvm::DICompileUnit *TheCU) {
1511 llvm::DICompileUnit *TheCU) {
1517 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
1519 if (RD->isDynamicClass() &&
1525 llvm::raw_svector_ostream Out(Identifier);
1532 llvm::dwarf::Tag Tag;
1534 Tag = llvm::dwarf::DW_TAG_structure_type;
1536 Tag = llvm::dwarf::DW_TAG_union_type;
1541 Tag = llvm::dwarf::DW_TAG_class_type;
1546llvm::DICompositeType *
1547CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
1548 llvm::DIScope *Ctx) {
1550 if (llvm::DIType *
T = getTypeOrNull(QualType(Ty, 0)))
1552 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
1553 const unsigned Line =
1555 StringRef RDName = getClassName(RD);
1562 Size = CGM.getContext().getTypeSize(Ty);
1564 llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
1569 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1570 if (!CXXRD->hasDefinition() ||
1571 (CXXRD->hasDefinition() && !CXXRD->isTrivial()))
1572 Flags |= llvm::DINode::FlagNonTrivial;
1575 SmallString<256> Identifier;
1577 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
1579 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
1582 if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
1583 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
1584 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
1585 CollectCXXTemplateParams(TSpecial, DefUnit));
1586 ReplaceMap.emplace_back(
1587 std::piecewise_construct, std::make_tuple(Ty),
1588 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
1592llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
1595 llvm::DIFile *Unit) {
1600 std::optional<unsigned> DWARFAddressSpace =
1601 CGM.getTarget().getDWARFAddressSpace(
1602 CGM.getTypes().getTargetAddressSpace(PointeeTy));
1604 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1605 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type) {
1606 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1607 Size, Align, DWARFAddressSpace);
1609 SmallVector<llvm::Metadata *, 4> Annots;
1610 CollectBTFTypeTagAnnotations(PointeeTy, Annots);
1612 llvm::DINodeArray Annotations =
nullptr;
1613 if (Annots.size() > 0)
1614 Annotations = DBuilder.getOrCreateArray(Annots);
1615 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1616 Align, DWARFAddressSpace, StringRef(),
1621llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1622 llvm::DIType *&
Cache) {
1625 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1626 TheCU, TheCU->getFile(), 0);
1627 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1628 Cache = DBuilder.createPointerType(
Cache, Size);
1632uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1633 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1634 unsigned LineNo, SmallVectorImpl<llvm::Metadata *> &EltTys) {
1644 if (CGM.getLangOpts().OpenCL) {
1645 FType = CGM.getContext().IntTy;
1646 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1647 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1649 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1650 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1651 FType = CGM.getContext().IntTy;
1652 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1653 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1655 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1656 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1657 uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
1658 uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
1659 EltTys.push_back(DBuilder.createMemberType(
1660 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1661 FieldOffset, llvm::DINode::FlagZero, DescTy));
1662 FieldOffset += FieldSize;
1668llvm::DIType *CGDebugInfo::CreateType(
const BlockPointerType *Ty,
1669 llvm::DIFile *Unit) {
1670 SmallVector<llvm::Metadata *, 8> EltTys;
1673 llvm::DINodeArray Elements;
1676 FType = CGM.getContext().UnsignedLongTy;
1677 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1678 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1680 Elements = DBuilder.getOrCreateArray(EltTys);
1683 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1686 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1687 FieldOffset, 0, Flags,
nullptr, Elements);
1692 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1694 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1697 Elements = DBuilder.getOrCreateArray(EltTys);
1703 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1704 Flags,
nullptr, Elements);
1706 return DBuilder.createPointerType(EltTy, Size);
1709static llvm::SmallVector<TemplateArgument>
1711 assert(Ty->isTypeAlias());
1720 ArrayRef SubstArgs = Ty->template_arguments();
1723 if (Param->isParameterPack()) {
1732 if (SubstArgs.empty()) {
1741 SpecArgs.push_back(SubstArgs.front());
1742 SubstArgs = SubstArgs.drop_front();
1747llvm::DIType *CGDebugInfo::CreateType(
const TemplateSpecializationType *Ty,
1748 llvm::DIFile *Unit) {
1749 assert(Ty->isTypeAlias());
1750 llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
1752 const TemplateDecl *TD = Ty->getTemplateName().getAsTemplateDecl();
1760 SmallString<128> NS;
1761 llvm::raw_svector_ostream
OS(NS);
1763 auto PP = getPrintingPolicy();
1766 SourceLocation Loc =
AliasDecl->getLocation();
1768 if (CGM.getCodeGenOpts().DebugTemplateAlias) {
1769 auto ArgVector = ::GetTemplateArgs(TD, Ty);
1778 llvm::raw_string_ostream
OS(Name);
1780 if (CGM.getCodeGenOpts().getDebugSimpleTemplateNames() !=
1781 llvm::codegenoptions::DebugTemplateNamesKind::Simple ||
1782 !HasReconstitutableArgs(Args.Args))
1783 printTemplateArgumentList(OS, Args.Args, PP);
1785 llvm::DIDerivedType *AliasTy = DBuilder.createTemplateAlias(
1786 Src, Name, getOrCreateFile(Loc), getLineNumber(Loc),
1787 getDeclContextDescriptor(
AliasDecl), CollectTemplateParams(Args, Unit));
1791 printTemplateArgumentList(OS, Ty->template_arguments(), PP,
1793 return DBuilder.createTypedef(Src,
OS.str(), getOrCreateFile(Loc),
1810 return llvm::DINode::FlagZero;
1814 return llvm::DINode::FlagPrivate;
1816 return llvm::DINode::FlagProtected;
1818 return llvm::DINode::FlagPublic;
1820 return llvm::DINode::FlagZero;
1822 llvm_unreachable(
"unexpected access enumerator");
1825llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1826 llvm::DIFile *Unit) {
1827 TypedefNameDecl *TND = Ty->
getDecl();
1830 if (TND->
hasAttr<NoDebugAttr>())
1843 SmallVector<llvm::Metadata *, 4> Annots;
1844 llvm::DINodeArray Annotations;
1846 CollectBTFDeclTagAnnotations(TND, Annots);
1847 if (!Annots.empty())
1848 Annotations = DBuilder.getOrCreateArray(Annots);
1850 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1855 return DBuilder.createTypedef(
1856 Underlying, TND->
getName(), getOrCreateFile(Loc), getLineNumber(Loc),
1865 if (
T.isSPIROrSPIRV())
1866 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1871 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1873 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1875 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1877 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1879 return llvm::dwarf::DW_CC_BORLAND_pascal;
1881 return llvm::dwarf::DW_CC_LLVM_Win64;
1883 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1887 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1889 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1891 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1893 return llvm::dwarf::DW_CC_LLVM_DeviceKernel;
1895 return llvm::dwarf::DW_CC_LLVM_Swift;
1897 return llvm::dwarf::DW_CC_LLVM_SwiftTail;
1899 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1901 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1903 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1905 return llvm::dwarf::DW_CC_LLVM_M68kRTD;
1907 return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1909 return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
1910#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
1924 return llvm::dwarf::DW_CC_LLVM_RISCVVLSCall;
1930 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1932 Flags |= llvm::DINode::FlagLValueReference;
1934 Flags |= llvm::DINode::FlagRValueReference;
1938llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1939 llvm::DIFile *Unit) {
1940 const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
1942 if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
1948 SmallVector<llvm::Metadata *, 16> EltTys;
1951 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1953 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1957 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1960 for (
const QualType &ParamType : FPT->param_types())
1961 EltTys.push_back(getOrCreateType(ParamType, Unit));
1962 if (FPT->isVariadic())
1963 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1966 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1967 llvm::DIType *F = DBuilder.createSubroutineType(
1968 EltTypeArray, Flags,
1973llvm::DIDerivedType *
1974CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1975 llvm::DIScope *RecordTy,
const RecordDecl *RD) {
1976 StringRef Name = BitFieldDecl->
getName();
1977 QualType Ty = BitFieldDecl->
getType();
1978 if (BitFieldDecl->
hasAttr<PreferredTypeAttr>())
1981 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1982 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1985 llvm::DIFile *
File = getOrCreateFile(Loc);
1986 unsigned Line = getLineNumber(Loc);
1988 const CGBitFieldInfo &BitFieldInfo =
1989 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1991 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1998 if (CGM.getDataLayout().isBigEndian())
2000 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
2002 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(BitFieldDecl);
2003 return DBuilder.createBitFieldMemberType(
2004 RecordTy, Name,
File,
Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
2005 Flags, DebugType, Annotations);
2008llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
2009 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
2010 llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI,
const RecordDecl *RD) {
2012 if (!CGM.getTargetCodeGenInfo().shouldEmitDWARFBitFieldSeparators())
2037 if (PreviousFieldsDI.empty())
2041 auto *PreviousMDEntry =
2042 PreviousFieldsDI.empty() ?
nullptr : PreviousFieldsDI.back();
2043 auto *PreviousMDField =
2044 dyn_cast_or_null<llvm::DIDerivedType>(PreviousMDEntry);
2045 if (!PreviousMDField || !PreviousMDField->isBitField() ||
2046 PreviousMDField->getSizeInBits() == 0)
2050 std::advance(PreviousBitfield, BitFieldDecl->
getFieldIndex() - 1);
2052 assert(PreviousBitfield->isBitField());
2054 if (!PreviousBitfield->isZeroLengthBitField())
2057 QualType Ty = PreviousBitfield->getType();
2058 SourceLocation Loc = PreviousBitfield->getLocation();
2059 llvm::DIFile *VUnit = getOrCreateFile(Loc);
2060 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
2061 llvm::DIScope *RecordTy = BitFieldDI->getScope();
2063 llvm::DIFile *
File = getOrCreateFile(Loc);
2064 unsigned Line = getLineNumber(Loc);
2070 llvm::DINode::DIFlags Flags =
2072 llvm::DINodeArray Annotations =
2073 CollectBTFDeclTagAnnotations(*PreviousBitfield);
2074 return DBuilder.createBitFieldMemberType(
2075 RecordTy,
"",
File,
Line, 0, StorageOffsetInBits, StorageOffsetInBits,
2076 Flags, DebugType, Annotations);
2079llvm::DIType *CGDebugInfo::createFieldType(
2082 llvm::DIScope *scope,
const RecordDecl *RD, llvm::DINodeArray Annotations) {
2083 llvm::DIType *debugType = getOrCreateType(
type, tunit);
2086 llvm::DIFile *file = getOrCreateFile(loc);
2087 const unsigned line = getLineNumber(loc.
isValid() ? loc : CurLoc);
2090 auto Align = AlignInBits;
2091 if (!
type->isIncompleteArrayType()) {
2092 TypeInfo TI = CGM.getContext().getTypeInfo(
type);
2093 SizeInBits = TI.
Width;
2099 return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
2100 offsetInBits, flags, debugType, Annotations);
2104CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
2105 llvm::DIFile *FileScope) {
2109 llvm::DISubprogram *&SP = InlinedSubprogramMap[FuncName];
2112 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(
nullptr);
2113 SP = DBuilder.createFunction(
2114 FileScope, FuncName, StringRef(),
2115 FileScope, 0, DIFnTy,
2117 llvm::DINode::FlagArtificial,
2118 llvm::DISubprogram::SPFlagDefinition,
2119 nullptr,
nullptr,
nullptr,
2120 nullptr, StringRef(),
2121 CGM.getCodeGenOpts().DebugKeyInstructions);
2128CGDebugInfo::GetLambdaCaptureName(
const LambdaCapture &
Capture) {
2130 return CGM.getCodeGenOpts().EmitCodeView ?
"__this" :
"this";
2132 assert(
Capture.capturesVariable());
2134 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2135 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2137 return CaptureDecl->
getName();
2140void CGDebugInfo::CollectRecordLambdaFields(
2141 const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
2142 llvm::DIType *RecordTy) {
2147 unsigned fieldno = 0;
2150 I != E; ++I, ++Field, ++fieldno) {
2151 const LambdaCapture &
Capture = *I;
2153 CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
2155 assert(!
Field->isBitField() &&
"lambdas don't have bitfield members!");
2165 Loc =
Field->getLocation();
2166 }
else if (
Capture.capturesVariable()) {
2169 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2170 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2177 llvm::DIFile *VUnit = getOrCreateFile(Loc);
2179 FieldIndexCache[*
Field] = elements.size();
2180 elements.push_back(createFieldType(
2182 Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
2188template <
typename T>
2189static llvm::Constant *
2200 return llvm::ConstantDataArray::get(Ctx, Vals);
2213 const QualType ElemQTy = ArrayTy->getElementType();
2220 switch (ElemBitWidth) {
2236llvm::DIDerivedType *
2237CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
2238 const RecordDecl *RD) {
2242 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
2243 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
2245 unsigned LineNumber = getLineNumber(Var->
getLocation());
2246 StringRef VName = Var->
getName();
2250 llvm::Constant *
C =
nullptr;
2255 C = llvm::ConstantInt::get(CGM.getLLVMContext(),
Value->getInt());
2256 if (
Value->isFloat())
2257 C = llvm::ConstantFP::get(CGM.getLLVMContext(),
Value->getFloat());
2258 if (
Value->isArray())
2264 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2265 ? llvm::dwarf::DW_TAG_variable
2266 : llvm::dwarf::DW_TAG_member;
2268 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
2269 RecordTy, VName, VUnit, LineNumber, VTy, Flags,
C, Tag, Align);
2274void CGDebugInfo::CollectRecordNormalField(
2275 const FieldDecl *field,
uint64_t OffsetInBits, llvm::DIFile *tunit,
2276 SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
2277 const RecordDecl *RD) {
2282 if (
name.empty() && !
type->isRecordType())
2285 llvm::DIType *FieldType;
2287 llvm::DIDerivedType *BitFieldType;
2288 FieldType = BitFieldType = createBitFieldType(field, RecordTy, RD);
2289 if (llvm::DIType *Separator =
2290 createBitFieldSeparatorIfNeeded(field, BitFieldType, elements, RD))
2291 elements.push_back(Separator);
2294 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
2297 OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
2300 FieldIndexCache[field] = elements.size();
2301 elements.push_back(FieldType);
2304void CGDebugInfo::CollectRecordNestedType(
2305 const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) {
2306 QualType Ty = CGM.getContext().getTypeDeclType(TD);
2313 if (llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)))
2314 elements.push_back(nestedType);
2317void CGDebugInfo::CollectRecordFields(
2318 const RecordDecl *record, llvm::DIFile *tunit,
2319 SmallVectorImpl<llvm::Metadata *> &elements,
2320 llvm::DICompositeType *RecordTy) {
2321 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
2323 if (CXXDecl && CXXDecl->
isLambda())
2324 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
2326 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
2329 unsigned fieldNo = 0;
2333 for (
const auto *I : record->
decls())
2334 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
2335 if (
V->hasAttr<NoDebugAttr>())
2340 if (CGM.getCodeGenOpts().EmitCodeView &&
2348 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
2349 if (MI != StaticDataMemberCache.end()) {
2350 assert(MI->second &&
2351 "Static data member declaration should still exist");
2352 elements.push_back(MI->second);
2354 auto Field = CreateRecordStaticField(
V, RecordTy, record);
2355 elements.push_back(Field);
2357 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
2358 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
2359 elements, RecordTy, record);
2363 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
2366 if (
const auto *nestedType = dyn_cast<TypeDecl>(I)) {
2371 if (!nestedType->isImplicit() &&
2372 nestedType->getDeclContext() == record)
2373 CollectRecordNestedType(nestedType, elements);
2379llvm::DISubroutineType *
2380CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *
Method,
2381 llvm::DIFile *Unit) {
2382 const FunctionProtoType *
Func =
Method->getType()->getAs<FunctionProtoType>();
2384 return cast_or_null<llvm::DISubroutineType>(
2385 getOrCreateType(QualType(
Func, 0), Unit));
2388 if (!
Method->hasCXXExplicitFunctionObjectParameter())
2389 ThisType =
Method->getThisType();
2391 return getOrCreateInstanceMethodType(ThisType,
Func, Unit);
2394llvm::DISubroutineType *CGDebugInfo::getOrCreateMethodTypeForDestructor(
2395 const CXXMethodDecl *
Method, llvm::DIFile *Unit, QualType FNType) {
2396 const FunctionProtoType *
Func = FNType->
getAs<FunctionProtoType>();
2398 return getOrCreateInstanceMethodType(
Method->getThisType(),
Func, Unit,
true);
2401llvm::DISubroutineType *
2402CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
2403 const FunctionProtoType *
Func,
2404 llvm::DIFile *Unit,
bool SkipFirst) {
2405 FunctionProtoType::ExtProtoInfo EPI =
Func->getExtProtoInfo();
2420 getOrCreateType(CGM.getContext().getFunctionType(
2421 Func->getReturnType(),
Func->getParamTypes(), EPI),
2423 llvm::DITypeArray Args = OriginalFunc->getTypeArray();
2424 assert(Args.size() &&
"Invalid number of arguments!");
2426 SmallVector<llvm::Metadata *, 16> Elts;
2429 Elts.push_back(Args[0]);
2431 const bool HasExplicitObjectParameter = ThisPtr.
isNull();
2435 if (!HasExplicitObjectParameter) {
2436 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2439 DBuilder.createObjectPointerType(ThisPtrType,
true);
2440 Elts.push_back(ThisPtrType);
2444 for (
unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i < e; ++i)
2445 Elts.push_back(Args[i]);
2448 if (HasExplicitObjectParameter) {
2449 assert(Elts.size() >= 2 && Args.size() >= 2 &&
2450 "Expected at least return type and object parameter.");
2451 Elts[1] = DBuilder.createObjectPointerType(Args[1],
false);
2454 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2456 return DBuilder.createSubroutineType(
2457 EltTypeArray, OriginalFunc->getFlags(),
2464 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
2472CGDebugInfo::GetMethodLinkageName(
const CXXMethodDecl *
Method)
const {
2475 const bool IsCtorOrDtor =
2478 if (IsCtorOrDtor && !CGM.getCodeGenOpts().DebugStructorDeclLinkageNames)
2485 if (IsCtorOrDtor && !CGM.getTarget().getCXXABI().hasConstructorVariants())
2488 if (
const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(
Method))
2491 if (
const auto *Dtor = llvm::dyn_cast<CXXDestructorDecl>(
Method))
2494 return CGM.getMangledName(
Method);
2497bool CGDebugInfo::shouldGenerateVirtualCallSite()
const {
2500 (CGM.getCodeGenOpts().DwarfVersion >= 5));
2503llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
2504 const CXXMethodDecl *
Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
2507 StringRef MethodName = getFunctionName(
Method);
2508 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(
Method, Unit);
2510 StringRef MethodLinkageName;
2517 MethodLinkageName = GetMethodLinkageName(
Method);
2520 llvm::DIFile *MethodDefUnit =
nullptr;
2521 unsigned MethodLine = 0;
2522 if (!
Method->isImplicit()) {
2523 MethodDefUnit = getOrCreateFile(
Method->getLocation());
2524 MethodLine = getLineNumber(
Method->getLocation());
2528 llvm::DIType *ContainingType =
nullptr;
2529 unsigned VIndex = 0;
2530 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2531 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
2532 int ThisAdjustment = 0;
2535 if (
Method->isPureVirtual())
2536 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
2538 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
2540 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2544 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(
Method);
2548 const auto *DD = dyn_cast<CXXDestructorDecl>(
Method);
2551 DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
2552 CGM.getContext().getLangOpts())
2556 MethodVFTableLocation ML =
2557 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
2565 if (
Method->size_overridden_methods() == 0)
2566 Flags |= llvm::DINode::FlagIntroducedVirtual;
2571 ThisAdjustment = CGM.getCXXABI()
2572 .getVirtualFunctionPrologueThisAdjustment(GD)
2575 ContainingType = RecordTy;
2578 if (
Method->getCanonicalDecl()->isDeleted())
2579 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
2581 if (
Method->isNoReturn())
2582 Flags |= llvm::DINode::FlagNoReturn;
2585 Flags |= llvm::DINode::FlagStaticMember;
2586 if (
Method->isImplicit())
2587 Flags |= llvm::DINode::FlagArtificial;
2589 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(
Method)) {
2590 if (CXXC->isExplicit())
2591 Flags |= llvm::DINode::FlagExplicit;
2592 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(
Method)) {
2593 if (CXXC->isExplicit())
2594 Flags |= llvm::DINode::FlagExplicit;
2596 if (
Method->hasPrototype())
2597 Flags |= llvm::DINode::FlagPrototyped;
2599 Flags |= llvm::DINode::FlagLValueReference;
2601 Flags |= llvm::DINode::FlagRValueReference;
2602 if (!
Method->isExternallyVisible())
2603 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2604 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
2605 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
2610 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor) {
2611 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(
Method)) {
2612 if (
const auto *Def =
2613 dyn_cast_or_null<CXXConstructorDecl>(CD->getDefinition());
2614 Def && !Def->isDelegatingConstructor()) {
2620 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(
Method, Unit);
2621 llvm::DISubprogram *SP = DBuilder.createMethod(
2622 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
2623 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
2624 TParamsArray.get(),
nullptr,
2625 CGM.getCodeGenOpts().DebugKeyInstructions);
2627 SPCache[
Method->getCanonicalDecl()].reset(SP);
2632void CGDebugInfo::CollectCXXMemberFunctions(
2633 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2634 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy) {
2639 for (
const auto *I : RD->
decls()) {
2640 const auto *
Method = dyn_cast<CXXMethodDecl>(I);
2654 if (
Method->getType()->castAs<FunctionProtoType>()->getContainedAutoType())
2663 auto MI = SPCache.find(
Method->getCanonicalDecl());
2664 EltTys.push_back(MI == SPCache.end()
2665 ? CreateCXXMemberFunction(
Method, Unit, RecordTy)
2666 :
static_cast<llvm::Metadata *
>(MI->second));
2670void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2671 SmallVectorImpl<llvm::Metadata *> &EltTys,
2672 llvm::DIType *RecordTy) {
2673 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
2674 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
2675 llvm::DINode::FlagZero);
2679 if (CGM.getCodeGenOpts().EmitCodeView) {
2680 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
2681 llvm::DINode::FlagIndirectVirtualBase);
2685void CGDebugInfo::CollectCXXBasesAux(
2686 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2687 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
2689 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
2690 llvm::DINode::DIFlags StartingFlags) {
2691 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
2692 for (
const auto &BI : Bases) {
2695 BI.getType()->castAsCanonical<RecordType>()->getDecl())
2697 if (!SeenTypes.insert(Base).second)
2699 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
2700 llvm::DINode::DIFlags BFlags = StartingFlags;
2704 if (BI.isVirtual()) {
2705 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2708 BaseOffset = 0 - CGM.getItaniumVTableContext()
2709 .getVirtualBaseOffsetOffset(RD, Base)
2715 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
2716 VBPtrOffset = CGM.getContext()
2717 .getASTRecordLayout(RD)
2721 BFlags |= llvm::DINode::FlagVirtual;
2728 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
2729 VBPtrOffset, BFlags);
2730 EltTys.push_back(DTy);
2735CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
2736 llvm::DIFile *Unit) {
2738 return llvm::DINodeArray();
2739 TemplateArgs &Args = *OArgs;
2740 SmallVector<llvm::Metadata *, 16> TemplateParams;
2741 for (
unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
2742 const TemplateArgument &TA = Args.Args[i];
2746 Name = Args.TList->getParam(i)->getName();
2750 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
2751 TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
2752 TheCU, Name, TTy, defaultParameter));
2757 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2758 TheCU, Name, TTy, defaultParameter,
2759 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
2764 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2765 llvm::Constant *
V =
nullptr;
2768 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
2769 !D->
hasAttr<CUDADeviceAttr>()) {
2772 if (
const auto *VD = dyn_cast<VarDecl>(D))
2773 V = CGM.GetAddrOfGlobalVar(VD);
2776 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(D);
2777 MD && MD->isImplicitObjectMemberFunction())
2778 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
2779 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2780 V = CGM.GetAddrOfFunction(FD);
2783 else if (
const auto *MPT =
2784 dyn_cast<MemberPointerType>(
T.getTypePtr())) {
2788 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
2790 CGM.getContext().toCharUnitsFromBits((
int64_t)fieldOffset);
2791 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
2792 }
else if (
const auto *GD = dyn_cast<MSGuidDecl>(D)) {
2793 V = CGM.GetAddrOfMSGuidDecl(GD).getPointer();
2794 }
else if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(D)) {
2796 V = ConstantEmitter(CGM).emitAbstract(
2797 SourceLocation(), TPO->getValue(), TPO->getType());
2799 V = CGM.GetAddrOfTemplateParamObject(TPO).getPointer();
2801 assert(
V &&
"Failed to find template parameter pointer");
2802 V =
V->stripPointerCasts();
2804 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2805 TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(
V)));
2809 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2810 llvm::Constant *
V =
nullptr;
2813 if (
const auto *MPT = dyn_cast<MemberPointerType>(
T.getTypePtr()))
2819 if (MPT->isMemberDataPointer())
2820 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
2822 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
2823 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2824 TheCU, Name, TTy, defaultParameter,
V));
2828 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2829 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(
2831 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2832 TheCU, Name, TTy, defaultParameter,
V));
2835 std::string QualName;
2836 llvm::raw_string_ostream
OS(QualName);
2838 OS, getPrintingPolicy());
2839 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2840 TheCU, Name,
nullptr, QualName, defaultParameter));
2844 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
2845 TheCU, Name,
nullptr,
2852 T = CGM.getContext().getLValueReferenceType(
T);
2853 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(E,
T);
2854 assert(
V &&
"Expression in template argument isn't constant");
2855 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2856 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2857 TheCU, Name, TTy, defaultParameter,
V->stripPointerCasts()));
2863 "These argument types shouldn't exist in concrete types");
2866 return DBuilder.getOrCreateArray(TemplateParams);
2869std::optional<CGDebugInfo::TemplateArgs>
2870CGDebugInfo::GetTemplateArgs(
const FunctionDecl *FD)
const {
2878 return std::nullopt;
2880std::optional<CGDebugInfo::TemplateArgs>
2881CGDebugInfo::GetTemplateArgs(
const VarDecl *VD)
const {
2885 auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VD);
2887 return std::nullopt;
2888 VarTemplateDecl *
T = TS->getSpecializedTemplate();
2889 const TemplateParameterList *TList =
T->getTemplateParameters();
2890 auto TA = TS->getTemplateArgs().asArray();
2891 return {{TList, TA}};
2893std::optional<CGDebugInfo::TemplateArgs>
2894CGDebugInfo::GetTemplateArgs(
const RecordDecl *RD)
const {
2895 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2899 TemplateParameterList *TPList =
2900 TSpecial->getSpecializedTemplate()->getTemplateParameters();
2901 const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
2902 return {{TPList, TAList.
asArray()}};
2904 return std::nullopt;
2908CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
2909 llvm::DIFile *Unit) {
2910 return CollectTemplateParams(GetTemplateArgs(FD), Unit);
2913llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
2914 llvm::DIFile *Unit) {
2915 return CollectTemplateParams(GetTemplateArgs(VL), Unit);
2918llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
const RecordDecl *RD,
2919 llvm::DIFile *Unit) {
2920 return CollectTemplateParams(GetTemplateArgs(RD), Unit);
2923void CGDebugInfo::CollectBTFDeclTagAnnotations(
2924 const Decl *D, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2926 llvm::Metadata *Ops[2] = {
2927 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_decl_tag")),
2928 llvm::MDString::get(CGM.getLLVMContext(), I->getBTFDeclTag())};
2929 Annotations.push_back(llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2933llvm::DINodeArray CGDebugInfo::CollectBTFDeclTagAnnotations(
const Decl *D) {
2934 if (!D->
hasAttr<BTFDeclTagAttr>())
2937 SmallVector<llvm::Metadata *, 4> Annotations;
2938 CollectBTFDeclTagAnnotations(D, Annotations);
2939 return DBuilder.getOrCreateArray(Annotations);
2942void CGDebugInfo::CollectBTFTypeTagAnnotations(
2943 QualType Ty, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2944 const BTFTagAttributedType *BTFAttrTy;
2946 BTFAttrTy = dyn_cast<BTFTagAttributedType>(
Atomic->getValueType());
2948 BTFAttrTy = dyn_cast<BTFTagAttributedType>(Ty);
2951 StringRef
Tag = BTFAttrTy->getAttr()->getBTFTypeTag();
2953 llvm::Metadata *Ops[2] = {
2954 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_type_tag")),
2955 llvm::MDString::get(CGM.getLLVMContext(), Tag)};
2956 Annotations.insert(Annotations.begin(),
2957 llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2959 BTFAttrTy = dyn_cast<BTFTagAttributedType>(BTFAttrTy->getWrappedType());
2963llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
2965 return VTablePtrType;
2967 ASTContext &Context = CGM.getContext();
2970 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
2971 llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy);
2972 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
2974 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2975 std::optional<unsigned> DWARFAddressSpace =
2976 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2978 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
2979 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2980 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
2981 return VTablePtrType;
2984StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
2996 if (!CGM.getTarget().getCXXABI().isItaniumFamily())
2998 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3008 if (CGM.getTarget().getTriple().isOSBinFormatCOFF() &&
3009 VTable->isDeclarationForLinker())
3013 StringRef SymbolName =
"__clang_vtable";
3015 QualType VoidPtr = Context.getPointerType(Context.VoidTy);
3024 llvm::DIScope *DContext = getContextDescriptor(RD, TheCU);
3026 llvm::DIFile *Unit = getOrCreateFile(Loc);
3027 llvm::DIType *VTy = getOrCreateType(VoidPtr, Unit);
3029 llvm::DINode::FlagArtificial;
3030 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
3031 ? llvm::dwarf::DW_TAG_variable
3032 : llvm::dwarf::DW_TAG_member;
3033 llvm::DIDerivedType *DT = DBuilder.createStaticMemberType(
3034 Ctxt, SymbolName, Unit, 0, VTy, Flags,
3038 unsigned PAlign = CGM.getVtableGlobalVarAlignment();
3042 llvm::DIGlobalVariableExpression *GVE =
3043 DBuilder.createGlobalVariableExpression(
3044 TheCU, SymbolName, VTable->getName(), Unit, 0,
3045 getOrCreateType(VoidPtr, Unit), VTable->hasLocalLinkage(),
3046 true,
nullptr, DT,
nullptr,
3048 VTable->addDebugInfo(GVE);
3051StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
3053 llvm::Function *InitFn) {
3058 return InitFn->getName();
3068 llvm::raw_svector_ostream OS(QualifiedGV);
3070 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
3072 std::swap(Quals, GVName);
3076 llvm::raw_svector_ostream OS(InitName);
3078 OS << Quals <<
"::";
3083 llvm_unreachable(
"not an initializer");
3085 OS <<
"`dynamic initializer for '";
3088 OS <<
"`dynamic atexit destructor for '";
3095 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3096 printTemplateArgumentList(OS, VTpl->getTemplateArgs().asArray(),
3097 getPrintingPolicy());
3102 return internString(
OS.str());
3105void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
3106 SmallVectorImpl<llvm::Metadata *> &EltTys) {
3115 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
3122 llvm::DIType *VPtrTy =
nullptr;
3123 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
3124 CGM.getTarget().getCXXABI().isMicrosoft();
3125 if (NeedVTableShape) {
3127 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3128 const VTableLayout &VFTLayout =
3129 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
3130 unsigned VSlotCount =
3132 unsigned VTableWidth = PtrWidth * VSlotCount;
3133 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
3134 std::optional<unsigned> DWARFAddressSpace =
3135 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
3138 llvm::DIType *VTableType = DBuilder.createPointerType(
3139 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
3140 EltTys.push_back(VTableType);
3143 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
3151 VPtrTy = getOrCreateVTablePtrType(Unit);
3153 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3154 llvm::DIType *VPtrMember =
3155 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
3156 llvm::DINode::FlagArtificial, VPtrTy);
3157 EltTys.push_back(VPtrMember);
3160std::pair<llvm::DIType *, unsigned>
3165 if (
const auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3172 auto I = FieldIndexCache.find(Field);
3173 assert(I != FieldIndexCache.end() &&
"Missing field debug information");
3174 return {
T, I->second};
3184 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3185 assert(!D.
isNull() &&
"null type");
3186 llvm::DIType *
T = getOrCreateType(D, getOrCreateFile(Loc));
3187 assert(
T &&
"could not create debug info for type");
3196 if (CGM.getCodeGenOpts().getDebugInfo() <=
3197 llvm::codegenoptions::DebugLineTablesOnly)
3201 node = llvm::MDNode::get(CGM.getLLVMContext(), {});
3203 node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));
3205 CI->setMetadata(
"heapallocsite", node);
3209 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3211 CanQualType Ty = CGM.getContext().getCanonicalTagType(ED);
3213 auto I = TypeCache.find(TyPtr);
3216 llvm::DIType *Res = CreateTypeDefinition(dyn_cast<EnumType>(Ty));
3217 assert(!Res->isForwardDecl());
3218 TypeCache[TyPtr].reset(Res);
3222 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3223 !CGM.getLangOpts().CPlusPlus)
3229 if (RD->
hasAttr<DLLImportAttr>())
3232 if (MD->hasAttr<DLLImportAttr>())
3245 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
3255 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
3256 Explicit = TD->isExplicitInstantiationOrSpecialization();
3260 if (CXXDecl->
fields().empty())
3270 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3271 if (CXXRD->isDynamicClass() &&
3272 CGM.getVTableLinkage(CXXRD) ==
3273 llvm::GlobalValue::AvailableExternallyLinkage &&
3284 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3286 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3288 auto I = TypeCache.find(TyPtr);
3295 auto [Res, PrefRes] = CreateTypeDefinition(dyn_cast<RecordType>(Ty));
3296 assert(!Res->isForwardDecl());
3297 TypeCache[TyPtr].reset(Res);
3304 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
3305 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
3332 bool HasNonDeletedCtor =
false;
3334 if (Ctor->isCopyOrMoveConstructor())
3341 if (CtorDef->isDelegatingConstructor())
3345 if (Ctor->isConstexpr() && !Ctor->isDeleted())
3348 if (!Ctor->isDeleted())
3349 HasNonDeletedCtor =
true;
3351 return HasNonDeletedCtor;
3367 if (DebugKind == llvm::codegenoptions::DebugLineTablesOnly)
3370 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3371 RD->
hasAttr<StandaloneDebugAttr>())
3374 if (!LangOpts.CPlusPlus)
3380 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3396 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3397 Spec = SD->getSpecializationKind();
3406 if ((DebugKind == llvm::codegenoptions::DebugInfoConstructor) &&
3417 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3418 llvm::DIType *
T = getTypeOrNull(Ty);
3419 if (
T &&
T->isForwardDecl())
3423llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
3425 llvm::DIType *
T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
3433 auto [Def, Pref] = CreateTypeDefinition(Ty);
3435 return Pref ? Pref : Def;
3438llvm::DIType *CGDebugInfo::GetPreferredNameType(
const CXXRecordDecl *RD,
3439 llvm::DIFile *Unit) {
3443 auto const *PNA = RD->
getAttr<PreferredNameAttr>();
3447 return getOrCreateType(PNA->getTypedefType(), Unit);
3474 const auto *RT = QT->
getAs<RecordType>();
3478 auto *CRD = dyn_cast<CXXRecordDecl>(RT->getDecl()->getDefinitionOrSelf());
3479 if (!CRD || !CRD->hasDefinition())
3484 assert(CRD->isStandardLayout());
3490std::pair<llvm::DIType *, llvm::DIType *>
3491CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
3495 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3503 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
3507 return {FwdDecl,
nullptr};
3509 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
3510 CollectContainingType(CXXDecl, FwdDecl);
3513 LexicalBlockStack.emplace_back(&*FwdDecl);
3514 RegionMap[RD].reset(FwdDecl);
3517 SmallVector<llvm::Metadata *, 16> EltTys;
3524 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3526 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
3527 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
3531 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
3532 if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMethods)
3533 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
3535 LexicalBlockStack.pop_back();
3536 RegionMap.erase(RD);
3538 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3539 DBuilder.replaceArrays(FwdDecl, Elements);
3541 if (FwdDecl->isTemporary())
3543 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
3545 RegionMap[RD].reset(FwdDecl);
3547 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor) {
3562 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
3563 if (
auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
3564 return {FwdDecl, PrefDI};
3566 return {FwdDecl,
nullptr};
3569llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectType *Ty,
3570 llvm::DIFile *Unit) {
3572 return getOrCreateType(Ty->getBaseType(), Unit);
3575llvm::DIType *CGDebugInfo::CreateType(
const ObjCTypeParamType *Ty,
3576 llvm::DIFile *Unit) {
3578 SourceLocation Loc = Ty->getDecl()->getLocation();
3581 return DBuilder.createTypedef(
3582 getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
3583 Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
3584 getDeclContextDescriptor(Ty->getDecl()));
3611llvm::DIType *CGDebugInfo::CreateType(
const ObjCInterfaceType *Ty,
3612 llvm::DIFile *Unit) {
3617 auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage
>(
3618 TheCU->getSourceLanguage().getUnversionedName());
3623 if (DebugTypeExtRefs &&
ID->isFromASTFile() &&
ID->getDefinition() &&
3624 !
ID->getImplementation())
3625 return DBuilder.createForwardDecl(
3626 llvm::dwarf::DW_TAG_structure_type,
ID->getName(),
3627 getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);
3630 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3631 unsigned Line = getLineNumber(
ID->getLocation());
3635 ObjCInterfaceDecl *Def =
ID->getDefinition();
3637 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3638 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
3639 llvm::dwarf::DW_TAG_structure_type,
ID->getName(), Mod ? Mod : TheCU,
3640 DefUnit,
Line, RuntimeLang);
3641 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
3645 return CreateTypeDefinition(Ty, Unit);
3648llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
3649 bool CreateSkeletonCU) {
3654 auto ModRef = ModuleCache.find(M);
3655 if (ModRef != ModuleCache.end())
3659 SmallString<128> ConfigMacros;
3661 llvm::raw_svector_ostream
OS(ConfigMacros);
3662 const auto &PPOpts = CGM.getPreprocessorOpts();
3665 for (
auto &M : PPOpts.Macros) {
3668 const std::string &
Macro = M.first;
3669 bool Undef = M.second;
3670 OS <<
"\"-" << (Undef ?
'U' :
'D');
3671 for (
char c :
Macro)
3686 bool IsRootModule = M ? !M->
Parent :
true;
3690 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
3691 assert(StringRef(M->
Name).starts_with(CGM.getLangOpts().ModuleName) &&
3692 "clang module without ASTFile must be specified by -fmodule-name");
3695 auto RemapPath = [
this](StringRef Path) -> std::string {
3697 StringRef Relative(Remapped);
3698 StringRef CompDir = TheCU->getDirectory();
3699 if (CompDir.empty())
3702 if (Relative.consume_front(CompDir))
3703 Relative.consume_front(llvm::sys::path::get_separator());
3705 return Relative.str();
3708 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
3715 Signature = ModSig.truncatedValue();
3719 llvm::DIBuilder DIB(CGM.getModule());
3721 if (!llvm::sys::path::is_absolute(Mod.
getASTFile())) {
3722 if (CGM.getHeaderSearchOpts().ModuleFileHomeIsCwd)
3723 PCM = getCurrentDirname();
3727 llvm::sys::path::append(PCM, Mod.
getASTFile());
3728 DIB.createCompileUnit(
3729 TheCU->getSourceLanguage(),
3732 TheCU->getProducer(),
false, StringRef(), 0, RemapPath(PCM),
3733 llvm::DICompileUnit::FullDebug, Signature);
3737 llvm::DIModule *Parent =
3739 : getOrCreateModuleRef(ASTSourceDescriptor(*M->
Parent),
3741 StringRef IncludePath = Mod.
getPath();
3742 if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
3743 StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
3744 if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
3747 llvm::DIModule *DIMod =
3748 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
3749 RemapPath(IncludePath));
3750 ModuleCache[M].reset(DIMod);
3754llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const ObjCInterfaceType *Ty,
3755 llvm::DIFile *Unit) {
3757 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3758 unsigned Line = getLineNumber(
ID->getLocation());
3760 unsigned RuntimeLang = TheCU->getSourceLanguage().getUnversionedName();
3766 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3767 if (
ID->getImplementation())
3768 Flags |= llvm::DINode::FlagObjcClassComplete;
3770 llvm::DINodeArray Annotations;
3771 const auto *RuntimeName =
ID->getAttr<ObjCRuntimeNameAttr>();
3772 if (RuntimeName && RuntimeName->getMetadataName() !=
ID->getName()) {
3773 llvm::LLVMContext &Ctx = CGM.getLLVMContext();
3774 llvm::Metadata *Ops[2] = {
3775 llvm::MDString::get(Ctx,
"objc_runtime_name"),
3776 llvm::MDString::get(Ctx, RuntimeName->getMetadataName())};
3777 Annotations = DBuilder.getOrCreateArray({llvm::MDNode::get(Ctx, Ops)});
3780 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3781 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
3782 Mod ? Mod : Unit,
ID->getName(), DefUnit,
Line, Size, Align, Flags,
3783 nullptr, llvm::DINodeArray(), RuntimeLang,
nullptr,
3787 QualType QTy(Ty, 0);
3788 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
3791 LexicalBlockStack.emplace_back(RealDecl);
3792 RegionMap[Ty->
getDecl()].reset(RealDecl);
3795 SmallVector<llvm::Metadata *, 16> EltTys;
3797 ObjCInterfaceDecl *SClass =
ID->getSuperClass();
3799 llvm::DIType *SClassTy =
3800 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
3804 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
3805 llvm::DINode::FlagZero);
3806 EltTys.push_back(InhTag);
3810 auto AddProperty = [&](
const ObjCPropertyDecl *PD) {
3811 SourceLocation Loc = PD->getLocation();
3812 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3813 unsigned PLine = getLineNumber(Loc);
3814 ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
3815 ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
3816 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
3817 PD->getName(), PUnit, PLine,
3819 : getSelectorName(PD->getGetterName()),
3821 : getSelectorName(PD->getSetterName()),
3822 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
3823 EltTys.push_back(PropertyNode);
3828 typedef std::pair<char, const IdentifierInfo *> IsClassAndIdent;
3832 llvm::DenseSet<IsClassAndIdent> PropertySet;
3834 auto GetIsClassAndIdent = [](
const ObjCPropertyDecl *PD) {
3835 return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
3837 for (
const ObjCCategoryDecl *ClassExt :
ID->known_extensions())
3838 for (
auto *PD : ClassExt->properties()) {
3839 PropertySet.insert(GetIsClassAndIdent(PD));
3842 for (
const auto *PD :
ID->properties()) {
3845 if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
3851 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
3852 unsigned FieldNo = 0;
3853 for (ObjCIvarDecl *Field =
ID->all_declared_ivar_begin(); Field;
3854 Field =
Field->getNextIvar(), ++FieldNo) {
3855 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
3859 StringRef FieldName =
Field->getName();
3862 if (FieldName.empty())
3866 llvm::DIFile *FieldDefUnit = getOrCreateFile(
Field->getLocation());
3867 unsigned FieldLine = getLineNumber(
Field->getLocation());
3868 QualType FType =
Field->getType();
3875 FieldSize =
Field->isBitField() ?
Field->getBitWidthValue()
3876 : CGM.getContext().getTypeSize(FType);
3881 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
3885 if (
Field->isBitField()) {
3887 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
3888 FieldOffset %= CGM.getContext().getCharWidth();
3896 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3898 Flags = llvm::DINode::FlagProtected;
3900 Flags = llvm::DINode::FlagPrivate;
3902 Flags = llvm::DINode::FlagPublic;
3904 if (
Field->isBitField())
3905 Flags |= llvm::DINode::FlagBitField;
3907 llvm::MDNode *PropertyNode =
nullptr;
3908 ObjCPropertyDecl *SynthesizedProperty =
nullptr;
3909 llvm::DIFile *PUnit =
nullptr;
3911 if (ObjCImplementationDecl *ImpD =
ID->getImplementation()) {
3912 if (ObjCPropertyImplDecl *PImpD =
3913 ImpD->FindPropertyImplIvarDecl(
Field->getIdentifier())) {
3914 if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
3915 SynthesizedProperty = PD;
3916 SourceLocation Loc = PD->getLocation();
3917 PUnit = getOrCreateFile(Loc);
3918 PLine = getLineNumber(Loc);
3919 ObjCMethodDecl *Getter = PImpD->getGetterMethodDecl();
3920 ObjCMethodDecl *Setter = PImpD->getSetterMethodDecl();
3921 PropertyNode = DBuilder.createObjCProperty(
3922 PD->getName(), PUnit, PLine,
3925 : getSelectorName(PD->getGetterName()),
3928 : getSelectorName(PD->getSetterName()),
3929 PD->getPropertyAttributes(),
3930 getOrCreateType(PD->getType(), PUnit));
3934 auto *IvarTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
3935 FieldSize, FieldAlign, FieldOffset,
3936 Flags, FieldTy, PropertyNode);
3937 EltTys.push_back(IvarTy);
3939 if (SynthesizedProperty) {
3940 assert(PUnit &&
"SynthesizedProperty implies PUnit");
3941 EltTys.push_back(DBuilder.createProperty(
3942 SynthesizedProperty->
getName(), PUnit, PLine,
3943 getOrCreateType(SynthesizedProperty->
getType(), PUnit), IvarTy));
3947 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3948 DBuilder.replaceArrays(RealDecl, Elements);
3950 LexicalBlockStack.pop_back();
3954llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
3955 llvm::DIFile *Unit) {
3963 auto &Ctx = CGM.getContext();
3968 QualType CharVecTy =
3970 return CreateType(CharVecTy->
getAs<VectorType>(), Unit);
3973 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3976 llvm::Metadata *Subscript;
3977 QualType QTy(Ty, 0);
3978 auto SizeExpr = SizeExprCache.find(QTy);
3979 if (SizeExpr != SizeExprCache.end())
3980 Subscript = DBuilder.getOrCreateSubrange(
3981 SizeExpr->getSecond() ,
nullptr ,
3982 nullptr ,
nullptr );
3985 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3986 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count ? Count : -1));
3987 Subscript = DBuilder.getOrCreateSubrange(
3988 CountNode ,
nullptr ,
nullptr ,
3991 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
3996 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
3999llvm::DIType *CGDebugInfo::CreateType(
const ConstantMatrixType *Ty,
4000 llvm::DIFile *Unit) {
4004 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
4009 llvm::SmallVector<llvm::Metadata *, 2> Subscripts;
4010 auto *ColumnCountNode =
4011 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4012 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumColumns()));
4013 auto *RowCountNode =
4014 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4015 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumRows()));
4016 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4017 ColumnCountNode ,
nullptr ,
nullptr ,
4019 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4020 RowCountNode ,
nullptr ,
nullptr ,
4022 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
4023 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
4026llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
4031 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
4046 Size = CGM.getContext().getTypeSize(Ty);
4053 SmallVector<llvm::Metadata *, 8> Subscripts;
4054 QualType EltTy(Ty, 0);
4055 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
4064 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
4065 Count = CAT->getZExtSize();
4066 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
4067 if (Expr *Size = VAT->getSizeExpr()) {
4069 if (
Size->EvaluateAsInt(
Result, CGM.getContext()))
4070 Count =
Result.Val.getInt().getExtValue();
4074 auto SizeNode = SizeExprCache.find(EltTy);
4075 if (SizeNode != SizeExprCache.end())
4076 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4077 SizeNode->getSecond() ,
nullptr ,
4078 nullptr ,
nullptr ));
4081 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4082 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count));
4083 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4084 CountNode ,
nullptr ,
nullptr ,
4090 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
4092 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
4096llvm::DIType *CGDebugInfo::CreateType(
const LValueReferenceType *Ty,
4097 llvm::DIFile *Unit) {
4098 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
4102llvm::DIType *CGDebugInfo::CreateType(
const RValueReferenceType *Ty,
4103 llvm::DIFile *Unit) {
4104 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
4106 if (CGM.getCodeGenOpts().DebugStrictDwarf &&
4107 CGM.getCodeGenOpts().DwarfVersion < 4)
4108 Tag = llvm::dwarf::DW_TAG_reference_type;
4110 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
4113llvm::DIType *CGDebugInfo::CreateType(
const MemberPointerType *Ty,
4115 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4119 Size = CGM.getContext().getTypeSize(Ty);
4122 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
4125 Flags |= llvm::DINode::FlagSingleInheritance;
4128 Flags |= llvm::DINode::FlagMultipleInheritance;
4131 Flags |= llvm::DINode::FlagVirtualInheritance;
4141 llvm::DIType *ClassType = getOrCreateType(
T, U);
4143 return DBuilder.createMemberPointerType(
4147 const FunctionProtoType *FPT =
4149 return DBuilder.createMemberPointerType(
4150 getOrCreateInstanceMethodType(
4153 ClassType, Size, 0, Flags);
4156llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
4158 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
4161llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
4165llvm::DIType *CGDebugInfo::CreateType(
const HLSLAttributedResourceType *Ty,
4167 return getOrCreateType(Ty->getWrappedType(), U);
4170llvm::DIType *CGDebugInfo::CreateType(
const HLSLInlineSpirvType *Ty,
4177 const EnumType *Ty) {
4189llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
4192 bool isImportedFromModule =
4193 DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
4197 if (isImportedFromModule || !ED->getDefinition()) {
4205 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4206 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
4207 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
4209 unsigned Line = getLineNumber(ED->getLocation());
4210 StringRef EDName = ED->getName();
4211 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
4212 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
4213 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
4215 ReplaceMap.emplace_back(
4216 std::piecewise_construct, std::make_tuple(Ty),
4217 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
4221 return CreateTypeDefinition(Ty);
4224llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
4227 SmallVector<llvm::Metadata *, 16> Enumerators;
4228 ED = ED->getDefinition();
4229 assert(ED &&
"An enumeration definition is required");
4230 for (
const auto *
Enum : ED->enumerators()) {
4231 Enumerators.push_back(
4232 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
4235 std::optional<EnumExtensibilityAttr::Kind> EnumKind;
4236 if (
auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
4237 EnumKind = Attr->getExtensibility();
4240 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
4242 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4243 unsigned Line = getLineNumber(ED->getLocation());
4245 llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
4246 return DBuilder.createEnumerationType(
4247 EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
4248 0, Identifier, ED->isScoped(), EnumKind);
4253 StringRef Name, StringRef
Value) {
4254 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4255 return DBuilder.createMacro(Parent,
Line, MType, Name,
Value);
4261 llvm::DIFile *FName = getOrCreateFile(FileLoc);
4262 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4263 return DBuilder.createTempMacroFile(Parent,
Line, FName);
4268 llvm::DISubprogram *SynthSubprogram) {
4269 return llvm::DILocation::get(CGM.getLLVMContext(), 0, 0,
4270 SynthSubprogram, ParentLocation);
4275 StringRef SynthFuncName,
4276 llvm::DIFile *SynthFile) {
4277 llvm::DISubprogram *SP = createInlinedSubprogram(SynthFuncName, SynthFile);
4282 llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) {
4288 FuncName += Category;
4290 FuncName += FailureMsg;
4293 TrapLocation->getFile());
4303 Quals += InnerQuals;
4305 switch (
T->getTypeClass()) {
4307 return C.getQualifiedType(
T.getTypePtr(), Quals);
4310 case Type::InjectedClassName:
4311 return C.getQualifiedType(
T->getCanonicalTypeUnqualified().getTypePtr(),
4313 case Type::TemplateSpecialization: {
4315 if (Spec->isTypeAlias())
4316 return C.getQualifiedType(
T.getTypePtr(), Quals);
4317 T = Spec->desugar();
4320 case Type::TypeOfExpr:
4326 case Type::Decltype:
4329 case Type::UnaryTransform:
4332 case Type::Attributed:
4335 case Type::BTFTagAttributed:
4338 case Type::CountAttributed:
4347 case Type::MacroQualified:
4350 case Type::SubstTemplateTypeParm:
4354 case Type::DeducedTemplateSpecialization: {
4356 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
4360 case Type::PackIndexing: {
4364 case Type::Adjusted:
4371 assert(
T != LastT &&
"Type unwrapping failed to unwrap!");
4376llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
4379 if (It != TypeCache.end()) {
4381 if (llvm::Metadata *
V = It->second)
4394 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
4401 RetainedTypes.push_back(
4402 CGM.getContext().getCanonicalTagType(&D).getAsOpaquePtr());
4405llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
4409 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
4411 llvm::raw_string_ostream OS(Name);
4412 Ty.
print(OS, getPrintingPolicy());
4419 if (
auto *
T = getTypeOrNull(Ty))
4422 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
4423 void *TyPtr = Ty.getAsOpaquePtr();
4426 TypeCache[TyPtr].reset(Res);
4431llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
4439 auto Info = Reader->getSourceDescriptor(Idx);
4441 return getOrCreateModuleRef(*Info,
true);
4442 }
else if (ClangModuleMap) {
4455 auto Info = ASTSourceDescriptor(*M);
4456 return getOrCreateModuleRef(Info,
false);
4459 return getOrCreateModuleRef(PCHDescriptor,
false);
4466llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
4469 return CreateQualifiedType(Ty, Unit);
4473#define TYPE(Class, Base)
4474#define ABSTRACT_TYPE(Class, Base)
4475#define NON_CANONICAL_TYPE(Class, Base)
4476#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4477#include "clang/AST/TypeNodes.inc"
4478 llvm_unreachable(
"Dependent types cannot show up in debug information");
4480 case Type::ExtVector:
4483 case Type::ConstantMatrix:
4485 case Type::ObjCObjectPointer:
4487 case Type::ObjCObject:
4489 case Type::ObjCTypeParam:
4491 case Type::ObjCInterface:
4499 case Type::BlockPointer:
4507 case Type::FunctionProto:
4508 case Type::FunctionNoProto:
4510 case Type::ConstantArray:
4511 case Type::VariableArray:
4512 case Type::IncompleteArray:
4513 case Type::ArrayParameter:
4516 case Type::LValueReference:
4518 case Type::RValueReference:
4521 case Type::MemberPointer:
4529 case Type::OverflowBehavior:
4534 case Type::TemplateSpecialization:
4536 case Type::HLSLAttributedResource:
4538 case Type::HLSLInlineSpirv:
4540 case Type::PredefinedSugar:
4542 case Type::CountAttributed:
4543 case Type::LateParsedAttr:
4545 case Type::Attributed:
4546 case Type::BTFTagAttributed:
4547 case Type::Adjusted:
4549 case Type::DeducedTemplateSpecialization:
4552 case Type::MacroQualified:
4553 case Type::SubstTemplateTypeParm:
4554 case Type::TypeOfExpr:
4556 case Type::Decltype:
4557 case Type::PackIndexing:
4558 case Type::UnaryTransform:
4562 llvm_unreachable(
"type should have been unwrapped!");
4565llvm::DICompositeType *
4566CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
4567 QualType QTy(Ty, 0);
4569 auto *
T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
4574 if (
T && !
T->isForwardDecl())
4578 llvm::DICompositeType *Res = CreateLimitedType(Ty);
4583 DBuilder.replaceArrays(Res,
T ?
T->getElements() : llvm::DINodeArray());
4586 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
4591llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
4593 bool NameIsSimplified =
false;
4596 StringRef RDName = getClassName(RD, &NameIsSimplified);
4598 llvm::DIFile *DefUnit =
nullptr;
4601 DefUnit = getOrCreateFile(Loc);
4602 Line = getLineNumber(Loc);
4609 auto *
T = cast_or_null<llvm::DICompositeType>(
4610 getTypeOrNull(CGM.getContext().getCanonicalTagType(RD)));
4618 return getOrCreateRecordFwdDecl(Ty, RDContext);
4631 auto Flags = llvm::DINode::FlagZero;
4632 if (NameIsSimplified)
4633 Flags |= llvm::DINode::FlagNameIsSimplified;
4634 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4636 Flags |= llvm::DINode::FlagTypePassByReference;
4638 Flags |= llvm::DINode::FlagTypePassByValue;
4641 if (!CXXRD->isTrivial())
4642 Flags |= llvm::DINode::FlagNonTrivial;
4645 if (CXXRD->isAnonymousStructOrUnion())
4646 Flags |= llvm::DINode::FlagExportSymbols;
4649 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
4652 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4653 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
4655 Flags, Identifier, Annotations);
4659 switch (RealDecl->getTag()) {
4661 llvm_unreachable(
"invalid composite type tag");
4663 case llvm::dwarf::DW_TAG_array_type:
4664 case llvm::dwarf::DW_TAG_enumeration_type:
4669 if (Identifier.empty())
4673 case llvm::dwarf::DW_TAG_structure_type:
4674 case llvm::dwarf::DW_TAG_union_type:
4675 case llvm::dwarf::DW_TAG_class_type:
4678 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
4682 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
4683 CXXRecordDecl *TemplateDecl =
4684 CTSD->getSpecializedTemplate()->getTemplatedDecl();
4685 RegionMap[TemplateDecl].reset(RealDecl);
4687 RegionMap[RD].reset(RealDecl);
4689 TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
4691 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
4692 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
4693 CollectCXXTemplateParams(TSpecial, DefUnit));
4697void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
4698 llvm::DICompositeType *RealDecl) {
4700 llvm::DIType *ContainingType =
nullptr;
4701 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4705 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
4712 CanQualType T = CGM.getContext().getCanonicalTagType(PBase);
4713 ContainingType = getOrCreateType(
T, getOrCreateFile(RD->
getLocation()));
4715 ContainingType = RealDecl;
4717 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4720llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
4721 StringRef Name,
uint64_t *Offset) {
4722 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4723 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
4726 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4727 *Offset, llvm::DINode::FlagZero, FieldTy);
4728 *Offset += FieldSize;
4732void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
4734 StringRef &LinkageName,
4735 llvm::DIScope *&FDContext,
4736 llvm::DINodeArray &TParamsArray,
4737 llvm::DINode::DIFlags &Flags) {
4739 bool NameIsSimplified =
false;
4740 Name = getFunctionName(FD, &NameIsSimplified);
4741 if (NameIsSimplified)
4742 Flags |= llvm::DINode::FlagNameIsSimplified;
4743 Name = getFunctionName(FD);
4746 LinkageName = CGM.getMangledName(GD);
4748 Flags |= llvm::DINode::FlagPrototyped;
4752 if (LinkageName == Name ||
4753 (CGM.getCodeGenOpts().CoverageNotesFile.empty() &&
4754 CGM.getCodeGenOpts().CoverageDataFile.empty() &&
4755 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
4756 !CGM.getCodeGenOpts().PseudoProbeForProfiling &&
4757 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4758 LinkageName = StringRef();
4762 if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
4763 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4764 CGM.getCodeGenOpts().EmitCodeView)) {
4765 if (
const NamespaceDecl *NSDecl =
4767 FDContext = getOrCreateNamespace(NSDecl);
4768 else if (
const RecordDecl *RDecl =
4770 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4771 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4774 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
4777 Flags |= llvm::DINode::FlagNoReturn;
4779 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4783void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4784 unsigned &LineNo, QualType &
T,
4785 StringRef &Name, StringRef &LinkageName,
4786 llvm::MDTuple *&TemplateParameters,
4787 llvm::DIScope *&VDContext) {
4796 llvm::APInt ConstVal(32, 1);
4797 QualType ET = CGM.getContext().getAsArrayType(
T)->getElementType();
4799 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
4806 LinkageName = CGM.getMangledName(VD);
4807 if (LinkageName == Name)
4808 LinkageName = StringRef();
4811 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4812 TemplateParameters = parameterNodes.get();
4814 TemplateParameters =
nullptr;
4820 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4821 VDContext = LexicalBlockStack.back();
4840 DC = CGM.getContext().getTranslationUnitDecl();
4842 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4843 VDContext = getContextDescriptor(
cast<Decl>(DC), Mod ? Mod : TheCU);
4846llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
4848 llvm::DINodeArray TParamsArray;
4849 StringRef Name, LinkageName;
4850 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4851 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4853 llvm::DIFile *Unit = getOrCreateFile(Loc);
4854 llvm::DIScope *DContext = Unit;
4855 unsigned Line = getLineNumber(Loc);
4856 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4861 SmallVector<QualType, 16> ArgTypes;
4862 for (
const ParmVarDecl *Parm : FD->
parameters())
4863 ArgTypes.push_back(Parm->getType());
4866 QualType FnType = CGM.getContext().getFunctionType(
4867 FD->
getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
4869 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4870 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
4871 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4875 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4876 return DBuilder.createFunction(
4877 DContext, Name, LinkageName, Unit,
Line,
4878 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4879 TParamsArray.get(), getFunctionDeclaration(FD),
nullptr,
4881 CGM.getCodeGenOpts().DebugKeyInstructions);
4884 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4885 DContext, Name, LinkageName, Unit,
Line,
4886 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4887 TParamsArray.get(), getFunctionDeclaration(FD));
4889 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4890 std::make_tuple(CanonDecl),
4891 std::make_tuple(SP));
4895llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
4896 return getFunctionFwdDeclOrStub(GD,
false);
4899llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
4900 return getFunctionFwdDeclOrStub(GD,
true);
4903llvm::DIGlobalVariable *
4904CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4906 StringRef Name, LinkageName;
4908 llvm::DIFile *Unit = getOrCreateFile(Loc);
4909 llvm::DIScope *DContext = Unit;
4910 unsigned Line = getLineNumber(Loc);
4911 llvm::MDTuple *TemplateParameters =
nullptr;
4913 collectVarDeclProps(VD, Unit,
Line,
T, Name, LinkageName, TemplateParameters,
4916 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4917 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(
T, Unit),
4919 FwdDeclReplaceMap.emplace_back(
4920 std::piecewise_construct,
4922 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4926llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
4931 if (
const auto *TD = dyn_cast<TypeDecl>(D)) {
4932 QualType Ty = CGM.getContext().getTypeDeclType(TD);
4933 return getOrCreateType(Ty, getOrCreateFile(TD->
getLocation()));
4937 if (I != DeclCache.end()) {
4939 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4940 return GVE->getVariable();
4948 if (IE != ImportedDeclCache.end()) {
4949 auto N = IE->second;
4950 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4952 return dyn_cast_or_null<llvm::DINode>(N);
4957 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4958 return getFunctionForwardDeclaration(FD);
4959 else if (
const auto *VD = dyn_cast<VarDecl>(D))
4960 return getGlobalVariableForwardDeclaration(VD);
4965llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
4966 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4969 const auto *FD = dyn_cast<FunctionDecl>(D);
4974 auto *S = getDeclContextDescriptor(D);
4977 if (MI == SPCache.end()) {
4979 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
4983 if (MI != SPCache.end()) {
4984 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4985 if (SP && !SP->isDefinition())
4989 for (
auto *NextFD : FD->
redecls()) {
4990 auto MI = SPCache.find(NextFD->getCanonicalDecl());
4991 if (MI != SPCache.end()) {
4992 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4993 if (SP && !SP->isDefinition())
5000llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
5001 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
5002 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
5003 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5006 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
5010 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
5014 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
5023 QualType QTy(
ID->getTypeForDecl(), 0);
5024 auto It = TypeCache.find(QTy.getAsOpaquePtr());
5025 if (It == TypeCache.end())
5028 llvm::DISubprogram *FD = DBuilder.createFunction(
5029 InterfaceType, getObjCMethodName(OMD), StringRef(),
5030 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
5031 DBuilder.finalizeSubprogram(FD);
5038llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
5043 if (!D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
5044 !CGM.getCodeGenOpts().EmitCodeView))
5047 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({}));
5049 if (
const auto *
Method = dyn_cast<CXXDestructorDecl>(D)) {
5052 return getOrCreateMethodTypeForDestructor(
Method, F, FnType);
5055 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(D))
5056 return getOrCreateMethodType(
Method, F);
5058 const auto *FTy = FnType->
getAs<FunctionType>();
5061 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
5063 SmallVector<llvm::Metadata *, 16> Elts;
5066 QualType ResultTy = OMethod->getReturnType();
5069 if (ResultTy == CGM.getContext().getObjCInstanceType())
5070 ResultTy = CGM.getContext().getPointerType(
5071 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
5073 Elts.push_back(getOrCreateType(ResultTy, F));
5075 QualType SelfDeclTy;
5076 if (
auto *SelfDecl = OMethod->getSelfDecl())
5077 SelfDeclTy = SelfDecl->getType();
5078 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
5081 if (!SelfDeclTy.
isNull())
5083 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
5085 Elts.push_back(DBuilder.createArtificialType(
5086 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
5088 for (
const auto *PI : OMethod->parameters())
5089 Elts.push_back(getOrCreateType(PI->getType(), F));
5091 if (OMethod->isVariadic())
5092 Elts.push_back(DBuilder.createUnspecifiedParameter());
5094 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
5095 return DBuilder.createSubroutineType(
5096 EltTypeArray, llvm::DINode::FlagZero,
5097 getDwarfCC(CC, CGM.getTarget().getTriple()));
5102 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
5103 if (FD->isVariadic()) {
5104 SmallVector<llvm::Metadata *, 16> EltTys;
5105 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
5106 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
5108 EltTys.push_back(getOrCreateType(ParamType, F));
5109 EltTys.push_back(DBuilder.createUnspecifiedParameter());
5110 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
5111 return DBuilder.createSubroutineType(
5112 EltTypeArray, llvm::DINode::FlagZero,
5113 getDwarfCC(CC, CGM.getTarget().getTriple()));
5125 CC = SrcFnTy->getCallConv();
5127 for (
const VarDecl *VD : Args)
5128 ArgTypes.push_back(VD->
getType());
5129 return CGM.getContext().getFunctionType(RetTy, ArgTypes,
5135 llvm::Function *Fn,
bool CurFuncIsThunk) {
5137 StringRef LinkageName;
5139 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5142 bool HasDecl = (D !=
nullptr);
5144 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5145 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5146 llvm::DIFile *Unit = getOrCreateFile(Loc);
5147 llvm::DIScope *FDContext = Unit;
5148 llvm::DINodeArray TParamsArray;
5149 bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
5152 LinkageName = Fn->getName();
5153 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5155 auto FI = SPCache.find(FD->getCanonicalDecl());
5156 if (FI != SPCache.end()) {
5157 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5158 if (SP && SP->isDefinition()) {
5159 LexicalBlockStack.emplace_back(SP);
5160 RegionMap[D].reset(SP);
5164 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5165 TParamsArray, Flags);
5168 KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
5169 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5170 Name = getObjCMethodName(OMD);
5171 Flags |= llvm::DINode::FlagPrototyped;
5177 if (Name != Fn->getName())
5178 LinkageName = Fn->getName();
5180 Name = Fn->getName();
5185 Flags |= llvm::DINode::FlagPrototyped;
5187 Name.consume_front(
"\01");
5191 "Unexpected DynamicInitKind !");
5195 Flags |= llvm::DINode::FlagArtificial;
5201 Flags |= llvm::DINode::FlagThunk;
5203 if (Fn->hasLocalLinkage())
5204 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
5205 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5206 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5209 llvm::DISubprogram::DISPFlags SPFlagsForDef =
5210 SPFlags | llvm::DISubprogram::SPFlagDefinition;
5212 const unsigned LineNo = getLineNumber(Loc.
isValid() ? Loc : CurLoc);
5213 unsigned ScopeLine = getLineNumber(ScopeLoc);
5214 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
5215 llvm::DISubprogram *
Decl =
nullptr;
5216 llvm::DINodeArray Annotations =
nullptr;
5219 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
5220 : getFunctionDeclaration(D);
5221 Annotations = CollectBTFDeclTagAnnotations(D);
5229 llvm::DISubprogram *SP = DBuilder.createFunction(
5230 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
5231 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
5232 Annotations,
"", KeyInstructions);
5233 Fn->setSubprogram(SP);
5242 LexicalBlockStack.emplace_back(SP);
5245 RegionMap[D].reset(SP);
5249 QualType FnType, llvm::Function *Fn) {
5251 StringRef LinkageName;
5257 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
5258 return GetName(D,
true);
5261 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5262 llvm::DIFile *Unit = getOrCreateFile(Loc);
5263 bool IsDeclForCallSite = Fn ?
true :
false;
5264 llvm::DIScope *FDContext =
5265 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
5266 llvm::DINodeArray TParamsArray;
5269 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5270 TParamsArray, Flags);
5271 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5272 Name = getObjCMethodName(OMD);
5273 Flags |= llvm::DINode::FlagPrototyped;
5275 llvm_unreachable(
"not a function or ObjC method");
5277 Name.consume_front(
"\01");
5280 Flags |= llvm::DINode::FlagArtificial;
5285 unsigned LineNo = getLineNumber(Loc);
5286 unsigned ScopeLine = 0;
5287 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5288 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5289 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5291 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
5292 llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
5294 assert(~SPFlags & llvm::DISubprogram::SPFlagDefinition);
5295 llvm::DISubprogram *SP = DBuilder.createFunction(
5296 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
5297 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations,
5303 if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
5304 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
5305 llvm::DITypeArray ParamTypes = STy->getTypeArray();
5308 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
5309 DBuilder.createParameterVariable(
5310 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
5311 llvm::DINode::FlagZero, ParamAnnotations);
5317 if (IsDeclForCallSite)
5318 Fn->setSubprogram(SP);
5322 llvm::CallBase *CI) {
5323 if (!shouldGenerateVirtualCallSite())
5329 assert(CI &&
"Invalid Call Instruction.");
5330 if (!CI->isIndirectCall())
5334 if (llvm::DISubprogram *MD = getFunctionDeclaration(FD))
5335 CI->setMetadata(llvm::LLVMContext::MD_call_target, MD);
5343 auto *
Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
5346 if (
Func->getSubprogram())
5350 if (!
Func->isDeclaration())
5372 if (
auto *SP = getFunctionDeclaration(CalleeDecl))
5373 Func->setSubprogram(SP);
5384 auto FI = SPCache.find(FD->getCanonicalDecl());
5385 llvm::DISubprogram *SP =
nullptr;
5386 if (FI != SPCache.end())
5387 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5388 if (!SP || !SP->isDefinition())
5389 SP = getFunctionStub(GD);
5390 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5391 LexicalBlockStack.emplace_back(SP);
5397 assert(CurInlinedAt &&
"unbalanced inline scope stack");
5406 if (CurLoc.isInvalid() ||
5407 (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) ||
5408 LexicalBlockStack.empty())
5411 llvm::MDNode *
Scope = LexicalBlockStack.back();
5412 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5413 CGM.getLLVMContext(), CurLocLine, CurLocColumn,
Scope, CurInlinedAt));
5417 llvm::MDNode *Back =
nullptr;
5418 if (!LexicalBlockStack.empty())
5419 Back = LexicalBlockStack.back().get();
5422 unsigned Line = getLineNumber(CurLoc);
5423 unsigned Column =
Line ? getColumnNumber(CurLoc) : 0;
5424 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
5428void CGDebugInfo::AppendAddressSpaceXDeref(
5430 std::optional<unsigned> DWARFAddressSpace =
5432 if (!DWARFAddressSpace)
5435 Expr.push_back(llvm::dwarf::DW_OP_constu);
5436 Expr.push_back(*DWARFAddressSpace);
5437 Expr.push_back(llvm::dwarf::DW_OP_swap);
5438 Expr.push_back(llvm::dwarf::DW_OP_xderef);
5447 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5448 CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
5449 LexicalBlockStack.back(), CurInlinedAt));
5451 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5455 CreateLexicalBlock(Loc);
5460 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5465 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5468 LexicalBlockStack.pop_back();
5472 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5473 unsigned RCount = FnBeginRegionCount.back();
5474 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
5477 while (LexicalBlockStack.size() != RCount) {
5480 LexicalBlockStack.pop_back();
5482 FnBeginRegionCount.pop_back();
5484 if (Fn && Fn->getSubprogram())
5485 DBuilder.finalizeSubprogram(Fn->getSubprogram());
5488CGDebugInfo::BlockByRefType
5489CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
5490 uint64_t *XOffset) {
5493 uint64_t FieldSize, FieldOffset;
5494 uint32_t FieldAlign;
5496 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5501 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
5502 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
5504 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
5505 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
5508 if (HasCopyAndDispose) {
5511 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
5513 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
5515 bool HasByrefExtendedLayout;
5518 HasByrefExtendedLayout) &&
5519 HasByrefExtendedLayout) {
5522 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
5531 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
5534 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
5537 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
5542 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
5543 FieldSize = CGM.getContext().getTypeSize(FType);
5544 FieldAlign = CGM.getContext().toBits(Align);
5546 *XOffset = FieldOffset;
5547 llvm::DIType *FieldTy = DBuilder.createMemberType(
5548 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
5549 llvm::DINode::FlagZero, WrappedTy);
5550 EltTys.push_back(FieldTy);
5551 FieldOffset += FieldSize;
5553 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
5554 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
5555 llvm::DINode::FlagZero,
nullptr, Elements),
5559llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
5560 llvm::Value *Storage,
5561 std::optional<unsigned> ArgNo,
5563 const bool UsePointerValue) {
5564 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5565 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5566 if (VD->
hasAttr<NoDebugAttr>())
5571 llvm::DIFile *Unit =
nullptr;
5572 if (!VarIsArtificial)
5576 if (VD->
hasAttr<BlocksAttr>())
5577 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5579 Ty = getOrCreateType(VD->
getType(), Unit);
5589 if (!VarIsArtificial) {
5593 SmallVector<uint64_t, 13> Expr;
5594 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5601 Flags |= llvm::DINode::FlagArtificial;
5605 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->
getType());
5606 AppendAddressSpaceXDeref(AddressSpace, Expr);
5610 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
5613 Flags |= llvm::DINode::FlagObjectPointer;
5614 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
5615 if (PVD->isExplicitObjectParameter())
5616 Flags |= llvm::DINode::FlagObjectPointer;
5624 StringRef Name = VD->
getName();
5625 if (!Name.empty()) {
5631 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5633 offset = CGM.getContext().toCharUnitsFromBits(
5636 Expr.push_back(llvm::dwarf::DW_OP_deref);
5637 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5639 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5642 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
5654 for (
const auto *Field : RD->
fields()) {
5655 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
5656 StringRef FieldName =
Field->getName();
5664 auto *D = DBuilder.createAutoVariable(
5665 Scope, FieldName, Unit,
Line, FieldTy,
5666 CGM.getCodeGenOpts().OptimizationLevel != 0,
5667 Flags | llvm::DINode::FlagArtificial, FieldAlign);
5670 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5671 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5674 Builder.GetInsertBlock());
5682 if (UsePointerValue) {
5683 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5684 "Debug info already contains DW_OP_deref.");
5685 Expr.push_back(llvm::dwarf::DW_OP_deref);
5689 llvm::DILocalVariable *D =
nullptr;
5691 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5692 D = DBuilder.createParameterVariable(
5693 Scope, Name, *ArgNo, Unit,
Line, Ty,
5694 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
5703 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
5709 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
5710 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
5711 if (DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
5712 DeclGroupRef DeclGroup = DeclStmtPtr->getDeclGroup();
5714 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
5720 if (Iter != CoroutineParameterMappings.end()) {
5721 ParmVarDecl *PD =
const_cast<ParmVarDecl *
>(Iter->first);
5722 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
5723 return DbgPair.first == PD && DbgPair.second->getScope() == Scope;
5725 if (Iter2 != ParamDbgMappings.end())
5726 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
5732 D = RemapCoroArgToLocalVar();
5735 D = DBuilder.createAutoVariable(
5736 Scope, Name, Unit,
Line, Ty,
5737 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
5740 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5741 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5742 Column, Scope, CurInlinedAt),
5743 Builder.GetInsertBlock());
5748llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
5749 llvm::Value *Storage,
5750 std::optional<unsigned> ArgNo,
5752 const bool UsePointerValue) {
5753 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5754 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5755 if (BD->
hasAttr<NoDebugAttr>())
5762 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
5763 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
5771 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->
getType());
5773 SmallVector<uint64_t, 3> Expr;
5774 AppendAddressSpaceXDeref(AddressSpace, Expr);
5779 if (UsePointerValue) {
5780 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5781 "Debug info already contains DW_OP_deref.");
5782 Expr.push_back(llvm::dwarf::DW_OP_deref);
5787 StringRef Name = BD->
getName();
5790 llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5791 Scope, Name, Unit,
Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
5792 llvm::DINode::FlagZero, Align);
5794 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(BD->
getBinding())) {
5795 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5796 const unsigned fieldIndex = FD->getFieldIndex();
5797 const clang::CXXRecordDecl *parent =
5798 (
const CXXRecordDecl *)FD->getParent();
5799 const ASTRecordLayout &layout =
5800 CGM.getContext().getASTRecordLayout(parent);
5802 if (FD->isBitField()) {
5803 const CGRecordLayout &RL =
5804 CGM.getTypes().getCGRecordLayout(FD->getParent());
5809 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5815 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5816 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5817 Expr.push_back(Info.
Offset);
5820 const uint64_t TypeSize = CGM.getContext().getTypeSize(BD->
getType());
5821 Expr.push_back(std::min((
uint64_t)Info.
Size, TypeSize));
5822 }
else if (fieldOffset != 0) {
5823 assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
5824 "Unexpected non-bitfield with non-byte-aligned offset");
5825 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5827 CGM.getContext().toCharUnitsFromBits(fieldOffset).getQuantity());
5830 }
else if (
const ArraySubscriptExpr *ASE =
5831 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5832 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5833 const uint64_t value = IL->getValue().getZExtValue();
5834 const uint64_t typeSize = CGM.getContext().getTypeSize(BD->
getType());
5837 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5838 Expr.push_back(CGM.getContext()
5839 .toCharUnitsFromBits(value * typeSize)
5846 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5847 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5848 Column, Scope, CurInlinedAt),
5849 Builder.GetInsertBlock());
5854llvm::DILocalVariable *
5857 const bool UsePointerValue) {
5858 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5860 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5862 EmitDeclare(B, Storage, std::nullopt, Builder,
5869 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5873 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5874 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5876 if (D->
hasAttr<NoDebugAttr>())
5880 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
5886 StringRef Name = D->
getName();
5892 CGM.getCodeGenOpts().OptimizationLevel != 0);
5895 DBuilder.insertLabel(L,
5896 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5897 Scope, CurInlinedAt),
5898 Builder.GetInsertBlock()->end());
5901llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5903 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5906 return DBuilder.createObjectPointerType(Ty,
true);
5911 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5912 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5913 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5915 if (Builder.GetInsertBlock() ==
nullptr)
5917 if (VD->
hasAttr<NoDebugAttr>())
5920 bool isByRef = VD->
hasAttr<BlocksAttr>();
5922 uint64_t XOffset = 0;
5923 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5926 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5928 Ty = getOrCreateType(VD->
getType(), Unit);
5932 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5934 Ty = CreateSelfType(VD->
getType(), Ty);
5937 const unsigned Line =
5941 const llvm::DataLayout &target = CGM.getDataLayout();
5948 addr.push_back(llvm::dwarf::DW_OP_deref);
5949 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5952 addr.push_back(llvm::dwarf::DW_OP_deref);
5953 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5956 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
5958 addr.push_back(llvm::dwarf::DW_OP_deref);
5959 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5961 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5967 auto *D = DBuilder.createAutoVariable(
5969 Line, Ty,
false, llvm::DINode::FlagZero, Align);
5972 auto DL = llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5973 LexicalBlockStack.back(), CurInlinedAt);
5974 auto *
Expr = DBuilder.createExpression(addr);
5976 DBuilder.insertDeclare(Storage, D,
Expr, DL, InsertPoint->getIterator());
5978 DBuilder.insertDeclare(Storage, D,
Expr, DL, Builder.GetInsertBlock());
5981llvm::DILocalVariable *
5984 bool UsePointerValue) {
5985 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5986 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
5990struct BlockLayoutChunk {
5991 uint64_t OffsetInBits;
5994bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
5995 return l.OffsetInBits < r.OffsetInBits;
5999void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
6001 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
6002 SmallVectorImpl<llvm::Metadata *> &Fields) {
6006 if (CGM.getLangOpts().OpenCL) {
6007 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
6008 BlockLayout.getElementOffsetInBits(0),
6010 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
6011 BlockLayout.getElementOffsetInBits(1),
6015 BlockLayout.getElementOffsetInBits(0),
6017 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
6018 BlockLayout.getElementOffsetInBits(1),
6022 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
6023 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
6024 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
6025 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
6026 BlockLayout.getElementOffsetInBits(3),
6028 Fields.push_back(createFieldType(
6033 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
6040 llvm::AllocaInst *Alloca,
6042 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6048 llvm::DIFile *tunit = getOrCreateFile(loc);
6049 unsigned line = getLineNumber(loc);
6050 unsigned column = getColumnNumber(loc);
6055 const llvm::StructLayout *blockLayout =
6059 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
6068 BlockLayoutChunk chunk;
6069 chunk.OffsetInBits =
6070 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
6071 chunk.Capture =
nullptr;
6072 chunks.push_back(chunk);
6076 for (
const auto &capture :
blockDecl->captures()) {
6077 const VarDecl *variable = capture.getVariable();
6084 BlockLayoutChunk chunk;
6085 chunk.OffsetInBits =
6086 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
6087 chunk.Capture = &capture;
6088 chunks.push_back(chunk);
6092 llvm::array_pod_sort(chunks.begin(), chunks.end());
6094 for (
const BlockLayoutChunk &Chunk : chunks) {
6095 uint64_t offsetInBits = Chunk.OffsetInBits;
6100 fields.push_back(createFieldType(
"this",
blockDecl->getCXXThisType(), loc,
6101 AS_public, offsetInBits, tunit, tunit));
6106 StringRef name = variable->
getName();
6108 llvm::DIType *fieldType;
6110 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
6115 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
6116 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
6117 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
6118 PtrInfo.
Width, Align, offsetInBits,
6119 llvm::DINode::FlagZero, fieldType);
6123 offsetInBits, Align, tunit, tunit);
6125 fields.push_back(fieldType);
6129 llvm::raw_svector_ostream(typeName)
6130 <<
"__block_literal_" << CGM.getUniqueBlockCount();
6132 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
6134 llvm::DIType *
type =
6135 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
6136 CGM.getContext().toBits(block.
BlockSize), 0,
6137 llvm::DINode::FlagZero,
nullptr, fieldsArray);
6138 type = DBuilder.createPointerType(
type, CGM.PointerWidthInBits);
6141 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
6145 auto *debugVar = DBuilder.createParameterVariable(
6146 scope, Name, ArgNo, tunit, line,
type,
6147 CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
6150 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
6151 llvm::DILocation::get(CGM.getLLVMContext(), line,
6152 column, scope, CurInlinedAt),
6153 Builder.GetInsertBlock());
6156llvm::DIDerivedType *
6157CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
6162 if (MI != StaticDataMemberCache.end()) {
6163 assert(MI->second &&
"Static data member declaration should still exist");
6174llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
6175 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
6176 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
6177 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6179 for (
const auto *Field : RD->
fields()) {
6180 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
6181 StringRef FieldName = Field->getName();
6184 if (FieldName.empty()) {
6185 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
6186 GVE = CollectAnonRecordDecls(RT->getDecl()->getDefinitionOrSelf(), Unit,
6187 LineNo, LinkageName, Var, DContext);
6191 GVE = DBuilder.createGlobalVariableExpression(
6192 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
6193 Var->hasLocalLinkage());
6194 Var->addDebugInfo(GVE);
6206 const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6211 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
6222 struct ReferencesAnonymous
6224 bool RefAnon =
false;
6225 bool VisitRecordType(RecordType *RT) {
6233 ReferencesAnonymous RT;
6246struct ReconstitutableType :
public RecursiveASTVisitor<ReconstitutableType> {
6247 bool Reconstitutable =
true;
6248 bool VisitVectorType(VectorType *FT) {
6249 Reconstitutable =
false;
6252 bool VisitAtomicType(AtomicType *FT) {
6253 Reconstitutable =
false;
6256 bool TraverseEnumType(EnumType *ET,
bool =
false) {
6259 const EnumDecl *ED = ET->getDecl();
6261 Reconstitutable =
false;
6265 Reconstitutable =
false;
6270 bool VisitFunctionProtoType(FunctionProtoType *FT) {
6274 return Reconstitutable;
6276 bool VisitRecordType(RecordType *RT,
bool =
false) {
6278 Reconstitutable =
false;
6288 ReconstitutableType
T;
6290 return T.Reconstitutable;
6293bool CGDebugInfo::HasReconstitutableArgs(
6294 ArrayRef<TemplateArgument> Args)
const {
6295 return llvm::all_of(Args, [&](
const TemplateArgument &TA) {
6335 llvm_unreachable(
"Other, unresolved, template arguments should "
6336 "not be seen here");
6341std::string CGDebugInfo::GetName(
const Decl *D,
bool Qualified,
6342 bool *NameIsSimplified)
const {
6344 llvm::raw_string_ostream
OS(Name);
6345 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
6348 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
6349 CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
6351 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6352 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
6354 std::optional<TemplateArgs> Args;
6356 bool IsOperatorOverload =
false;
6357 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
6358 Args = GetTemplateArgs(RD);
6359 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
6360 Args = GetTemplateArgs(FD);
6362 IsOperatorOverload |=
6365 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
6366 Args = GetTemplateArgs(VD);
6390 bool Reconstitutable =
6391 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
6393 PrintingPolicy PP = getPrintingPolicy();
6395 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
6400 if (NameIsSimplified)
6401 *NameIsSimplified =
true;
6402 bool Mangled = TemplateNamesKind ==
6403 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
6409 std::string EncodedOriginalName;
6410 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
6415 printTemplateArgumentList(OS, Args->Args, PP);
6416 printTemplateArgumentList(EncodedOriginalNameOS, Args->Args, PP);
6418 std::string CanonicalOriginalName;
6419 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
6421 assert(EncodedOriginalName == CanonicalOriginalName);
6430 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6431 if (D->
hasAttr<NoDebugAttr>())
6434 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
6435 return GetName(D,
true);
6441 if (Cached != DeclCache.end())
6442 return Var->addDebugInfo(
6446 llvm::DIFile *Unit =
nullptr;
6447 llvm::DIScope *DContext =
nullptr;
6449 StringRef DeclName, LinkageName;
6451 llvm::MDTuple *TemplateParameters =
nullptr;
6452 collectVarDeclProps(D, Unit, LineNo,
T, DeclName, LinkageName,
6453 TemplateParameters, DContext);
6457 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6462 if (
T->isUnionType() && DeclName.empty()) {
6463 const auto *RD =
T->castAsRecordDecl();
6465 "unnamed non-anonymous struct or union?");
6466 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
6471 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->
getType());
6472 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
6473 if (D->
hasAttr<CUDASharedAttr>())
6476 else if (D->
hasAttr<CUDAConstantAttr>())
6480 AppendAddressSpaceXDeref(AddressSpace,
Expr);
6482 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
6483 GVE = DBuilder.createGlobalVariableExpression(
6484 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(
T, Unit),
6485 Var->hasLocalLinkage(),
true,
6486 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
6487 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
6488 Align, Annotations);
6489 Var->addDebugInfo(GVE);
6495 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6496 if (VD->
hasAttr<NoDebugAttr>())
6498 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
6499 return GetName(VD,
true);
6504 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
6505 StringRef Name = VD->
getName();
6506 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
6508 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
6510 if (CGM.getCodeGenOpts().EmitCodeView) {
6521 CanQualType T = CGM.getContext().getCanonicalTagType(ED);
6522 [[maybe_unused]] llvm::DIType *EDTy = getOrCreateType(
T, Unit);
6523 assert(EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
6533 auto *VarD = dyn_cast<VarDecl>(VD);
6534 if (VarD && VarD->isStaticDataMember()) {
6536 getDeclContextDescriptor(VarD);
6541 RetainedTypes.push_back(
6542 CGM.getContext().getCanonicalTagType(RD).getAsOpaquePtr());
6546 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
6548 auto &GV = DeclCache[VD];
6552 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
6553 llvm::MDTuple *TemplateParameters =
nullptr;
6557 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
6558 TemplateParameters = parameterNodes.get();
6561 GV.reset(DBuilder.createGlobalVariableExpression(
6562 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
6563 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
6564 TemplateParameters, Align));
6569 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6570 if (D->
hasAttr<NoDebugAttr>())
6574 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
6575 StringRef Name = D->
getName();
6576 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
6578 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6579 llvm::DIGlobalVariableExpression *GVE =
6580 DBuilder.createGlobalVariableExpression(
6581 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
6582 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
6583 Var->addDebugInfo(GVE);
6590 if (CGM.getCodeGenOpts().getDebugInfo() <=
6591 llvm::codegenoptions::DebugLineTablesOnly)
6594 llvm::DILocation *DIL =
Value->getDebugLoc().get();
6598 llvm::DIFile *Unit = DIL->getFile();
6599 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
6604 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
6605 llvm::Value *Var = Load->getPointerOperand();
6610 auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
6611 return DbgDeclare->getVariable()->getType() ==
Type;
6613 if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6617 llvm::DILocalVariable *D =
6618 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
6619 Type,
false, llvm::DINode::FlagArtificial);
6621 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
6622 DBuilder.insertDbgValue(
Value, D, DBuilder.createExpression(), DIL,
6632 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6636 if (D->
hasAttr<NoDebugAttr>())
6639 auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
6654 if (!(DI = getDeclarationOrDefinition(
6655 AliaseeDecl.getCanonicalDecl().getDecl())))
6658 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6661 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
6662 DContext, DI, getOrCreateFile(Loc), getLineNumber(Loc), D->getName());
6676 llvm::DIFile *
File = getOrCreateFile(Loc);
6677 llvm::DIGlobalVariableExpression *Debug =
6678 DBuilder.createGlobalVariableExpression(
6679 nullptr, StringRef(), StringRef(),
File, getLineNumber(Loc),
6681 GV->addDebugInfo(Debug);
6684llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
6685 if (!LexicalBlockStack.empty())
6686 return LexicalBlockStack.back();
6687 llvm::DIScope *Mod = getParentModuleOrNull(D);
6688 return getContextDescriptor(D, Mod ? Mod : TheCU);
6692 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6696 CGM.getCodeGenOpts().DebugExplicitImport) {
6700 DBuilder.createImportedModule(
6702 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
6707 if (llvm::DINode *
Target =
6710 DBuilder.createImportedDeclaration(
6712 getOrCreateFile(Loc), getLineNumber(Loc));
6717 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6720 "We shouldn't be codegening an invalid UsingDecl containing no decls");
6722 for (
const auto *USD : UD.
shadows()) {
6727 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
6728 if (
const auto *AT = FD->getType()
6731 if (AT->getDeducedType().isNull())
6742 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6745 "We shouldn't be codegening an invalid UsingEnumDecl"
6746 " containing no decls");
6748 for (
const auto *USD : UD.
shadows())
6753 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
6755 if (
Module *M = ID.getImportedModule()) {
6757 auto Loc = ID.getLocation();
6758 DBuilder.createImportedDeclaration(
6759 getCurrentContextDescriptor(
cast<Decl>(ID.getDeclContext())),
6760 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
6761 getLineNumber(Loc));
6765llvm::DIImportedEntity *
6767 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6769 auto &VH = NamespaceAliasCache[&NA];
6772 llvm::DIImportedEntity *R;
6774 if (
const auto *Underlying =
6777 R = DBuilder.createImportedDeclaration(
6780 getLineNumber(Loc), NA.
getName());
6782 R = DBuilder.createImportedDeclaration(
6785 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
6791CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6795 auto I = NamespaceCache.find(NSDecl);
6796 if (I != NamespaceCache.end())
6799 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6801 llvm::DINamespace *NS =
6802 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6803 NamespaceCache[NSDecl].reset(NS);
6808 assert(TheCU &&
"no main compile unit");
6809 TheCU->setDWOId(Signature);
6815 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6816 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
6818 ? CreateTypeDefinition(E.Type, E.Unit)
6820 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
6824 for (
const auto &P : ObjCMethodCache) {
6825 if (P.second.empty())
6828 QualType QTy(P.first->getTypeForDecl(), 0);
6830 assert(It != TypeCache.end());
6832 llvm::DICompositeType *InterfaceDecl =
6835 auto CurElts = InterfaceDecl->getElements();
6839 for (
auto &SubprogramDirect : P.second)
6840 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6841 EltTys.push_back(SubprogramDirect.getPointer());
6843 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6844 DBuilder.replaceArrays(InterfaceDecl, Elements);
6847 for (
const auto &P : ReplaceMap) {
6850 assert(Ty->isForwardDecl());
6852 auto It = TypeCache.find(P.first);
6853 assert(It != TypeCache.end());
6856 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6860 for (
const auto &P : FwdDeclReplaceMap) {
6863 llvm::Metadata *Repl;
6865 auto It = DeclCache.find(P.first);
6869 if (It == DeclCache.end())
6874 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6875 Repl = GVE->getVariable();
6881 for (
auto &RT : RetainedTypes)
6882 if (
auto MD = TypeCache[RT])
6885 DBuilder.finalize();
6890 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
6891 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6892 DBuilder.retainType(DieTy);
6896 if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
6897 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6898 DBuilder.retainType(DieTy);
6902 if (LexicalBlockStack.empty())
6903 return llvm::DebugLoc();
6905 llvm::MDNode *
Scope = LexicalBlockStack.back();
6906 return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
6907 getColumnNumber(Loc),
Scope);
6913 if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
6914 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6915 DebugKind == llvm::codegenoptions::LocTrackingOnly ||
6916 !CGM.getCodeGenOpts().DebugCallSiteInfo)
6917 return llvm::DINode::FlagZero;
6922 bool SupportsDWARFv4Ext =
6923 CGM.getCodeGenOpts().DwarfVersion == 4 &&
6924 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6925 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6927 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
6928 return llvm::DINode::FlagZero;
6930 return llvm::DINode::FlagAllCallsDescribed;
6941 return DBuilder.createConstantValueExpression(
6942 Val.
getFloat().bitcastToAPInt().getZExtValue());
6947 llvm::APSInt
const &ValInt = Val.
getInt();
6948 std::optional<uint64_t> ValIntOpt;
6949 if (ValInt.isUnsigned())
6950 ValIntOpt = ValInt.tryZExtValue();
6951 else if (
auto tmp = ValInt.trySExtValue())
6954 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6957 return DBuilder.createConstantValueExpression(ValIntOpt.value());
6962CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &
CGF,
6964 : RunCleanupsScope(
CGF), Range(Range), ParentScope(
CGF.CurLexicalScope) {
6965 CGF.CurLexicalScope =
this;
6967 DI->EmitLexicalBlockStart(
CGF.Builder, Range.getBegin());
6972 DI->EmitLexicalBlockEnd(
CGF.Builder, Range.getEnd());
6985#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
6987 Label = "__ubsan_check_" #Name; \
6991#undef SANITIZER_CHECK
7002#define SANITIZER(NAME, ID) \
7003 case SanitizerKind::SO_##ID: \
7004 Label = "__ubsan_check_" NAME; \
7006#include "clang/Basic/Sanitizers.def"
7008 llvm_unreachable(
"unexpected sanitizer kind");
7013 for (
unsigned int i = 0; i < Label.length(); i++)
7014 if (!std::isalpha(Label[i]))
7023 llvm::DILocation *CheckDebugLoc =
Builder.getCurrentDebugLocation();
7025 if (!DI || !CheckDebugLoc)
7026 return CheckDebugLoc;
7027 const auto &AnnotateDebugInfo =
7028 CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo;
7029 if (AnnotateDebugInfo.empty())
7030 return CheckDebugLoc;
7033 if (Ordinals.size() == 1)
7038 if (any_of(Ordinals, [&](
auto Ord) {
return AnnotateDebugInfo.has(Ord); })) {
7042 llvm::DIFile *
File = llvm::DIFile::get(
CGM.getLLVMContext(),
7043 "ubsan_interface.h",
7045 return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label,
File);
7048 return CheckDebugLoc;
7056 assert(!CGF->IsSanitizerScope);
7057 CGF->IsSanitizerScope =
true;
7061 assert(CGF->IsSanitizerScope);
7062 CGF->IsSanitizerScope =
false;
Defines the clang::ASTContext interface.
static bool IsReconstitutableType(QualType QT)
static void stripUnusedQualifiers(Qualifiers &Q)
static std::string SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal)
static llvm::Constant * buildConstantDataArrayFromElements(llvm::LLVMContext &Ctx, const APValue &Arr)
Build an llvm::ConstantDataArray from the initialized elements of an APValue array,...
static unsigned getDwarfCC(CallingConv CC, const llvm::Triple &T)
static std::string SanitizerHandlerToCheckLabel(SanitizerHandler Handler)
static bool IsObjCSynthesizedPropertyExplicitParameter(VarDecl const *VD)
Returns true if the specified variable VD is an explicit parameter of a synthesized Objective-C prope...
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 void completeStandardLayoutUnionType(CGDebugInfo &DebugInfo, QualType QT)
static llvm::DINode::DIFlags getRefFlags(const FunctionProtoType *Func)
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C)
static SourceLocation getMacroDebugLoc(const CodeGenModule &CGM, SourceLocation Loc)
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 bool hasCXXMangling(llvm::dwarf::SourceLanguage Lang, bool IsTagDecl)
static uint32_t getDeclAlignIfRequired(const Decl *D, const ASTContext &Ctx)
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, CXXRecordDecl::method_iterator End)
static auto getEnumInfo(CodeGenModule &CGM, llvm::DICompileUnit *TheCU, const EnumType *Ty)
static bool canUseCtorHoming(const CXXRecordDecl *RD)
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Getter)
static llvm::Constant * tryEmitConstexprArrayAsConstant(CodeGenModule &CGM, const VarDecl *Var, const APValue *Value)
Try to create an llvm::Constant for a constexpr array of integer elements.
static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD)
Return true if the class or any of its methods are marked dllimport.
static llvm::DISourceLanguageName GetDISourceLanguageName(const CodeGenModule &CGM)
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 void completeStandardLayoutUnionMembers(CGDebugInfo &DebugInfo, const CXXRecordDecl *RD)
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 bool ReferencesAnonymousEntity(ArrayRef< TemplateArgument > Args)
static llvm::dwarf::SourceLanguage GetSourceLanguage(const CodeGenModule &CGM)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
#define CC_VLS_CASE(ABI_VLEN)
Defines the LambdaCapture class.
constexpr llvm::StringRef ClangTrapPrefix
static StringRef getTriple(const Command &Job)
#define LIST_SANITIZER_CHECKS
static const NamedDecl * getDefinition(const Decl *D)
Defines the SourceManager interface.
Defines version macros and version-related utility functions for Clang.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
bool hasArrayFiller() const
APValue & getArrayInitializedElt(unsigned I)
unsigned getArrayInitializedElts() const
APValue & getArrayFiller()
unsigned getArraySize() const
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.
SourceManager & getSourceManager()
const ConstantArrayType * getAsConstantArrayType(QualType T) const
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
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.
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.
const clang::PrintingPolicy & getPrintingPolicy() const
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
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.
CanQualType getCanonicalTagType(const TagDecl *TD) const
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
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
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.
unsigned getNumBits() const
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
StringRef getName(const PrintingPolicy &Policy) const
Represents a base class of a C++ class.
Represents a C++ constructor within a class.
Represents a static or instance method of a struct/union/class.
QualType getThisType() const
Return the type of the this pointer.
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 isStandardLayout() const
Determine whether this class is standard-layout per C++ [class]p7.
llvm::iterator_range< base_class_const_iterator > base_class_const_range
specific_decl_iterator< CXXMethodDecl > method_iterator
Iterator access to method members.
bool isLambda() const
Determine whether this class describes a lambda function object.
bool needsImplicitDefaultConstructor() const
Determine if we need to declare a default constructor for this class.
capture_const_iterator captures_end() const
method_range methods() const
bool defaultedDefaultConstructorIsConstexpr() const
Determine whether a defaulted default constructor for this class would be constexpr.
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
const LambdaCapture * capture_const_iterator
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
CXXRecordDecl * getDefinitionOrSelf() const
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
This is an opaque type for sizes expressed in character units.
bool isPositive() const
Test whether the quantity is greater than zero.
bool isZero() const
Test whether the quantity equals zero.
CharUnits alignTo(CharUnits Align) const
Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is a multiple...
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
A scoped helper to set the current debug location to the specified location or preferred location of ...
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
@ RAA_Indirect
Pass it as a pointer to temporary memory.
MangleContext & getMangleContext()
Gets the mangle context.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
Add KeyInstruction and an optional Backup instruction to the current atom group, created using ApplyA...
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 completeFunction()
Reset internal state.
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 completeUnusedClass(const CXXRecordDecl &D)
llvm::DenseMap< const llvm::DIFile *, OptionalFileEntryRef > getDIFileSources() const
Return the source file each DIFile was created for, or std::nullopt for a DIFile shared by several fi...
void setInlinedAt(llvm::DILocation *InlinedAt)
Update the current inline scope.
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 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.
llvm::DINode::DIFlags getCallSiteRelatedAttrs() const
Return flags which enable debug info emission for call sites, provided that it is supported and enabl...
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.
void recordDeclarationLexicalScope(const Decl &D)
Map AST declaration to its lexical block scope if available.
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 emitVTableSymbol(llvm::GlobalVariable *VTable, const CXXRecordDecl *RD)
Emit symbol for debugger that holds the pointer to the vtable.
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 addInstToSpecificSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup, uint64_t Atom)
Add KeyInstruction and an optional Backup instruction to the atom group Atom.
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.
std::pair< llvm::DIType *, unsigned > getOrCreatePreserveAccessInfo(QualType Ty, const FieldDecl *Field)
Return the complete record type and field index for preserve-access intrinsics.
void completeClassData(const RecordDecl *RD)
void EmitFuncDeclForCallSite(llvm::CallBase *CallOrInvoke, QualType CalleeType, GlobalDecl CalleeGlobalDecl)
Emit debug info for an extern function being called.
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 directive...
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::DIScope * getDeclarationLexicalScope(const Decl *D)
Get lexical scope of AST declaration.
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...
void addCallTargetIfVirtual(const FunctionDecl *FD, llvm::CallBase *CI)
Add call target information.
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.
llvm::DILocation * getInlinedAt() const
llvm::DILocation * CreateSyntheticInlineAt(llvm::DebugLoc ParentLocation, llvm::DISubprogram *SynthSubprogram)
Create a debug location from Location that adds an artificial inline frame where the frame name is Fu...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
~LexicalScope()
Exit this cleanup scope, emitting any accumulated cleanups.
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CGDebugInfo * getDebugInfo()
llvm::DILocation * SanitizerAnnotateDebugInfo(ArrayRef< SanitizerKind::SanitizerOrdinal > Ordinals, SanitizerHandler Handler)
Returns debug info, with additional annotation if CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[Ordi...
This class organizes the cross-function state that is used while generating LLVM code.
const LangOptions & getLangOpts() const
const TargetInfo & getTarget() const
CGCXXABI & getCXXABI() const
ASTContext & getContext() const
const CodeGenOptions & getCodeGenOpts() const
llvm::LLVMContext & getLLVMContext()
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
SanitizerDebugLocation(CodeGenFunction *CGF, ArrayRef< SanitizerKind::SanitizerOrdinal > Ordinals, SanitizerHandler Handler)
~SanitizerDebugLocation()
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
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.
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...
bool isInvalidDecl() const
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.
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
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.
bool isComplete() const
Returns true if this can be considered a complete type.
EnumDecl * getDefinitionOrSelf() 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...
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
Represents a function declaration or definition.
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.
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.
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
FunctionDecl * getDefinition()
Get the definition for this declaration.
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
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Represents the declaration of a label.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
clang::ObjCRuntime ObjCRuntime
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
std::optional< uint32_t > getCPlusPlusLangStd() const
Returns the most applicable C++ standard-compliant language version code.
std::optional< uint32_t > getCLangStd() const
Returns the most applicable C standard-compliant language version code.
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
QualType getElementType() const
Returns type of the elements being stored in the matrix.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
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.
NamespaceBaseDecl * 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.
ObjCImplementationDecl * getImplementation() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
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()
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Represents one property declaration in an Objective-C interface.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Represents a parameter to a function.
QualType getElementType() const
bool isIsaPointer() const
bool authenticatesNullValues() const
bool isAddressDiscriminated() const
unsigned getExtraDiscriminator() const
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.
unsigned getLine() const
Return the presumed line number 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
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()
PointerAuthQualifier getPointerAuth() const
Represents a struct/union/class.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
specific_decl_iterator< FieldDecl > field_iterator
RecordDecl * getDefinitionOrSelf() const
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
field_iterator field_begin() const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
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.
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.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
StringRef getBufferData(FileID FID, bool *Invalid=nullptr) const
Return a StringRef to the source buffer data for the specified FileID.
FileID getMainFileID() const
Returns the FileID of the main source file.
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID.
SourceLocation getFileLoc(SourceLocation Loc, unsigned MaxDepth=std::numeric_limits< unsigned >::max()) const
Given Loc, if it is a macro location return the expansion location or the spelling location,...
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
const SrcMgr::SLocEntry & getSLocEntry(FileID FID, bool *Invalid=nullptr) const
A trivial tuple used to represent a source range.
bool hasLineDirectives() const
Return true if this FileID has #line directives in it.
const FileInfo & getFile() const
StringLiteral - This represents a string literal expression, e.g.
SourceLocation getStrTokenLoc(unsigned TokNum) const
Get one of the string literal token.
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 * getDefinitionOrSelf() const
virtual std::optional< unsigned > getDWARFAddressSpace(unsigned AddressSpace) const
uint64_t getPointerAlign(LangAS AddrSpace) const
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(bool IgnoreDeduced=false) const
Retrieve the underlying template declaration that this template name refers to, if known.
ArrayRef< NamedDecl * > asArray()
The base class of the type hierarchy.
bool isPackedVectorBoolType(const ASTContext &ctx) const
bool isIncompleteArrayType() const
RecordDecl * getAsRecordDecl() const
Retrieves the RecordDecl this type refers to.
CanQualType getCanonicalTypeUnqualified() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isMemberDataPointerType() const
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
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
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.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
unsigned getNumElements() const
QualType getElementType() const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Default
Set to the current date and time.
@ Result
The result type of a method or function.
const FunctionProtoType * T
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Deleting
Deleting dtor.
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
U cast(CodeGen::Address addr)
@ 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,...
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t int64_t
__builtin_elementwise_add_sat __builtin_elementwise_sub_sat uint32_t uint64_t __builtin_riscv_ssha_i32 __builtin_riscv_sshl_u32 uint64_t
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, not including padding.
unsigned StorageSize
The storage size in bits which should be used when accessing this bitfield.
unsigned IsSigned
Whether the bit-field is signed.
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 PrettyEnums
Whether to print enumerators with a matching enumerator name or via cast.
unsigned SplitTemplateClosers
Whether nested templates must be closed like 'a<b<c> >' rather than 'a<b<c>>'.
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.
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.