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"
71 if (TI.isAlignRequired())
99 llvm::dyn_cast_or_null<DeclRefExpr>(
Init->IgnoreUnlessSpelledInSource());
103 return llvm::dyn_cast_or_null<DecompositionDecl>(RefExpr->getDecl());
127 if (!llvm::isa<ParmVarDecl>(VD))
137 if (!Method->isImplicit() || !Method->isPropertyAccessor())
148 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
149 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
150 DBuilder(CGM.getModule()) {
155 assert(LexicalBlockStack.empty() &&
156 "Region stack mismatch, stack not empty!");
159void CGDebugInfo::addInstSourceAtomMetadata(llvm::Instruction *I,
160 uint64_t Group, uint8_t Rank) {
161 if (!I->getDebugLoc() || Group == 0 || !I->getDebugLoc()->getLine())
165 Rank = std::min<uint8_t>(Rank, 7);
167 const llvm::DebugLoc &DL = I->getDebugLoc();
172 if (DL->getAtomGroup() && DL->getAtomRank() && DL->getAtomRank() < Rank) {
173 Group = DL->getAtomGroup();
174 Rank = DL->getAtomRank();
179 KeyInstructionsInfo.HighestEmittedAtom =
180 std::max(Group, KeyInstructionsInfo.HighestEmittedAtom);
183 llvm::DILocation *NewDL = llvm::DILocation::get(
184 I->getContext(), DL.getLine(), DL.getCol(), DL.getScope(),
185 DL.getInlinedAt(), DL.isImplicitCode(), Group, Rank);
186 I->setDebugLoc(NewDL);
190 llvm::Value *Backup) {
192 KeyInstructionsInfo.CurrentAtom);
198 if (!Group || !CGM.getCodeGenOpts().DebugKeyInstructions)
201 llvm::DISubprogram *SP = KeyInstruction->getFunction()->getSubprogram();
202 if (!SP || !SP->getKeyInstructionsEnabled())
205 addInstSourceAtomMetadata(KeyInstruction, Group, 1);
207 llvm::Instruction *BackupI =
208 llvm::dyn_cast_or_null<llvm::Instruction>(Backup);
213 addInstSourceAtomMetadata(BackupI, Group, 2);
219 while (
auto *Cast = dyn_cast<llvm::CastInst>(BackupI)) {
220 BackupI = dyn_cast<llvm::Instruction>(Cast->getOperand(0));
223 addInstSourceAtomMetadata(BackupI, Group, Rank++);
229 KeyInstructionsInfo.NextAtom = 1;
230 KeyInstructionsInfo.HighestEmittedAtom = 0;
231 KeyInstructionsInfo.CurrentAtom = 0;
237 OriginalAtom = DI->KeyInstructionsInfo.CurrentAtom;
238 DI->KeyInstructionsInfo.CurrentAtom = DI->KeyInstructionsInfo.NextAtom++;
246 DI->KeyInstructionsInfo.NextAtom =
247 std::min(DI->KeyInstructionsInfo.HighestEmittedAtom + 1,
248 DI->KeyInstructionsInfo.NextAtom);
250 DI->KeyInstructionsInfo.CurrentAtom = OriginalAtom;
256 init(TemporaryLocation);
263 init(TemporaryLocation, DefaultToEmpty);
267 bool DefaultToEmpty) {
274 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
276 if (OriginalLocation && !DI->CGM.getExpressionLocationsEnabled())
279 if (TemporaryLocation.
isValid()) {
280 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
284 if (DefaultToEmpty) {
285 CGF->Builder.SetCurrentDebugLocation(llvm::DebugLoc());
290 assert(!DI->LexicalBlockStack.empty());
291 CGF->Builder.SetCurrentDebugLocation(
292 llvm::DILocation::get(DI->LexicalBlockStack.back()->getContext(), 0, 0,
293 DI->LexicalBlockStack.back(), DI->getInlinedAt()));
303 if (!CGF.getDebugInfo()) {
307 OriginalLocation = CGF.Builder.getCurrentDebugLocation();
311 if (Loc->getAtomGroup())
312 Loc = llvm::DILocation::get(Loc->getContext(), Loc.getLine(),
313 Loc->getColumn(), Loc->getScope(),
314 Loc->getInlinedAt(), Loc.isImplicitCode());
315 CGF.Builder.SetCurrentDebugLocation(std::move(Loc));
323 CGF->Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
329 if (!CGF.getDebugInfo()) {
333 auto &DI = *CGF.getDebugInfo();
334 SavedLocation = DI.getLocation();
335 assert((DI.getInlinedAt() ==
336 CGF.Builder.getCurrentDebugLocation()->getInlinedAt()) &&
337 "CGDebugInfo and IRBuilder are out of sync");
339 DI.EmitInlineFunctionStart(CGF.Builder, InlinedFn);
345 auto &DI = *CGF->getDebugInfo();
346 DI.EmitInlineFunctionEnd(CGF->Builder);
347 DI.EmitLocation(CGF->Builder, SavedLocation);
357 if (CurLoc != NewLoc) {
359 CurLocFile =
nullptr;
368 if (CGM.getCodeGenOpts().DebugColumnInfo)
370 CurLocFile = getOrCreateFile(CurLoc);
376 if (LexicalBlockStack.empty())
380 if (!CurLocFile ||
Scope->getFile() == CurLocFile)
383 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
384 LexicalBlockStack.pop_back();
385 LexicalBlockStack.emplace_back(
386 DBuilder.createLexicalBlockFile(LBF->getScope(), CurLocFile));
389 LexicalBlockStack.pop_back();
390 LexicalBlockStack.emplace_back(
391 DBuilder.createLexicalBlockFile(
Scope, CurLocFile));
395llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
396 llvm::DIScope *Mod = getParentModuleOrNull(D);
401llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *Context,
406 auto I = RegionMap.find(Context);
407 if (I != RegionMap.end()) {
408 llvm::Metadata *
V = I->second;
409 return dyn_cast_or_null<llvm::DIScope>(
V);
413 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
414 return getOrCreateNamespace(NSDecl);
416 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
417 if (!RDecl->isDependentType())
423PrintingPolicy CGDebugInfo::getPrintingPolicy()
const {
424 PrintingPolicy PP = CGM.getContext().getPrintingPolicy();
431 if (CGM.getCodeGenOpts().EmitCodeView) {
453StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD,
454 bool *NameIsSimplified) {
455 return internString(GetName(FD,
false, NameIsSimplified));
458StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
459 SmallString<256> MethodName;
460 llvm::raw_svector_ostream
OS(MethodName);
463 if (
const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
464 OS << OID->getName();
465 }
else if (
const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
466 OS << OID->getName();
467 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
468 if (OC->IsClassExtension()) {
469 OS << OC->getClassInterface()->getName();
471 OS << OC->getIdentifier()->getNameStart() <<
'('
472 << OC->getIdentifier()->getNameStart() <<
')';
474 }
else if (
const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
475 OS << OCD->getClassInterface()->getName() <<
'(' << OCD->getName() <<
')';
479 return internString(
OS.str());
482StringRef CGDebugInfo::getSelectorName(Selector S) {
486StringRef CGDebugInfo::getClassName(
const RecordDecl *RD,
487 bool *NameIsSimplified) {
490 return internString(GetName(RD,
false, NameIsSimplified));
496 return II->getName();
501 if (CGM.getCodeGenOpts().EmitCodeView) {
504 "Typedef should not be in another decl context!");
505 assert(D->getDeclName().getAsIdentifierInfo() &&
506 "Typedef was not named!");
507 return D->getDeclName().getAsIdentifierInfo()->getName();
510 if (CGM.getLangOpts().CPlusPlus) {
513 ASTContext &Context = CGM.getContext();
517 Name = DD->getName();
518 else if (
const TypedefNameDecl *TND =
522 Name = TND->getName();
525 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
526 if (CXXRD->isLambda())
528 CGM.getCXXABI().getMangleContext().getLambdaString(CXXRD));
531 SmallString<256> UnnamedType(
"<unnamed-type-");
534 return internString(UnnamedType);
542std::optional<llvm::DIFile::ChecksumKind>
543CGDebugInfo::computeChecksum(FileID FID, SmallString<64> &Checksum)
const {
546 if (!CGM.getCodeGenOpts().EmitCodeView &&
547 CGM.getCodeGenOpts().DwarfVersion < 5)
550 SourceManager &SM = CGM.getContext().getSourceManager();
551 std::optional<llvm::MemoryBufferRef> MemBuffer = SM.
getBufferOrNone(FID);
555 auto Data = llvm::arrayRefFromStringRef(MemBuffer->getBuffer());
556 switch (CGM.getCodeGenOpts().getDebugSrcHash()) {
558 llvm::toHex(llvm::MD5::hash(
Data),
true, Checksum);
559 return llvm::DIFile::CSK_MD5;
561 llvm::toHex(llvm::SHA1::hash(
Data),
true, Checksum);
562 return llvm::DIFile::CSK_SHA1;
564 llvm::toHex(llvm::SHA256::hash(
Data),
true, Checksum);
565 return llvm::DIFile::CSK_SHA256;
569 llvm_unreachable(
"Unhandled DebugSrcHashKind enum");
572std::optional<StringRef> CGDebugInfo::getSource(
const SourceManager &SM,
574 if (!CGM.getCodeGenOpts().EmbedSource)
577 bool SourceInvalid =
false;
586llvm::DIFile *CGDebugInfo::getOrCreateFile(SourceLocation Loc) {
587 SourceManager &SM = CGM.getContext().getSourceManager();
590 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
596 FileName = TheCU->getFile()->getFilename();
597 CSInfo = TheCU->getFile()->getChecksum();
600 if (Loc == CurLoc && CurLocFile)
607 FileName = TheCU->getFile()->getFilename();
615 auto It = DIFileCache.find(
FileName.data());
616 if (It != DIFileCache.end()) {
618 if (llvm::Metadata *
V = It->second)
623 SmallString<64> Checksum;
625 std::optional<llvm::DIFile::ChecksumKind> CSKind =
626 computeChecksum(FID, Checksum);
628 CSInfo.emplace(*CSKind, Checksum);
634llvm::DIFile *CGDebugInfo::createFile(
636 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo,
637 std::optional<StringRef> Source) {
641 std::string CurDir =
remapDIPath(getCurrentDirname());
642 SmallString<128> DirBuf;
643 SmallString<128> FileBuf;
644 if (llvm::sys::path::is_absolute(RemappedFile)) {
647 auto FileIt = llvm::sys::path::begin(RemappedFile);
648 auto FileE = llvm::sys::path::end(RemappedFile);
649 auto CurDirIt = llvm::sys::path::begin(CurDir);
650 auto CurDirE = llvm::sys::path::end(CurDir);
651 for (; CurDirIt != CurDirE && *CurDirIt == *FileIt; ++CurDirIt, ++FileIt)
652 llvm::sys::path::append(DirBuf, *CurDirIt);
653 if (llvm::sys::path::root_path(DirBuf) == DirBuf) {
659 for (; FileIt != FileE; ++FileIt)
660 llvm::sys::path::append(FileBuf, *FileIt);
665 if (!llvm::sys::path::is_absolute(
FileName))
669 llvm::DIFile *F = DBuilder.createFile(
File, Dir, CSInfo, Source);
670 DIFileCache[
FileName.data()].reset(F);
676 for (
auto &[From, To] : llvm::reverse(CGM.getCodeGenOpts().DebugPrefixMap))
677 if (llvm::sys::path::replace_path_prefix(P, From, To))
679 return P.str().str();
687 if (DebugLoc == CurLoc)
702 if (DebugLoc == CurLoc)
708StringRef CGDebugInfo::getCurrentDirname() {
716 assert(CGO.DwarfVersion <= 5);
718 llvm::dwarf::SourceLanguage LangTag;
721 LangTag = llvm::dwarf::DW_LANG_HLSL;
723 LangTag = llvm::dwarf::DW_LANG_HIP;
725 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
726 else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
727 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
728 else if (LO.CPlusPlus14)
729 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
730 else if (LO.CPlusPlus11)
731 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
733 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
734 }
else if (LO.ObjC) {
735 LangTag = llvm::dwarf::DW_LANG_ObjC;
736 }
else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
737 LangTag = llvm::dwarf::DW_LANG_OpenCL;
738 }
else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
739 LangTag = llvm::dwarf::DW_LANG_C11;
741 LangTag = llvm::dwarf::DW_LANG_C99;
743 LangTag = llvm::dwarf::DW_LANG_C89;
749static llvm::DISourceLanguageName
758 llvm::dwarf::SourceLanguageName LangTag;
761 LangTag = llvm::dwarf::DW_LNAME_HLSL;
763 LangTag = llvm::dwarf::DW_LNAME_HIP;
764 }
else if (LO.ObjC) {
765 LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
767 LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
770 }
else if (LO.ObjC) {
771 LangTag = llvm::dwarf::DW_LNAME_ObjC;
772 }
else if (LO.OpenCL) {
773 LangTag = llvm::dwarf::DW_LNAME_OpenCL_C;
775 LangTag = llvm::dwarf::DW_LNAME_C;
779 return llvm::DISourceLanguageName(LangTag, LangVersion);
782void CGDebugInfo::CreateCompileUnit() {
783 SmallString<64> Checksum;
784 std::optional<llvm::DIFile::ChecksumKind> CSKind;
785 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
795 SourceManager &SM = CGM.getContext().getSourceManager();
796 auto &CGO = CGM.getCodeGenOpts();
797 const LangOptions &LO = CGM.getLangOpts();
798 std::string MainFileName = CGO.MainFileName;
799 if (MainFileName.empty())
800 MainFileName =
"<stdin>";
806 std::string MainFileDir;
809 MainFileDir = std::string(MainFile->getDir().getName());
810 if (!llvm::sys::path::is_absolute(MainFileName)) {
811 llvm::SmallString<1024> MainFileDirSS(MainFileDir);
812 llvm::sys::path::Style Style =
814 ? (CGM.getTarget().
getTriple().isOSWindows()
815 ? llvm::sys::path::Style::windows_backslash
816 : llvm::sys::path::Style::posix)
817 : llvm::sys::path::Style::native;
818 llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
819 MainFileName = std::string(
820 llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
827 if (MainFile->getName() == MainFileName &&
829 MainFile->getName().rsplit(
'.').second)
831 MainFileName = CGM.getModule().getName().str();
840 unsigned RuntimeVers = 0;
844 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
846 case llvm::codegenoptions::NoDebugInfo:
847 case llvm::codegenoptions::LocTrackingOnly:
848 EmissionKind = llvm::DICompileUnit::NoDebug;
850 case llvm::codegenoptions::DebugLineTablesOnly:
851 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
853 case llvm::codegenoptions::DebugDirectivesOnly:
854 EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
856 case llvm::codegenoptions::DebugInfoConstructor:
857 case llvm::codegenoptions::LimitedDebugInfo:
858 case llvm::codegenoptions::FullDebugInfo:
859 case llvm::codegenoptions::UnusedTypeInfo:
860 EmissionKind = llvm::DICompileUnit::FullDebug;
865 auto &CGOpts = CGM.getCodeGenOpts();
871 CSInfo.emplace(*CSKind, Checksum);
872 llvm::DIFile *CUFile = DBuilder.createFile(
876 StringRef Sysroot, SDK;
877 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
878 StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
879 if (CGM.getCodeGenOpts().DebugRecordSysroot)
880 Sysroot = FullSysroot;
881 auto B = llvm::sys::path::rbegin(FullSysroot);
882 auto E = llvm::sys::path::rend(FullSysroot);
884 std::find_if(B, E, [](
auto SDK) {
return SDK.ends_with(
".sdk"); });
889 llvm::DICompileUnit::DebugNameTableKind NameTableKind =
890 static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
891 CGOpts.DebugNameTable);
892 if (CGM.getTarget().getTriple().isNVPTX())
893 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
894 else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
895 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
898 TheCU = DBuilder.createCompileUnit(
900 CGOpts.EmitVersionIdentMetadata ? Producer :
"",
901 CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
902 CGOpts.PrepareForThinLTO,
903 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
904 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
905 NameTableKind, CGOpts.DebugRangesBaseAddress,
remapDIPath(Sysroot), SDK);
908llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
912#define BUILTIN_TYPE(Id, SingletonId)
913#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
914#include "clang/AST/BuiltinTypes.def"
915 case BuiltinType::Dependent:
916 llvm_unreachable(
"Unexpected builtin type");
917 case BuiltinType::NullPtr:
918 return DBuilder.createNullPtrType();
919 case BuiltinType::Void:
921 case BuiltinType::ObjCClass:
924 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
925 "objc_class", TheCU, TheCU->getFile(), 0);
927 case BuiltinType::ObjCId: {
938 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
939 "objc_class", TheCU, TheCU->getFile(), 0);
941 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
943 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
945 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
946 (uint64_t)0, 0, llvm::DINode::FlagZero,
947 nullptr, llvm::DINodeArray());
949 DBuilder.replaceArrays(
950 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
951 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
952 llvm::DINode::FlagZero, ISATy)));
955 case BuiltinType::ObjCSel: {
957 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
958 "objc_selector", TheCU,
959 TheCU->getFile(), 0);
963#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
964 case BuiltinType::Id: \
965 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
967#include "clang/Basic/OpenCLImageTypes.def"
968 case BuiltinType::OCLSampler:
969 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
970 case BuiltinType::OCLEvent:
971 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
972 case BuiltinType::OCLClkEvent:
973 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
974 case BuiltinType::OCLQueue:
975 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
976 case BuiltinType::OCLReserveID:
977 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
978#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
979 case BuiltinType::Id: \
980 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
981#include "clang/Basic/OpenCLExtensionTypes.def"
982#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
983 case BuiltinType::Id: \
984 return getOrCreateStructPtrType(#Name, SingletonId);
985#include "clang/Basic/HLSLIntangibleTypes.def"
987#define SVE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
988#include "clang/Basic/AArch64ACLETypes.def"
990 if (BT->
getKind() == BuiltinType::MFloat8) {
991 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
992 BTName = BT->
getName(CGM.getLangOpts());
995 return DBuilder.createBasicType(BTName, Size, Encoding);
997 ASTContext::BuiltinVectorTypeInfo Info =
999 BT->
getKind() == BuiltinType::SveCount
1000 ? ASTContext::BuiltinVectorTypeInfo(
1001 CGM.getContext().BoolTy, llvm::ElementCount::getFixed(16),
1003 : CGM.getContext().getBuiltinVectorTypeInfo(BT);
1010 "Unsupported number of vectors for svcount_t");
1012 unsigned NumElems = Info.
EC.getKnownMinValue() * Info.
NumVectors;
1013 llvm::Metadata *BitStride =
nullptr;
1014 if (BT->
getKind() == BuiltinType::SveBool) {
1015 Info.
ElementType = CGM.getContext().UnsignedCharTy;
1016 BitStride = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1017 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 1));
1018 }
else if (BT->
getKind() == BuiltinType::SveCount) {
1020 Info.
ElementType = CGM.getContext().UnsignedCharTy;
1023 llvm::Metadata *LowerBound, *UpperBound;
1024 LowerBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1025 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 0));
1026 if (Info.
EC.isScalable()) {
1027 unsigned NumElemsPerVG = NumElems / 2;
1028 SmallVector<uint64_t, 9> Expr(
1029 {llvm::dwarf::DW_OP_constu, NumElemsPerVG, llvm::dwarf::DW_OP_bregx,
1030 46, 0, llvm::dwarf::DW_OP_mul,
1031 llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
1032 UpperBound = DBuilder.createExpression(Expr);
1034 UpperBound = llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1035 llvm::Type::getInt64Ty(CGM.getLLVMContext()), NumElems - 1));
1037 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
1038 nullptr, LowerBound, UpperBound,
nullptr);
1039 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
1040 llvm::DIType *ElemTy =
1041 getOrCreateType(Info.
ElementType, TheCU->getFile());
1043 return DBuilder.createVectorType( 0, Align, ElemTy,
1044 SubscriptArray, BitStride);
1048#define PPC_VECTOR_TYPE(Name, Id, size) \
1049 case BuiltinType::Id:
1050#include "clang/Basic/PPCTypes.def"
1053#define RVV_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
1054#include "clang/Basic/RISCVVTypes.def"
1056 ASTContext::BuiltinVectorTypeInfo Info =
1057 CGM.getContext().getBuiltinVectorTypeInfo(BT);
1059 unsigned ElementCount = Info.
EC.getKnownMinValue();
1060 unsigned SEW = CGM.getContext().getTypeSize(Info.
ElementType);
1062 bool Fractional =
false;
1065 unsigned FixedSize = ElementCount * SEW;
1066 if (Info.
ElementType == CGM.getContext().BoolTy) {
1069 }
else if (FixedSize < 64) {
1072 LMUL = 64 / FixedSize;
1074 LMUL = FixedSize / 64;
1078 SmallVector<uint64_t, 12> Expr(
1082 {llvm::dwarf::DW_OP_bregx,
1085 llvm::dwarf::DW_OP_constu,
1087 llvm::dwarf::DW_OP_div, llvm::dwarf::DW_OP_constu, LMUL});
1089 Expr.push_back(llvm::dwarf::DW_OP_div);
1091 Expr.push_back(llvm::dwarf::DW_OP_mul);
1094 Expr.append({llvm::dwarf::DW_OP_constu, NFIELDS, llvm::dwarf::DW_OP_mul});
1096 Expr.append({llvm::dwarf::DW_OP_constu, 1, llvm::dwarf::DW_OP_minus});
1099 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
1100 llvm::Type::getInt64Ty(CGM.getLLVMContext()), 0));
1101 auto *UpperBound = DBuilder.createExpression(Expr);
1102 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(
1103 nullptr, LowerBound, UpperBound,
nullptr);
1104 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
1105 llvm::DIType *ElemTy =
1106 getOrCreateType(Info.
ElementType, TheCU->getFile());
1109 return DBuilder.createVectorType(0, Align, ElemTy,
1113#define WASM_REF_TYPE(Name, MangledName, Id, SingletonId, AS) \
1114 case BuiltinType::Id: { \
1117 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, \
1118 MangledName, TheCU, TheCU->getFile(), 0); \
1119 return SingletonId; \
1121#include "clang/Basic/WebAssemblyReferenceTypes.def"
1122#define AMDGPU_OPAQUE_PTR_TYPE(Name, Id, SingletonId, Width, Align, AS) \
1123 case BuiltinType::Id: { \
1126 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name, \
1127 TheCU, TheCU->getFile(), 0); \
1128 return SingletonId; \
1130#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope) \
1131 case BuiltinType::Id: { \
1134 DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); \
1135 return SingletonId; \
1137#define AMDGPU_FEATURE_PREDICATE_TYPE(Name, Id, SingletonId, Width, Align) \
1138 case BuiltinType::Id: { \
1141 DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_boolean); \
1142 return SingletonId; \
1144#include "clang/Basic/AMDGPUTypes.def"
1145#define SPIRV_TYPE(Name, Id, SingletonId) \
1146 case BuiltinType::Id: \
1147 return getOrCreateStructPtrType(Name, SingletonId);
1148#include "clang/Basic/SPIRVTypes.def"
1149 case BuiltinType::UChar:
1150 case BuiltinType::Char_U:
1151 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
1153 case BuiltinType::Char_S:
1154 case BuiltinType::SChar:
1155 Encoding = llvm::dwarf::DW_ATE_signed_char;
1157 case BuiltinType::Char8:
1158 case BuiltinType::Char16:
1159 case BuiltinType::Char32:
1160 Encoding = llvm::dwarf::DW_ATE_UTF;
1162 case BuiltinType::UShort:
1163 case BuiltinType::UInt:
1164 case BuiltinType::UInt128:
1165 case BuiltinType::ULong:
1166 case BuiltinType::WChar_U:
1167 case BuiltinType::ULongLong:
1168 Encoding = llvm::dwarf::DW_ATE_unsigned;
1170 case BuiltinType::Short:
1171 case BuiltinType::Int:
1172 case BuiltinType::Int128:
1173 case BuiltinType::Long:
1174 case BuiltinType::WChar_S:
1175 case BuiltinType::LongLong:
1176 Encoding = llvm::dwarf::DW_ATE_signed;
1178 case BuiltinType::Bool:
1179 Encoding = llvm::dwarf::DW_ATE_boolean;
1181 case BuiltinType::Half:
1182 case BuiltinType::Float:
1183 case BuiltinType::LongDouble:
1184 case BuiltinType::Float16:
1185 case BuiltinType::BFloat16:
1186 case BuiltinType::Float128:
1187 case BuiltinType::Double:
1188 case BuiltinType::Ibm128:
1194 Encoding = llvm::dwarf::DW_ATE_float;
1196 case BuiltinType::ShortAccum:
1197 case BuiltinType::Accum:
1198 case BuiltinType::LongAccum:
1199 case BuiltinType::ShortFract:
1200 case BuiltinType::Fract:
1201 case BuiltinType::LongFract:
1202 case BuiltinType::SatShortFract:
1203 case BuiltinType::SatFract:
1204 case BuiltinType::SatLongFract:
1205 case BuiltinType::SatShortAccum:
1206 case BuiltinType::SatAccum:
1207 case BuiltinType::SatLongAccum:
1208 Encoding = llvm::dwarf::DW_ATE_signed_fixed;
1210 case BuiltinType::UShortAccum:
1211 case BuiltinType::UAccum:
1212 case BuiltinType::ULongAccum:
1213 case BuiltinType::UShortFract:
1214 case BuiltinType::UFract:
1215 case BuiltinType::ULongFract:
1216 case BuiltinType::SatUShortAccum:
1217 case BuiltinType::SatUAccum:
1218 case BuiltinType::SatULongAccum:
1219 case BuiltinType::SatUShortFract:
1220 case BuiltinType::SatUFract:
1221 case BuiltinType::SatULongFract:
1222 Encoding = llvm::dwarf::DW_ATE_unsigned_fixed;
1226 BTName = BT->
getName(CGM.getLangOpts());
1229 return DBuilder.createBasicType(BTName, Size, Encoding);
1232llvm::DIType *CGDebugInfo::CreateType(
const BitIntType *Ty) {
1233 SmallString<32> Name;
1234 llvm::raw_svector_ostream
OS(Name);
1235 OS << (Ty->
isUnsigned() ?
"unsigned _BitInt(" :
"_BitInt(")
1238 ? llvm::dwarf::DW_ATE_unsigned
1239 : llvm::dwarf::DW_ATE_signed;
1240 return DBuilder.createBasicType(Name, CGM.getContext().getTypeSize(Ty),
1241 Encoding, llvm::DINode::FlagZero, 0,
1245llvm::DIType *CGDebugInfo::CreateType(
const OverflowBehaviorType *Ty,
1247 return getOrCreateType(Ty->getUnderlyingType(), U);
1250llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
1252 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
1254 Encoding = llvm::dwarf::DW_ATE_lo_user;
1257 return DBuilder.createBasicType(
"complex", Size, Encoding);
1271 return llvm::dwarf::DW_TAG_const_type;
1275 return llvm::dwarf::DW_TAG_volatile_type;
1279 return llvm::dwarf::DW_TAG_restrict_type;
1281 return (llvm::dwarf::Tag)0;
1284llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty,
1285 llvm::DIFile *Unit) {
1286 QualifierCollector Qc;
1300 bool AuthenticatesNullValues =
1303 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1304 llvm::DIType *FromTy = getOrCreateType(QualType(
T, 0), Unit);
1305 return DBuilder.createPtrAuthQualifiedType(FromTy, Key, IsDiscr,
1306 ExtraDiscr, IsaPointer,
1307 AuthenticatesNullValues);
1309 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1310 return getOrCreateType(QualType(
T, 0), Unit);
1314 auto *FromTy = getOrCreateType(Qc.
apply(CGM.getContext(),
T), Unit);
1318 return DBuilder.createQualifiedType(Tag, FromTy);
1321llvm::DIType *CGDebugInfo::CreateQualifiedType(
const FunctionProtoType *F,
1322 llvm::DIFile *Unit) {
1331 assert(Q.
empty() &&
"Unknown type qualifier for debug info");
1336 getOrCreateType(CGM.getContext().getFunctionType(F->
getReturnType(),
1342 return DBuilder.createQualifiedType(Tag, FromTy);
1345llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectPointerType *Ty,
1346 llvm::DIFile *Unit) {
1352 return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
1354 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1358llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
1359 llvm::DIFile *Unit) {
1360 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1366 case llvm::dwarf::DW_LANG_C_plus_plus:
1367 case llvm::dwarf::DW_LANG_C_plus_plus_11:
1368 case llvm::dwarf::DW_LANG_C_plus_plus_14:
1369 case llvm::dwarf::DW_LANG_HIP:
1371 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
1381 case llvm::dwarf::DW_LNAME_C_plus_plus:
1382 case llvm::dwarf::DW_LNAME_HIP:
1384 case llvm::dwarf::DW_LNAME_ObjC_plus_plus:
1395 if (llvm::DISourceLanguageName SourceLang = TheCU->getSourceLanguage();
1396 SourceLang.hasVersionedName())
1398 static_cast<llvm::dwarf::SourceLanguageName
>(SourceLang.getName()),
1402 static_cast<llvm::dwarf::SourceLanguage
>(SourceLang.getName()),
1428 llvm::DICompileUnit *TheCU) {
1446 llvm::DICompileUnit *TheCU) {
1452 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
1454 if (RD->isDynamicClass() &&
1460 llvm::raw_svector_ostream Out(Identifier);
1467 llvm::dwarf::Tag Tag;
1469 Tag = llvm::dwarf::DW_TAG_structure_type;
1471 Tag = llvm::dwarf::DW_TAG_union_type;
1476 Tag = llvm::dwarf::DW_TAG_class_type;
1481llvm::DICompositeType *
1482CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
1483 llvm::DIScope *Ctx) {
1485 if (llvm::DIType *
T = getTypeOrNull(QualType(Ty, 0)))
1487 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
1488 const unsigned Line =
1490 StringRef RDName = getClassName(RD);
1497 Size = CGM.getContext().getTypeSize(Ty);
1499 llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
1504 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1505 if (!CXXRD->hasDefinition() ||
1506 (CXXRD->hasDefinition() && !CXXRD->isTrivial()))
1507 Flags |= llvm::DINode::FlagNonTrivial;
1510 SmallString<256> Identifier;
1512 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
1514 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
1517 if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
1518 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
1519 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
1520 CollectCXXTemplateParams(TSpecial, DefUnit));
1521 ReplaceMap.emplace_back(
1522 std::piecewise_construct, std::make_tuple(Ty),
1523 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
1527llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
1530 llvm::DIFile *Unit) {
1535 std::optional<unsigned> DWARFAddressSpace =
1536 CGM.getTarget().getDWARFAddressSpace(
1537 CGM.getTypes().getTargetAddressSpace(PointeeTy));
1539 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1540 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type) {
1541 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1542 Size, Align, DWARFAddressSpace);
1544 SmallVector<llvm::Metadata *, 4> Annots;
1545 CollectBTFTypeTagAnnotations(PointeeTy, Annots);
1547 llvm::DINodeArray Annotations =
nullptr;
1548 if (Annots.size() > 0)
1549 Annotations = DBuilder.getOrCreateArray(Annots);
1550 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1551 Align, DWARFAddressSpace, StringRef(),
1556llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1557 llvm::DIType *&
Cache) {
1560 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1561 TheCU, TheCU->getFile(), 0);
1562 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1563 Cache = DBuilder.createPointerType(
Cache, Size);
1567uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1568 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1569 unsigned LineNo, SmallVectorImpl<llvm::Metadata *> &EltTys) {
1579 if (CGM.getLangOpts().OpenCL) {
1580 FType = CGM.getContext().IntTy;
1581 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1582 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1584 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1585 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1586 FType = CGM.getContext().IntTy;
1587 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1588 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1590 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1591 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1592 uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
1593 uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
1594 EltTys.push_back(DBuilder.createMemberType(
1595 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1596 FieldOffset, llvm::DINode::FlagZero, DescTy));
1597 FieldOffset += FieldSize;
1603llvm::DIType *CGDebugInfo::CreateType(
const BlockPointerType *Ty,
1604 llvm::DIFile *Unit) {
1605 SmallVector<llvm::Metadata *, 8> EltTys;
1608 llvm::DINodeArray Elements;
1611 FType = CGM.getContext().UnsignedLongTy;
1612 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1613 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1615 Elements = DBuilder.getOrCreateArray(EltTys);
1618 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1621 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1622 FieldOffset, 0, Flags,
nullptr, Elements);
1627 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1629 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1632 Elements = DBuilder.getOrCreateArray(EltTys);
1638 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1639 Flags,
nullptr, Elements);
1641 return DBuilder.createPointerType(EltTy, Size);
1644static llvm::SmallVector<TemplateArgument>
1646 assert(Ty->isTypeAlias());
1655 ArrayRef SubstArgs = Ty->template_arguments();
1658 if (Param->isParameterPack()) {
1667 if (SubstArgs.empty()) {
1676 SpecArgs.push_back(SubstArgs.front());
1677 SubstArgs = SubstArgs.drop_front();
1682llvm::DIType *CGDebugInfo::CreateType(
const TemplateSpecializationType *Ty,
1683 llvm::DIFile *Unit) {
1684 assert(Ty->isTypeAlias());
1685 llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
1687 const TemplateDecl *TD = Ty->getTemplateName().getAsTemplateDecl();
1695 SmallString<128> NS;
1696 llvm::raw_svector_ostream
OS(NS);
1698 auto PP = getPrintingPolicy();
1701 SourceLocation Loc =
AliasDecl->getLocation();
1703 if (CGM.getCodeGenOpts().DebugTemplateAlias) {
1704 auto ArgVector = ::GetTemplateArgs(TD, Ty);
1713 llvm::raw_string_ostream
OS(Name);
1715 if (CGM.getCodeGenOpts().getDebugSimpleTemplateNames() !=
1716 llvm::codegenoptions::DebugTemplateNamesKind::Simple ||
1717 !HasReconstitutableArgs(Args.Args))
1718 printTemplateArgumentList(OS, Args.Args, PP);
1720 llvm::DIDerivedType *AliasTy = DBuilder.createTemplateAlias(
1721 Src, Name, getOrCreateFile(Loc), getLineNumber(Loc),
1722 getDeclContextDescriptor(
AliasDecl), CollectTemplateParams(Args, Unit));
1726 printTemplateArgumentList(OS, Ty->template_arguments(), PP,
1728 return DBuilder.createTypedef(Src,
OS.str(), getOrCreateFile(Loc),
1745 return llvm::DINode::FlagZero;
1749 return llvm::DINode::FlagPrivate;
1751 return llvm::DINode::FlagProtected;
1753 return llvm::DINode::FlagPublic;
1755 return llvm::DINode::FlagZero;
1757 llvm_unreachable(
"unexpected access enumerator");
1760llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1761 llvm::DIFile *Unit) {
1762 llvm::DIType *Underlying =
1778 SmallVector<llvm::Metadata *, 4> Annots;
1779 llvm::DINodeArray Annotations;
1781 CollectBTFDeclTagAnnotations(Ty->
getDecl(), Annots);
1782 if (!Annots.empty())
1783 Annotations = DBuilder.getOrCreateArray(Annots);
1785 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1790 return DBuilder.createTypedef(Underlying, Ty->
getDecl()->
getName(),
1791 getOrCreateFile(Loc), getLineNumber(Loc),
1792 getDeclContextDescriptor(Ty->
getDecl()), Align,
1793 Flags, Annotations);
1803 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1805 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1807 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1809 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1811 return llvm::dwarf::DW_CC_BORLAND_pascal;
1813 return llvm::dwarf::DW_CC_LLVM_Win64;
1815 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1819 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1821 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1823 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1825 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1827 return llvm::dwarf::DW_CC_LLVM_DeviceKernel;
1829 return llvm::dwarf::DW_CC_LLVM_Swift;
1831 return llvm::dwarf::DW_CC_LLVM_SwiftTail;
1833 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1835 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1837 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1839 return llvm::dwarf::DW_CC_LLVM_M68kRTD;
1841 return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1843 return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
1844#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
1858 return llvm::dwarf::DW_CC_LLVM_RISCVVLSCall;
1864 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1866 Flags |= llvm::DINode::FlagLValueReference;
1868 Flags |= llvm::DINode::FlagRValueReference;
1872llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1873 llvm::DIFile *Unit) {
1874 const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
1876 if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
1882 SmallVector<llvm::Metadata *, 16> EltTys;
1885 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1887 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1891 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1894 for (
const QualType &ParamType : FPT->param_types())
1895 EltTys.push_back(getOrCreateType(ParamType, Unit));
1896 if (FPT->isVariadic())
1897 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1900 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1901 llvm::DIType *F = DBuilder.createSubroutineType(
1906llvm::DIDerivedType *
1907CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1908 llvm::DIScope *RecordTy,
const RecordDecl *RD) {
1909 StringRef Name = BitFieldDecl->
getName();
1910 QualType Ty = BitFieldDecl->
getType();
1911 if (BitFieldDecl->
hasAttr<PreferredTypeAttr>())
1914 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1915 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1918 llvm::DIFile *
File = getOrCreateFile(Loc);
1919 unsigned Line = getLineNumber(Loc);
1921 const CGBitFieldInfo &BitFieldInfo =
1922 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1924 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1931 if (CGM.getDataLayout().isBigEndian())
1933 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1935 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(BitFieldDecl);
1936 return DBuilder.createBitFieldMemberType(
1937 RecordTy, Name,
File,
Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1938 Flags, DebugType, Annotations);
1941llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
1942 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
1943 llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI,
const RecordDecl *RD) {
1945 if (!CGM.getTargetCodeGenInfo().shouldEmitDWARFBitFieldSeparators())
1970 if (PreviousFieldsDI.empty())
1974 auto *PreviousMDEntry =
1975 PreviousFieldsDI.empty() ?
nullptr : PreviousFieldsDI.back();
1976 auto *PreviousMDField =
1977 dyn_cast_or_null<llvm::DIDerivedType>(PreviousMDEntry);
1978 if (!PreviousMDField || !PreviousMDField->isBitField() ||
1979 PreviousMDField->getSizeInBits() == 0)
1983 std::advance(PreviousBitfield, BitFieldDecl->
getFieldIndex() - 1);
1985 assert(PreviousBitfield->isBitField());
1987 if (!PreviousBitfield->isZeroLengthBitField())
1990 QualType Ty = PreviousBitfield->getType();
1991 SourceLocation Loc = PreviousBitfield->getLocation();
1992 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1993 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1994 llvm::DIScope *RecordTy = BitFieldDI->getScope();
1996 llvm::DIFile *
File = getOrCreateFile(Loc);
1997 unsigned Line = getLineNumber(Loc);
2003 llvm::DINode::DIFlags Flags =
2005 llvm::DINodeArray Annotations =
2006 CollectBTFDeclTagAnnotations(*PreviousBitfield);
2007 return DBuilder.createBitFieldMemberType(
2008 RecordTy,
"",
File,
Line, 0, StorageOffsetInBits, StorageOffsetInBits,
2009 Flags, DebugType, Annotations);
2012llvm::DIType *CGDebugInfo::createFieldType(
2014 uint64_t offsetInBits,
uint32_t AlignInBits, llvm::DIFile *tunit,
2015 llvm::DIScope *scope,
const RecordDecl *RD, llvm::DINodeArray Annotations) {
2016 llvm::DIType *debugType = getOrCreateType(
type, tunit);
2019 llvm::DIFile *file = getOrCreateFile(loc);
2020 const unsigned line = getLineNumber(loc.
isValid() ? loc : CurLoc);
2023 auto Align = AlignInBits;
2024 if (!
type->isIncompleteArrayType()) {
2025 TypeInfo TI = CGM.getContext().getTypeInfo(
type);
2026 SizeInBits = TI.
Width;
2032 return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
2033 offsetInBits, flags, debugType, Annotations);
2037CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
2038 llvm::DIFile *FileScope) {
2042 llvm::DISubprogram *&SP = InlinedSubprogramMap[FuncName];
2045 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(
nullptr);
2046 SP = DBuilder.createFunction(
2047 FileScope, FuncName, StringRef(),
2048 FileScope, 0, DIFnTy,
2050 llvm::DINode::FlagArtificial,
2051 llvm::DISubprogram::SPFlagDefinition,
2052 nullptr,
nullptr,
nullptr,
2053 nullptr, StringRef(),
2054 CGM.getCodeGenOpts().DebugKeyInstructions);
2061CGDebugInfo::GetLambdaCaptureName(
const LambdaCapture &
Capture) {
2063 return CGM.getCodeGenOpts().EmitCodeView ?
"__this" :
"this";
2065 assert(
Capture.capturesVariable());
2067 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2068 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2070 return CaptureDecl->
getName();
2073void CGDebugInfo::CollectRecordLambdaFields(
2074 const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
2075 llvm::DIType *RecordTy) {
2080 unsigned fieldno = 0;
2083 I != E; ++I, ++Field, ++fieldno) {
2084 const LambdaCapture &
Capture = *I;
2086 CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
2088 assert(!
Field->isBitField() &&
"lambdas don't have bitfield members!");
2098 Loc =
Field->getLocation();
2099 }
else if (
Capture.capturesVariable()) {
2102 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2103 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2110 llvm::DIFile *VUnit = getOrCreateFile(Loc);
2112 elements.push_back(createFieldType(
2114 Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
2120template <
typename T>
2121static llvm::Constant *
2132 return llvm::ConstantDataArray::get(Ctx, Vals);
2145 const QualType ElemQTy = ArrayTy->getElementType();
2152 switch (ElemBitWidth) {
2168llvm::DIDerivedType *
2169CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
2170 const RecordDecl *RD) {
2174 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
2175 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
2177 unsigned LineNumber = getLineNumber(Var->
getLocation());
2178 StringRef VName = Var->
getName();
2182 llvm::Constant *
C =
nullptr;
2187 C = llvm::ConstantInt::get(CGM.getLLVMContext(),
Value->getInt());
2188 if (
Value->isFloat())
2189 C = llvm::ConstantFP::get(CGM.getLLVMContext(),
Value->getFloat());
2190 if (
Value->isArray())
2196 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2197 ? llvm::dwarf::DW_TAG_variable
2198 : llvm::dwarf::DW_TAG_member;
2200 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
2201 RecordTy, VName, VUnit, LineNumber, VTy, Flags,
C, Tag, Align);
2206void CGDebugInfo::CollectRecordNormalField(
2207 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
2208 SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
2209 const RecordDecl *RD) {
2214 if (
name.empty() && !
type->isRecordType())
2217 llvm::DIType *FieldType;
2219 llvm::DIDerivedType *BitFieldType;
2220 FieldType = BitFieldType = createBitFieldType(field, RecordTy, RD);
2221 if (llvm::DIType *Separator =
2222 createBitFieldSeparatorIfNeeded(field, BitFieldType, elements, RD))
2223 elements.push_back(Separator);
2226 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
2229 OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
2232 elements.push_back(FieldType);
2235void CGDebugInfo::CollectRecordNestedType(
2236 const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) {
2237 QualType Ty = CGM.getContext().getTypeDeclType(TD);
2244 if (llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)))
2245 elements.push_back(nestedType);
2248void CGDebugInfo::CollectRecordFields(
2249 const RecordDecl *record, llvm::DIFile *tunit,
2250 SmallVectorImpl<llvm::Metadata *> &elements,
2251 llvm::DICompositeType *RecordTy) {
2252 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
2254 if (CXXDecl && CXXDecl->
isLambda())
2255 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
2257 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
2260 unsigned fieldNo = 0;
2264 for (
const auto *I : record->
decls())
2265 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
2266 if (
V->hasAttr<NoDebugAttr>())
2271 if (CGM.getCodeGenOpts().EmitCodeView &&
2279 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
2280 if (MI != StaticDataMemberCache.end()) {
2281 assert(MI->second &&
2282 "Static data member declaration should still exist");
2283 elements.push_back(MI->second);
2285 auto Field = CreateRecordStaticField(
V, RecordTy, record);
2286 elements.push_back(Field);
2288 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
2289 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
2290 elements, RecordTy, record);
2294 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
2297 if (
const auto *nestedType = dyn_cast<TypeDecl>(I)) {
2302 if (!nestedType->isImplicit() &&
2303 nestedType->getDeclContext() == record)
2304 CollectRecordNestedType(nestedType, elements);
2310llvm::DISubroutineType *
2311CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *
Method,
2312 llvm::DIFile *Unit) {
2313 const FunctionProtoType *
Func =
Method->getType()->getAs<FunctionProtoType>();
2315 return cast_or_null<llvm::DISubroutineType>(
2316 getOrCreateType(QualType(
Func, 0), Unit));
2319 if (!
Method->hasCXXExplicitFunctionObjectParameter())
2320 ThisType =
Method->getThisType();
2322 return getOrCreateInstanceMethodType(ThisType,
Func, Unit);
2325llvm::DISubroutineType *CGDebugInfo::getOrCreateMethodTypeForDestructor(
2326 const CXXMethodDecl *
Method, llvm::DIFile *Unit, QualType FNType) {
2327 const FunctionProtoType *
Func = FNType->
getAs<FunctionProtoType>();
2329 return getOrCreateInstanceMethodType(
Method->getThisType(),
Func, Unit,
true);
2332llvm::DISubroutineType *
2333CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
2334 const FunctionProtoType *
Func,
2335 llvm::DIFile *Unit,
bool SkipFirst) {
2336 FunctionProtoType::ExtProtoInfo EPI =
Func->getExtProtoInfo();
2351 getOrCreateType(CGM.getContext().getFunctionType(
2352 Func->getReturnType(),
Func->getParamTypes(), EPI),
2354 llvm::DITypeArray Args = OriginalFunc->getTypeArray();
2355 assert(Args.size() &&
"Invalid number of arguments!");
2357 SmallVector<llvm::Metadata *, 16> Elts;
2360 Elts.push_back(Args[0]);
2362 const bool HasExplicitObjectParameter = ThisPtr.
isNull();
2366 if (!HasExplicitObjectParameter) {
2367 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2370 DBuilder.createObjectPointerType(ThisPtrType,
true);
2371 Elts.push_back(ThisPtrType);
2375 for (
unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i < e; ++i)
2376 Elts.push_back(Args[i]);
2379 if (HasExplicitObjectParameter) {
2380 assert(Elts.size() >= 2 && Args.size() >= 2 &&
2381 "Expected at least return type and object parameter.");
2382 Elts[1] = DBuilder.createObjectPointerType(Args[1],
false);
2385 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2387 return DBuilder.createSubroutineType(EltTypeArray, OriginalFunc->getFlags(),
2394 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
2402CGDebugInfo::GetMethodLinkageName(
const CXXMethodDecl *
Method)
const {
2405 const bool IsCtorOrDtor =
2408 if (IsCtorOrDtor && !CGM.getCodeGenOpts().DebugStructorDeclLinkageNames)
2415 if (IsCtorOrDtor && !CGM.getTarget().getCXXABI().hasConstructorVariants())
2418 if (
const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(
Method))
2421 if (
const auto *Dtor = llvm::dyn_cast<CXXDestructorDecl>(
Method))
2424 return CGM.getMangledName(
Method);
2427bool CGDebugInfo::shouldGenerateVirtualCallSite()
const {
2430 (CGM.getCodeGenOpts().DwarfVersion >= 5));
2433llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
2434 const CXXMethodDecl *
Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
2437 StringRef MethodName = getFunctionName(
Method);
2438 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(
Method, Unit);
2440 StringRef MethodLinkageName;
2447 MethodLinkageName = GetMethodLinkageName(
Method);
2450 llvm::DIFile *MethodDefUnit =
nullptr;
2451 unsigned MethodLine = 0;
2452 if (!
Method->isImplicit()) {
2453 MethodDefUnit = getOrCreateFile(
Method->getLocation());
2454 MethodLine = getLineNumber(
Method->getLocation());
2458 llvm::DIType *ContainingType =
nullptr;
2459 unsigned VIndex = 0;
2460 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2461 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
2462 int ThisAdjustment = 0;
2465 if (
Method->isPureVirtual())
2466 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
2468 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
2470 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2474 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(
Method);
2478 const auto *DD = dyn_cast<CXXDestructorDecl>(
Method);
2481 DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
2482 CGM.getContext().getLangOpts())
2486 MethodVFTableLocation ML =
2487 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
2495 if (
Method->size_overridden_methods() == 0)
2496 Flags |= llvm::DINode::FlagIntroducedVirtual;
2501 ThisAdjustment = CGM.getCXXABI()
2502 .getVirtualFunctionPrologueThisAdjustment(GD)
2505 ContainingType = RecordTy;
2508 if (
Method->getCanonicalDecl()->isDeleted())
2509 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
2511 if (
Method->isNoReturn())
2512 Flags |= llvm::DINode::FlagNoReturn;
2515 Flags |= llvm::DINode::FlagStaticMember;
2516 if (
Method->isImplicit())
2517 Flags |= llvm::DINode::FlagArtificial;
2519 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(
Method)) {
2520 if (CXXC->isExplicit())
2521 Flags |= llvm::DINode::FlagExplicit;
2522 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(
Method)) {
2523 if (CXXC->isExplicit())
2524 Flags |= llvm::DINode::FlagExplicit;
2526 if (
Method->hasPrototype())
2527 Flags |= llvm::DINode::FlagPrototyped;
2529 Flags |= llvm::DINode::FlagLValueReference;
2531 Flags |= llvm::DINode::FlagRValueReference;
2532 if (!
Method->isExternallyVisible())
2533 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2534 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
2535 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
2539 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor)
2540 if (
const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(
Method))
2543 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(
Method, Unit);
2544 llvm::DISubprogram *SP = DBuilder.createMethod(
2545 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
2546 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
2547 TParamsArray.get(),
nullptr,
2548 CGM.getCodeGenOpts().DebugKeyInstructions);
2550 SPCache[
Method->getCanonicalDecl()].reset(SP);
2555void CGDebugInfo::CollectCXXMemberFunctions(
2556 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2557 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy) {
2562 for (
const auto *I : RD->
decls()) {
2563 const auto *
Method = dyn_cast<CXXMethodDecl>(I);
2577 if (
Method->getType()->castAs<FunctionProtoType>()->getContainedAutoType())
2586 auto MI = SPCache.find(
Method->getCanonicalDecl());
2587 EltTys.push_back(MI == SPCache.end()
2588 ? CreateCXXMemberFunction(
Method, Unit, RecordTy)
2589 :
static_cast<llvm::Metadata *
>(MI->second));
2593void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2594 SmallVectorImpl<llvm::Metadata *> &EltTys,
2595 llvm::DIType *RecordTy) {
2596 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
2597 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
2598 llvm::DINode::FlagZero);
2602 if (CGM.getCodeGenOpts().EmitCodeView) {
2603 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
2604 llvm::DINode::FlagIndirectVirtualBase);
2608void CGDebugInfo::CollectCXXBasesAux(
2609 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2610 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
2612 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
2613 llvm::DINode::DIFlags StartingFlags) {
2614 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
2615 for (
const auto &BI : Bases) {
2618 BI.getType()->castAsCanonical<RecordType>()->getDecl())
2620 if (!SeenTypes.insert(Base).second)
2622 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
2623 llvm::DINode::DIFlags BFlags = StartingFlags;
2627 if (BI.isVirtual()) {
2628 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2631 BaseOffset = 0 - CGM.getItaniumVTableContext()
2632 .getVirtualBaseOffsetOffset(RD, Base)
2638 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
2639 VBPtrOffset = CGM.getContext()
2640 .getASTRecordLayout(RD)
2644 BFlags |= llvm::DINode::FlagVirtual;
2651 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
2652 VBPtrOffset, BFlags);
2653 EltTys.push_back(DTy);
2658CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
2659 llvm::DIFile *Unit) {
2661 return llvm::DINodeArray();
2662 TemplateArgs &Args = *OArgs;
2663 SmallVector<llvm::Metadata *, 16> TemplateParams;
2664 for (
unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
2665 const TemplateArgument &TA = Args.Args[i];
2669 Name = Args.TList->getParam(i)->getName();
2673 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
2674 TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
2675 TheCU, Name, TTy, defaultParameter));
2680 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2681 TheCU, Name, TTy, defaultParameter,
2682 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
2687 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2688 llvm::Constant *
V =
nullptr;
2691 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
2692 !D->
hasAttr<CUDADeviceAttr>()) {
2695 if (
const auto *VD = dyn_cast<VarDecl>(D))
2696 V = CGM.GetAddrOfGlobalVar(VD);
2699 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(D);
2700 MD && MD->isImplicitObjectMemberFunction())
2701 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
2702 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2703 V = CGM.GetAddrOfFunction(FD);
2706 else if (
const auto *MPT =
2707 dyn_cast<MemberPointerType>(
T.getTypePtr())) {
2711 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
2713 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
2714 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
2715 }
else if (
const auto *GD = dyn_cast<MSGuidDecl>(D)) {
2716 V = CGM.GetAddrOfMSGuidDecl(GD).getPointer();
2717 }
else if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(D)) {
2719 V = ConstantEmitter(CGM).emitAbstract(
2720 SourceLocation(), TPO->getValue(), TPO->getType());
2722 V = CGM.GetAddrOfTemplateParamObject(TPO).getPointer();
2724 assert(
V &&
"Failed to find template parameter pointer");
2725 V =
V->stripPointerCasts();
2727 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2728 TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(
V)));
2732 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2733 llvm::Constant *
V =
nullptr;
2736 if (
const auto *MPT = dyn_cast<MemberPointerType>(
T.getTypePtr()))
2742 if (MPT->isMemberDataPointer())
2743 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
2745 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
2746 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2747 TheCU, Name, TTy, defaultParameter,
V));
2751 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2752 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(
2754 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2755 TheCU, Name, TTy, defaultParameter,
V));
2758 std::string QualName;
2759 llvm::raw_string_ostream
OS(QualName);
2761 OS, getPrintingPolicy());
2762 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2763 TheCU, Name,
nullptr, QualName, defaultParameter));
2767 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
2768 TheCU, Name,
nullptr,
2775 T = CGM.getContext().getLValueReferenceType(
T);
2776 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(E,
T);
2777 assert(
V &&
"Expression in template argument isn't constant");
2778 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2779 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2780 TheCU, Name, TTy, defaultParameter,
V->stripPointerCasts()));
2786 "These argument types shouldn't exist in concrete types");
2789 return DBuilder.getOrCreateArray(TemplateParams);
2792std::optional<CGDebugInfo::TemplateArgs>
2793CGDebugInfo::GetTemplateArgs(
const FunctionDecl *FD)
const {
2801 return std::nullopt;
2803std::optional<CGDebugInfo::TemplateArgs>
2804CGDebugInfo::GetTemplateArgs(
const VarDecl *VD)
const {
2808 auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VD);
2810 return std::nullopt;
2811 VarTemplateDecl *
T = TS->getSpecializedTemplate();
2812 const TemplateParameterList *TList =
T->getTemplateParameters();
2813 auto TA = TS->getTemplateArgs().asArray();
2814 return {{TList, TA}};
2816std::optional<CGDebugInfo::TemplateArgs>
2817CGDebugInfo::GetTemplateArgs(
const RecordDecl *RD)
const {
2818 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2822 TemplateParameterList *TPList =
2823 TSpecial->getSpecializedTemplate()->getTemplateParameters();
2824 const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
2825 return {{TPList, TAList.
asArray()}};
2827 return std::nullopt;
2831CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
2832 llvm::DIFile *Unit) {
2833 return CollectTemplateParams(GetTemplateArgs(FD), Unit);
2836llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
2837 llvm::DIFile *Unit) {
2838 return CollectTemplateParams(GetTemplateArgs(VL), Unit);
2841llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
const RecordDecl *RD,
2842 llvm::DIFile *Unit) {
2843 return CollectTemplateParams(GetTemplateArgs(RD), Unit);
2846void CGDebugInfo::CollectBTFDeclTagAnnotations(
2847 const Decl *D, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2849 llvm::Metadata *Ops[2] = {
2850 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_decl_tag")),
2851 llvm::MDString::get(CGM.getLLVMContext(), I->getBTFDeclTag())};
2852 Annotations.push_back(llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2856llvm::DINodeArray CGDebugInfo::CollectBTFDeclTagAnnotations(
const Decl *D) {
2857 if (!D->
hasAttr<BTFDeclTagAttr>())
2860 SmallVector<llvm::Metadata *, 4> Annotations;
2861 CollectBTFDeclTagAnnotations(D, Annotations);
2862 return DBuilder.getOrCreateArray(Annotations);
2865void CGDebugInfo::CollectBTFTypeTagAnnotations(
2866 QualType Ty, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2867 const BTFTagAttributedType *BTFAttrTy;
2869 BTFAttrTy = dyn_cast<BTFTagAttributedType>(
Atomic->getValueType());
2871 BTFAttrTy = dyn_cast<BTFTagAttributedType>(Ty);
2874 StringRef
Tag = BTFAttrTy->getAttr()->getBTFTypeTag();
2876 llvm::Metadata *Ops[2] = {
2877 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_type_tag")),
2878 llvm::MDString::get(CGM.getLLVMContext(), Tag)};
2879 Annotations.insert(Annotations.begin(),
2880 llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2882 BTFAttrTy = dyn_cast<BTFTagAttributedType>(BTFAttrTy->getWrappedType());
2886llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
2888 return VTablePtrType;
2890 ASTContext &Context = CGM.getContext();
2893 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
2894 llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy);
2895 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
2897 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2898 std::optional<unsigned> DWARFAddressSpace =
2899 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2901 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
2902 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2903 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
2904 return VTablePtrType;
2907StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
2919 if (!CGM.getTarget().getCXXABI().isItaniumFamily())
2921 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
2931 if (CGM.getTarget().getTriple().isOSBinFormatCOFF() &&
2932 VTable->isDeclarationForLinker())
2936 StringRef SymbolName =
"__clang_vtable";
2938 QualType VoidPtr = Context.getPointerType(Context.VoidTy);
2947 llvm::DIScope *DContext = getContextDescriptor(RD, TheCU);
2949 llvm::DIFile *Unit = getOrCreateFile(Loc);
2950 llvm::DIType *VTy = getOrCreateType(VoidPtr, Unit);
2952 llvm::DINode::FlagArtificial;
2953 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2954 ? llvm::dwarf::DW_TAG_variable
2955 : llvm::dwarf::DW_TAG_member;
2956 llvm::DIDerivedType *DT = DBuilder.createStaticMemberType(
2957 Ctxt, SymbolName, Unit, 0, VTy, Flags,
2961 unsigned PAlign = CGM.getVtableGlobalVarAlignment();
2965 llvm::DIGlobalVariableExpression *GVE =
2966 DBuilder.createGlobalVariableExpression(
2967 TheCU, SymbolName, VTable->getName(), Unit, 0,
2968 getOrCreateType(VoidPtr, Unit), VTable->hasLocalLinkage(),
2969 true,
nullptr, DT,
nullptr,
2971 VTable->addDebugInfo(GVE);
2974StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
2976 llvm::Function *InitFn) {
2981 return InitFn->getName();
2991 llvm::raw_svector_ostream OS(QualifiedGV);
2993 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
2995 std::swap(Quals, GVName);
2999 llvm::raw_svector_ostream OS(InitName);
3001 OS << Quals <<
"::";
3006 llvm_unreachable(
"not an initializer");
3008 OS <<
"`dynamic initializer for '";
3011 OS <<
"`dynamic atexit destructor for '";
3018 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3019 printTemplateArgumentList(OS, VTpl->getTemplateArgs().asArray(),
3020 getPrintingPolicy());
3025 return internString(
OS.str());
3028void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
3029 SmallVectorImpl<llvm::Metadata *> &EltTys) {
3038 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
3045 llvm::DIType *VPtrTy =
nullptr;
3046 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
3047 CGM.getTarget().getCXXABI().isMicrosoft();
3048 if (NeedVTableShape) {
3050 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3051 const VTableLayout &VFTLayout =
3052 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
3053 unsigned VSlotCount =
3055 unsigned VTableWidth = PtrWidth * VSlotCount;
3056 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
3057 std::optional<unsigned> DWARFAddressSpace =
3058 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
3061 llvm::DIType *VTableType = DBuilder.createPointerType(
3062 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
3063 EltTys.push_back(VTableType);
3066 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
3074 VPtrTy = getOrCreateVTablePtrType(Unit);
3076 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3077 llvm::DIType *VPtrMember =
3078 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
3079 llvm::DINode::FlagArtificial, VPtrTy);
3080 EltTys.push_back(VPtrMember);
3085 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3086 llvm::DIType *
T = getOrCreateType(RTy, getOrCreateFile(Loc));
3097 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3098 assert(!D.
isNull() &&
"null type");
3099 llvm::DIType *
T = getOrCreateType(D, getOrCreateFile(Loc));
3100 assert(
T &&
"could not create debug info for type");
3109 if (CGM.getCodeGenOpts().getDebugInfo() <=
3110 llvm::codegenoptions::DebugLineTablesOnly)
3114 node = llvm::MDNode::get(CGM.getLLVMContext(), {});
3116 node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));
3118 CI->setMetadata(
"heapallocsite", node);
3122 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3124 CanQualType Ty = CGM.getContext().getCanonicalTagType(ED);
3126 auto I = TypeCache.find(TyPtr);
3129 llvm::DIType *Res = CreateTypeDefinition(dyn_cast<EnumType>(Ty));
3130 assert(!Res->isForwardDecl());
3131 TypeCache[TyPtr].reset(Res);
3135 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3136 !CGM.getLangOpts().CPlusPlus)
3142 if (RD->
hasAttr<DLLImportAttr>())
3145 if (MD->hasAttr<DLLImportAttr>())
3158 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
3168 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
3169 Explicit = TD->isExplicitInstantiationOrSpecialization();
3173 if (CXXDecl->
fields().empty())
3183 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3184 if (CXXRD->isDynamicClass() &&
3185 CGM.getVTableLinkage(CXXRD) ==
3186 llvm::GlobalValue::AvailableExternallyLinkage &&
3197 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3199 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3201 auto I = TypeCache.find(TyPtr);
3208 auto [Res, PrefRes] = CreateTypeDefinition(dyn_cast<RecordType>(Ty));
3209 assert(!Res->isForwardDecl());
3210 TypeCache[TyPtr].reset(Res);
3217 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
3218 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
3241 if (Ctor->isCopyOrMoveConstructor())
3243 if (!Ctor->isDeleted())
3262 if (DebugKind == llvm::codegenoptions::DebugLineTablesOnly)
3265 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3266 RD->
hasAttr<StandaloneDebugAttr>())
3269 if (!LangOpts.CPlusPlus)
3275 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3291 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3292 Spec = SD->getSpecializationKind();
3301 if ((DebugKind == llvm::codegenoptions::DebugInfoConstructor) &&
3312 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3313 llvm::DIType *
T = getTypeOrNull(Ty);
3314 if (
T &&
T->isForwardDecl())
3318llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
3320 llvm::DIType *
T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
3324 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
3328 auto [Def, Pref] = CreateTypeDefinition(Ty);
3330 return Pref ? Pref : Def;
3333llvm::DIType *CGDebugInfo::GetPreferredNameType(
const CXXRecordDecl *RD,
3334 llvm::DIFile *Unit) {
3338 auto const *PNA = RD->
getAttr<PreferredNameAttr>();
3342 return getOrCreateType(PNA->getTypedefType(), Unit);
3345std::pair<llvm::DIType *, llvm::DIType *>
3346CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
3350 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3358 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
3362 return {FwdDecl,
nullptr};
3364 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
3365 CollectContainingType(CXXDecl, FwdDecl);
3368 LexicalBlockStack.emplace_back(&*FwdDecl);
3369 RegionMap[RD].reset(FwdDecl);
3372 SmallVector<llvm::Metadata *, 16> EltTys;
3379 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3381 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
3382 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
3386 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
3387 if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMethods)
3388 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
3390 LexicalBlockStack.pop_back();
3391 RegionMap.erase(RD);
3393 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3394 DBuilder.replaceArrays(FwdDecl, Elements);
3396 if (FwdDecl->isTemporary())
3398 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
3400 RegionMap[RD].reset(FwdDecl);
3402 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
3403 if (
auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
3404 return {FwdDecl, PrefDI};
3406 return {FwdDecl,
nullptr};
3409llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectType *Ty,
3410 llvm::DIFile *Unit) {
3412 return getOrCreateType(Ty->getBaseType(), Unit);
3415llvm::DIType *CGDebugInfo::CreateType(
const ObjCTypeParamType *Ty,
3416 llvm::DIFile *Unit) {
3418 SourceLocation Loc = Ty->getDecl()->getLocation();
3421 return DBuilder.createTypedef(
3422 getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
3423 Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
3424 getDeclContextDescriptor(Ty->getDecl()));
3451llvm::DIType *CGDebugInfo::CreateType(
const ObjCInterfaceType *Ty,
3452 llvm::DIFile *Unit) {
3457 auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage
>(
3458 TheCU->getSourceLanguage().getUnversionedName());
3463 if (DebugTypeExtRefs &&
ID->isFromASTFile() &&
ID->getDefinition() &&
3464 !
ID->getImplementation())
3465 return DBuilder.createForwardDecl(
3466 llvm::dwarf::DW_TAG_structure_type,
ID->getName(),
3467 getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);
3470 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3471 unsigned Line = getLineNumber(
ID->getLocation());
3475 ObjCInterfaceDecl *Def =
ID->getDefinition();
3477 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3478 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
3479 llvm::dwarf::DW_TAG_structure_type,
ID->getName(), Mod ? Mod : TheCU,
3480 DefUnit,
Line, RuntimeLang);
3481 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
3485 return CreateTypeDefinition(Ty, Unit);
3488llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
3489 bool CreateSkeletonCU) {
3494 auto ModRef = ModuleCache.find(M);
3495 if (ModRef != ModuleCache.end())
3499 SmallString<128> ConfigMacros;
3501 llvm::raw_svector_ostream
OS(ConfigMacros);
3502 const auto &PPOpts = CGM.getPreprocessorOpts();
3505 for (
auto &M : PPOpts.Macros) {
3508 const std::string &
Macro = M.first;
3509 bool Undef = M.second;
3510 OS <<
"\"-" << (Undef ?
'U' :
'D');
3511 for (
char c :
Macro)
3526 bool IsRootModule = M ? !M->
Parent :
true;
3530 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
3531 assert(StringRef(M->
Name).starts_with(CGM.getLangOpts().ModuleName) &&
3532 "clang module without ASTFile must be specified by -fmodule-name");
3535 auto RemapPath = [
this](StringRef Path) -> std::string {
3537 StringRef Relative(Remapped);
3538 StringRef CompDir = TheCU->getDirectory();
3539 if (CompDir.empty())
3542 if (Relative.consume_front(CompDir))
3543 Relative.consume_front(llvm::sys::path::get_separator());
3545 return Relative.str();
3548 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
3555 Signature = ModSig.truncatedValue();
3559 llvm::DIBuilder DIB(CGM.getModule());
3561 if (!llvm::sys::path::is_absolute(Mod.
getASTFile())) {
3562 if (CGM.getHeaderSearchOpts().ModuleFileHomeIsCwd)
3563 PCM = getCurrentDirname();
3567 llvm::sys::path::append(PCM, Mod.
getASTFile());
3568 DIB.createCompileUnit(
3569 TheCU->getSourceLanguage(),
3572 TheCU->getProducer(),
false, StringRef(), 0, RemapPath(PCM),
3573 llvm::DICompileUnit::FullDebug, Signature);
3577 llvm::DIModule *Parent =
3579 : getOrCreateModuleRef(ASTSourceDescriptor(*M->
Parent),
3581 StringRef IncludePath = Mod.
getPath();
3582 if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
3583 StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
3584 if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
3587 llvm::DIModule *DIMod =
3588 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
3589 RemapPath(IncludePath));
3590 ModuleCache[M].reset(DIMod);
3594llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const ObjCInterfaceType *Ty,
3595 llvm::DIFile *Unit) {
3597 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3598 unsigned Line = getLineNumber(
ID->getLocation());
3600 unsigned RuntimeLang = TheCU->getSourceLanguage().getUnversionedName();
3606 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3607 if (
ID->getImplementation())
3608 Flags |= llvm::DINode::FlagObjcClassComplete;
3610 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3611 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
3612 Mod ? Mod : Unit,
ID->getName(), DefUnit,
Line, Size, Align, Flags,
3613 nullptr, llvm::DINodeArray(), RuntimeLang);
3615 QualType QTy(Ty, 0);
3616 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
3619 LexicalBlockStack.emplace_back(RealDecl);
3620 RegionMap[Ty->
getDecl()].reset(RealDecl);
3623 SmallVector<llvm::Metadata *, 16> EltTys;
3625 ObjCInterfaceDecl *SClass =
ID->getSuperClass();
3627 llvm::DIType *SClassTy =
3628 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
3632 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
3633 llvm::DINode::FlagZero);
3634 EltTys.push_back(InhTag);
3638 auto AddProperty = [&](
const ObjCPropertyDecl *PD) {
3639 SourceLocation Loc = PD->getLocation();
3640 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3641 unsigned PLine = getLineNumber(Loc);
3642 ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
3643 ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
3644 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
3645 PD->getName(), PUnit, PLine,
3647 : getSelectorName(PD->getGetterName()),
3649 : getSelectorName(PD->getSetterName()),
3650 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
3651 EltTys.push_back(PropertyNode);
3656 typedef std::pair<char, const IdentifierInfo *> IsClassAndIdent;
3660 llvm::DenseSet<IsClassAndIdent> PropertySet;
3662 auto GetIsClassAndIdent = [](
const ObjCPropertyDecl *PD) {
3663 return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
3665 for (
const ObjCCategoryDecl *ClassExt :
ID->known_extensions())
3666 for (
auto *PD : ClassExt->properties()) {
3667 PropertySet.insert(GetIsClassAndIdent(PD));
3670 for (
const auto *PD :
ID->properties()) {
3673 if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
3679 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
3680 unsigned FieldNo = 0;
3681 for (ObjCIvarDecl *Field =
ID->all_declared_ivar_begin(); Field;
3682 Field =
Field->getNextIvar(), ++FieldNo) {
3683 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
3687 StringRef FieldName =
Field->getName();
3690 if (FieldName.empty())
3694 llvm::DIFile *FieldDefUnit = getOrCreateFile(
Field->getLocation());
3695 unsigned FieldLine = getLineNumber(
Field->getLocation());
3696 QualType FType =
Field->getType();
3703 FieldSize =
Field->isBitField() ?
Field->getBitWidthValue()
3704 : CGM.getContext().getTypeSize(FType);
3709 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
3713 if (
Field->isBitField()) {
3715 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
3716 FieldOffset %= CGM.getContext().getCharWidth();
3724 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3726 Flags = llvm::DINode::FlagProtected;
3728 Flags = llvm::DINode::FlagPrivate;
3730 Flags = llvm::DINode::FlagPublic;
3732 if (
Field->isBitField())
3733 Flags |= llvm::DINode::FlagBitField;
3735 llvm::MDNode *PropertyNode =
nullptr;
3736 if (ObjCImplementationDecl *ImpD =
ID->getImplementation()) {
3737 if (ObjCPropertyImplDecl *PImpD =
3738 ImpD->FindPropertyImplIvarDecl(
Field->getIdentifier())) {
3739 if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
3740 SourceLocation Loc = PD->getLocation();
3741 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3742 unsigned PLine = getLineNumber(Loc);
3743 ObjCMethodDecl *Getter = PImpD->getGetterMethodDecl();
3744 ObjCMethodDecl *Setter = PImpD->getSetterMethodDecl();
3745 PropertyNode = DBuilder.createObjCProperty(
3746 PD->getName(), PUnit, PLine,
3749 : getSelectorName(PD->getGetterName()),
3752 : getSelectorName(PD->getSetterName()),
3753 PD->getPropertyAttributes(),
3754 getOrCreateType(PD->getType(), PUnit));
3758 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
3759 FieldSize, FieldAlign, FieldOffset, Flags,
3760 FieldTy, PropertyNode);
3761 EltTys.push_back(FieldTy);
3764 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3765 DBuilder.replaceArrays(RealDecl, Elements);
3767 LexicalBlockStack.pop_back();
3771llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
3772 llvm::DIFile *Unit) {
3780 auto &Ctx = CGM.getContext();
3785 QualType CharVecTy =
3787 return CreateType(CharVecTy->
getAs<VectorType>(), Unit);
3790 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3793 llvm::Metadata *Subscript;
3794 QualType QTy(Ty, 0);
3795 auto SizeExpr = SizeExprCache.find(QTy);
3796 if (SizeExpr != SizeExprCache.end())
3797 Subscript = DBuilder.getOrCreateSubrange(
3798 SizeExpr->getSecond() ,
nullptr ,
3799 nullptr ,
nullptr );
3802 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3803 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count ? Count : -1));
3804 Subscript = DBuilder.getOrCreateSubrange(
3805 CountNode ,
nullptr ,
nullptr ,
3808 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
3813 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
3816llvm::DIType *CGDebugInfo::CreateType(
const ConstantMatrixType *Ty,
3817 llvm::DIFile *Unit) {
3821 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3826 llvm::SmallVector<llvm::Metadata *, 2> Subscripts;
3827 auto *ColumnCountNode =
3828 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3829 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumColumns()));
3830 auto *RowCountNode =
3831 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3832 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumRows()));
3833 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3834 ColumnCountNode ,
nullptr ,
nullptr ,
3836 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3837 RowCountNode ,
nullptr ,
nullptr ,
3839 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3840 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
3843llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
3848 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3863 Size = CGM.getContext().getTypeSize(Ty);
3870 SmallVector<llvm::Metadata *, 8> Subscripts;
3871 QualType EltTy(Ty, 0);
3872 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
3881 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
3882 Count = CAT->getZExtSize();
3883 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3884 if (Expr *Size = VAT->getSizeExpr()) {
3886 if (
Size->EvaluateAsInt(
Result, CGM.getContext()))
3887 Count =
Result.Val.getInt().getExtValue();
3891 auto SizeNode = SizeExprCache.find(EltTy);
3892 if (SizeNode != SizeExprCache.end())
3893 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3894 SizeNode->getSecond() ,
nullptr ,
3895 nullptr ,
nullptr ));
3898 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3899 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count));
3900 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3901 CountNode ,
nullptr ,
nullptr ,
3907 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3909 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
3913llvm::DIType *CGDebugInfo::CreateType(
const LValueReferenceType *Ty,
3914 llvm::DIFile *Unit) {
3915 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
3919llvm::DIType *CGDebugInfo::CreateType(
const RValueReferenceType *Ty,
3920 llvm::DIFile *Unit) {
3921 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
3923 if (CGM.getCodeGenOpts().DebugStrictDwarf &&
3924 CGM.getCodeGenOpts().DwarfVersion < 4)
3925 Tag = llvm::dwarf::DW_TAG_reference_type;
3927 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
3930llvm::DIType *CGDebugInfo::CreateType(
const MemberPointerType *Ty,
3932 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3936 Size = CGM.getContext().getTypeSize(Ty);
3939 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3942 Flags |= llvm::DINode::FlagSingleInheritance;
3945 Flags |= llvm::DINode::FlagMultipleInheritance;
3948 Flags |= llvm::DINode::FlagVirtualInheritance;
3958 llvm::DIType *ClassType = getOrCreateType(
T, U);
3960 return DBuilder.createMemberPointerType(
3964 const FunctionProtoType *FPT =
3966 return DBuilder.createMemberPointerType(
3967 getOrCreateInstanceMethodType(
3970 ClassType, Size, 0, Flags);
3973llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
3975 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
3978llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
3982llvm::DIType *CGDebugInfo::CreateType(
const HLSLAttributedResourceType *Ty,
3984 return getOrCreateType(Ty->getWrappedType(), U);
3987llvm::DIType *CGDebugInfo::CreateType(
const HLSLInlineSpirvType *Ty,
3994 const EnumType *Ty) {
4006llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
4009 bool isImportedFromModule =
4010 DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
4014 if (isImportedFromModule || !ED->getDefinition()) {
4021 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
4022 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4023 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
4024 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
4026 unsigned Line = getLineNumber(ED->getLocation());
4027 StringRef EDName = ED->getName();
4028 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
4029 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
4030 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
4032 ReplaceMap.emplace_back(
4033 std::piecewise_construct, std::make_tuple(Ty),
4034 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
4038 return CreateTypeDefinition(Ty);
4041llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
4044 SmallVector<llvm::Metadata *, 16> Enumerators;
4045 ED = ED->getDefinition();
4046 assert(ED &&
"An enumeration definition is required");
4047 for (
const auto *
Enum : ED->enumerators()) {
4048 Enumerators.push_back(
4049 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
4052 std::optional<EnumExtensibilityAttr::Kind> EnumKind;
4053 if (
auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
4054 EnumKind = Attr->getExtensibility();
4057 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
4059 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4060 unsigned Line = getLineNumber(ED->getLocation());
4061 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
4062 llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
4063 return DBuilder.createEnumerationType(
4064 EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
4065 0, Identifier, ED->isScoped(), EnumKind);
4070 StringRef Name, StringRef
Value) {
4071 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4072 return DBuilder.createMacro(Parent,
Line, MType, Name,
Value);
4078 llvm::DIFile *FName = getOrCreateFile(FileLoc);
4079 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4080 return DBuilder.createTempMacroFile(Parent,
Line, FName);
4085 llvm::DISubprogram *SynthSubprogram) {
4086 return llvm::DILocation::get(CGM.getLLVMContext(), 0, 0,
4087 SynthSubprogram, ParentLocation);
4092 StringRef SynthFuncName,
4093 llvm::DIFile *SynthFile) {
4094 llvm::DISubprogram *SP = createInlinedSubprogram(SynthFuncName, SynthFile);
4099 llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) {
4105 FuncName += Category;
4107 FuncName += FailureMsg;
4110 TrapLocation->getFile());
4120 Quals += InnerQuals;
4122 switch (
T->getTypeClass()) {
4124 return C.getQualifiedType(
T.getTypePtr(), Quals);
4127 case Type::InjectedClassName:
4128 return C.getQualifiedType(
T->getCanonicalTypeUnqualified().getTypePtr(),
4130 case Type::TemplateSpecialization: {
4132 if (Spec->isTypeAlias())
4133 return C.getQualifiedType(
T.getTypePtr(), Quals);
4134 T = Spec->desugar();
4137 case Type::TypeOfExpr:
4143 case Type::Decltype:
4146 case Type::UnaryTransform:
4149 case Type::Attributed:
4152 case Type::BTFTagAttributed:
4155 case Type::CountAttributed:
4164 case Type::MacroQualified:
4167 case Type::SubstTemplateTypeParm:
4171 case Type::DeducedTemplateSpecialization: {
4173 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
4177 case Type::PackIndexing: {
4181 case Type::Adjusted:
4188 assert(
T != LastT &&
"Type unwrapping failed to unwrap!");
4193llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
4196 if (It != TypeCache.end()) {
4198 if (llvm::Metadata *
V = It->second)
4211 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
4218 RetainedTypes.push_back(
4219 CGM.getContext().getCanonicalTagType(&D).getAsOpaquePtr());
4222llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
4226 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
4228 llvm::raw_string_ostream OS(Name);
4229 Ty.
print(OS, getPrintingPolicy());
4236 if (
auto *
T = getTypeOrNull(Ty))
4239 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
4240 void *TyPtr = Ty.getAsOpaquePtr();
4243 TypeCache[TyPtr].reset(Res);
4248llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
4256 auto Info = Reader->getSourceDescriptor(Idx);
4258 return getOrCreateModuleRef(*Info,
true);
4259 }
else if (ClangModuleMap) {
4272 auto Info = ASTSourceDescriptor(*M);
4273 return getOrCreateModuleRef(Info,
false);
4276 return getOrCreateModuleRef(PCHDescriptor,
false);
4283llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
4286 return CreateQualifiedType(Ty, Unit);
4290#define TYPE(Class, Base)
4291#define ABSTRACT_TYPE(Class, Base)
4292#define NON_CANONICAL_TYPE(Class, Base)
4293#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4294#include "clang/AST/TypeNodes.inc"
4295 llvm_unreachable(
"Dependent types cannot show up in debug information");
4297 case Type::ExtVector:
4300 case Type::ConstantMatrix:
4302 case Type::ObjCObjectPointer:
4304 case Type::ObjCObject:
4306 case Type::ObjCTypeParam:
4308 case Type::ObjCInterface:
4316 case Type::BlockPointer:
4324 case Type::FunctionProto:
4325 case Type::FunctionNoProto:
4327 case Type::ConstantArray:
4328 case Type::VariableArray:
4329 case Type::IncompleteArray:
4330 case Type::ArrayParameter:
4333 case Type::LValueReference:
4335 case Type::RValueReference:
4338 case Type::MemberPointer:
4346 case Type::OverflowBehavior:
4351 case Type::TemplateSpecialization:
4353 case Type::HLSLAttributedResource:
4355 case Type::HLSLInlineSpirv:
4357 case Type::PredefinedSugar:
4359 case Type::CountAttributed:
4360 case Type::LateParsedAttr:
4362 case Type::Attributed:
4363 case Type::BTFTagAttributed:
4364 case Type::Adjusted:
4366 case Type::DeducedTemplateSpecialization:
4369 case Type::MacroQualified:
4370 case Type::SubstTemplateTypeParm:
4371 case Type::TypeOfExpr:
4373 case Type::Decltype:
4374 case Type::PackIndexing:
4375 case Type::UnaryTransform:
4379 llvm_unreachable(
"type should have been unwrapped!");
4382llvm::DICompositeType *
4383CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
4384 QualType QTy(Ty, 0);
4386 auto *
T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
4391 if (
T && !
T->isForwardDecl())
4395 llvm::DICompositeType *Res = CreateLimitedType(Ty);
4400 DBuilder.replaceArrays(Res,
T ?
T->getElements() : llvm::DINodeArray());
4403 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
4408llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
4410 bool NameIsSimplified =
false;
4413 StringRef RDName = getClassName(RD, &NameIsSimplified);
4415 llvm::DIFile *DefUnit =
nullptr;
4418 DefUnit = getOrCreateFile(Loc);
4419 Line = getLineNumber(Loc);
4422 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
4426 auto *
T = cast_or_null<llvm::DICompositeType>(
4427 getTypeOrNull(CGM.getContext().getCanonicalTagType(RD)));
4435 return getOrCreateRecordFwdDecl(Ty, RDContext);
4448 auto Flags = llvm::DINode::FlagZero;
4449 if (NameIsSimplified)
4450 Flags |= llvm::DINode::FlagNameIsSimplified;
4451 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4453 Flags |= llvm::DINode::FlagTypePassByReference;
4455 Flags |= llvm::DINode::FlagTypePassByValue;
4458 if (!CXXRD->isTrivial())
4459 Flags |= llvm::DINode::FlagNonTrivial;
4462 if (CXXRD->isAnonymousStructOrUnion())
4463 Flags |= llvm::DINode::FlagExportSymbols;
4466 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
4469 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4470 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
4472 Flags, Identifier, Annotations);
4476 switch (RealDecl->getTag()) {
4478 llvm_unreachable(
"invalid composite type tag");
4480 case llvm::dwarf::DW_TAG_array_type:
4481 case llvm::dwarf::DW_TAG_enumeration_type:
4486 if (Identifier.empty())
4490 case llvm::dwarf::DW_TAG_structure_type:
4491 case llvm::dwarf::DW_TAG_union_type:
4492 case llvm::dwarf::DW_TAG_class_type:
4495 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
4499 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
4500 CXXRecordDecl *TemplateDecl =
4501 CTSD->getSpecializedTemplate()->getTemplatedDecl();
4502 RegionMap[TemplateDecl].reset(RealDecl);
4504 RegionMap[RD].reset(RealDecl);
4506 TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
4508 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
4509 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
4510 CollectCXXTemplateParams(TSpecial, DefUnit));
4514void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
4515 llvm::DICompositeType *RealDecl) {
4517 llvm::DIType *ContainingType =
nullptr;
4518 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4522 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
4529 CanQualType T = CGM.getContext().getCanonicalTagType(PBase);
4530 ContainingType = getOrCreateType(
T, getOrCreateFile(RD->
getLocation()));
4532 ContainingType = RealDecl;
4534 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4537llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
4538 StringRef Name, uint64_t *Offset) {
4539 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4540 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
4543 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4544 *Offset, llvm::DINode::FlagZero, FieldTy);
4545 *Offset += FieldSize;
4549void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
4551 StringRef &LinkageName,
4552 llvm::DIScope *&FDContext,
4553 llvm::DINodeArray &TParamsArray,
4554 llvm::DINode::DIFlags &Flags) {
4556 bool NameIsSimplified =
false;
4557 Name = getFunctionName(FD, &NameIsSimplified);
4558 if (NameIsSimplified)
4559 Flags |= llvm::DINode::FlagNameIsSimplified;
4560 Name = getFunctionName(FD);
4563 LinkageName = CGM.getMangledName(GD);
4565 Flags |= llvm::DINode::FlagPrototyped;
4569 if (LinkageName == Name ||
4570 (CGM.getCodeGenOpts().CoverageNotesFile.empty() &&
4571 CGM.getCodeGenOpts().CoverageDataFile.empty() &&
4572 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
4573 !CGM.getCodeGenOpts().PseudoProbeForProfiling &&
4574 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4575 LinkageName = StringRef();
4579 if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
4580 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4581 CGM.getCodeGenOpts().EmitCodeView)) {
4582 if (
const NamespaceDecl *NSDecl =
4584 FDContext = getOrCreateNamespace(NSDecl);
4585 else if (
const RecordDecl *RDecl =
4587 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4588 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4591 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
4594 Flags |= llvm::DINode::FlagNoReturn;
4596 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4600void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4601 unsigned &LineNo, QualType &
T,
4602 StringRef &Name, StringRef &LinkageName,
4603 llvm::MDTuple *&TemplateParameters,
4604 llvm::DIScope *&VDContext) {
4613 llvm::APInt ConstVal(32, 1);
4614 QualType ET = CGM.getContext().getAsArrayType(
T)->getElementType();
4616 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
4623 LinkageName = CGM.getMangledName(VD);
4624 if (LinkageName == Name)
4625 LinkageName = StringRef();
4628 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4629 TemplateParameters = parameterNodes.get();
4631 TemplateParameters =
nullptr;
4649 DC = CGM.getContext().getTranslationUnitDecl();
4651 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4652 VDContext = getContextDescriptor(
cast<Decl>(DC), Mod ? Mod : TheCU);
4655llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
4657 llvm::DINodeArray TParamsArray;
4658 StringRef Name, LinkageName;
4659 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4660 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4662 llvm::DIFile *Unit = getOrCreateFile(Loc);
4663 llvm::DIScope *DContext = Unit;
4664 unsigned Line = getLineNumber(Loc);
4665 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4670 SmallVector<QualType, 16> ArgTypes;
4671 for (
const ParmVarDecl *Parm : FD->
parameters())
4672 ArgTypes.push_back(Parm->getType());
4675 QualType FnType = CGM.getContext().getFunctionType(
4676 FD->
getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
4678 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4679 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
4680 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4684 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4685 return DBuilder.createFunction(
4686 DContext, Name, LinkageName, Unit,
Line,
4687 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4688 TParamsArray.get(), getFunctionDeclaration(FD),
nullptr,
4690 CGM.getCodeGenOpts().DebugKeyInstructions);
4693 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4694 DContext, Name, LinkageName, Unit,
Line,
4695 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4696 TParamsArray.get(), getFunctionDeclaration(FD));
4698 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4699 std::make_tuple(CanonDecl),
4700 std::make_tuple(SP));
4704llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
4705 return getFunctionFwdDeclOrStub(GD,
false);
4708llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
4709 return getFunctionFwdDeclOrStub(GD,
true);
4712llvm::DIGlobalVariable *
4713CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4715 StringRef Name, LinkageName;
4717 llvm::DIFile *Unit = getOrCreateFile(Loc);
4718 llvm::DIScope *DContext = Unit;
4719 unsigned Line = getLineNumber(Loc);
4720 llvm::MDTuple *TemplateParameters =
nullptr;
4722 collectVarDeclProps(VD, Unit,
Line,
T, Name, LinkageName, TemplateParameters,
4725 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4726 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(
T, Unit),
4728 FwdDeclReplaceMap.emplace_back(
4729 std::piecewise_construct,
4731 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4735llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
4740 if (
const auto *TD = dyn_cast<TypeDecl>(D)) {
4741 QualType Ty = CGM.getContext().getTypeDeclType(TD);
4742 return getOrCreateType(Ty, getOrCreateFile(TD->
getLocation()));
4746 if (I != DeclCache.end()) {
4748 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4749 return GVE->getVariable();
4757 if (IE != ImportedDeclCache.end()) {
4758 auto N = IE->second;
4759 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4761 return dyn_cast_or_null<llvm::DINode>(N);
4766 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4767 return getFunctionForwardDeclaration(FD);
4768 else if (
const auto *VD = dyn_cast<VarDecl>(D))
4769 return getGlobalVariableForwardDeclaration(VD);
4774llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
4775 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4778 const auto *FD = dyn_cast<FunctionDecl>(D);
4783 auto *S = getDeclContextDescriptor(D);
4786 if (MI == SPCache.end()) {
4788 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
4792 if (MI != SPCache.end()) {
4793 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4794 if (SP && !SP->isDefinition())
4798 for (
auto *NextFD : FD->
redecls()) {
4799 auto MI = SPCache.find(NextFD->getCanonicalDecl());
4800 if (MI != SPCache.end()) {
4801 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4802 if (SP && !SP->isDefinition())
4809llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
4810 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
4811 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
4812 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4815 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
4819 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
4823 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
4832 QualType QTy(
ID->getTypeForDecl(), 0);
4833 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4834 if (It == TypeCache.end())
4837 llvm::DISubprogram *FD = DBuilder.createFunction(
4838 InterfaceType, getObjCMethodName(OMD), StringRef(),
4839 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
4840 DBuilder.finalizeSubprogram(FD);
4847llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
4852 if (!D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
4853 !CGM.getCodeGenOpts().EmitCodeView))
4856 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({}));
4858 if (
const auto *
Method = dyn_cast<CXXDestructorDecl>(D)) {
4861 return getOrCreateMethodTypeForDestructor(
Method, F, FnType);
4864 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(D))
4865 return getOrCreateMethodType(
Method, F);
4867 const auto *FTy = FnType->
getAs<FunctionType>();
4870 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
4872 SmallVector<llvm::Metadata *, 16> Elts;
4875 QualType ResultTy = OMethod->getReturnType();
4878 if (ResultTy == CGM.getContext().getObjCInstanceType())
4879 ResultTy = CGM.getContext().getPointerType(
4880 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
4882 Elts.push_back(getOrCreateType(ResultTy, F));
4884 QualType SelfDeclTy;
4885 if (
auto *SelfDecl = OMethod->getSelfDecl())
4886 SelfDeclTy = SelfDecl->getType();
4887 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4890 if (!SelfDeclTy.
isNull())
4892 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
4894 Elts.push_back(DBuilder.createArtificialType(
4895 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
4897 for (
const auto *PI : OMethod->parameters())
4898 Elts.push_back(getOrCreateType(PI->getType(), F));
4900 if (OMethod->isVariadic())
4901 Elts.push_back(DBuilder.createUnspecifiedParameter());
4903 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
4904 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
4910 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4911 if (FD->isVariadic()) {
4912 SmallVector<llvm::Metadata *, 16> EltTys;
4913 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
4914 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4916 EltTys.push_back(getOrCreateType(ParamType, F));
4917 EltTys.push_back(DBuilder.createUnspecifiedParameter());
4918 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
4919 return DBuilder.createSubroutineType(EltTypeArray, llvm::DINode::FlagZero,
4932 CC = SrcFnTy->getCallConv();
4934 for (
const VarDecl *VD : Args)
4935 ArgTypes.push_back(VD->
getType());
4936 return CGM.getContext().getFunctionType(RetTy, ArgTypes,
4942 llvm::Function *Fn,
bool CurFuncIsThunk) {
4944 StringRef LinkageName;
4946 FnBeginRegionCount.push_back(LexicalBlockStack.size());
4949 bool HasDecl = (D !=
nullptr);
4951 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4952 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4953 llvm::DIFile *Unit = getOrCreateFile(Loc);
4954 llvm::DIScope *FDContext = Unit;
4955 llvm::DINodeArray TParamsArray;
4956 bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
4959 LinkageName = Fn->getName();
4960 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
4962 auto FI = SPCache.find(FD->getCanonicalDecl());
4963 if (FI != SPCache.end()) {
4964 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
4965 if (SP && SP->isDefinition()) {
4966 LexicalBlockStack.emplace_back(SP);
4967 RegionMap[D].reset(SP);
4971 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
4972 TParamsArray, Flags);
4975 KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
4976 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
4977 Name = getObjCMethodName(OMD);
4978 Flags |= llvm::DINode::FlagPrototyped;
4984 if (Name != Fn->getName())
4985 LinkageName = Fn->getName();
4987 Name = Fn->getName();
4992 Flags |= llvm::DINode::FlagPrototyped;
4994 Name.consume_front(
"\01");
4998 "Unexpected DynamicInitKind !");
5002 Flags |= llvm::DINode::FlagArtificial;
5008 Flags |= llvm::DINode::FlagThunk;
5010 if (Fn->hasLocalLinkage())
5011 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
5012 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5013 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5016 llvm::DISubprogram::DISPFlags SPFlagsForDef =
5017 SPFlags | llvm::DISubprogram::SPFlagDefinition;
5019 const unsigned LineNo = getLineNumber(Loc.
isValid() ? Loc : CurLoc);
5020 unsigned ScopeLine = getLineNumber(ScopeLoc);
5021 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
5022 llvm::DISubprogram *
Decl =
nullptr;
5023 llvm::DINodeArray Annotations =
nullptr;
5026 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
5027 : getFunctionDeclaration(D);
5028 Annotations = CollectBTFDeclTagAnnotations(D);
5036 llvm::DISubprogram *SP = DBuilder.createFunction(
5037 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
5038 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
5039 Annotations,
"", KeyInstructions);
5040 Fn->setSubprogram(SP);
5049 LexicalBlockStack.emplace_back(SP);
5052 RegionMap[D].reset(SP);
5056 QualType FnType, llvm::Function *Fn) {
5058 StringRef LinkageName;
5064 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
5065 return GetName(D,
true);
5068 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5069 llvm::DIFile *Unit = getOrCreateFile(Loc);
5070 bool IsDeclForCallSite = Fn ?
true :
false;
5071 llvm::DIScope *FDContext =
5072 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
5073 llvm::DINodeArray TParamsArray;
5076 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5077 TParamsArray, Flags);
5078 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5079 Name = getObjCMethodName(OMD);
5080 Flags |= llvm::DINode::FlagPrototyped;
5082 llvm_unreachable(
"not a function or ObjC method");
5084 Name.consume_front(
"\01");
5087 Flags |= llvm::DINode::FlagArtificial;
5092 unsigned LineNo = getLineNumber(Loc);
5093 unsigned ScopeLine = 0;
5094 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5095 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5096 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5098 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
5099 llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
5101 assert(~SPFlags & llvm::DISubprogram::SPFlagDefinition);
5102 llvm::DISubprogram *SP = DBuilder.createFunction(
5103 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
5104 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations,
5110 if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
5111 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
5112 llvm::DITypeArray ParamTypes = STy->getTypeArray();
5115 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
5116 DBuilder.createParameterVariable(
5117 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
5118 llvm::DINode::FlagZero, ParamAnnotations);
5124 if (IsDeclForCallSite)
5125 Fn->setSubprogram(SP);
5129 llvm::CallBase *CI) {
5130 if (!shouldGenerateVirtualCallSite())
5136 assert(CI &&
"Invalid Call Instruction.");
5137 if (!CI->isIndirectCall())
5141 if (llvm::DISubprogram *MD = getFunctionDeclaration(FD))
5142 CI->setMetadata(llvm::LLVMContext::MD_call_target, MD);
5150 auto *
Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
5153 if (
Func->getSubprogram())
5161 if (CalleeDecl->
hasAttr<NoDebugAttr>() ||
5176 auto FI = SPCache.find(FD->getCanonicalDecl());
5177 llvm::DISubprogram *SP =
nullptr;
5178 if (FI != SPCache.end())
5179 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5180 if (!SP || !SP->isDefinition())
5181 SP = getFunctionStub(GD);
5182 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5183 LexicalBlockStack.emplace_back(SP);
5189 assert(CurInlinedAt &&
"unbalanced inline scope stack");
5198 if (CurLoc.isInvalid() ||
5199 (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) ||
5200 LexicalBlockStack.empty())
5203 llvm::MDNode *
Scope = LexicalBlockStack.back();
5204 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5205 CGM.getLLVMContext(), CurLocLine, CurLocColumn,
Scope, CurInlinedAt));
5209 llvm::MDNode *Back =
nullptr;
5210 if (!LexicalBlockStack.empty())
5211 Back = LexicalBlockStack.back().get();
5212 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
5214 getColumnNumber(CurLoc)));
5217void CGDebugInfo::AppendAddressSpaceXDeref(
5219 std::optional<unsigned> DWARFAddressSpace =
5221 if (!DWARFAddressSpace)
5224 Expr.push_back(llvm::dwarf::DW_OP_constu);
5225 Expr.push_back(*DWARFAddressSpace);
5226 Expr.push_back(llvm::dwarf::DW_OP_swap);
5227 Expr.push_back(llvm::dwarf::DW_OP_xderef);
5236 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5237 CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
5238 LexicalBlockStack.back(), CurInlinedAt));
5240 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5244 CreateLexicalBlock(Loc);
5249 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5254 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5257 LexicalBlockStack.pop_back();
5261 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5262 unsigned RCount = FnBeginRegionCount.back();
5263 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
5266 while (LexicalBlockStack.size() != RCount) {
5269 LexicalBlockStack.pop_back();
5271 FnBeginRegionCount.pop_back();
5273 if (Fn && Fn->getSubprogram())
5274 DBuilder.finalizeSubprogram(Fn->getSubprogram());
5277CGDebugInfo::BlockByRefType
5278CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
5279 uint64_t *XOffset) {
5282 uint64_t FieldSize, FieldOffset;
5283 uint32_t FieldAlign;
5285 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5290 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
5291 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
5293 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
5294 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
5297 if (HasCopyAndDispose) {
5300 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
5302 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
5304 bool HasByrefExtendedLayout;
5307 HasByrefExtendedLayout) &&
5308 HasByrefExtendedLayout) {
5311 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
5320 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
5323 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
5326 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
5331 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
5332 FieldSize = CGM.getContext().getTypeSize(FType);
5333 FieldAlign = CGM.getContext().toBits(Align);
5335 *XOffset = FieldOffset;
5336 llvm::DIType *FieldTy = DBuilder.createMemberType(
5337 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
5338 llvm::DINode::FlagZero, WrappedTy);
5339 EltTys.push_back(FieldTy);
5340 FieldOffset += FieldSize;
5342 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
5343 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
5344 llvm::DINode::FlagZero,
nullptr, Elements),
5348llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
5349 llvm::Value *Storage,
5350 std::optional<unsigned> ArgNo,
5352 const bool UsePointerValue) {
5353 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5354 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5355 if (VD->
hasAttr<NoDebugAttr>())
5360 llvm::DIFile *Unit =
nullptr;
5361 if (!VarIsArtificial)
5365 if (VD->
hasAttr<BlocksAttr>())
5366 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5368 Ty = getOrCreateType(VD->
getType(), Unit);
5378 if (!VarIsArtificial) {
5382 SmallVector<uint64_t, 13> Expr;
5383 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5390 Flags |= llvm::DINode::FlagArtificial;
5394 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->
getType());
5395 AppendAddressSpaceXDeref(AddressSpace, Expr);
5399 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
5402 Flags |= llvm::DINode::FlagObjectPointer;
5403 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
5404 if (PVD->isExplicitObjectParameter())
5405 Flags |= llvm::DINode::FlagObjectPointer;
5413 StringRef Name = VD->
getName();
5414 if (!Name.empty()) {
5420 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5422 offset = CGM.getContext().toCharUnitsFromBits(
5425 Expr.push_back(llvm::dwarf::DW_OP_deref);
5426 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5428 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5431 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
5443 for (
const auto *Field : RD->
fields()) {
5444 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
5445 StringRef FieldName =
Field->getName();
5453 auto *D = DBuilder.createAutoVariable(
5454 Scope, FieldName, Unit,
Line, FieldTy,
5455 CGM.getCodeGenOpts().OptimizationLevel != 0,
5456 Flags | llvm::DINode::FlagArtificial, FieldAlign);
5459 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5460 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5463 Builder.GetInsertBlock());
5471 if (UsePointerValue) {
5472 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5473 "Debug info already contains DW_OP_deref.");
5474 Expr.push_back(llvm::dwarf::DW_OP_deref);
5478 llvm::DILocalVariable *D =
nullptr;
5480 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5481 D = DBuilder.createParameterVariable(
5482 Scope, Name, *ArgNo, Unit,
Line, Ty,
5483 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
5492 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
5498 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
5499 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
5500 if (DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
5501 DeclGroupRef DeclGroup = DeclStmtPtr->getDeclGroup();
5503 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
5509 if (Iter != CoroutineParameterMappings.end()) {
5510 ParmVarDecl *PD =
const_cast<ParmVarDecl *
>(Iter->first);
5511 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
5512 return DbgPair.first == PD && DbgPair.second->getScope() == Scope;
5514 if (Iter2 != ParamDbgMappings.end())
5515 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
5521 D = RemapCoroArgToLocalVar();
5524 D = DBuilder.createAutoVariable(
5525 Scope, Name, Unit,
Line, Ty,
5526 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
5529 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5530 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5531 Column, Scope, CurInlinedAt),
5532 Builder.GetInsertBlock());
5537llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
5538 llvm::Value *Storage,
5539 std::optional<unsigned> ArgNo,
5541 const bool UsePointerValue) {
5542 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5543 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5544 if (BD->
hasAttr<NoDebugAttr>())
5551 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
5552 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
5560 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->
getType());
5562 SmallVector<uint64_t, 3> Expr;
5563 AppendAddressSpaceXDeref(AddressSpace, Expr);
5568 if (UsePointerValue) {
5569 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5570 "Debug info already contains DW_OP_deref.");
5571 Expr.push_back(llvm::dwarf::DW_OP_deref);
5576 StringRef Name = BD->
getName();
5579 llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5580 Scope, Name, Unit,
Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
5581 llvm::DINode::FlagZero, Align);
5583 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(BD->
getBinding())) {
5584 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5585 const unsigned fieldIndex = FD->getFieldIndex();
5586 const clang::CXXRecordDecl *parent =
5587 (
const CXXRecordDecl *)FD->getParent();
5588 const ASTRecordLayout &layout =
5589 CGM.getContext().getASTRecordLayout(parent);
5591 if (FD->isBitField()) {
5592 const CGRecordLayout &RL =
5593 CGM.getTypes().getCGRecordLayout(FD->getParent());
5598 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5604 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5605 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5606 Expr.push_back(Info.
Offset);
5609 const uint64_t TypeSize = CGM.getContext().getTypeSize(BD->
getType());
5610 Expr.push_back(std::min((uint64_t)Info.
Size, TypeSize));
5611 }
else if (fieldOffset != 0) {
5612 assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
5613 "Unexpected non-bitfield with non-byte-aligned offset");
5614 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5616 CGM.getContext().toCharUnitsFromBits(fieldOffset).getQuantity());
5619 }
else if (
const ArraySubscriptExpr *ASE =
5620 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5621 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5622 const uint64_t value = IL->getValue().getZExtValue();
5623 const uint64_t typeSize = CGM.getContext().getTypeSize(BD->
getType());
5626 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5627 Expr.push_back(CGM.getContext()
5628 .toCharUnitsFromBits(value * typeSize)
5635 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5636 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5637 Column, Scope, CurInlinedAt),
5638 Builder.GetInsertBlock());
5643llvm::DILocalVariable *
5646 const bool UsePointerValue) {
5647 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5649 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5651 EmitDeclare(B, Storage, std::nullopt, Builder,
5658 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5662 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5663 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5665 if (D->
hasAttr<NoDebugAttr>())
5669 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
5675 StringRef Name = D->
getName();
5681 CGM.getCodeGenOpts().OptimizationLevel != 0);
5684 DBuilder.insertLabel(L,
5685 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5686 Scope, CurInlinedAt),
5687 Builder.GetInsertBlock()->end());
5690llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5692 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5695 return DBuilder.createObjectPointerType(Ty,
true);
5700 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5701 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5702 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5704 if (Builder.GetInsertBlock() ==
nullptr)
5706 if (VD->
hasAttr<NoDebugAttr>())
5709 bool isByRef = VD->
hasAttr<BlocksAttr>();
5711 uint64_t XOffset = 0;
5712 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5715 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5717 Ty = getOrCreateType(VD->
getType(), Unit);
5721 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5723 Ty = CreateSelfType(VD->
getType(), Ty);
5726 const unsigned Line =
5730 const llvm::DataLayout &target = CGM.getDataLayout();
5737 addr.push_back(llvm::dwarf::DW_OP_deref);
5738 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5741 addr.push_back(llvm::dwarf::DW_OP_deref);
5742 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5745 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
5747 addr.push_back(llvm::dwarf::DW_OP_deref);
5748 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5750 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5756 auto *D = DBuilder.createAutoVariable(
5758 Line, Ty,
false, llvm::DINode::FlagZero, Align);
5761 auto DL = llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5762 LexicalBlockStack.back(), CurInlinedAt);
5763 auto *
Expr = DBuilder.createExpression(addr);
5765 DBuilder.insertDeclare(Storage, D,
Expr, DL, InsertPoint->getIterator());
5767 DBuilder.insertDeclare(Storage, D,
Expr, DL, Builder.GetInsertBlock());
5770llvm::DILocalVariable *
5773 bool UsePointerValue) {
5774 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5775 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
5779struct BlockLayoutChunk {
5780 uint64_t OffsetInBits;
5783bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
5784 return l.OffsetInBits < r.OffsetInBits;
5788void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
5790 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
5791 SmallVectorImpl<llvm::Metadata *> &Fields) {
5795 if (CGM.getLangOpts().OpenCL) {
5796 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
5797 BlockLayout.getElementOffsetInBits(0),
5799 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
5800 BlockLayout.getElementOffsetInBits(1),
5804 BlockLayout.getElementOffsetInBits(0),
5806 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
5807 BlockLayout.getElementOffsetInBits(1),
5811 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
5812 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
5813 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
5814 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
5815 BlockLayout.getElementOffsetInBits(3),
5817 Fields.push_back(createFieldType(
5822 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
5829 llvm::AllocaInst *Alloca,
5831 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5837 llvm::DIFile *tunit = getOrCreateFile(loc);
5838 unsigned line = getLineNumber(loc);
5839 unsigned column = getColumnNumber(loc);
5844 const llvm::StructLayout *blockLayout =
5848 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
5857 BlockLayoutChunk chunk;
5858 chunk.OffsetInBits =
5859 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
5860 chunk.Capture =
nullptr;
5861 chunks.push_back(chunk);
5865 for (
const auto &capture :
blockDecl->captures()) {
5866 const VarDecl *variable = capture.getVariable();
5873 BlockLayoutChunk chunk;
5874 chunk.OffsetInBits =
5875 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
5876 chunk.Capture = &capture;
5877 chunks.push_back(chunk);
5881 llvm::array_pod_sort(chunks.begin(), chunks.end());
5883 for (
const BlockLayoutChunk &Chunk : chunks) {
5884 uint64_t offsetInBits = Chunk.OffsetInBits;
5891 cast_or_null<CXXMethodDecl>(
blockDecl->getNonClosureContext()))
5893 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(
blockDecl->getParent()))
5894 type = CGM.getContext().getCanonicalTagType(RDecl);
5896 llvm_unreachable(
"unexpected block declcontext");
5898 fields.push_back(createFieldType(
"this",
type, loc,
AS_public,
5899 offsetInBits, tunit, tunit));
5904 StringRef name = variable->
getName();
5906 llvm::DIType *fieldType;
5908 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
5913 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
5914 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
5915 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
5916 PtrInfo.
Width, Align, offsetInBits,
5917 llvm::DINode::FlagZero, fieldType);
5921 offsetInBits, Align, tunit, tunit);
5923 fields.push_back(fieldType);
5927 llvm::raw_svector_ostream(typeName)
5928 <<
"__block_literal_" << CGM.getUniqueBlockCount();
5930 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
5932 llvm::DIType *
type =
5933 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
5934 CGM.getContext().toBits(block.
BlockSize), 0,
5935 llvm::DINode::FlagZero,
nullptr, fieldsArray);
5936 type = DBuilder.createPointerType(
type, CGM.PointerWidthInBits);
5939 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
5943 auto *debugVar = DBuilder.createParameterVariable(
5944 scope, Name, ArgNo, tunit, line,
type,
5945 CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
5948 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
5949 llvm::DILocation::get(CGM.getLLVMContext(), line,
5950 column, scope, CurInlinedAt),
5951 Builder.GetInsertBlock());
5954llvm::DIDerivedType *
5955CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
5960 if (MI != StaticDataMemberCache.end()) {
5961 assert(MI->second &&
"Static data member declaration should still exist");
5972llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
5973 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
5974 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5975 llvm::DIGlobalVariableExpression *GVE =
nullptr;
5977 for (
const auto *Field : RD->
fields()) {
5978 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
5979 StringRef FieldName = Field->getName();
5982 if (FieldName.empty()) {
5983 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
5984 GVE = CollectAnonRecordDecls(RT->getDecl()->getDefinitionOrSelf(), Unit,
5985 LineNo, LinkageName, Var, DContext);
5989 GVE = DBuilder.createGlobalVariableExpression(
5990 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
5991 Var->hasLocalLinkage());
5992 Var->addDebugInfo(GVE);
6004 const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6009 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
6020 struct ReferencesAnonymous
6022 bool RefAnon =
false;
6023 bool VisitRecordType(RecordType *RT) {
6031 ReferencesAnonymous RT;
6044struct ReconstitutableType :
public RecursiveASTVisitor<ReconstitutableType> {
6045 bool Reconstitutable =
true;
6046 bool VisitVectorType(VectorType *FT) {
6047 Reconstitutable =
false;
6050 bool VisitAtomicType(AtomicType *FT) {
6051 Reconstitutable =
false;
6054 bool TraverseEnumType(EnumType *ET,
bool =
false) {
6057 const EnumDecl *ED = ET->getDecl();
6059 Reconstitutable =
false;
6063 Reconstitutable =
false;
6068 bool VisitFunctionProtoType(FunctionProtoType *FT) {
6072 return Reconstitutable;
6074 bool VisitRecordType(RecordType *RT,
bool =
false) {
6076 Reconstitutable =
false;
6086 ReconstitutableType
T;
6088 return T.Reconstitutable;
6091bool CGDebugInfo::HasReconstitutableArgs(
6092 ArrayRef<TemplateArgument> Args)
const {
6093 return llvm::all_of(Args, [&](
const TemplateArgument &TA) {
6133 llvm_unreachable(
"Other, unresolved, template arguments should "
6134 "not be seen here");
6139std::string CGDebugInfo::GetName(
const Decl *D,
bool Qualified,
6140 bool *NameIsSimplified)
const {
6142 llvm::raw_string_ostream
OS(Name);
6143 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
6146 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
6147 CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
6149 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6150 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
6152 std::optional<TemplateArgs> Args;
6154 bool IsOperatorOverload =
false;
6155 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
6156 Args = GetTemplateArgs(RD);
6157 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
6158 Args = GetTemplateArgs(FD);
6160 IsOperatorOverload |=
6163 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
6164 Args = GetTemplateArgs(VD);
6188 bool Reconstitutable =
6189 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
6191 PrintingPolicy PP = getPrintingPolicy();
6193 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
6198 if (NameIsSimplified)
6199 *NameIsSimplified =
true;
6200 bool Mangled = TemplateNamesKind ==
6201 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
6207 std::string EncodedOriginalName;
6208 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
6213 printTemplateArgumentList(OS, Args->Args, PP);
6214 printTemplateArgumentList(EncodedOriginalNameOS, Args->Args, PP);
6216 std::string CanonicalOriginalName;
6217 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
6219 assert(EncodedOriginalName == CanonicalOriginalName);
6228 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6229 if (D->
hasAttr<NoDebugAttr>())
6232 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
6233 return GetName(D,
true);
6239 if (Cached != DeclCache.end())
6240 return Var->addDebugInfo(
6244 llvm::DIFile *Unit =
nullptr;
6245 llvm::DIScope *DContext =
nullptr;
6247 StringRef DeclName, LinkageName;
6249 llvm::MDTuple *TemplateParameters =
nullptr;
6250 collectVarDeclProps(D, Unit, LineNo,
T, DeclName, LinkageName,
6251 TemplateParameters, DContext);
6255 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6260 if (
T->isUnionType() && DeclName.empty()) {
6261 const auto *RD =
T->castAsRecordDecl();
6263 "unnamed non-anonymous struct or union?");
6264 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
6269 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->
getType());
6270 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
6271 if (D->
hasAttr<CUDASharedAttr>())
6274 else if (D->
hasAttr<CUDAConstantAttr>())
6278 AppendAddressSpaceXDeref(AddressSpace,
Expr);
6280 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
6281 GVE = DBuilder.createGlobalVariableExpression(
6282 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(
T, Unit),
6283 Var->hasLocalLinkage(),
true,
6284 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
6285 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
6286 Align, Annotations);
6287 Var->addDebugInfo(GVE);
6293 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6294 if (VD->
hasAttr<NoDebugAttr>())
6296 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
6297 return GetName(VD,
true);
6302 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
6303 StringRef Name = VD->
getName();
6304 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
6306 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
6308 if (CGM.getCodeGenOpts().EmitCodeView) {
6319 CanQualType T = CGM.getContext().getCanonicalTagType(ED);
6320 [[maybe_unused]] llvm::DIType *EDTy = getOrCreateType(
T, Unit);
6321 assert(EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
6331 auto *VarD = dyn_cast<VarDecl>(VD);
6332 if (VarD && VarD->isStaticDataMember()) {
6334 getDeclContextDescriptor(VarD);
6339 RetainedTypes.push_back(
6340 CGM.getContext().getCanonicalTagType(RD).getAsOpaquePtr());
6344 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
6346 auto &GV = DeclCache[VD];
6350 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
6351 llvm::MDTuple *TemplateParameters =
nullptr;
6355 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
6356 TemplateParameters = parameterNodes.get();
6359 GV.reset(DBuilder.createGlobalVariableExpression(
6360 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
6361 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
6362 TemplateParameters, Align));
6367 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6368 if (D->
hasAttr<NoDebugAttr>())
6372 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
6373 StringRef Name = D->
getName();
6374 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
6376 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6377 llvm::DIGlobalVariableExpression *GVE =
6378 DBuilder.createGlobalVariableExpression(
6379 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
6380 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
6381 Var->addDebugInfo(GVE);
6388 if (CGM.getCodeGenOpts().getDebugInfo() <=
6389 llvm::codegenoptions::DebugLineTablesOnly)
6392 llvm::DILocation *DIL =
Value->getDebugLoc().get();
6396 llvm::DIFile *Unit = DIL->getFile();
6397 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
6402 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
6403 llvm::Value *Var = Load->getPointerOperand();
6408 auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
6409 return DbgDeclare->getVariable()->getType() ==
Type;
6411 if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6415 llvm::DILocalVariable *D =
6416 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
6417 Type,
false, llvm::DINode::FlagArtificial);
6419 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
6420 DBuilder.insertDbgValue(
Value, D, DBuilder.createExpression(), DIL,
6430 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6434 if (D->
hasAttr<NoDebugAttr>())
6437 auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
6452 if (!(DI = getDeclarationOrDefinition(
6453 AliaseeDecl.getCanonicalDecl().getDecl())))
6456 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6459 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
6460 DContext, DI, getOrCreateFile(Loc), getLineNumber(Loc), D->getName());
6474 llvm::DIFile *
File = getOrCreateFile(Loc);
6475 llvm::DIGlobalVariableExpression *Debug =
6476 DBuilder.createGlobalVariableExpression(
6477 nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
6478 getLineNumber(Loc), getOrCreateType(S->
getType(),
File),
true);
6479 GV->addDebugInfo(Debug);
6482llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
6483 if (!LexicalBlockStack.empty())
6484 return LexicalBlockStack.back();
6485 llvm::DIScope *Mod = getParentModuleOrNull(D);
6486 return getContextDescriptor(D, Mod ? Mod : TheCU);
6490 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6494 CGM.getCodeGenOpts().DebugExplicitImport) {
6498 DBuilder.createImportedModule(
6500 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
6505 if (llvm::DINode *
Target =
6508 DBuilder.createImportedDeclaration(
6510 getOrCreateFile(Loc), getLineNumber(Loc));
6515 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6518 "We shouldn't be codegening an invalid UsingDecl containing no decls");
6520 for (
const auto *USD : UD.
shadows()) {
6525 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
6526 if (
const auto *AT = FD->getType()
6529 if (AT->getDeducedType().isNull())
6540 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6543 "We shouldn't be codegening an invalid UsingEnumDecl"
6544 " containing no decls");
6546 for (
const auto *USD : UD.
shadows())
6551 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
6553 if (
Module *M = ID.getImportedModule()) {
6555 auto Loc = ID.getLocation();
6556 DBuilder.createImportedDeclaration(
6557 getCurrentContextDescriptor(
cast<Decl>(ID.getDeclContext())),
6558 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
6559 getLineNumber(Loc));
6563llvm::DIImportedEntity *
6565 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6567 auto &VH = NamespaceAliasCache[&NA];
6570 llvm::DIImportedEntity *R;
6572 if (
const auto *Underlying =
6575 R = DBuilder.createImportedDeclaration(
6578 getLineNumber(Loc), NA.
getName());
6580 R = DBuilder.createImportedDeclaration(
6583 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
6589CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6593 auto I = NamespaceCache.find(NSDecl);
6594 if (I != NamespaceCache.end())
6597 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6599 llvm::DINamespace *NS =
6600 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6601 NamespaceCache[NSDecl].reset(NS);
6606 assert(TheCU &&
"no main compile unit");
6607 TheCU->setDWOId(Signature);
6613 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6614 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
6616 ? CreateTypeDefinition(E.Type, E.Unit)
6618 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
6622 for (
const auto &P : ObjCMethodCache) {
6623 if (P.second.empty())
6626 QualType QTy(P.first->getTypeForDecl(), 0);
6628 assert(It != TypeCache.end());
6630 llvm::DICompositeType *InterfaceDecl =
6633 auto CurElts = InterfaceDecl->getElements();
6637 for (
auto &SubprogramDirect : P.second)
6638 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6639 EltTys.push_back(SubprogramDirect.getPointer());
6641 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6642 DBuilder.replaceArrays(InterfaceDecl, Elements);
6645 for (
const auto &P : ReplaceMap) {
6648 assert(Ty->isForwardDecl());
6650 auto It = TypeCache.find(P.first);
6651 assert(It != TypeCache.end());
6654 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6658 for (
const auto &P : FwdDeclReplaceMap) {
6661 llvm::Metadata *Repl;
6663 auto It = DeclCache.find(P.first);
6667 if (It == DeclCache.end())
6672 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6673 Repl = GVE->getVariable();
6679 for (
auto &RT : RetainedTypes)
6680 if (
auto MD = TypeCache[RT])
6683 DBuilder.finalize();
6688 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
6689 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6690 DBuilder.retainType(DieTy);
6694 if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
6695 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6696 DBuilder.retainType(DieTy);
6700 if (LexicalBlockStack.empty())
6701 return llvm::DebugLoc();
6703 llvm::MDNode *
Scope = LexicalBlockStack.back();
6704 return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
6705 getColumnNumber(Loc),
Scope);
6711 if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
6712 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6713 DebugKind == llvm::codegenoptions::LocTrackingOnly ||
6714 !CGM.getCodeGenOpts().DebugCallSiteInfo)
6715 return llvm::DINode::FlagZero;
6720 bool SupportsDWARFv4Ext =
6721 CGM.getCodeGenOpts().DwarfVersion == 4 &&
6722 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6723 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6725 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
6726 return llvm::DINode::FlagZero;
6728 return llvm::DINode::FlagAllCallsDescribed;
6739 return DBuilder.createConstantValueExpression(
6740 Val.
getFloat().bitcastToAPInt().getZExtValue());
6745 llvm::APSInt
const &ValInt = Val.
getInt();
6746 std::optional<uint64_t> ValIntOpt;
6747 if (ValInt.isUnsigned())
6748 ValIntOpt = ValInt.tryZExtValue();
6749 else if (
auto tmp = ValInt.trySExtValue())
6752 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6755 return DBuilder.createConstantValueExpression(ValIntOpt.value());
6760CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &
CGF,
6762 : RunCleanupsScope(
CGF), Range(Range), ParentScope(
CGF.CurLexicalScope) {
6763 CGF.CurLexicalScope =
this;
6765 DI->EmitLexicalBlockStart(
CGF.Builder, Range.getBegin());
6770 DI->EmitLexicalBlockEnd(
CGF.Builder, Range.getEnd());
6783#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
6785 Label = "__ubsan_check_" #Name; \
6789#undef SANITIZER_CHECK
6800#define SANITIZER(NAME, ID) \
6801 case SanitizerKind::SO_##ID: \
6802 Label = "__ubsan_check_" NAME; \
6804#include "clang/Basic/Sanitizers.def"
6806 llvm_unreachable(
"unexpected sanitizer kind");
6811 for (
unsigned int i = 0; i < Label.length(); i++)
6812 if (!std::isalpha(Label[i]))
6821 llvm::DILocation *CheckDebugLoc =
Builder.getCurrentDebugLocation();
6823 if (!DI || !CheckDebugLoc)
6824 return CheckDebugLoc;
6825 const auto &AnnotateDebugInfo =
6826 CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo;
6827 if (AnnotateDebugInfo.empty())
6828 return CheckDebugLoc;
6831 if (Ordinals.size() == 1)
6836 if (any_of(Ordinals, [&](
auto Ord) {
return AnnotateDebugInfo.has(Ord); })) {
6840 llvm::DIFile *
File = llvm::DIFile::get(
CGM.getLLVMContext(),
6841 "ubsan_interface.h",
6843 return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label,
File);
6846 return CheckDebugLoc;
6854 assert(!CGF->IsSanitizerScope);
6855 CGF->IsSanitizerScope =
true;
6859 assert(CGF->IsSanitizerScope);
6860 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 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 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 llvm::dwarf::Tag getNextQualifier(Qualifiers &Q)
static bool IsDecomposedVarDecl(VarDecl const *VD)
Returns true if VD is a a holding variable (aka a VarDecl retrieved using BindingDecl::getHoldingVar)...
static SmallString< 256 > getTypeIdentifier(const TagType *Ty, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static unsigned getDwarfCC(CallingConv CC)
static bool ReferencesAnonymousEntity(ArrayRef< TemplateArgument > Args)
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.
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 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).
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.
capture_const_iterator captures_end() const
method_range methods() const
bool hasConstexprNonCopyMoveConstructor() const
Determine whether this class has at least one constexpr constructor other than the copy or move const...
method_iterator method_begin() const
Method begin iterator.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
base_class_range vbases()
bool isDynamicClass() const
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.
CharUnits - This is an opaque type for sizes expressed in character units.
bool isPositive() const
isPositive - Test whether the quantity is greater than zero.
bool isZero() const
isZero - Test whether the quantity equals zero.
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
static CharUnits Zero()
Zero - Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
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)
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.
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.
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::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
void EmitPseudoVariable(CGBuilderTy &Builder, llvm::Instruction *Value, QualType Ty)
Emit a pseudo variable and debug info for an intermediate value if it does not correspond to a variab...
void addCallTargetIfVirtual(const FunctionDecl *FD, llvm::CallBase *CI)
Add call target information.
std::string remapDIPath(StringRef) const
Remap a given path with the current debug prefix map.
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
void addHeapAllocSiteMetadata(llvm::CallBase *CallSite, QualType AllocatedTy, SourceLocation Loc)
Add heapallocsite metadata for MSAllocator calls.
void setDwoId(uint64_t Signature)
Module debugging: Support for building PCMs.
QualType getFunctionType(const FunctionDecl *FD, QualType RetTy, const SmallVectorImpl< const VarDecl * > &Args)
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
void completeType(const EnumDecl *ED)
void EmitDeclareOfBlockDeclRefVariable(const VarDecl *variable, llvm::Value *storage, CGBuilderTy &Builder, const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint=nullptr)
Emit call to llvm.dbg.declare for an imported variable declaration in a block.
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
llvm::DILocation * getInlinedAt() const
llvm::DILocation * CreateSyntheticInlineAt(llvm::DebugLoc ParentLocation, llvm::DISubprogram *SynthSubprogram)
Create a debug location from Location that adds an artificial inline frame where the frame name is Fu...
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
~LexicalScope()
Exit this cleanup scope, emitting any accumulated cleanups.
void ForceCleanup()
Force the emission of cleanups now, instead of waiting until this object is destroyed.
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
CGDebugInfo * getDebugInfo()
llvm::DILocation * SanitizerAnnotateDebugInfo(ArrayRef< SanitizerKind::SanitizerOrdinal > Ordinals, SanitizerHandler Handler)
Returns debug info, with additional annotation if CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo[Ordi...
This class organizes the cross-function state that is used while generating LLVM code.
const LangOptions & getLangOpts() const
const TargetInfo & getTarget() const
CGCXXABI & getCXXABI() const
ASTContext & getContext() const
const CodeGenOptions & getCodeGenOpts() const
llvm::LLVMContext & getLLVMContext()
llvm::GlobalVariable::LinkageTypes getVTableLinkage(const CXXRecordDecl *RD)
Return the appropriate linkage for the vtable, VTT, and type information of the given class.
SanitizerDebugLocation(CodeGenFunction *CGF, ArrayRef< SanitizerKind::SanitizerOrdinal > Ordinals, SanitizerHandler Handler)
~SanitizerDebugLocation()
unsigned getNumColumns() const
Returns the number of columns in the matrix.
unsigned getNumRows() const
Returns the number of rows in the matrix.
DeclContext * 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...
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...
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.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
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.
SourceLocation getFileLoc(SourceLocation Loc) const
Given Loc, if it is a macro location return the expansion location or the spelling location,...
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.
std::optional< llvm::MemoryBufferRef > getBufferOrNone(FileID FID, SourceLocation Loc=SourceLocation()) const
Return the buffer for the specified FileID.
A trivial tuple used to represent a source range.
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.
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
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.
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,...
The JSON file list parser is used to communicate input to InstallAPI.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Default
Set to the current date and time.
@ Result
The result type of a method or function.
const FunctionProtoType * T
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Deleting
Deleting dtor.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ Generic
not a target-specific vector type
U cast(CodeGen::Address addr)
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ CXXThis
Parameter for C++ 'this' argument.
@ ObjCSelf
Parameter for Objective-C 'self' argument.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
__packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 uint32_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.
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.
unsigned PrettyEnums
Whether to print enumerators with a matching enumerator name or via cast.
unsigned MSVCFormatting
Use whitespace and punctuation like MSVC does.
unsigned SplitTemplateClosers
Whether nested templates must be closed like 'a<b<c> >' rather than 'a<b<c>>'.
unsigned AlwaysIncludeTypeForTemplateArgument
Whether to use type suffixes (eg: 1U) on integral non-type template parameters.
unsigned UsePreferredNames
Whether to use C++ template preferred_name attributes when printing templates.
unsigned UseEnumerators
Whether to print enumerator non-type template parameters with a matching enumerator name or via cast ...
unsigned SuppressInlineNamespace
Suppress printing parts of scope specifiers that correspond to inline namespaces.
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.
unsigned PrintAsCanonical
Whether to print entities as written or canonically.