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();
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 CooperativeMatrixType *Ty,
4027 llvm::DIFile *Unit) {
4031 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
4036 llvm::SmallVector<llvm::Metadata *, 2> Subscripts;
4037 auto *ColumnCountNode =
4038 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4039 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumColumns()));
4040 auto *RowCountNode =
4041 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4042 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumRows()));
4043 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4044 ColumnCountNode ,
nullptr ,
nullptr ,
4046 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4047 RowCountNode ,
nullptr ,
nullptr ,
4049 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
4050 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
4053llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
4058 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
4073 Size = CGM.getContext().getTypeSize(Ty);
4080 SmallVector<llvm::Metadata *, 8> Subscripts;
4081 QualType EltTy(Ty, 0);
4082 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
4091 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
4092 Count = CAT->getZExtSize();
4093 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
4094 if (Expr *Size = VAT->getSizeExpr()) {
4096 if (
Size->EvaluateAsInt(
Result, CGM.getContext()))
4097 Count =
Result.Val.getInt().getExtValue();
4101 auto SizeNode = SizeExprCache.find(EltTy);
4102 if (SizeNode != SizeExprCache.end())
4103 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4104 SizeNode->getSecond() ,
nullptr ,
4105 nullptr ,
nullptr ));
4108 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
4109 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count));
4110 Subscripts.push_back(DBuilder.getOrCreateSubrange(
4111 CountNode ,
nullptr ,
nullptr ,
4117 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
4119 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
4123llvm::DIType *CGDebugInfo::CreateType(
const LValueReferenceType *Ty,
4124 llvm::DIFile *Unit) {
4125 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
4129llvm::DIType *CGDebugInfo::CreateType(
const RValueReferenceType *Ty,
4130 llvm::DIFile *Unit) {
4131 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
4133 if (CGM.getCodeGenOpts().DebugStrictDwarf &&
4134 CGM.getCodeGenOpts().DwarfVersion < 4)
4135 Tag = llvm::dwarf::DW_TAG_reference_type;
4137 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
4140llvm::DIType *CGDebugInfo::CreateType(
const MemberPointerType *Ty,
4142 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4146 Size = CGM.getContext().getTypeSize(Ty);
4149 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
4152 Flags |= llvm::DINode::FlagSingleInheritance;
4155 Flags |= llvm::DINode::FlagMultipleInheritance;
4158 Flags |= llvm::DINode::FlagVirtualInheritance;
4168 llvm::DIType *ClassType = getOrCreateType(T, U);
4170 return DBuilder.createMemberPointerType(
4174 const FunctionProtoType *FPT =
4176 return DBuilder.createMemberPointerType(
4177 getOrCreateInstanceMethodType(
4180 ClassType, Size, 0, Flags);
4183llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
4185 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
4188llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
4192llvm::DIType *CGDebugInfo::CreateType(
const HLSLAttributedResourceType *Ty,
4194 return getOrCreateType(Ty->getWrappedType(), U);
4197llvm::DIType *CGDebugInfo::CreateType(
const HLSLInlineSpirvType *Ty,
4204 const EnumType *Ty) {
4216llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
4219 bool isImportedFromModule =
4220 DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
4224 if (isImportedFromModule || !ED->getDefinition()) {
4232 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4233 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
4234 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
4236 unsigned Line = getLineNumber(ED->getLocation());
4237 StringRef EDName = ED->getName();
4238 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
4239 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
4240 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
4242 ReplaceMap.emplace_back(
4243 std::piecewise_construct, std::make_tuple(Ty),
4244 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
4248 return CreateTypeDefinition(Ty);
4251llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
4254 SmallVector<llvm::Metadata *, 16> Enumerators;
4255 ED = ED->getDefinition();
4256 assert(ED &&
"An enumeration definition is required");
4257 for (
const auto *
Enum : ED->enumerators()) {
4258 Enumerators.push_back(
4259 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
4262 std::optional<EnumExtensibilityAttr::Kind> EnumKind;
4263 if (
auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
4264 EnumKind = Attr->getExtensibility();
4267 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
4269 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4270 unsigned Line = getLineNumber(ED->getLocation());
4272 llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
4273 return DBuilder.createEnumerationType(
4274 EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
4275 0, Identifier, ED->isScoped(), EnumKind);
4280 StringRef Name, StringRef
Value) {
4281 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4282 return DBuilder.createMacro(Parent,
Line, MType, Name,
Value);
4288 llvm::DIFile *FName = getOrCreateFile(FileLoc);
4289 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4290 return DBuilder.createTempMacroFile(Parent,
Line, FName);
4295 llvm::DISubprogram *SynthSubprogram) {
4296 return llvm::DILocation::get(CGM.getLLVMContext(), 0, 0,
4297 SynthSubprogram, ParentLocation);
4302 StringRef SynthFuncName,
4303 llvm::DIFile *SynthFile) {
4304 llvm::DISubprogram *SP = createInlinedSubprogram(SynthFuncName, SynthFile);
4309 llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) {
4315 FuncName += Category;
4317 FuncName += FailureMsg;
4320 TrapLocation->getFile());
4326 Qualifiers InnerQuals = T.getLocalQualifiers();
4330 Quals += InnerQuals;
4332 switch (T->getTypeClass()) {
4334 return C.getQualifiedType(T.getTypePtr(), Quals);
4337 case Type::InjectedClassName:
4338 return C.getQualifiedType(T->getCanonicalTypeUnqualified().getTypePtr(),
4340 case Type::TemplateSpecialization: {
4342 if (Spec->isTypeAlias())
4343 return C.getQualifiedType(T.getTypePtr(), Quals);
4344 T = Spec->desugar();
4347 case Type::TypeOfExpr:
4353 case Type::Decltype:
4356 case Type::UnaryTransform:
4359 case Type::Attributed:
4362 case Type::BTFTagAttributed:
4365 case Type::CountAttributed:
4374 case Type::MacroQualified:
4377 case Type::SubstTemplateTypeParm:
4381 case Type::DeducedTemplateSpecialization: {
4383 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
4387 case Type::PackIndexing: {
4391 case Type::Adjusted:
4398 assert(T != LastT &&
"Type unwrapping failed to unwrap!");
4403llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
4406 if (It != TypeCache.end()) {
4408 if (llvm::Metadata *
V = It->second)
4421 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
4428 RetainedTypes.push_back(
4429 CGM.getContext().getCanonicalTagType(&D).getAsOpaquePtr());
4432llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
4436 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
4438 llvm::raw_string_ostream OS(Name);
4439 Ty.
print(OS, getPrintingPolicy());
4446 if (
auto *T = getTypeOrNull(Ty))
4449 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
4450 void *TyPtr = Ty.getAsOpaquePtr();
4453 TypeCache[TyPtr].reset(Res);
4458llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
4466 auto Info = Reader->getSourceDescriptor(Idx);
4468 return getOrCreateModuleRef(*Info,
true);
4469 }
else if (ClangModuleMap) {
4482 auto Info = ASTSourceDescriptor(*M);
4483 return getOrCreateModuleRef(Info,
false);
4486 return getOrCreateModuleRef(PCHDescriptor,
false);
4493llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
4496 return CreateQualifiedType(Ty, Unit);
4500#define TYPE(Class, Base)
4501#define ABSTRACT_TYPE(Class, Base)
4502#define NON_CANONICAL_TYPE(Class, Base)
4503#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4504#include "clang/AST/TypeNodes.inc"
4505 llvm_unreachable(
"Dependent types cannot show up in debug information");
4507 case Type::ExtVector:
4510 case Type::ConstantMatrix:
4512 case Type::CooperativeMatrix:
4514 case Type::ObjCObjectPointer:
4516 case Type::ObjCObject:
4518 case Type::ObjCTypeParam:
4520 case Type::ObjCInterface:
4528 case Type::BlockPointer:
4536 case Type::FunctionProto:
4537 case Type::FunctionNoProto:
4539 case Type::ConstantArray:
4540 case Type::VariableArray:
4541 case Type::IncompleteArray:
4542 case Type::ArrayParameter:
4545 case Type::LValueReference:
4547 case Type::RValueReference:
4550 case Type::MemberPointer:
4558 case Type::OverflowBehavior:
4563 case Type::TemplateSpecialization:
4565 case Type::HLSLAttributedResource:
4567 case Type::HLSLInlineSpirv:
4569 case Type::PredefinedSugar:
4571 case Type::CountAttributed:
4572 case Type::LateParsedAttr:
4574 case Type::Attributed:
4575 case Type::BTFTagAttributed:
4576 case Type::Adjusted:
4578 case Type::DeducedTemplateSpecialization:
4581 case Type::MacroQualified:
4582 case Type::SubstTemplateTypeParm:
4583 case Type::TypeOfExpr:
4585 case Type::Decltype:
4586 case Type::PackIndexing:
4587 case Type::UnaryTransform:
4591 llvm_unreachable(
"type should have been unwrapped!");
4594llvm::DICompositeType *
4595CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
4596 QualType QTy(Ty, 0);
4598 auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
4603 if (T && !T->isForwardDecl())
4607 llvm::DICompositeType *Res = CreateLimitedType(Ty);
4612 DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
4615 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
4620llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
4622 bool NameIsSimplified =
false;
4625 StringRef RDName = getClassName(RD, &NameIsSimplified);
4627 llvm::DIFile *DefUnit =
nullptr;
4630 DefUnit = getOrCreateFile(Loc);
4631 Line = getLineNumber(Loc);
4638 auto *T = cast_or_null<llvm::DICompositeType>(
4639 getTypeOrNull(CGM.getContext().getCanonicalTagType(RD)));
4647 return getOrCreateRecordFwdDecl(Ty, RDContext);
4660 auto Flags = llvm::DINode::FlagZero;
4661 if (NameIsSimplified)
4662 Flags |= llvm::DINode::FlagNameIsSimplified;
4663 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4665 Flags |= llvm::DINode::FlagTypePassByReference;
4667 Flags |= llvm::DINode::FlagTypePassByValue;
4670 if (!CXXRD->isTrivial())
4671 Flags |= llvm::DINode::FlagNonTrivial;
4674 if (CXXRD->isAnonymousStructOrUnion())
4675 Flags |= llvm::DINode::FlagExportSymbols;
4678 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
4681 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4682 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
4684 Flags, Identifier, Annotations);
4688 switch (RealDecl->getTag()) {
4690 llvm_unreachable(
"invalid composite type tag");
4692 case llvm::dwarf::DW_TAG_array_type:
4693 case llvm::dwarf::DW_TAG_enumeration_type:
4698 if (Identifier.empty())
4702 case llvm::dwarf::DW_TAG_structure_type:
4703 case llvm::dwarf::DW_TAG_union_type:
4704 case llvm::dwarf::DW_TAG_class_type:
4707 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
4711 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
4712 CXXRecordDecl *TemplateDecl =
4713 CTSD->getSpecializedTemplate()->getTemplatedDecl();
4714 RegionMap[TemplateDecl].reset(RealDecl);
4716 RegionMap[RD].reset(RealDecl);
4718 TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
4720 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
4721 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
4722 CollectCXXTemplateParams(TSpecial, DefUnit));
4726void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
4727 llvm::DICompositeType *RealDecl) {
4729 llvm::DIType *ContainingType =
nullptr;
4730 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4734 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
4741 CanQualType T = CGM.getContext().getCanonicalTagType(PBase);
4742 ContainingType = getOrCreateType(T, getOrCreateFile(RD->
getLocation()));
4744 ContainingType = RealDecl;
4746 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4749llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
4750 StringRef Name,
uint64_t *Offset) {
4751 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4752 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
4755 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4756 *Offset, llvm::DINode::FlagZero, FieldTy);
4757 *Offset += FieldSize;
4761void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
4763 StringRef &LinkageName,
4764 llvm::DIScope *&FDContext,
4765 llvm::DINodeArray &TParamsArray,
4766 llvm::DINode::DIFlags &Flags) {
4768 bool NameIsSimplified =
false;
4769 Name = getFunctionName(FD, &NameIsSimplified);
4770 if (NameIsSimplified)
4771 Flags |= llvm::DINode::FlagNameIsSimplified;
4772 Name = getFunctionName(FD);
4775 LinkageName = CGM.getMangledName(GD);
4777 Flags |= llvm::DINode::FlagPrototyped;
4781 if (LinkageName == Name ||
4782 (CGM.getCodeGenOpts().CoverageNotesFile.empty() &&
4783 CGM.getCodeGenOpts().CoverageDataFile.empty() &&
4784 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
4785 !CGM.getCodeGenOpts().PseudoProbeForProfiling &&
4786 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4787 LinkageName = StringRef();
4791 if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
4792 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4793 CGM.getCodeGenOpts().EmitCodeView)) {
4794 if (
const NamespaceDecl *NSDecl =
4796 FDContext = getOrCreateNamespace(NSDecl);
4797 else if (
const RecordDecl *RDecl =
4799 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4800 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4803 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
4806 Flags |= llvm::DINode::FlagNoReturn;
4808 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4812void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4813 unsigned &LineNo, QualType &T,
4814 StringRef &Name, StringRef &LinkageName,
4815 llvm::MDTuple *&TemplateParameters,
4816 llvm::DIScope *&VDContext) {
4825 llvm::APInt ConstVal(32, 1);
4826 QualType ET = CGM.getContext().getAsArrayType(T)->getElementType();
4828 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
4835 LinkageName = CGM.getMangledName(VD);
4836 if (LinkageName == Name)
4837 LinkageName = StringRef();
4840 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4841 TemplateParameters = parameterNodes.get();
4843 TemplateParameters =
nullptr;
4849 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4850 VDContext = LexicalBlockStack.back();
4869 DC = CGM.getContext().getTranslationUnitDecl();
4871 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4872 VDContext = getContextDescriptor(
cast<Decl>(DC), Mod ? Mod : TheCU);
4875llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
4877 llvm::DINodeArray TParamsArray;
4878 StringRef Name, LinkageName;
4879 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4880 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4882 llvm::DIFile *Unit = getOrCreateFile(Loc);
4883 llvm::DIScope *DContext = Unit;
4884 unsigned Line = getLineNumber(Loc);
4885 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4890 SmallVector<QualType, 16> ArgTypes;
4891 for (
const ParmVarDecl *Parm : FD->
parameters())
4892 ArgTypes.push_back(Parm->getType());
4895 QualType FnType = CGM.getContext().getFunctionType(
4896 FD->
getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
4898 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4899 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
4900 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4904 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4905 return DBuilder.createFunction(
4906 DContext, Name, LinkageName, Unit,
Line,
4907 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4908 TParamsArray.get(), getFunctionDeclaration(FD),
nullptr,
4910 CGM.getCodeGenOpts().DebugKeyInstructions);
4913 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4914 DContext, Name, LinkageName, Unit,
Line,
4915 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4916 TParamsArray.get(), getFunctionDeclaration(FD));
4918 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4919 std::make_tuple(CanonDecl),
4920 std::make_tuple(SP));
4924llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
4925 return getFunctionFwdDeclOrStub(GD,
false);
4928llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
4929 return getFunctionFwdDeclOrStub(GD,
true);
4932llvm::DIGlobalVariable *
4933CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4935 StringRef Name, LinkageName;
4937 llvm::DIFile *Unit = getOrCreateFile(Loc);
4938 llvm::DIScope *DContext = Unit;
4939 unsigned Line = getLineNumber(Loc);
4940 llvm::MDTuple *TemplateParameters =
nullptr;
4942 collectVarDeclProps(VD, Unit,
Line, T, Name, LinkageName, TemplateParameters,
4945 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4946 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(T, Unit),
4948 FwdDeclReplaceMap.emplace_back(
4949 std::piecewise_construct,
4951 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4955llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
4960 if (
const auto *TD = dyn_cast<TypeDecl>(D)) {
4961 QualType Ty = CGM.getContext().getTypeDeclType(TD);
4962 return getOrCreateType(Ty, getOrCreateFile(TD->
getLocation()));
4966 if (I != DeclCache.end()) {
4968 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4969 return GVE->getVariable();
4977 if (IE != ImportedDeclCache.end()) {
4978 auto N = IE->second;
4979 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4981 return dyn_cast_or_null<llvm::DINode>(N);
4986 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4987 return getFunctionForwardDeclaration(FD);
4988 else if (
const auto *VD = dyn_cast<VarDecl>(D))
4989 return getGlobalVariableForwardDeclaration(VD);
4994llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
4995 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4998 const auto *FD = dyn_cast<FunctionDecl>(D);
5003 auto *S = getDeclContextDescriptor(D);
5006 if (MI == SPCache.end()) {
5008 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
5012 if (MI != SPCache.end()) {
5013 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
5014 if (SP && !SP->isDefinition())
5018 for (
auto *NextFD : FD->
redecls()) {
5019 auto MI = SPCache.find(NextFD->getCanonicalDecl());
5020 if (MI != SPCache.end()) {
5021 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
5022 if (SP && !SP->isDefinition())
5029llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
5030 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
5031 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
5032 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5035 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
5039 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
5043 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
5052 QualType QTy(
ID->getTypeForDecl(), 0);
5053 auto It = TypeCache.find(QTy.getAsOpaquePtr());
5054 if (It == TypeCache.end())
5057 llvm::DISubprogram *FD = DBuilder.createFunction(
5058 InterfaceType, getObjCMethodName(OMD), StringRef(),
5059 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
5060 DBuilder.finalizeSubprogram(FD);
5067llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
5072 if (!D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
5073 !CGM.getCodeGenOpts().EmitCodeView))
5076 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({}));
5078 if (
const auto *
Method = dyn_cast<CXXDestructorDecl>(D)) {
5081 return getOrCreateMethodTypeForDestructor(
Method, F, FnType);
5084 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(D))
5085 return getOrCreateMethodType(
Method, F);
5087 const auto *FTy = FnType->
getAs<FunctionType>();
5090 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
5092 SmallVector<llvm::Metadata *, 16> Elts;
5095 QualType ResultTy = OMethod->getReturnType();
5098 if (ResultTy == CGM.getContext().getObjCInstanceType())
5099 ResultTy = CGM.getContext().getPointerType(
5100 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
5102 Elts.push_back(getOrCreateType(ResultTy, F));
5104 QualType SelfDeclTy;
5105 if (
auto *SelfDecl = OMethod->getSelfDecl())
5106 SelfDeclTy = SelfDecl->getType();
5107 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
5110 if (!SelfDeclTy.
isNull())
5112 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
5114 Elts.push_back(DBuilder.createArtificialType(
5115 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
5117 for (
const auto *PI : OMethod->parameters())
5118 Elts.push_back(getOrCreateType(PI->getType(), F));
5120 if (OMethod->isVariadic())
5121 Elts.push_back(DBuilder.createUnspecifiedParameter());
5123 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
5124 return DBuilder.createSubroutineType(
5125 EltTypeArray, llvm::DINode::FlagZero,
5126 getDwarfCC(CC, CGM.getTarget().getTriple()));
5131 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
5132 if (FD->isVariadic()) {
5133 SmallVector<llvm::Metadata *, 16> EltTys;
5134 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
5135 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
5137 EltTys.push_back(getOrCreateType(ParamType, F));
5138 EltTys.push_back(DBuilder.createUnspecifiedParameter());
5139 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
5140 return DBuilder.createSubroutineType(
5141 EltTypeArray, llvm::DINode::FlagZero,
5142 getDwarfCC(CC, CGM.getTarget().getTriple()));
5154 CC = SrcFnTy->getCallConv();
5156 for (
const VarDecl *VD : Args)
5157 ArgTypes.push_back(VD->
getType());
5158 return CGM.getContext().getFunctionType(RetTy, ArgTypes,
5164 llvm::Function *Fn,
bool CurFuncIsThunk) {
5166 StringRef LinkageName;
5168 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5171 bool HasDecl = (D !=
nullptr);
5173 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5174 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5175 llvm::DIFile *Unit = getOrCreateFile(Loc);
5176 llvm::DIScope *FDContext = Unit;
5177 llvm::DINodeArray TParamsArray;
5178 bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
5181 LinkageName = Fn->getName();
5182 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5184 auto FI = SPCache.find(FD->getCanonicalDecl());
5185 if (FI != SPCache.end()) {
5186 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5187 if (SP && SP->isDefinition()) {
5188 LexicalBlockStack.emplace_back(SP);
5189 RegionMap[D].reset(SP);
5193 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5194 TParamsArray, Flags);
5197 KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
5198 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5199 Name = getObjCMethodName(OMD);
5200 Flags |= llvm::DINode::FlagPrototyped;
5206 if (Name != Fn->getName())
5207 LinkageName = Fn->getName();
5209 Name = Fn->getName();
5214 Flags |= llvm::DINode::FlagPrototyped;
5216 Name.consume_front(
"\01");
5220 "Unexpected DynamicInitKind !");
5224 Flags |= llvm::DINode::FlagArtificial;
5230 Flags |= llvm::DINode::FlagThunk;
5232 if (Fn->hasLocalLinkage())
5233 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
5234 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5235 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5238 llvm::DISubprogram::DISPFlags SPFlagsForDef =
5239 SPFlags | llvm::DISubprogram::SPFlagDefinition;
5241 const unsigned LineNo = getLineNumber(Loc.
isValid() ? Loc : CurLoc);
5242 unsigned ScopeLine = getLineNumber(ScopeLoc);
5243 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
5244 llvm::DISubprogram *
Decl =
nullptr;
5245 llvm::DINodeArray Annotations =
nullptr;
5248 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
5249 : getFunctionDeclaration(D);
5250 Annotations = CollectBTFDeclTagAnnotations(D);
5258 llvm::DISubprogram *SP = DBuilder.createFunction(
5259 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
5260 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
5261 Annotations,
"", KeyInstructions);
5262 Fn->setSubprogram(SP);
5271 LexicalBlockStack.emplace_back(SP);
5274 RegionMap[D].reset(SP);
5278 QualType FnType, llvm::Function *Fn) {
5280 StringRef LinkageName;
5286 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
5287 return GetName(D,
true);
5290 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5291 llvm::DIFile *Unit = getOrCreateFile(Loc);
5292 bool IsDeclForCallSite = Fn ?
true :
false;
5293 llvm::DIScope *FDContext =
5294 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
5295 llvm::DINodeArray TParamsArray;
5298 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5299 TParamsArray, Flags);
5300 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5301 Name = getObjCMethodName(OMD);
5302 Flags |= llvm::DINode::FlagPrototyped;
5304 llvm_unreachable(
"not a function or ObjC method");
5306 Name.consume_front(
"\01");
5309 Flags |= llvm::DINode::FlagArtificial;
5314 unsigned LineNo = getLineNumber(Loc);
5315 unsigned ScopeLine = 0;
5316 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5317 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5318 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5320 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
5321 llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
5323 assert(~SPFlags & llvm::DISubprogram::SPFlagDefinition);
5324 llvm::DISubprogram *SP = DBuilder.createFunction(
5325 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
5326 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations,
5332 if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
5333 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
5334 llvm::DITypeArray ParamTypes = STy->getTypeArray();
5337 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
5338 DBuilder.createParameterVariable(
5339 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
5340 llvm::DINode::FlagZero, ParamAnnotations);
5346 if (IsDeclForCallSite)
5347 Fn->setSubprogram(SP);
5351 llvm::CallBase *CI) {
5352 if (!shouldGenerateVirtualCallSite())
5358 assert(CI &&
"Invalid Call Instruction.");
5359 if (!CI->isIndirectCall())
5363 if (llvm::DISubprogram *MD = getFunctionDeclaration(FD))
5364 CI->setMetadata(llvm::LLVMContext::MD_call_target, MD);
5372 auto *
Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
5375 if (
Func->getSubprogram())
5379 if (!
Func->isDeclaration())
5401 if (
auto *SP = getFunctionDeclaration(CalleeDecl))
5402 Func->setSubprogram(SP);
5413 auto FI = SPCache.find(FD->getCanonicalDecl());
5414 llvm::DISubprogram *SP =
nullptr;
5415 if (FI != SPCache.end())
5416 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5417 if (!SP || !SP->isDefinition())
5418 SP = getFunctionStub(GD);
5419 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5420 LexicalBlockStack.emplace_back(SP);
5426 assert(CurInlinedAt &&
"unbalanced inline scope stack");
5435 if (CurLoc.isInvalid() ||
5436 (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) ||
5437 LexicalBlockStack.empty())
5440 llvm::MDNode *
Scope = LexicalBlockStack.back();
5441 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5442 CGM.getLLVMContext(), CurLocLine, CurLocColumn,
Scope, CurInlinedAt));
5446 llvm::MDNode *Back =
nullptr;
5447 if (!LexicalBlockStack.empty())
5448 Back = LexicalBlockStack.back().get();
5451 unsigned Line = getLineNumber(CurLoc);
5452 unsigned Column =
Line ? getColumnNumber(CurLoc) : 0;
5453 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
5457void CGDebugInfo::AppendAddressSpaceXDeref(
5459 std::optional<unsigned> DWARFAddressSpace =
5461 if (!DWARFAddressSpace)
5464 Expr.push_back(llvm::dwarf::DW_OP_constu);
5465 Expr.push_back(*DWARFAddressSpace);
5466 Expr.push_back(llvm::dwarf::DW_OP_swap);
5467 Expr.push_back(llvm::dwarf::DW_OP_xderef);
5476 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5477 CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
5478 LexicalBlockStack.back(), CurInlinedAt));
5480 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5484 CreateLexicalBlock(Loc);
5489 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5494 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5497 LexicalBlockStack.pop_back();
5501 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5502 unsigned RCount = FnBeginRegionCount.back();
5503 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
5506 while (LexicalBlockStack.size() != RCount) {
5509 LexicalBlockStack.pop_back();
5511 FnBeginRegionCount.pop_back();
5513 if (Fn && Fn->getSubprogram())
5514 DBuilder.finalizeSubprogram(Fn->getSubprogram());
5517CGDebugInfo::BlockByRefType
5518CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
5519 uint64_t *XOffset) {
5522 uint64_t FieldSize, FieldOffset;
5523 uint32_t FieldAlign;
5525 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5530 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
5531 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
5533 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
5534 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
5537 if (HasCopyAndDispose) {
5540 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
5542 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
5544 bool HasByrefExtendedLayout;
5547 HasByrefExtendedLayout) &&
5548 HasByrefExtendedLayout) {
5551 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
5560 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
5563 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
5566 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
5571 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
5572 FieldSize = CGM.getContext().getTypeSize(FType);
5573 FieldAlign = CGM.getContext().toBits(Align);
5575 *XOffset = FieldOffset;
5576 llvm::DIType *FieldTy = DBuilder.createMemberType(
5577 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
5578 llvm::DINode::FlagZero, WrappedTy);
5579 EltTys.push_back(FieldTy);
5580 FieldOffset += FieldSize;
5582 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
5583 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
5584 llvm::DINode::FlagZero,
nullptr, Elements),
5588llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
5589 llvm::Value *Storage,
5590 std::optional<unsigned> ArgNo,
5592 const bool UsePointerValue) {
5593 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5594 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5595 if (VD->
hasAttr<NoDebugAttr>())
5600 llvm::DIFile *Unit =
nullptr;
5601 if (!VarIsArtificial)
5605 if (VD->
hasAttr<BlocksAttr>())
5606 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5608 Ty = getOrCreateType(VD->
getType(), Unit);
5618 if (!VarIsArtificial) {
5622 SmallVector<uint64_t, 13> Expr;
5623 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5630 Flags |= llvm::DINode::FlagArtificial;
5634 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->
getType());
5635 AppendAddressSpaceXDeref(AddressSpace, Expr);
5639 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
5642 Flags |= llvm::DINode::FlagObjectPointer;
5643 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
5644 if (PVD->isExplicitObjectParameter())
5645 Flags |= llvm::DINode::FlagObjectPointer;
5653 StringRef Name = VD->
getName();
5654 if (!Name.empty()) {
5660 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5662 offset = CGM.getContext().toCharUnitsFromBits(
5665 Expr.push_back(llvm::dwarf::DW_OP_deref);
5666 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5668 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5671 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
5683 for (
const auto *Field : RD->
fields()) {
5684 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
5685 StringRef FieldName =
Field->getName();
5693 auto *D = DBuilder.createAutoVariable(
5694 Scope, FieldName, Unit,
Line, FieldTy,
5695 CGM.getCodeGenOpts().OptimizationLevel != 0,
5696 Flags | llvm::DINode::FlagArtificial, FieldAlign);
5699 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5700 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5703 Builder.GetInsertBlock());
5711 if (UsePointerValue) {
5712 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5713 "Debug info already contains DW_OP_deref.");
5714 Expr.push_back(llvm::dwarf::DW_OP_deref);
5718 llvm::DILocalVariable *D =
nullptr;
5720 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5721 D = DBuilder.createParameterVariable(
5722 Scope, Name, *ArgNo, Unit,
Line, Ty,
5723 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
5732 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
5738 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
5739 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
5740 if (DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
5741 DeclGroupRef DeclGroup = DeclStmtPtr->getDeclGroup();
5743 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
5749 if (Iter != CoroutineParameterMappings.end()) {
5750 ParmVarDecl *PD =
const_cast<ParmVarDecl *
>(Iter->first);
5751 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
5752 return DbgPair.first == PD && DbgPair.second->getScope() == Scope;
5754 if (Iter2 != ParamDbgMappings.end())
5755 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
5761 D = RemapCoroArgToLocalVar();
5764 D = DBuilder.createAutoVariable(
5765 Scope, Name, Unit,
Line, Ty,
5766 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
5769 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5770 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5771 Column, Scope, CurInlinedAt),
5772 Builder.GetInsertBlock());
5777llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
5778 llvm::Value *Storage,
5779 std::optional<unsigned> ArgNo,
5781 const bool UsePointerValue) {
5782 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5783 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5784 if (BD->
hasAttr<NoDebugAttr>())
5791 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
5792 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
5800 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->
getType());
5802 SmallVector<uint64_t, 3> Expr;
5803 AppendAddressSpaceXDeref(AddressSpace, Expr);
5808 if (UsePointerValue) {
5809 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5810 "Debug info already contains DW_OP_deref.");
5811 Expr.push_back(llvm::dwarf::DW_OP_deref);
5816 StringRef Name = BD->
getName();
5819 llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5820 Scope, Name, Unit,
Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
5821 llvm::DINode::FlagZero, Align);
5823 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(BD->
getBinding())) {
5824 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5825 const unsigned fieldIndex = FD->getFieldIndex();
5826 const clang::CXXRecordDecl *parent =
5827 (
const CXXRecordDecl *)FD->getParent();
5828 const ASTRecordLayout &layout =
5829 CGM.getContext().getASTRecordLayout(parent);
5831 if (FD->isBitField()) {
5832 const CGRecordLayout &RL =
5833 CGM.getTypes().getCGRecordLayout(FD->getParent());
5838 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5844 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5845 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5846 Expr.push_back(Info.
Offset);
5849 const uint64_t TypeSize = CGM.getContext().getTypeSize(BD->
getType());
5850 Expr.push_back(std::min((
uint64_t)Info.
Size, TypeSize));
5851 }
else if (fieldOffset != 0) {
5852 assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
5853 "Unexpected non-bitfield with non-byte-aligned offset");
5854 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5856 CGM.getContext().toCharUnitsFromBits(fieldOffset).getQuantity());
5859 }
else if (
const ArraySubscriptExpr *ASE =
5860 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5861 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5862 const uint64_t value = IL->getValue().getZExtValue();
5863 const uint64_t typeSize = CGM.getContext().getTypeSize(BD->
getType());
5866 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5867 Expr.push_back(CGM.getContext()
5868 .toCharUnitsFromBits(value * typeSize)
5875 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5876 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5877 Column, Scope, CurInlinedAt),
5878 Builder.GetInsertBlock());
5883llvm::DILocalVariable *
5886 const bool UsePointerValue) {
5887 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5889 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5891 EmitDeclare(B, Storage, std::nullopt, Builder,
5898 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5902 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5903 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5905 if (D->
hasAttr<NoDebugAttr>())
5909 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
5915 StringRef Name = D->
getName();
5921 CGM.getCodeGenOpts().OptimizationLevel != 0);
5924 DBuilder.insertLabel(L,
5925 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5926 Scope, CurInlinedAt),
5927 Builder.GetInsertBlock()->end());
5930llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5932 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5935 return DBuilder.createObjectPointerType(Ty,
true);
5940 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5941 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5942 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5944 if (Builder.GetInsertBlock() ==
nullptr)
5946 if (VD->
hasAttr<NoDebugAttr>())
5949 bool isByRef = VD->
hasAttr<BlocksAttr>();
5951 uint64_t XOffset = 0;
5952 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5955 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5957 Ty = getOrCreateType(VD->
getType(), Unit);
5961 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5963 Ty = CreateSelfType(VD->
getType(), Ty);
5966 const unsigned Line =
5970 const llvm::DataLayout &target = CGM.getDataLayout();
5977 addr.push_back(llvm::dwarf::DW_OP_deref);
5978 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5981 addr.push_back(llvm::dwarf::DW_OP_deref);
5982 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5985 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
5987 addr.push_back(llvm::dwarf::DW_OP_deref);
5988 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5990 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5996 auto *D = DBuilder.createAutoVariable(
5998 Line, Ty,
false, llvm::DINode::FlagZero, Align);
6001 auto DL = llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
6002 LexicalBlockStack.back(), CurInlinedAt);
6003 auto *
Expr = DBuilder.createExpression(addr);
6005 DBuilder.insertDeclare(Storage, D,
Expr, DL, InsertPoint->getIterator());
6007 DBuilder.insertDeclare(Storage, D,
Expr, DL, Builder.GetInsertBlock());
6010llvm::DILocalVariable *
6013 bool UsePointerValue) {
6014 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6015 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
6019struct BlockLayoutChunk {
6020 uint64_t OffsetInBits;
6023bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
6024 return l.OffsetInBits < r.OffsetInBits;
6028void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
6030 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
6031 SmallVectorImpl<llvm::Metadata *> &Fields) {
6035 if (CGM.getLangOpts().OpenCL) {
6036 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
6037 BlockLayout.getElementOffsetInBits(0),
6039 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
6040 BlockLayout.getElementOffsetInBits(1),
6044 BlockLayout.getElementOffsetInBits(0),
6046 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
6047 BlockLayout.getElementOffsetInBits(1),
6051 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
6052 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
6053 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
6054 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
6055 BlockLayout.getElementOffsetInBits(3),
6057 Fields.push_back(createFieldType(
6062 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
6069 llvm::AllocaInst *Alloca,
6071 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6077 llvm::DIFile *tunit = getOrCreateFile(loc);
6078 unsigned line = getLineNumber(loc);
6079 unsigned column = getColumnNumber(loc);
6084 const llvm::StructLayout *blockLayout =
6088 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
6097 BlockLayoutChunk chunk;
6098 chunk.OffsetInBits =
6099 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
6100 chunk.Capture =
nullptr;
6101 chunks.push_back(chunk);
6105 for (
const auto &capture :
blockDecl->captures()) {
6106 const VarDecl *variable = capture.getVariable();
6113 BlockLayoutChunk chunk;
6114 chunk.OffsetInBits =
6115 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
6116 chunk.Capture = &capture;
6117 chunks.push_back(chunk);
6121 llvm::array_pod_sort(chunks.begin(), chunks.end());
6123 for (
const BlockLayoutChunk &Chunk : chunks) {
6124 uint64_t offsetInBits = Chunk.OffsetInBits;
6129 fields.push_back(createFieldType(
"this",
blockDecl->getCXXThisType(), loc,
6130 AS_public, offsetInBits, tunit, tunit));
6135 StringRef name = variable->
getName();
6137 llvm::DIType *fieldType;
6139 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
6144 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
6145 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
6146 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
6147 PtrInfo.
Width, Align, offsetInBits,
6148 llvm::DINode::FlagZero, fieldType);
6152 offsetInBits, Align, tunit, tunit);
6154 fields.push_back(fieldType);
6158 llvm::raw_svector_ostream(typeName)
6159 <<
"__block_literal_" << CGM.getUniqueBlockCount();
6161 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
6163 llvm::DIType *
type =
6164 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
6165 CGM.getContext().toBits(block.
BlockSize), 0,
6166 llvm::DINode::FlagZero,
nullptr, fieldsArray);
6167 type = DBuilder.createPointerType(
type, CGM.PointerWidthInBits);
6170 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
6174 auto *debugVar = DBuilder.createParameterVariable(
6175 scope, Name, ArgNo, tunit, line,
type,
6176 CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
6179 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
6180 llvm::DILocation::get(CGM.getLLVMContext(), line,
6181 column, scope, CurInlinedAt),
6182 Builder.GetInsertBlock());
6185llvm::DIDerivedType *
6186CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
6191 if (MI != StaticDataMemberCache.end()) {
6192 assert(MI->second &&
"Static data member declaration should still exist");
6203llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
6204 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
6205 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
6206 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6208 for (
const auto *Field : RD->
fields()) {
6209 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
6210 StringRef FieldName = Field->getName();
6213 if (FieldName.empty()) {
6214 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
6215 GVE = CollectAnonRecordDecls(RT->getDecl()->getDefinitionOrSelf(), Unit,
6216 LineNo, LinkageName, Var, DContext);
6220 GVE = DBuilder.createGlobalVariableExpression(
6221 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
6222 Var->hasLocalLinkage());
6223 Var->addDebugInfo(GVE);
6235 const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6240 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
6251 struct ReferencesAnonymous
6253 bool RefAnon =
false;
6254 bool VisitRecordType(RecordType *RT) {
6262 ReferencesAnonymous RT;
6275struct ReconstitutableType :
public RecursiveASTVisitor<ReconstitutableType> {
6276 bool Reconstitutable =
true;
6277 bool VisitVectorType(VectorType *FT) {
6278 Reconstitutable =
false;
6281 bool VisitAtomicType(AtomicType *FT) {
6282 Reconstitutable =
false;
6285 bool TraverseEnumType(EnumType *ET,
bool =
false) {
6288 const EnumDecl *ED = ET->getDecl();
6290 Reconstitutable =
false;
6294 Reconstitutable =
false;
6299 bool VisitFunctionProtoType(FunctionProtoType *FT) {
6303 return Reconstitutable;
6305 bool VisitRecordType(RecordType *RT,
bool =
false) {
6307 Reconstitutable =
false;
6317 ReconstitutableType T;
6319 return T.Reconstitutable;
6322bool CGDebugInfo::HasReconstitutableArgs(
6323 ArrayRef<TemplateArgument> Args)
const {
6324 return llvm::all_of(Args, [&](
const TemplateArgument &TA) {
6364 llvm_unreachable(
"Other, unresolved, template arguments should "
6365 "not be seen here");
6370std::string CGDebugInfo::GetName(
const Decl *D,
bool Qualified,
6371 bool *NameIsSimplified)
const {
6373 llvm::raw_string_ostream
OS(Name);
6374 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
6377 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
6378 CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
6380 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6381 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
6383 std::optional<TemplateArgs> Args;
6385 bool IsOperatorOverload =
false;
6386 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
6387 Args = GetTemplateArgs(RD);
6388 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
6389 Args = GetTemplateArgs(FD);
6391 IsOperatorOverload |=
6394 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
6395 Args = GetTemplateArgs(VD);
6419 bool Reconstitutable =
6420 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
6422 PrintingPolicy PP = getPrintingPolicy();
6424 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
6429 if (NameIsSimplified)
6430 *NameIsSimplified =
true;
6431 bool Mangled = TemplateNamesKind ==
6432 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
6438 std::string EncodedOriginalName;
6439 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
6444 printTemplateArgumentList(OS, Args->Args, PP);
6445 printTemplateArgumentList(EncodedOriginalNameOS, Args->Args, PP);
6447 std::string CanonicalOriginalName;
6448 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
6450 assert(EncodedOriginalName == CanonicalOriginalName);
6459 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6460 if (D->
hasAttr<NoDebugAttr>())
6463 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
6464 return GetName(D,
true);
6470 if (Cached != DeclCache.end())
6471 return Var->addDebugInfo(
6475 llvm::DIFile *Unit =
nullptr;
6476 llvm::DIScope *DContext =
nullptr;
6478 StringRef DeclName, LinkageName;
6480 llvm::MDTuple *TemplateParameters =
nullptr;
6481 collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName,
6482 TemplateParameters, DContext);
6486 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6491 if (T->isUnionType() && DeclName.empty()) {
6492 const auto *RD = T->castAsRecordDecl();
6494 "unnamed non-anonymous struct or union?");
6495 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
6500 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->
getType());
6501 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
6502 if (D->
hasAttr<CUDASharedAttr>())
6505 else if (D->
hasAttr<CUDAConstantAttr>())
6509 AppendAddressSpaceXDeref(AddressSpace,
Expr);
6511 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
6512 GVE = DBuilder.createGlobalVariableExpression(
6513 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
6514 Var->hasLocalLinkage(),
true,
6515 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
6516 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
6517 Align, Annotations);
6518 Var->addDebugInfo(GVE);
6524 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6525 if (VD->
hasAttr<NoDebugAttr>())
6527 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
6528 return GetName(VD,
true);
6533 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
6534 StringRef Name = VD->
getName();
6535 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
6537 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
6539 if (CGM.getCodeGenOpts().EmitCodeView) {
6550 CanQualType T = CGM.getContext().getCanonicalTagType(ED);
6551 [[maybe_unused]] llvm::DIType *EDTy = getOrCreateType(T, Unit);
6552 assert(EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
6562 auto *VarD = dyn_cast<VarDecl>(VD);
6563 if (VarD && VarD->isStaticDataMember()) {
6565 getDeclContextDescriptor(VarD);
6570 RetainedTypes.push_back(
6571 CGM.getContext().getCanonicalTagType(RD).getAsOpaquePtr());
6575 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
6577 auto &GV = DeclCache[VD];
6581 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
6582 llvm::MDTuple *TemplateParameters =
nullptr;
6586 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
6587 TemplateParameters = parameterNodes.get();
6590 GV.reset(DBuilder.createGlobalVariableExpression(
6591 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
6592 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
6593 TemplateParameters, Align));
6598 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6599 if (D->
hasAttr<NoDebugAttr>())
6603 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
6604 StringRef Name = D->
getName();
6605 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
6607 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6608 llvm::DIGlobalVariableExpression *GVE =
6609 DBuilder.createGlobalVariableExpression(
6610 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
6611 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
6612 Var->addDebugInfo(GVE);
6619 if (CGM.getCodeGenOpts().getDebugInfo() <=
6620 llvm::codegenoptions::DebugLineTablesOnly)
6623 llvm::DILocation *DIL =
Value->getDebugLoc().get();
6627 llvm::DIFile *Unit = DIL->getFile();
6628 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
6633 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
6634 llvm::Value *Var = Load->getPointerOperand();
6639 auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
6640 return DbgDeclare->getVariable()->getType() ==
Type;
6642 if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6646 llvm::DILocalVariable *D =
6647 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
6648 Type,
false, llvm::DINode::FlagArtificial);
6650 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
6651 DBuilder.insertDbgValue(
Value, D, DBuilder.createExpression(), DIL,
6661 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6665 if (D->
hasAttr<NoDebugAttr>())
6668 auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
6683 if (!(DI = getDeclarationOrDefinition(
6684 AliaseeDecl.getCanonicalDecl().getDecl())))
6687 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6690 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
6691 DContext, DI, getOrCreateFile(Loc), getLineNumber(Loc), D->getName());
6705 llvm::DIFile *
File = getOrCreateFile(Loc);
6706 llvm::DIGlobalVariableExpression *Debug =
6707 DBuilder.createGlobalVariableExpression(
6708 nullptr, StringRef(), StringRef(),
File, getLineNumber(Loc),
6710 GV->addDebugInfo(Debug);
6713llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
6714 if (!LexicalBlockStack.empty())
6715 return LexicalBlockStack.back();
6716 llvm::DIScope *Mod = getParentModuleOrNull(D);
6717 return getContextDescriptor(D, Mod ? Mod : TheCU);
6721 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6725 CGM.getCodeGenOpts().DebugExplicitImport) {
6729 DBuilder.createImportedModule(
6731 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
6736 if (llvm::DINode *
Target =
6739 DBuilder.createImportedDeclaration(
6741 getOrCreateFile(Loc), getLineNumber(Loc));
6746 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6749 "We shouldn't be codegening an invalid UsingDecl containing no decls");
6751 for (
const auto *USD : UD.
shadows()) {
6756 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
6757 if (
const auto *AT = FD->getType()
6760 if (AT->getDeducedType().isNull())
6771 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6774 "We shouldn't be codegening an invalid UsingEnumDecl"
6775 " containing no decls");
6777 for (
const auto *USD : UD.
shadows())
6782 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
6784 if (
Module *M = ID.getImportedModule()) {
6786 auto Loc = ID.getLocation();
6787 DBuilder.createImportedDeclaration(
6788 getCurrentContextDescriptor(
cast<Decl>(ID.getDeclContext())),
6789 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
6790 getLineNumber(Loc));
6794llvm::DIImportedEntity *
6796 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6798 auto &VH = NamespaceAliasCache[&NA];
6801 llvm::DIImportedEntity *R;
6803 if (
const auto *Underlying =
6806 R = DBuilder.createImportedDeclaration(
6809 getLineNumber(Loc), NA.
getName());
6811 R = DBuilder.createImportedDeclaration(
6814 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
6820CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6824 auto I = NamespaceCache.find(NSDecl);
6825 if (I != NamespaceCache.end())
6828 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6830 llvm::DINamespace *NS =
6831 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6832 NamespaceCache[NSDecl].reset(NS);
6837 assert(TheCU &&
"no main compile unit");
6838 TheCU->setDWOId(Signature);
6844 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6845 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
6847 ? CreateTypeDefinition(E.Type, E.Unit)
6849 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
6853 for (
const auto &P : ObjCMethodCache) {
6854 if (P.second.empty())
6857 QualType QTy(P.first->getTypeForDecl(), 0);
6859 assert(It != TypeCache.end());
6861 llvm::DICompositeType *InterfaceDecl =
6864 auto CurElts = InterfaceDecl->getElements();
6868 for (
auto &SubprogramDirect : P.second)
6869 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6870 EltTys.push_back(SubprogramDirect.getPointer());
6872 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6873 DBuilder.replaceArrays(InterfaceDecl, Elements);
6876 for (
const auto &P : ReplaceMap) {
6879 assert(Ty->isForwardDecl());
6881 auto It = TypeCache.find(P.first);
6882 assert(It != TypeCache.end());
6885 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6889 for (
const auto &P : FwdDeclReplaceMap) {
6892 llvm::Metadata *Repl;
6894 auto It = DeclCache.find(P.first);
6898 if (It == DeclCache.end())
6903 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6904 Repl = GVE->getVariable();
6910 for (
auto &RT : RetainedTypes)
6911 if (
auto MD = TypeCache[RT])
6914 DBuilder.finalize();
6919 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
6920 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6921 DBuilder.retainType(DieTy);
6925 if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
6926 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6927 DBuilder.retainType(DieTy);
6931 if (LexicalBlockStack.empty())
6932 return llvm::DebugLoc();
6934 llvm::MDNode *
Scope = LexicalBlockStack.back();
6935 return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
6936 getColumnNumber(Loc),
Scope);
6942 if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
6943 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6944 DebugKind == llvm::codegenoptions::LocTrackingOnly ||
6945 !CGM.getCodeGenOpts().DebugCallSiteInfo)
6946 return llvm::DINode::FlagZero;
6951 bool SupportsDWARFv4Ext =
6952 CGM.getCodeGenOpts().DwarfVersion == 4 &&
6953 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6954 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6956 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
6957 return llvm::DINode::FlagZero;
6959 return llvm::DINode::FlagAllCallsDescribed;
6970 return DBuilder.createConstantValueExpression(
6971 Val.
getFloat().bitcastToAPInt().getZExtValue());
6976 llvm::APSInt
const &ValInt = Val.
getInt();
6977 std::optional<uint64_t> ValIntOpt;
6978 if (ValInt.isUnsigned())
6979 ValIntOpt = ValInt.tryZExtValue();
6980 else if (
auto tmp = ValInt.trySExtValue())
6983 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6986 return DBuilder.createConstantValueExpression(ValIntOpt.value());
6991CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &
CGF,
6993 : RunCleanupsScope(
CGF), Range(Range), ParentScope(
CGF.CurLexicalScope) {
6994 CGF.CurLexicalScope =
this;
6996 DI->EmitLexicalBlockStart(
CGF.Builder, Range.getBegin());
7001 DI->EmitLexicalBlockEnd(
CGF.Builder, Range.getEnd());
7014#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
7016 Label = "__ubsan_check_" #Name; \
7020#undef SANITIZER_CHECK
7031#define SANITIZER(NAME, ID) \
7032 case SanitizerKind::SO_##ID: \
7033 Label = "__ubsan_check_" NAME; \
7035#include "clang/Basic/Sanitizers.def"
7037 llvm_unreachable(
"unexpected sanitizer kind");
7042 for (
unsigned int i = 0; i < Label.length(); i++)
7043 if (!std::isalpha(Label[i]))
7052 llvm::DILocation *CheckDebugLoc =
Builder.getCurrentDebugLocation();
7054 if (!DI || !CheckDebugLoc)
7055 return CheckDebugLoc;
7056 const auto &AnnotateDebugInfo =
7057 CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo;
7058 if (AnnotateDebugInfo.empty())
7059 return CheckDebugLoc;
7062 if (Ordinals.size() == 1)
7067 if (any_of(Ordinals, [&](
auto Ord) {
return AnnotateDebugInfo.has(Ord); })) {
7071 llvm::DIFile *
File = llvm::DIFile::get(
CGM.getLLVMContext(),
7072 "ubsan_interface.h",
7074 return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label,
File);
7077 return CheckDebugLoc;
7085 assert(!CGF->IsSanitizerScope);
7086 CGF->IsSanitizerScope =
true;
7090 assert(CGF->IsSanitizerScope);
7091 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 constexpr 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.
unsigned getNumColumns() const
Returns the number of columns.
QualType getElementType() const
Returns the element type.
unsigned getNumRows() const
Returns the number of rows.
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.
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.