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);
1801 if (
T.isSPIROrSPIRV())
1802 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1807 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1809 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1811 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1813 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1815 return llvm::dwarf::DW_CC_BORLAND_pascal;
1817 return llvm::dwarf::DW_CC_LLVM_Win64;
1819 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1823 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1825 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1827 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1829 return llvm::dwarf::DW_CC_LLVM_DeviceKernel;
1831 return llvm::dwarf::DW_CC_LLVM_Swift;
1833 return llvm::dwarf::DW_CC_LLVM_SwiftTail;
1835 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1837 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1839 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1841 return llvm::dwarf::DW_CC_LLVM_M68kRTD;
1843 return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1845 return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
1846#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
1860 return llvm::dwarf::DW_CC_LLVM_RISCVVLSCall;
1866 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1868 Flags |= llvm::DINode::FlagLValueReference;
1870 Flags |= llvm::DINode::FlagRValueReference;
1874llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1875 llvm::DIFile *Unit) {
1876 const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
1878 if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
1884 SmallVector<llvm::Metadata *, 16> EltTys;
1887 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1889 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1893 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1896 for (
const QualType &ParamType : FPT->param_types())
1897 EltTys.push_back(getOrCreateType(ParamType, Unit));
1898 if (FPT->isVariadic())
1899 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1902 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1903 llvm::DIType *F = DBuilder.createSubroutineType(
1904 EltTypeArray, Flags,
1909llvm::DIDerivedType *
1910CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1911 llvm::DIScope *RecordTy,
const RecordDecl *RD) {
1912 StringRef Name = BitFieldDecl->
getName();
1913 QualType Ty = BitFieldDecl->
getType();
1914 if (BitFieldDecl->
hasAttr<PreferredTypeAttr>())
1917 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1918 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1921 llvm::DIFile *
File = getOrCreateFile(Loc);
1922 unsigned Line = getLineNumber(Loc);
1924 const CGBitFieldInfo &BitFieldInfo =
1925 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1927 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1934 if (CGM.getDataLayout().isBigEndian())
1936 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1938 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(BitFieldDecl);
1939 return DBuilder.createBitFieldMemberType(
1940 RecordTy, Name,
File,
Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1941 Flags, DebugType, Annotations);
1944llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
1945 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
1946 llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI,
const RecordDecl *RD) {
1948 if (!CGM.getTargetCodeGenInfo().shouldEmitDWARFBitFieldSeparators())
1973 if (PreviousFieldsDI.empty())
1977 auto *PreviousMDEntry =
1978 PreviousFieldsDI.empty() ?
nullptr : PreviousFieldsDI.back();
1979 auto *PreviousMDField =
1980 dyn_cast_or_null<llvm::DIDerivedType>(PreviousMDEntry);
1981 if (!PreviousMDField || !PreviousMDField->isBitField() ||
1982 PreviousMDField->getSizeInBits() == 0)
1986 std::advance(PreviousBitfield, BitFieldDecl->
getFieldIndex() - 1);
1988 assert(PreviousBitfield->isBitField());
1990 if (!PreviousBitfield->isZeroLengthBitField())
1993 QualType Ty = PreviousBitfield->getType();
1994 SourceLocation Loc = PreviousBitfield->getLocation();
1995 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1996 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1997 llvm::DIScope *RecordTy = BitFieldDI->getScope();
1999 llvm::DIFile *
File = getOrCreateFile(Loc);
2000 unsigned Line = getLineNumber(Loc);
2006 llvm::DINode::DIFlags Flags =
2008 llvm::DINodeArray Annotations =
2009 CollectBTFDeclTagAnnotations(*PreviousBitfield);
2010 return DBuilder.createBitFieldMemberType(
2011 RecordTy,
"",
File,
Line, 0, StorageOffsetInBits, StorageOffsetInBits,
2012 Flags, DebugType, Annotations);
2015llvm::DIType *CGDebugInfo::createFieldType(
2017 uint64_t offsetInBits,
uint32_t AlignInBits, llvm::DIFile *tunit,
2018 llvm::DIScope *scope,
const RecordDecl *RD, llvm::DINodeArray Annotations) {
2019 llvm::DIType *debugType = getOrCreateType(
type, tunit);
2022 llvm::DIFile *file = getOrCreateFile(loc);
2023 const unsigned line = getLineNumber(loc.
isValid() ? loc : CurLoc);
2026 auto Align = AlignInBits;
2027 if (!
type->isIncompleteArrayType()) {
2028 TypeInfo TI = CGM.getContext().getTypeInfo(
type);
2029 SizeInBits = TI.
Width;
2035 return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
2036 offsetInBits, flags, debugType, Annotations);
2040CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
2041 llvm::DIFile *FileScope) {
2045 llvm::DISubprogram *&SP = InlinedSubprogramMap[FuncName];
2048 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(
nullptr);
2049 SP = DBuilder.createFunction(
2050 FileScope, FuncName, StringRef(),
2051 FileScope, 0, DIFnTy,
2053 llvm::DINode::FlagArtificial,
2054 llvm::DISubprogram::SPFlagDefinition,
2055 nullptr,
nullptr,
nullptr,
2056 nullptr, StringRef(),
2057 CGM.getCodeGenOpts().DebugKeyInstructions);
2064CGDebugInfo::GetLambdaCaptureName(
const LambdaCapture &
Capture) {
2066 return CGM.getCodeGenOpts().EmitCodeView ?
"__this" :
"this";
2068 assert(
Capture.capturesVariable());
2070 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2071 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2073 return CaptureDecl->
getName();
2076void CGDebugInfo::CollectRecordLambdaFields(
2077 const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
2078 llvm::DIType *RecordTy) {
2083 unsigned fieldno = 0;
2086 I != E; ++I, ++Field, ++fieldno) {
2087 const LambdaCapture &
Capture = *I;
2089 CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
2091 assert(!
Field->isBitField() &&
"lambdas don't have bitfield members!");
2101 Loc =
Field->getLocation();
2102 }
else if (
Capture.capturesVariable()) {
2105 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2106 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2113 llvm::DIFile *VUnit = getOrCreateFile(Loc);
2115 elements.push_back(createFieldType(
2117 Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
2123template <
typename T>
2124static llvm::Constant *
2135 return llvm::ConstantDataArray::get(Ctx, Vals);
2148 const QualType ElemQTy = ArrayTy->getElementType();
2155 switch (ElemBitWidth) {
2171llvm::DIDerivedType *
2172CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
2173 const RecordDecl *RD) {
2177 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
2178 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
2180 unsigned LineNumber = getLineNumber(Var->
getLocation());
2181 StringRef VName = Var->
getName();
2185 llvm::Constant *
C =
nullptr;
2190 C = llvm::ConstantInt::get(CGM.getLLVMContext(),
Value->getInt());
2191 if (
Value->isFloat())
2192 C = llvm::ConstantFP::get(CGM.getLLVMContext(),
Value->getFloat());
2193 if (
Value->isArray())
2199 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2200 ? llvm::dwarf::DW_TAG_variable
2201 : llvm::dwarf::DW_TAG_member;
2203 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
2204 RecordTy, VName, VUnit, LineNumber, VTy, Flags,
C, Tag, Align);
2209void CGDebugInfo::CollectRecordNormalField(
2210 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
2211 SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
2212 const RecordDecl *RD) {
2217 if (
name.empty() && !
type->isRecordType())
2220 llvm::DIType *FieldType;
2222 llvm::DIDerivedType *BitFieldType;
2223 FieldType = BitFieldType = createBitFieldType(field, RecordTy, RD);
2224 if (llvm::DIType *Separator =
2225 createBitFieldSeparatorIfNeeded(field, BitFieldType, elements, RD))
2226 elements.push_back(Separator);
2229 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
2232 OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
2235 elements.push_back(FieldType);
2238void CGDebugInfo::CollectRecordNestedType(
2239 const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) {
2240 QualType Ty = CGM.getContext().getTypeDeclType(TD);
2247 if (llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)))
2248 elements.push_back(nestedType);
2251void CGDebugInfo::CollectRecordFields(
2252 const RecordDecl *record, llvm::DIFile *tunit,
2253 SmallVectorImpl<llvm::Metadata *> &elements,
2254 llvm::DICompositeType *RecordTy) {
2255 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
2257 if (CXXDecl && CXXDecl->
isLambda())
2258 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
2260 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
2263 unsigned fieldNo = 0;
2267 for (
const auto *I : record->
decls())
2268 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
2269 if (
V->hasAttr<NoDebugAttr>())
2274 if (CGM.getCodeGenOpts().EmitCodeView &&
2282 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
2283 if (MI != StaticDataMemberCache.end()) {
2284 assert(MI->second &&
2285 "Static data member declaration should still exist");
2286 elements.push_back(MI->second);
2288 auto Field = CreateRecordStaticField(
V, RecordTy, record);
2289 elements.push_back(Field);
2291 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
2292 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
2293 elements, RecordTy, record);
2297 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
2300 if (
const auto *nestedType = dyn_cast<TypeDecl>(I)) {
2305 if (!nestedType->isImplicit() &&
2306 nestedType->getDeclContext() == record)
2307 CollectRecordNestedType(nestedType, elements);
2313llvm::DISubroutineType *
2314CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *
Method,
2315 llvm::DIFile *Unit) {
2316 const FunctionProtoType *
Func =
Method->getType()->getAs<FunctionProtoType>();
2318 return cast_or_null<llvm::DISubroutineType>(
2319 getOrCreateType(QualType(
Func, 0), Unit));
2322 if (!
Method->hasCXXExplicitFunctionObjectParameter())
2323 ThisType =
Method->getThisType();
2325 return getOrCreateInstanceMethodType(ThisType,
Func, Unit);
2328llvm::DISubroutineType *CGDebugInfo::getOrCreateMethodTypeForDestructor(
2329 const CXXMethodDecl *
Method, llvm::DIFile *Unit, QualType FNType) {
2330 const FunctionProtoType *
Func = FNType->
getAs<FunctionProtoType>();
2332 return getOrCreateInstanceMethodType(
Method->getThisType(),
Func, Unit,
true);
2335llvm::DISubroutineType *
2336CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
2337 const FunctionProtoType *
Func,
2338 llvm::DIFile *Unit,
bool SkipFirst) {
2339 FunctionProtoType::ExtProtoInfo EPI =
Func->getExtProtoInfo();
2354 getOrCreateType(CGM.getContext().getFunctionType(
2355 Func->getReturnType(),
Func->getParamTypes(), EPI),
2357 llvm::DITypeArray Args = OriginalFunc->getTypeArray();
2358 assert(Args.size() &&
"Invalid number of arguments!");
2360 SmallVector<llvm::Metadata *, 16> Elts;
2363 Elts.push_back(Args[0]);
2365 const bool HasExplicitObjectParameter = ThisPtr.
isNull();
2369 if (!HasExplicitObjectParameter) {
2370 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2373 DBuilder.createObjectPointerType(ThisPtrType,
true);
2374 Elts.push_back(ThisPtrType);
2378 for (
unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i < e; ++i)
2379 Elts.push_back(Args[i]);
2382 if (HasExplicitObjectParameter) {
2383 assert(Elts.size() >= 2 && Args.size() >= 2 &&
2384 "Expected at least return type and object parameter.");
2385 Elts[1] = DBuilder.createObjectPointerType(Args[1],
false);
2388 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2390 return DBuilder.createSubroutineType(
2391 EltTypeArray, OriginalFunc->getFlags(),
2398 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
2406CGDebugInfo::GetMethodLinkageName(
const CXXMethodDecl *
Method)
const {
2409 const bool IsCtorOrDtor =
2412 if (IsCtorOrDtor && !CGM.getCodeGenOpts().DebugStructorDeclLinkageNames)
2419 if (IsCtorOrDtor && !CGM.getTarget().getCXXABI().hasConstructorVariants())
2422 if (
const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(
Method))
2425 if (
const auto *Dtor = llvm::dyn_cast<CXXDestructorDecl>(
Method))
2428 return CGM.getMangledName(
Method);
2431bool CGDebugInfo::shouldGenerateVirtualCallSite()
const {
2434 (CGM.getCodeGenOpts().DwarfVersion >= 5));
2437llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
2438 const CXXMethodDecl *
Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
2441 StringRef MethodName = getFunctionName(
Method);
2442 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(
Method, Unit);
2444 StringRef MethodLinkageName;
2451 MethodLinkageName = GetMethodLinkageName(
Method);
2454 llvm::DIFile *MethodDefUnit =
nullptr;
2455 unsigned MethodLine = 0;
2456 if (!
Method->isImplicit()) {
2457 MethodDefUnit = getOrCreateFile(
Method->getLocation());
2458 MethodLine = getLineNumber(
Method->getLocation());
2462 llvm::DIType *ContainingType =
nullptr;
2463 unsigned VIndex = 0;
2464 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2465 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
2466 int ThisAdjustment = 0;
2469 if (
Method->isPureVirtual())
2470 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
2472 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
2474 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2478 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(
Method);
2482 const auto *DD = dyn_cast<CXXDestructorDecl>(
Method);
2485 DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
2486 CGM.getContext().getLangOpts())
2490 MethodVFTableLocation ML =
2491 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
2499 if (
Method->size_overridden_methods() == 0)
2500 Flags |= llvm::DINode::FlagIntroducedVirtual;
2505 ThisAdjustment = CGM.getCXXABI()
2506 .getVirtualFunctionPrologueThisAdjustment(GD)
2509 ContainingType = RecordTy;
2512 if (
Method->getCanonicalDecl()->isDeleted())
2513 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
2515 if (
Method->isNoReturn())
2516 Flags |= llvm::DINode::FlagNoReturn;
2519 Flags |= llvm::DINode::FlagStaticMember;
2520 if (
Method->isImplicit())
2521 Flags |= llvm::DINode::FlagArtificial;
2523 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(
Method)) {
2524 if (CXXC->isExplicit())
2525 Flags |= llvm::DINode::FlagExplicit;
2526 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(
Method)) {
2527 if (CXXC->isExplicit())
2528 Flags |= llvm::DINode::FlagExplicit;
2530 if (
Method->hasPrototype())
2531 Flags |= llvm::DINode::FlagPrototyped;
2533 Flags |= llvm::DINode::FlagLValueReference;
2535 Flags |= llvm::DINode::FlagRValueReference;
2536 if (!
Method->isExternallyVisible())
2537 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2538 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
2539 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
2543 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor)
2544 if (
const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(
Method))
2547 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(
Method, Unit);
2548 llvm::DISubprogram *SP = DBuilder.createMethod(
2549 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
2550 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
2551 TParamsArray.get(),
nullptr,
2552 CGM.getCodeGenOpts().DebugKeyInstructions);
2554 SPCache[
Method->getCanonicalDecl()].reset(SP);
2559void CGDebugInfo::CollectCXXMemberFunctions(
2560 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2561 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy) {
2566 for (
const auto *I : RD->
decls()) {
2567 const auto *
Method = dyn_cast<CXXMethodDecl>(I);
2581 if (
Method->getType()->castAs<FunctionProtoType>()->getContainedAutoType())
2590 auto MI = SPCache.find(
Method->getCanonicalDecl());
2591 EltTys.push_back(MI == SPCache.end()
2592 ? CreateCXXMemberFunction(
Method, Unit, RecordTy)
2593 :
static_cast<llvm::Metadata *
>(MI->second));
2597void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2598 SmallVectorImpl<llvm::Metadata *> &EltTys,
2599 llvm::DIType *RecordTy) {
2600 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
2601 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
2602 llvm::DINode::FlagZero);
2606 if (CGM.getCodeGenOpts().EmitCodeView) {
2607 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
2608 llvm::DINode::FlagIndirectVirtualBase);
2612void CGDebugInfo::CollectCXXBasesAux(
2613 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2614 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
2616 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
2617 llvm::DINode::DIFlags StartingFlags) {
2618 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
2619 for (
const auto &BI : Bases) {
2622 BI.getType()->castAsCanonical<RecordType>()->getDecl())
2624 if (!SeenTypes.insert(Base).second)
2626 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
2627 llvm::DINode::DIFlags BFlags = StartingFlags;
2631 if (BI.isVirtual()) {
2632 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2635 BaseOffset = 0 - CGM.getItaniumVTableContext()
2636 .getVirtualBaseOffsetOffset(RD, Base)
2642 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
2643 VBPtrOffset = CGM.getContext()
2644 .getASTRecordLayout(RD)
2648 BFlags |= llvm::DINode::FlagVirtual;
2655 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
2656 VBPtrOffset, BFlags);
2657 EltTys.push_back(DTy);
2662CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
2663 llvm::DIFile *Unit) {
2665 return llvm::DINodeArray();
2666 TemplateArgs &Args = *OArgs;
2667 SmallVector<llvm::Metadata *, 16> TemplateParams;
2668 for (
unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
2669 const TemplateArgument &TA = Args.Args[i];
2673 Name = Args.TList->getParam(i)->getName();
2677 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
2678 TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
2679 TheCU, Name, TTy, defaultParameter));
2684 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2685 TheCU, Name, TTy, defaultParameter,
2686 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
2691 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2692 llvm::Constant *
V =
nullptr;
2695 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
2696 !D->
hasAttr<CUDADeviceAttr>()) {
2699 if (
const auto *VD = dyn_cast<VarDecl>(D))
2700 V = CGM.GetAddrOfGlobalVar(VD);
2703 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(D);
2704 MD && MD->isImplicitObjectMemberFunction())
2705 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
2706 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2707 V = CGM.GetAddrOfFunction(FD);
2710 else if (
const auto *MPT =
2711 dyn_cast<MemberPointerType>(
T.getTypePtr())) {
2715 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
2717 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
2718 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
2719 }
else if (
const auto *GD = dyn_cast<MSGuidDecl>(D)) {
2720 V = CGM.GetAddrOfMSGuidDecl(GD).getPointer();
2721 }
else if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(D)) {
2723 V = ConstantEmitter(CGM).emitAbstract(
2724 SourceLocation(), TPO->getValue(), TPO->getType());
2726 V = CGM.GetAddrOfTemplateParamObject(TPO).getPointer();
2728 assert(
V &&
"Failed to find template parameter pointer");
2729 V =
V->stripPointerCasts();
2731 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2732 TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(
V)));
2736 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2737 llvm::Constant *
V =
nullptr;
2740 if (
const auto *MPT = dyn_cast<MemberPointerType>(
T.getTypePtr()))
2746 if (MPT->isMemberDataPointer())
2747 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
2749 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
2750 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2751 TheCU, Name, TTy, defaultParameter,
V));
2755 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2756 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(
2758 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2759 TheCU, Name, TTy, defaultParameter,
V));
2762 std::string QualName;
2763 llvm::raw_string_ostream
OS(QualName);
2765 OS, getPrintingPolicy());
2766 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2767 TheCU, Name,
nullptr, QualName, defaultParameter));
2771 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
2772 TheCU, Name,
nullptr,
2779 T = CGM.getContext().getLValueReferenceType(
T);
2780 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(E,
T);
2781 assert(
V &&
"Expression in template argument isn't constant");
2782 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2783 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2784 TheCU, Name, TTy, defaultParameter,
V->stripPointerCasts()));
2790 "These argument types shouldn't exist in concrete types");
2793 return DBuilder.getOrCreateArray(TemplateParams);
2796std::optional<CGDebugInfo::TemplateArgs>
2797CGDebugInfo::GetTemplateArgs(
const FunctionDecl *FD)
const {
2805 return std::nullopt;
2807std::optional<CGDebugInfo::TemplateArgs>
2808CGDebugInfo::GetTemplateArgs(
const VarDecl *VD)
const {
2812 auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VD);
2814 return std::nullopt;
2815 VarTemplateDecl *
T = TS->getSpecializedTemplate();
2816 const TemplateParameterList *TList =
T->getTemplateParameters();
2817 auto TA = TS->getTemplateArgs().asArray();
2818 return {{TList, TA}};
2820std::optional<CGDebugInfo::TemplateArgs>
2821CGDebugInfo::GetTemplateArgs(
const RecordDecl *RD)
const {
2822 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2826 TemplateParameterList *TPList =
2827 TSpecial->getSpecializedTemplate()->getTemplateParameters();
2828 const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
2829 return {{TPList, TAList.
asArray()}};
2831 return std::nullopt;
2835CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
2836 llvm::DIFile *Unit) {
2837 return CollectTemplateParams(GetTemplateArgs(FD), Unit);
2840llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
2841 llvm::DIFile *Unit) {
2842 return CollectTemplateParams(GetTemplateArgs(VL), Unit);
2845llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
const RecordDecl *RD,
2846 llvm::DIFile *Unit) {
2847 return CollectTemplateParams(GetTemplateArgs(RD), Unit);
2850void CGDebugInfo::CollectBTFDeclTagAnnotations(
2851 const Decl *D, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2853 llvm::Metadata *Ops[2] = {
2854 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_decl_tag")),
2855 llvm::MDString::get(CGM.getLLVMContext(), I->getBTFDeclTag())};
2856 Annotations.push_back(llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2860llvm::DINodeArray CGDebugInfo::CollectBTFDeclTagAnnotations(
const Decl *D) {
2861 if (!D->
hasAttr<BTFDeclTagAttr>())
2864 SmallVector<llvm::Metadata *, 4> Annotations;
2865 CollectBTFDeclTagAnnotations(D, Annotations);
2866 return DBuilder.getOrCreateArray(Annotations);
2869void CGDebugInfo::CollectBTFTypeTagAnnotations(
2870 QualType Ty, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2871 const BTFTagAttributedType *BTFAttrTy;
2873 BTFAttrTy = dyn_cast<BTFTagAttributedType>(
Atomic->getValueType());
2875 BTFAttrTy = dyn_cast<BTFTagAttributedType>(Ty);
2878 StringRef
Tag = BTFAttrTy->getAttr()->getBTFTypeTag();
2880 llvm::Metadata *Ops[2] = {
2881 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_type_tag")),
2882 llvm::MDString::get(CGM.getLLVMContext(), Tag)};
2883 Annotations.insert(Annotations.begin(),
2884 llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2886 BTFAttrTy = dyn_cast<BTFTagAttributedType>(BTFAttrTy->getWrappedType());
2890llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
2892 return VTablePtrType;
2894 ASTContext &Context = CGM.getContext();
2897 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
2898 llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy);
2899 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
2901 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2902 std::optional<unsigned> DWARFAddressSpace =
2903 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2905 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
2906 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2907 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
2908 return VTablePtrType;
2911StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
2923 if (!CGM.getTarget().getCXXABI().isItaniumFamily())
2925 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
2935 if (CGM.getTarget().getTriple().isOSBinFormatCOFF() &&
2936 VTable->isDeclarationForLinker())
2940 StringRef SymbolName =
"__clang_vtable";
2942 QualType VoidPtr = Context.getPointerType(Context.VoidTy);
2951 llvm::DIScope *DContext = getContextDescriptor(RD, TheCU);
2953 llvm::DIFile *Unit = getOrCreateFile(Loc);
2954 llvm::DIType *VTy = getOrCreateType(VoidPtr, Unit);
2956 llvm::DINode::FlagArtificial;
2957 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2958 ? llvm::dwarf::DW_TAG_variable
2959 : llvm::dwarf::DW_TAG_member;
2960 llvm::DIDerivedType *DT = DBuilder.createStaticMemberType(
2961 Ctxt, SymbolName, Unit, 0, VTy, Flags,
2965 unsigned PAlign = CGM.getVtableGlobalVarAlignment();
2969 llvm::DIGlobalVariableExpression *GVE =
2970 DBuilder.createGlobalVariableExpression(
2971 TheCU, SymbolName, VTable->getName(), Unit, 0,
2972 getOrCreateType(VoidPtr, Unit), VTable->hasLocalLinkage(),
2973 true,
nullptr, DT,
nullptr,
2975 VTable->addDebugInfo(GVE);
2978StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
2980 llvm::Function *InitFn) {
2985 return InitFn->getName();
2995 llvm::raw_svector_ostream OS(QualifiedGV);
2997 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
2999 std::swap(Quals, GVName);
3003 llvm::raw_svector_ostream OS(InitName);
3005 OS << Quals <<
"::";
3010 llvm_unreachable(
"not an initializer");
3012 OS <<
"`dynamic initializer for '";
3015 OS <<
"`dynamic atexit destructor for '";
3022 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3023 printTemplateArgumentList(OS, VTpl->getTemplateArgs().asArray(),
3024 getPrintingPolicy());
3029 return internString(
OS.str());
3032void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
3033 SmallVectorImpl<llvm::Metadata *> &EltTys) {
3042 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
3049 llvm::DIType *VPtrTy =
nullptr;
3050 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
3051 CGM.getTarget().getCXXABI().isMicrosoft();
3052 if (NeedVTableShape) {
3054 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3055 const VTableLayout &VFTLayout =
3056 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
3057 unsigned VSlotCount =
3059 unsigned VTableWidth = PtrWidth * VSlotCount;
3060 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
3061 std::optional<unsigned> DWARFAddressSpace =
3062 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
3065 llvm::DIType *VTableType = DBuilder.createPointerType(
3066 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
3067 EltTys.push_back(VTableType);
3070 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
3078 VPtrTy = getOrCreateVTablePtrType(Unit);
3080 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3081 llvm::DIType *VPtrMember =
3082 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
3083 llvm::DINode::FlagArtificial, VPtrTy);
3084 EltTys.push_back(VPtrMember);
3089 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3090 llvm::DIType *
T = getOrCreateType(RTy, getOrCreateFile(Loc));
3101 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3102 assert(!D.
isNull() &&
"null type");
3103 llvm::DIType *
T = getOrCreateType(D, getOrCreateFile(Loc));
3104 assert(
T &&
"could not create debug info for type");
3113 if (CGM.getCodeGenOpts().getDebugInfo() <=
3114 llvm::codegenoptions::DebugLineTablesOnly)
3118 node = llvm::MDNode::get(CGM.getLLVMContext(), {});
3120 node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));
3122 CI->setMetadata(
"heapallocsite", node);
3126 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3128 CanQualType Ty = CGM.getContext().getCanonicalTagType(ED);
3130 auto I = TypeCache.find(TyPtr);
3133 llvm::DIType *Res = CreateTypeDefinition(dyn_cast<EnumType>(Ty));
3134 assert(!Res->isForwardDecl());
3135 TypeCache[TyPtr].reset(Res);
3139 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3140 !CGM.getLangOpts().CPlusPlus)
3146 if (RD->
hasAttr<DLLImportAttr>())
3149 if (MD->hasAttr<DLLImportAttr>())
3162 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
3172 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
3173 Explicit = TD->isExplicitInstantiationOrSpecialization();
3177 if (CXXDecl->
fields().empty())
3187 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3188 if (CXXRD->isDynamicClass() &&
3189 CGM.getVTableLinkage(CXXRD) ==
3190 llvm::GlobalValue::AvailableExternallyLinkage &&
3201 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3203 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3205 auto I = TypeCache.find(TyPtr);
3212 auto [Res, PrefRes] = CreateTypeDefinition(dyn_cast<RecordType>(Ty));
3213 assert(!Res->isForwardDecl());
3214 TypeCache[TyPtr].reset(Res);
3221 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
3222 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
3245 if (Ctor->isCopyOrMoveConstructor())
3247 if (!Ctor->isDeleted())
3266 if (DebugKind == llvm::codegenoptions::DebugLineTablesOnly)
3269 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3270 RD->
hasAttr<StandaloneDebugAttr>())
3273 if (!LangOpts.CPlusPlus)
3279 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3295 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3296 Spec = SD->getSpecializationKind();
3305 if ((DebugKind == llvm::codegenoptions::DebugInfoConstructor) &&
3316 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3317 llvm::DIType *
T = getTypeOrNull(Ty);
3318 if (
T &&
T->isForwardDecl())
3322llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
3324 llvm::DIType *
T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
3328 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
3332 auto [Def, Pref] = CreateTypeDefinition(Ty);
3334 return Pref ? Pref : Def;
3337llvm::DIType *CGDebugInfo::GetPreferredNameType(
const CXXRecordDecl *RD,
3338 llvm::DIFile *Unit) {
3342 auto const *PNA = RD->
getAttr<PreferredNameAttr>();
3346 return getOrCreateType(PNA->getTypedefType(), Unit);
3349std::pair<llvm::DIType *, llvm::DIType *>
3350CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
3354 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3362 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
3366 return {FwdDecl,
nullptr};
3368 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
3369 CollectContainingType(CXXDecl, FwdDecl);
3372 LexicalBlockStack.emplace_back(&*FwdDecl);
3373 RegionMap[RD].reset(FwdDecl);
3376 SmallVector<llvm::Metadata *, 16> EltTys;
3383 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3385 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
3386 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
3390 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
3391 if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMethods)
3392 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
3394 LexicalBlockStack.pop_back();
3395 RegionMap.erase(RD);
3397 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3398 DBuilder.replaceArrays(FwdDecl, Elements);
3400 if (FwdDecl->isTemporary())
3402 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
3404 RegionMap[RD].reset(FwdDecl);
3406 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
3407 if (
auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
3408 return {FwdDecl, PrefDI};
3410 return {FwdDecl,
nullptr};
3413llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectType *Ty,
3414 llvm::DIFile *Unit) {
3416 return getOrCreateType(Ty->getBaseType(), Unit);
3419llvm::DIType *CGDebugInfo::CreateType(
const ObjCTypeParamType *Ty,
3420 llvm::DIFile *Unit) {
3422 SourceLocation Loc = Ty->getDecl()->getLocation();
3425 return DBuilder.createTypedef(
3426 getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
3427 Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
3428 getDeclContextDescriptor(Ty->getDecl()));
3455llvm::DIType *CGDebugInfo::CreateType(
const ObjCInterfaceType *Ty,
3456 llvm::DIFile *Unit) {
3461 auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage
>(
3462 TheCU->getSourceLanguage().getUnversionedName());
3467 if (DebugTypeExtRefs &&
ID->isFromASTFile() &&
ID->getDefinition() &&
3468 !
ID->getImplementation())
3469 return DBuilder.createForwardDecl(
3470 llvm::dwarf::DW_TAG_structure_type,
ID->getName(),
3471 getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);
3474 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3475 unsigned Line = getLineNumber(
ID->getLocation());
3479 ObjCInterfaceDecl *Def =
ID->getDefinition();
3481 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3482 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
3483 llvm::dwarf::DW_TAG_structure_type,
ID->getName(), Mod ? Mod : TheCU,
3484 DefUnit,
Line, RuntimeLang);
3485 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
3489 return CreateTypeDefinition(Ty, Unit);
3492llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
3493 bool CreateSkeletonCU) {
3498 auto ModRef = ModuleCache.find(M);
3499 if (ModRef != ModuleCache.end())
3503 SmallString<128> ConfigMacros;
3505 llvm::raw_svector_ostream
OS(ConfigMacros);
3506 const auto &PPOpts = CGM.getPreprocessorOpts();
3509 for (
auto &M : PPOpts.Macros) {
3512 const std::string &
Macro = M.first;
3513 bool Undef = M.second;
3514 OS <<
"\"-" << (Undef ?
'U' :
'D');
3515 for (
char c :
Macro)
3530 bool IsRootModule = M ? !M->
Parent :
true;
3534 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
3535 assert(StringRef(M->
Name).starts_with(CGM.getLangOpts().ModuleName) &&
3536 "clang module without ASTFile must be specified by -fmodule-name");
3539 auto RemapPath = [
this](StringRef Path) -> std::string {
3541 StringRef Relative(Remapped);
3542 StringRef CompDir = TheCU->getDirectory();
3543 if (CompDir.empty())
3546 if (Relative.consume_front(CompDir))
3547 Relative.consume_front(llvm::sys::path::get_separator());
3549 return Relative.str();
3552 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
3559 Signature = ModSig.truncatedValue();
3563 llvm::DIBuilder DIB(CGM.getModule());
3565 if (!llvm::sys::path::is_absolute(Mod.
getASTFile())) {
3566 if (CGM.getHeaderSearchOpts().ModuleFileHomeIsCwd)
3567 PCM = getCurrentDirname();
3571 llvm::sys::path::append(PCM, Mod.
getASTFile());
3572 DIB.createCompileUnit(
3573 TheCU->getSourceLanguage(),
3576 TheCU->getProducer(),
false, StringRef(), 0, RemapPath(PCM),
3577 llvm::DICompileUnit::FullDebug, Signature);
3581 llvm::DIModule *Parent =
3583 : getOrCreateModuleRef(ASTSourceDescriptor(*M->
Parent),
3585 StringRef IncludePath = Mod.
getPath();
3586 if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
3587 StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
3588 if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
3591 llvm::DIModule *DIMod =
3592 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
3593 RemapPath(IncludePath));
3594 ModuleCache[M].reset(DIMod);
3598llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const ObjCInterfaceType *Ty,
3599 llvm::DIFile *Unit) {
3601 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3602 unsigned Line = getLineNumber(
ID->getLocation());
3604 unsigned RuntimeLang = TheCU->getSourceLanguage().getUnversionedName();
3610 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3611 if (
ID->getImplementation())
3612 Flags |= llvm::DINode::FlagObjcClassComplete;
3614 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3615 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
3616 Mod ? Mod : Unit,
ID->getName(), DefUnit,
Line, Size, Align, Flags,
3617 nullptr, llvm::DINodeArray(), RuntimeLang);
3619 QualType QTy(Ty, 0);
3620 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
3623 LexicalBlockStack.emplace_back(RealDecl);
3624 RegionMap[Ty->
getDecl()].reset(RealDecl);
3627 SmallVector<llvm::Metadata *, 16> EltTys;
3629 ObjCInterfaceDecl *SClass =
ID->getSuperClass();
3631 llvm::DIType *SClassTy =
3632 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
3636 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
3637 llvm::DINode::FlagZero);
3638 EltTys.push_back(InhTag);
3642 auto AddProperty = [&](
const ObjCPropertyDecl *PD) {
3643 SourceLocation Loc = PD->getLocation();
3644 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3645 unsigned PLine = getLineNumber(Loc);
3646 ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
3647 ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
3648 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
3649 PD->getName(), PUnit, PLine,
3651 : getSelectorName(PD->getGetterName()),
3653 : getSelectorName(PD->getSetterName()),
3654 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
3655 EltTys.push_back(PropertyNode);
3660 typedef std::pair<char, const IdentifierInfo *> IsClassAndIdent;
3664 llvm::DenseSet<IsClassAndIdent> PropertySet;
3666 auto GetIsClassAndIdent = [](
const ObjCPropertyDecl *PD) {
3667 return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
3669 for (
const ObjCCategoryDecl *ClassExt :
ID->known_extensions())
3670 for (
auto *PD : ClassExt->properties()) {
3671 PropertySet.insert(GetIsClassAndIdent(PD));
3674 for (
const auto *PD :
ID->properties()) {
3677 if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
3683 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
3684 unsigned FieldNo = 0;
3685 for (ObjCIvarDecl *Field =
ID->all_declared_ivar_begin(); Field;
3686 Field =
Field->getNextIvar(), ++FieldNo) {
3687 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
3691 StringRef FieldName =
Field->getName();
3694 if (FieldName.empty())
3698 llvm::DIFile *FieldDefUnit = getOrCreateFile(
Field->getLocation());
3699 unsigned FieldLine = getLineNumber(
Field->getLocation());
3700 QualType FType =
Field->getType();
3707 FieldSize =
Field->isBitField() ?
Field->getBitWidthValue()
3708 : CGM.getContext().getTypeSize(FType);
3713 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
3717 if (
Field->isBitField()) {
3719 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
3720 FieldOffset %= CGM.getContext().getCharWidth();
3728 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3730 Flags = llvm::DINode::FlagProtected;
3732 Flags = llvm::DINode::FlagPrivate;
3734 Flags = llvm::DINode::FlagPublic;
3736 if (
Field->isBitField())
3737 Flags |= llvm::DINode::FlagBitField;
3739 llvm::MDNode *PropertyNode =
nullptr;
3740 if (ObjCImplementationDecl *ImpD =
ID->getImplementation()) {
3741 if (ObjCPropertyImplDecl *PImpD =
3742 ImpD->FindPropertyImplIvarDecl(
Field->getIdentifier())) {
3743 if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
3744 SourceLocation Loc = PD->getLocation();
3745 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3746 unsigned PLine = getLineNumber(Loc);
3747 ObjCMethodDecl *Getter = PImpD->getGetterMethodDecl();
3748 ObjCMethodDecl *Setter = PImpD->getSetterMethodDecl();
3749 PropertyNode = DBuilder.createObjCProperty(
3750 PD->getName(), PUnit, PLine,
3753 : getSelectorName(PD->getGetterName()),
3756 : getSelectorName(PD->getSetterName()),
3757 PD->getPropertyAttributes(),
3758 getOrCreateType(PD->getType(), PUnit));
3762 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
3763 FieldSize, FieldAlign, FieldOffset, Flags,
3764 FieldTy, PropertyNode);
3765 EltTys.push_back(FieldTy);
3768 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3769 DBuilder.replaceArrays(RealDecl, Elements);
3771 LexicalBlockStack.pop_back();
3775llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
3776 llvm::DIFile *Unit) {
3784 auto &Ctx = CGM.getContext();
3789 QualType CharVecTy =
3791 return CreateType(CharVecTy->
getAs<VectorType>(), Unit);
3794 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3797 llvm::Metadata *Subscript;
3798 QualType QTy(Ty, 0);
3799 auto SizeExpr = SizeExprCache.find(QTy);
3800 if (SizeExpr != SizeExprCache.end())
3801 Subscript = DBuilder.getOrCreateSubrange(
3802 SizeExpr->getSecond() ,
nullptr ,
3803 nullptr ,
nullptr );
3806 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3807 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count ? Count : -1));
3808 Subscript = DBuilder.getOrCreateSubrange(
3809 CountNode ,
nullptr ,
nullptr ,
3812 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
3817 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
3820llvm::DIType *CGDebugInfo::CreateType(
const ConstantMatrixType *Ty,
3821 llvm::DIFile *Unit) {
3825 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3830 llvm::SmallVector<llvm::Metadata *, 2> Subscripts;
3831 auto *ColumnCountNode =
3832 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3833 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumColumns()));
3834 auto *RowCountNode =
3835 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3836 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumRows()));
3837 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3838 ColumnCountNode ,
nullptr ,
nullptr ,
3840 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3841 RowCountNode ,
nullptr ,
nullptr ,
3843 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3844 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
3847llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
3852 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3867 Size = CGM.getContext().getTypeSize(Ty);
3874 SmallVector<llvm::Metadata *, 8> Subscripts;
3875 QualType EltTy(Ty, 0);
3876 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
3885 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
3886 Count = CAT->getZExtSize();
3887 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3888 if (Expr *Size = VAT->getSizeExpr()) {
3890 if (
Size->EvaluateAsInt(
Result, CGM.getContext()))
3891 Count =
Result.Val.getInt().getExtValue();
3895 auto SizeNode = SizeExprCache.find(EltTy);
3896 if (SizeNode != SizeExprCache.end())
3897 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3898 SizeNode->getSecond() ,
nullptr ,
3899 nullptr ,
nullptr ));
3902 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3903 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count));
3904 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3905 CountNode ,
nullptr ,
nullptr ,
3911 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3913 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
3917llvm::DIType *CGDebugInfo::CreateType(
const LValueReferenceType *Ty,
3918 llvm::DIFile *Unit) {
3919 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
3923llvm::DIType *CGDebugInfo::CreateType(
const RValueReferenceType *Ty,
3924 llvm::DIFile *Unit) {
3925 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
3927 if (CGM.getCodeGenOpts().DebugStrictDwarf &&
3928 CGM.getCodeGenOpts().DwarfVersion < 4)
3929 Tag = llvm::dwarf::DW_TAG_reference_type;
3931 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
3934llvm::DIType *CGDebugInfo::CreateType(
const MemberPointerType *Ty,
3936 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3940 Size = CGM.getContext().getTypeSize(Ty);
3943 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
3946 Flags |= llvm::DINode::FlagSingleInheritance;
3949 Flags |= llvm::DINode::FlagMultipleInheritance;
3952 Flags |= llvm::DINode::FlagVirtualInheritance;
3962 llvm::DIType *ClassType = getOrCreateType(
T, U);
3964 return DBuilder.createMemberPointerType(
3968 const FunctionProtoType *FPT =
3970 return DBuilder.createMemberPointerType(
3971 getOrCreateInstanceMethodType(
3974 ClassType, Size, 0, Flags);
3977llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
3979 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
3982llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
3986llvm::DIType *CGDebugInfo::CreateType(
const HLSLAttributedResourceType *Ty,
3988 return getOrCreateType(Ty->getWrappedType(), U);
3991llvm::DIType *CGDebugInfo::CreateType(
const HLSLInlineSpirvType *Ty,
3998 const EnumType *Ty) {
4010llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
4013 bool isImportedFromModule =
4014 DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
4018 if (isImportedFromModule || !ED->getDefinition()) {
4025 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
4026 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4027 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
4028 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
4030 unsigned Line = getLineNumber(ED->getLocation());
4031 StringRef EDName = ED->getName();
4032 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
4033 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
4034 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
4036 ReplaceMap.emplace_back(
4037 std::piecewise_construct, std::make_tuple(Ty),
4038 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
4042 return CreateTypeDefinition(Ty);
4045llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
4048 SmallVector<llvm::Metadata *, 16> Enumerators;
4049 ED = ED->getDefinition();
4050 assert(ED &&
"An enumeration definition is required");
4051 for (
const auto *
Enum : ED->enumerators()) {
4052 Enumerators.push_back(
4053 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
4056 std::optional<EnumExtensibilityAttr::Kind> EnumKind;
4057 if (
auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
4058 EnumKind = Attr->getExtensibility();
4061 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
4063 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4064 unsigned Line = getLineNumber(ED->getLocation());
4065 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
4066 llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
4067 return DBuilder.createEnumerationType(
4068 EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
4069 0, Identifier, ED->isScoped(), EnumKind);
4074 StringRef Name, StringRef
Value) {
4075 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4076 return DBuilder.createMacro(Parent,
Line, MType, Name,
Value);
4082 llvm::DIFile *FName = getOrCreateFile(FileLoc);
4083 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4084 return DBuilder.createTempMacroFile(Parent,
Line, FName);
4089 llvm::DISubprogram *SynthSubprogram) {
4090 return llvm::DILocation::get(CGM.getLLVMContext(), 0, 0,
4091 SynthSubprogram, ParentLocation);
4096 StringRef SynthFuncName,
4097 llvm::DIFile *SynthFile) {
4098 llvm::DISubprogram *SP = createInlinedSubprogram(SynthFuncName, SynthFile);
4103 llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) {
4109 FuncName += Category;
4111 FuncName += FailureMsg;
4114 TrapLocation->getFile());
4124 Quals += InnerQuals;
4126 switch (
T->getTypeClass()) {
4128 return C.getQualifiedType(
T.getTypePtr(), Quals);
4131 case Type::InjectedClassName:
4132 return C.getQualifiedType(
T->getCanonicalTypeUnqualified().getTypePtr(),
4134 case Type::TemplateSpecialization: {
4136 if (Spec->isTypeAlias())
4137 return C.getQualifiedType(
T.getTypePtr(), Quals);
4138 T = Spec->desugar();
4141 case Type::TypeOfExpr:
4147 case Type::Decltype:
4150 case Type::UnaryTransform:
4153 case Type::Attributed:
4156 case Type::BTFTagAttributed:
4159 case Type::CountAttributed:
4168 case Type::MacroQualified:
4171 case Type::SubstTemplateTypeParm:
4175 case Type::DeducedTemplateSpecialization: {
4177 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
4181 case Type::PackIndexing: {
4185 case Type::Adjusted:
4192 assert(
T != LastT &&
"Type unwrapping failed to unwrap!");
4197llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
4200 if (It != TypeCache.end()) {
4202 if (llvm::Metadata *
V = It->second)
4215 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
4222 RetainedTypes.push_back(
4223 CGM.getContext().getCanonicalTagType(&D).getAsOpaquePtr());
4226llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
4230 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
4232 llvm::raw_string_ostream OS(Name);
4233 Ty.
print(OS, getPrintingPolicy());
4240 if (
auto *
T = getTypeOrNull(Ty))
4243 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
4244 void *TyPtr = Ty.getAsOpaquePtr();
4247 TypeCache[TyPtr].reset(Res);
4252llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
4260 auto Info = Reader->getSourceDescriptor(Idx);
4262 return getOrCreateModuleRef(*Info,
true);
4263 }
else if (ClangModuleMap) {
4276 auto Info = ASTSourceDescriptor(*M);
4277 return getOrCreateModuleRef(Info,
false);
4280 return getOrCreateModuleRef(PCHDescriptor,
false);
4287llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
4290 return CreateQualifiedType(Ty, Unit);
4294#define TYPE(Class, Base)
4295#define ABSTRACT_TYPE(Class, Base)
4296#define NON_CANONICAL_TYPE(Class, Base)
4297#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4298#include "clang/AST/TypeNodes.inc"
4299 llvm_unreachable(
"Dependent types cannot show up in debug information");
4301 case Type::ExtVector:
4304 case Type::ConstantMatrix:
4306 case Type::ObjCObjectPointer:
4308 case Type::ObjCObject:
4310 case Type::ObjCTypeParam:
4312 case Type::ObjCInterface:
4320 case Type::BlockPointer:
4328 case Type::FunctionProto:
4329 case Type::FunctionNoProto:
4331 case Type::ConstantArray:
4332 case Type::VariableArray:
4333 case Type::IncompleteArray:
4334 case Type::ArrayParameter:
4337 case Type::LValueReference:
4339 case Type::RValueReference:
4342 case Type::MemberPointer:
4350 case Type::OverflowBehavior:
4355 case Type::TemplateSpecialization:
4357 case Type::HLSLAttributedResource:
4359 case Type::HLSLInlineSpirv:
4361 case Type::PredefinedSugar:
4363 case Type::CountAttributed:
4364 case Type::LateParsedAttr:
4366 case Type::Attributed:
4367 case Type::BTFTagAttributed:
4368 case Type::Adjusted:
4370 case Type::DeducedTemplateSpecialization:
4373 case Type::MacroQualified:
4374 case Type::SubstTemplateTypeParm:
4375 case Type::TypeOfExpr:
4377 case Type::Decltype:
4378 case Type::PackIndexing:
4379 case Type::UnaryTransform:
4383 llvm_unreachable(
"type should have been unwrapped!");
4386llvm::DICompositeType *
4387CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
4388 QualType QTy(Ty, 0);
4390 auto *
T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
4395 if (
T && !
T->isForwardDecl())
4399 llvm::DICompositeType *Res = CreateLimitedType(Ty);
4404 DBuilder.replaceArrays(Res,
T ?
T->getElements() : llvm::DINodeArray());
4407 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
4412llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
4414 bool NameIsSimplified =
false;
4417 StringRef RDName = getClassName(RD, &NameIsSimplified);
4419 llvm::DIFile *DefUnit =
nullptr;
4422 DefUnit = getOrCreateFile(Loc);
4423 Line = getLineNumber(Loc);
4426 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
4430 auto *
T = cast_or_null<llvm::DICompositeType>(
4431 getTypeOrNull(CGM.getContext().getCanonicalTagType(RD)));
4439 return getOrCreateRecordFwdDecl(Ty, RDContext);
4452 auto Flags = llvm::DINode::FlagZero;
4453 if (NameIsSimplified)
4454 Flags |= llvm::DINode::FlagNameIsSimplified;
4455 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4457 Flags |= llvm::DINode::FlagTypePassByReference;
4459 Flags |= llvm::DINode::FlagTypePassByValue;
4462 if (!CXXRD->isTrivial())
4463 Flags |= llvm::DINode::FlagNonTrivial;
4466 if (CXXRD->isAnonymousStructOrUnion())
4467 Flags |= llvm::DINode::FlagExportSymbols;
4470 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
4473 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4474 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
4476 Flags, Identifier, Annotations);
4480 switch (RealDecl->getTag()) {
4482 llvm_unreachable(
"invalid composite type tag");
4484 case llvm::dwarf::DW_TAG_array_type:
4485 case llvm::dwarf::DW_TAG_enumeration_type:
4490 if (Identifier.empty())
4494 case llvm::dwarf::DW_TAG_structure_type:
4495 case llvm::dwarf::DW_TAG_union_type:
4496 case llvm::dwarf::DW_TAG_class_type:
4499 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
4503 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
4504 CXXRecordDecl *TemplateDecl =
4505 CTSD->getSpecializedTemplate()->getTemplatedDecl();
4506 RegionMap[TemplateDecl].reset(RealDecl);
4508 RegionMap[RD].reset(RealDecl);
4510 TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
4512 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
4513 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
4514 CollectCXXTemplateParams(TSpecial, DefUnit));
4518void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
4519 llvm::DICompositeType *RealDecl) {
4521 llvm::DIType *ContainingType =
nullptr;
4522 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4526 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
4533 CanQualType T = CGM.getContext().getCanonicalTagType(PBase);
4534 ContainingType = getOrCreateType(
T, getOrCreateFile(RD->
getLocation()));
4536 ContainingType = RealDecl;
4538 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4541llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
4542 StringRef Name, uint64_t *Offset) {
4543 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4544 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
4547 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4548 *Offset, llvm::DINode::FlagZero, FieldTy);
4549 *Offset += FieldSize;
4553void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
4555 StringRef &LinkageName,
4556 llvm::DIScope *&FDContext,
4557 llvm::DINodeArray &TParamsArray,
4558 llvm::DINode::DIFlags &Flags) {
4560 bool NameIsSimplified =
false;
4561 Name = getFunctionName(FD, &NameIsSimplified);
4562 if (NameIsSimplified)
4563 Flags |= llvm::DINode::FlagNameIsSimplified;
4564 Name = getFunctionName(FD);
4567 LinkageName = CGM.getMangledName(GD);
4569 Flags |= llvm::DINode::FlagPrototyped;
4573 if (LinkageName == Name ||
4574 (CGM.getCodeGenOpts().CoverageNotesFile.empty() &&
4575 CGM.getCodeGenOpts().CoverageDataFile.empty() &&
4576 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
4577 !CGM.getCodeGenOpts().PseudoProbeForProfiling &&
4578 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4579 LinkageName = StringRef();
4583 if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
4584 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4585 CGM.getCodeGenOpts().EmitCodeView)) {
4586 if (
const NamespaceDecl *NSDecl =
4588 FDContext = getOrCreateNamespace(NSDecl);
4589 else if (
const RecordDecl *RDecl =
4591 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4592 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4595 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
4598 Flags |= llvm::DINode::FlagNoReturn;
4600 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4604void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4605 unsigned &LineNo, QualType &
T,
4606 StringRef &Name, StringRef &LinkageName,
4607 llvm::MDTuple *&TemplateParameters,
4608 llvm::DIScope *&VDContext) {
4617 llvm::APInt ConstVal(32, 1);
4618 QualType ET = CGM.getContext().getAsArrayType(
T)->getElementType();
4620 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
4627 LinkageName = CGM.getMangledName(VD);
4628 if (LinkageName == Name)
4629 LinkageName = StringRef();
4632 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4633 TemplateParameters = parameterNodes.get();
4635 TemplateParameters =
nullptr;
4641 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4642 VDContext = LexicalBlockStack.back();
4661 DC = CGM.getContext().getTranslationUnitDecl();
4663 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4664 VDContext = getContextDescriptor(
cast<Decl>(DC), Mod ? Mod : TheCU);
4667llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
4669 llvm::DINodeArray TParamsArray;
4670 StringRef Name, LinkageName;
4671 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4672 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4674 llvm::DIFile *Unit = getOrCreateFile(Loc);
4675 llvm::DIScope *DContext = Unit;
4676 unsigned Line = getLineNumber(Loc);
4677 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4682 SmallVector<QualType, 16> ArgTypes;
4683 for (
const ParmVarDecl *Parm : FD->
parameters())
4684 ArgTypes.push_back(Parm->getType());
4687 QualType FnType = CGM.getContext().getFunctionType(
4688 FD->
getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
4690 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4691 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
4692 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4696 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4697 return DBuilder.createFunction(
4698 DContext, Name, LinkageName, Unit,
Line,
4699 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4700 TParamsArray.get(), getFunctionDeclaration(FD),
nullptr,
4702 CGM.getCodeGenOpts().DebugKeyInstructions);
4705 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4706 DContext, Name, LinkageName, Unit,
Line,
4707 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4708 TParamsArray.get(), getFunctionDeclaration(FD));
4710 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4711 std::make_tuple(CanonDecl),
4712 std::make_tuple(SP));
4716llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
4717 return getFunctionFwdDeclOrStub(GD,
false);
4720llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
4721 return getFunctionFwdDeclOrStub(GD,
true);
4724llvm::DIGlobalVariable *
4725CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4727 StringRef Name, LinkageName;
4729 llvm::DIFile *Unit = getOrCreateFile(Loc);
4730 llvm::DIScope *DContext = Unit;
4731 unsigned Line = getLineNumber(Loc);
4732 llvm::MDTuple *TemplateParameters =
nullptr;
4734 collectVarDeclProps(VD, Unit,
Line,
T, Name, LinkageName, TemplateParameters,
4737 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4738 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(
T, Unit),
4740 FwdDeclReplaceMap.emplace_back(
4741 std::piecewise_construct,
4743 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4747llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
4752 if (
const auto *TD = dyn_cast<TypeDecl>(D)) {
4753 QualType Ty = CGM.getContext().getTypeDeclType(TD);
4754 return getOrCreateType(Ty, getOrCreateFile(TD->
getLocation()));
4758 if (I != DeclCache.end()) {
4760 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4761 return GVE->getVariable();
4769 if (IE != ImportedDeclCache.end()) {
4770 auto N = IE->second;
4771 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4773 return dyn_cast_or_null<llvm::DINode>(N);
4778 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4779 return getFunctionForwardDeclaration(FD);
4780 else if (
const auto *VD = dyn_cast<VarDecl>(D))
4781 return getGlobalVariableForwardDeclaration(VD);
4786llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
4787 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4790 const auto *FD = dyn_cast<FunctionDecl>(D);
4795 auto *S = getDeclContextDescriptor(D);
4798 if (MI == SPCache.end()) {
4800 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
4804 if (MI != SPCache.end()) {
4805 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4806 if (SP && !SP->isDefinition())
4810 for (
auto *NextFD : FD->
redecls()) {
4811 auto MI = SPCache.find(NextFD->getCanonicalDecl());
4812 if (MI != SPCache.end()) {
4813 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4814 if (SP && !SP->isDefinition())
4821llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
4822 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
4823 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
4824 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4827 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
4831 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
4835 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
4844 QualType QTy(
ID->getTypeForDecl(), 0);
4845 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4846 if (It == TypeCache.end())
4849 llvm::DISubprogram *FD = DBuilder.createFunction(
4850 InterfaceType, getObjCMethodName(OMD), StringRef(),
4851 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
4852 DBuilder.finalizeSubprogram(FD);
4859llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
4864 if (!D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
4865 !CGM.getCodeGenOpts().EmitCodeView))
4868 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({}));
4870 if (
const auto *
Method = dyn_cast<CXXDestructorDecl>(D)) {
4873 return getOrCreateMethodTypeForDestructor(
Method, F, FnType);
4876 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(D))
4877 return getOrCreateMethodType(
Method, F);
4879 const auto *FTy = FnType->
getAs<FunctionType>();
4882 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
4884 SmallVector<llvm::Metadata *, 16> Elts;
4887 QualType ResultTy = OMethod->getReturnType();
4890 if (ResultTy == CGM.getContext().getObjCInstanceType())
4891 ResultTy = CGM.getContext().getPointerType(
4892 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
4894 Elts.push_back(getOrCreateType(ResultTy, F));
4896 QualType SelfDeclTy;
4897 if (
auto *SelfDecl = OMethod->getSelfDecl())
4898 SelfDeclTy = SelfDecl->getType();
4899 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4902 if (!SelfDeclTy.
isNull())
4904 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
4906 Elts.push_back(DBuilder.createArtificialType(
4907 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
4909 for (
const auto *PI : OMethod->parameters())
4910 Elts.push_back(getOrCreateType(PI->getType(), F));
4912 if (OMethod->isVariadic())
4913 Elts.push_back(DBuilder.createUnspecifiedParameter());
4915 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
4916 return DBuilder.createSubroutineType(
4917 EltTypeArray, llvm::DINode::FlagZero,
4918 getDwarfCC(CC, CGM.getTarget().getTriple()));
4923 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4924 if (FD->isVariadic()) {
4925 SmallVector<llvm::Metadata *, 16> EltTys;
4926 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
4927 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4929 EltTys.push_back(getOrCreateType(ParamType, F));
4930 EltTys.push_back(DBuilder.createUnspecifiedParameter());
4931 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
4932 return DBuilder.createSubroutineType(
4933 EltTypeArray, llvm::DINode::FlagZero,
4934 getDwarfCC(CC, CGM.getTarget().getTriple()));
4946 CC = SrcFnTy->getCallConv();
4948 for (
const VarDecl *VD : Args)
4949 ArgTypes.push_back(VD->
getType());
4950 return CGM.getContext().getFunctionType(RetTy, ArgTypes,
4956 llvm::Function *Fn,
bool CurFuncIsThunk) {
4958 StringRef LinkageName;
4960 FnBeginRegionCount.push_back(LexicalBlockStack.size());
4963 bool HasDecl = (D !=
nullptr);
4965 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4966 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4967 llvm::DIFile *Unit = getOrCreateFile(Loc);
4968 llvm::DIScope *FDContext = Unit;
4969 llvm::DINodeArray TParamsArray;
4970 bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
4973 LinkageName = Fn->getName();
4974 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
4976 auto FI = SPCache.find(FD->getCanonicalDecl());
4977 if (FI != SPCache.end()) {
4978 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
4979 if (SP && SP->isDefinition()) {
4980 LexicalBlockStack.emplace_back(SP);
4981 RegionMap[D].reset(SP);
4985 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
4986 TParamsArray, Flags);
4989 KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
4990 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
4991 Name = getObjCMethodName(OMD);
4992 Flags |= llvm::DINode::FlagPrototyped;
4998 if (Name != Fn->getName())
4999 LinkageName = Fn->getName();
5001 Name = Fn->getName();
5006 Flags |= llvm::DINode::FlagPrototyped;
5008 Name.consume_front(
"\01");
5012 "Unexpected DynamicInitKind !");
5016 Flags |= llvm::DINode::FlagArtificial;
5022 Flags |= llvm::DINode::FlagThunk;
5024 if (Fn->hasLocalLinkage())
5025 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
5026 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5027 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5030 llvm::DISubprogram::DISPFlags SPFlagsForDef =
5031 SPFlags | llvm::DISubprogram::SPFlagDefinition;
5033 const unsigned LineNo = getLineNumber(Loc.
isValid() ? Loc : CurLoc);
5034 unsigned ScopeLine = getLineNumber(ScopeLoc);
5035 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
5036 llvm::DISubprogram *
Decl =
nullptr;
5037 llvm::DINodeArray Annotations =
nullptr;
5040 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
5041 : getFunctionDeclaration(D);
5042 Annotations = CollectBTFDeclTagAnnotations(D);
5050 llvm::DISubprogram *SP = DBuilder.createFunction(
5051 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
5052 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
5053 Annotations,
"", KeyInstructions);
5054 Fn->setSubprogram(SP);
5063 LexicalBlockStack.emplace_back(SP);
5066 RegionMap[D].reset(SP);
5070 QualType FnType, llvm::Function *Fn) {
5072 StringRef LinkageName;
5078 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
5079 return GetName(D,
true);
5082 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5083 llvm::DIFile *Unit = getOrCreateFile(Loc);
5084 bool IsDeclForCallSite = Fn ?
true :
false;
5085 llvm::DIScope *FDContext =
5086 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
5087 llvm::DINodeArray TParamsArray;
5090 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5091 TParamsArray, Flags);
5092 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5093 Name = getObjCMethodName(OMD);
5094 Flags |= llvm::DINode::FlagPrototyped;
5096 llvm_unreachable(
"not a function or ObjC method");
5098 Name.consume_front(
"\01");
5101 Flags |= llvm::DINode::FlagArtificial;
5106 unsigned LineNo = getLineNumber(Loc);
5107 unsigned ScopeLine = 0;
5108 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5109 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5110 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5112 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
5113 llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
5115 assert(~SPFlags & llvm::DISubprogram::SPFlagDefinition);
5116 llvm::DISubprogram *SP = DBuilder.createFunction(
5117 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
5118 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations,
5124 if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
5125 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
5126 llvm::DITypeArray ParamTypes = STy->getTypeArray();
5129 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
5130 DBuilder.createParameterVariable(
5131 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
5132 llvm::DINode::FlagZero, ParamAnnotations);
5138 if (IsDeclForCallSite)
5139 Fn->setSubprogram(SP);
5143 llvm::CallBase *CI) {
5144 if (!shouldGenerateVirtualCallSite())
5150 assert(CI &&
"Invalid Call Instruction.");
5151 if (!CI->isIndirectCall())
5155 if (llvm::DISubprogram *MD = getFunctionDeclaration(FD))
5156 CI->setMetadata(llvm::LLVMContext::MD_call_target, MD);
5164 auto *
Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
5167 if (
Func->getSubprogram())
5175 if (CalleeDecl->
hasAttr<NoDebugAttr>() ||
5190 auto FI = SPCache.find(FD->getCanonicalDecl());
5191 llvm::DISubprogram *SP =
nullptr;
5192 if (FI != SPCache.end())
5193 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5194 if (!SP || !SP->isDefinition())
5195 SP = getFunctionStub(GD);
5196 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5197 LexicalBlockStack.emplace_back(SP);
5203 assert(CurInlinedAt &&
"unbalanced inline scope stack");
5212 if (CurLoc.isInvalid() ||
5213 (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) ||
5214 LexicalBlockStack.empty())
5217 llvm::MDNode *
Scope = LexicalBlockStack.back();
5218 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5219 CGM.getLLVMContext(), CurLocLine, CurLocColumn,
Scope, CurInlinedAt));
5223 llvm::MDNode *Back =
nullptr;
5224 if (!LexicalBlockStack.empty())
5225 Back = LexicalBlockStack.back().get();
5226 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
5228 getColumnNumber(CurLoc)));
5231void CGDebugInfo::AppendAddressSpaceXDeref(
5233 std::optional<unsigned> DWARFAddressSpace =
5235 if (!DWARFAddressSpace)
5238 Expr.push_back(llvm::dwarf::DW_OP_constu);
5239 Expr.push_back(*DWARFAddressSpace);
5240 Expr.push_back(llvm::dwarf::DW_OP_swap);
5241 Expr.push_back(llvm::dwarf::DW_OP_xderef);
5250 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5251 CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
5252 LexicalBlockStack.back(), CurInlinedAt));
5254 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5258 CreateLexicalBlock(Loc);
5263 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5268 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5271 LexicalBlockStack.pop_back();
5275 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5276 unsigned RCount = FnBeginRegionCount.back();
5277 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
5280 while (LexicalBlockStack.size() != RCount) {
5283 LexicalBlockStack.pop_back();
5285 FnBeginRegionCount.pop_back();
5287 if (Fn && Fn->getSubprogram())
5288 DBuilder.finalizeSubprogram(Fn->getSubprogram());
5291CGDebugInfo::BlockByRefType
5292CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
5293 uint64_t *XOffset) {
5296 uint64_t FieldSize, FieldOffset;
5297 uint32_t FieldAlign;
5299 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5304 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
5305 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
5307 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
5308 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
5311 if (HasCopyAndDispose) {
5314 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
5316 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
5318 bool HasByrefExtendedLayout;
5321 HasByrefExtendedLayout) &&
5322 HasByrefExtendedLayout) {
5325 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
5334 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
5337 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
5340 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
5345 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
5346 FieldSize = CGM.getContext().getTypeSize(FType);
5347 FieldAlign = CGM.getContext().toBits(Align);
5349 *XOffset = FieldOffset;
5350 llvm::DIType *FieldTy = DBuilder.createMemberType(
5351 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
5352 llvm::DINode::FlagZero, WrappedTy);
5353 EltTys.push_back(FieldTy);
5354 FieldOffset += FieldSize;
5356 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
5357 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
5358 llvm::DINode::FlagZero,
nullptr, Elements),
5362llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
5363 llvm::Value *Storage,
5364 std::optional<unsigned> ArgNo,
5366 const bool UsePointerValue) {
5367 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5368 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5369 if (VD->
hasAttr<NoDebugAttr>())
5374 llvm::DIFile *Unit =
nullptr;
5375 if (!VarIsArtificial)
5379 if (VD->
hasAttr<BlocksAttr>())
5380 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5382 Ty = getOrCreateType(VD->
getType(), Unit);
5392 if (!VarIsArtificial) {
5396 SmallVector<uint64_t, 13> Expr;
5397 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5404 Flags |= llvm::DINode::FlagArtificial;
5408 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->
getType());
5409 AppendAddressSpaceXDeref(AddressSpace, Expr);
5413 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
5416 Flags |= llvm::DINode::FlagObjectPointer;
5417 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
5418 if (PVD->isExplicitObjectParameter())
5419 Flags |= llvm::DINode::FlagObjectPointer;
5427 StringRef Name = VD->
getName();
5428 if (!Name.empty()) {
5434 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5436 offset = CGM.getContext().toCharUnitsFromBits(
5439 Expr.push_back(llvm::dwarf::DW_OP_deref);
5440 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5442 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5445 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
5457 for (
const auto *Field : RD->
fields()) {
5458 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
5459 StringRef FieldName =
Field->getName();
5467 auto *D = DBuilder.createAutoVariable(
5468 Scope, FieldName, Unit,
Line, FieldTy,
5469 CGM.getCodeGenOpts().OptimizationLevel != 0,
5470 Flags | llvm::DINode::FlagArtificial, FieldAlign);
5473 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5474 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5477 Builder.GetInsertBlock());
5485 if (UsePointerValue) {
5486 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5487 "Debug info already contains DW_OP_deref.");
5488 Expr.push_back(llvm::dwarf::DW_OP_deref);
5492 llvm::DILocalVariable *D =
nullptr;
5494 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5495 D = DBuilder.createParameterVariable(
5496 Scope, Name, *ArgNo, Unit,
Line, Ty,
5497 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
5506 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
5512 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
5513 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
5514 if (DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
5515 DeclGroupRef DeclGroup = DeclStmtPtr->getDeclGroup();
5517 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
5523 if (Iter != CoroutineParameterMappings.end()) {
5524 ParmVarDecl *PD =
const_cast<ParmVarDecl *
>(Iter->first);
5525 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
5526 return DbgPair.first == PD && DbgPair.second->getScope() == Scope;
5528 if (Iter2 != ParamDbgMappings.end())
5529 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
5535 D = RemapCoroArgToLocalVar();
5538 D = DBuilder.createAutoVariable(
5539 Scope, Name, Unit,
Line, Ty,
5540 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
5543 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5544 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5545 Column, Scope, CurInlinedAt),
5546 Builder.GetInsertBlock());
5551llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
5552 llvm::Value *Storage,
5553 std::optional<unsigned> ArgNo,
5555 const bool UsePointerValue) {
5556 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5557 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5558 if (BD->
hasAttr<NoDebugAttr>())
5565 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
5566 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
5574 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->
getType());
5576 SmallVector<uint64_t, 3> Expr;
5577 AppendAddressSpaceXDeref(AddressSpace, Expr);
5582 if (UsePointerValue) {
5583 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5584 "Debug info already contains DW_OP_deref.");
5585 Expr.push_back(llvm::dwarf::DW_OP_deref);
5590 StringRef Name = BD->
getName();
5593 llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5594 Scope, Name, Unit,
Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
5595 llvm::DINode::FlagZero, Align);
5597 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(BD->
getBinding())) {
5598 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5599 const unsigned fieldIndex = FD->getFieldIndex();
5600 const clang::CXXRecordDecl *parent =
5601 (
const CXXRecordDecl *)FD->getParent();
5602 const ASTRecordLayout &layout =
5603 CGM.getContext().getASTRecordLayout(parent);
5605 if (FD->isBitField()) {
5606 const CGRecordLayout &RL =
5607 CGM.getTypes().getCGRecordLayout(FD->getParent());
5612 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5618 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5619 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5620 Expr.push_back(Info.
Offset);
5623 const uint64_t TypeSize = CGM.getContext().getTypeSize(BD->
getType());
5624 Expr.push_back(std::min((uint64_t)Info.
Size, TypeSize));
5625 }
else if (fieldOffset != 0) {
5626 assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
5627 "Unexpected non-bitfield with non-byte-aligned offset");
5628 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5630 CGM.getContext().toCharUnitsFromBits(fieldOffset).getQuantity());
5633 }
else if (
const ArraySubscriptExpr *ASE =
5634 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5635 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5636 const uint64_t value = IL->getValue().getZExtValue();
5637 const uint64_t typeSize = CGM.getContext().getTypeSize(BD->
getType());
5640 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5641 Expr.push_back(CGM.getContext()
5642 .toCharUnitsFromBits(value * typeSize)
5649 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5650 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5651 Column, Scope, CurInlinedAt),
5652 Builder.GetInsertBlock());
5657llvm::DILocalVariable *
5660 const bool UsePointerValue) {
5661 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5663 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5665 EmitDeclare(B, Storage, std::nullopt, Builder,
5672 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5676 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5677 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5679 if (D->
hasAttr<NoDebugAttr>())
5683 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
5689 StringRef Name = D->
getName();
5695 CGM.getCodeGenOpts().OptimizationLevel != 0);
5698 DBuilder.insertLabel(L,
5699 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5700 Scope, CurInlinedAt),
5701 Builder.GetInsertBlock()->end());
5704llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5706 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5709 return DBuilder.createObjectPointerType(Ty,
true);
5714 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5715 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5716 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5718 if (Builder.GetInsertBlock() ==
nullptr)
5720 if (VD->
hasAttr<NoDebugAttr>())
5723 bool isByRef = VD->
hasAttr<BlocksAttr>();
5725 uint64_t XOffset = 0;
5726 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5729 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5731 Ty = getOrCreateType(VD->
getType(), Unit);
5735 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5737 Ty = CreateSelfType(VD->
getType(), Ty);
5740 const unsigned Line =
5744 const llvm::DataLayout &target = CGM.getDataLayout();
5751 addr.push_back(llvm::dwarf::DW_OP_deref);
5752 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5755 addr.push_back(llvm::dwarf::DW_OP_deref);
5756 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5759 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
5761 addr.push_back(llvm::dwarf::DW_OP_deref);
5762 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5764 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5770 auto *D = DBuilder.createAutoVariable(
5772 Line, Ty,
false, llvm::DINode::FlagZero, Align);
5775 auto DL = llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5776 LexicalBlockStack.back(), CurInlinedAt);
5777 auto *
Expr = DBuilder.createExpression(addr);
5779 DBuilder.insertDeclare(Storage, D,
Expr, DL, InsertPoint->getIterator());
5781 DBuilder.insertDeclare(Storage, D,
Expr, DL, Builder.GetInsertBlock());
5784llvm::DILocalVariable *
5787 bool UsePointerValue) {
5788 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5789 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
5793struct BlockLayoutChunk {
5794 uint64_t OffsetInBits;
5797bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
5798 return l.OffsetInBits < r.OffsetInBits;
5802void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
5804 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
5805 SmallVectorImpl<llvm::Metadata *> &Fields) {
5809 if (CGM.getLangOpts().OpenCL) {
5810 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
5811 BlockLayout.getElementOffsetInBits(0),
5813 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
5814 BlockLayout.getElementOffsetInBits(1),
5818 BlockLayout.getElementOffsetInBits(0),
5820 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
5821 BlockLayout.getElementOffsetInBits(1),
5825 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
5826 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
5827 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
5828 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
5829 BlockLayout.getElementOffsetInBits(3),
5831 Fields.push_back(createFieldType(
5836 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
5843 llvm::AllocaInst *Alloca,
5845 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5851 llvm::DIFile *tunit = getOrCreateFile(loc);
5852 unsigned line = getLineNumber(loc);
5853 unsigned column = getColumnNumber(loc);
5858 const llvm::StructLayout *blockLayout =
5862 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
5871 BlockLayoutChunk chunk;
5872 chunk.OffsetInBits =
5873 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
5874 chunk.Capture =
nullptr;
5875 chunks.push_back(chunk);
5879 for (
const auto &capture :
blockDecl->captures()) {
5880 const VarDecl *variable = capture.getVariable();
5887 BlockLayoutChunk chunk;
5888 chunk.OffsetInBits =
5889 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
5890 chunk.Capture = &capture;
5891 chunks.push_back(chunk);
5895 llvm::array_pod_sort(chunks.begin(), chunks.end());
5897 for (
const BlockLayoutChunk &Chunk : chunks) {
5898 uint64_t offsetInBits = Chunk.OffsetInBits;
5905 cast_or_null<CXXMethodDecl>(
blockDecl->getNonClosureContext()))
5907 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(
blockDecl->getParent()))
5908 type = CGM.getContext().getCanonicalTagType(RDecl);
5910 llvm_unreachable(
"unexpected block declcontext");
5912 fields.push_back(createFieldType(
"this",
type, loc,
AS_public,
5913 offsetInBits, tunit, tunit));
5918 StringRef name = variable->
getName();
5920 llvm::DIType *fieldType;
5922 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
5927 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
5928 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
5929 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
5930 PtrInfo.
Width, Align, offsetInBits,
5931 llvm::DINode::FlagZero, fieldType);
5935 offsetInBits, Align, tunit, tunit);
5937 fields.push_back(fieldType);
5941 llvm::raw_svector_ostream(typeName)
5942 <<
"__block_literal_" << CGM.getUniqueBlockCount();
5944 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
5946 llvm::DIType *
type =
5947 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
5948 CGM.getContext().toBits(block.
BlockSize), 0,
5949 llvm::DINode::FlagZero,
nullptr, fieldsArray);
5950 type = DBuilder.createPointerType(
type, CGM.PointerWidthInBits);
5953 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
5957 auto *debugVar = DBuilder.createParameterVariable(
5958 scope, Name, ArgNo, tunit, line,
type,
5959 CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
5962 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
5963 llvm::DILocation::get(CGM.getLLVMContext(), line,
5964 column, scope, CurInlinedAt),
5965 Builder.GetInsertBlock());
5968llvm::DIDerivedType *
5969CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
5974 if (MI != StaticDataMemberCache.end()) {
5975 assert(MI->second &&
"Static data member declaration should still exist");
5986llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
5987 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
5988 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
5989 llvm::DIGlobalVariableExpression *GVE =
nullptr;
5991 for (
const auto *Field : RD->
fields()) {
5992 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
5993 StringRef FieldName = Field->getName();
5996 if (FieldName.empty()) {
5997 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
5998 GVE = CollectAnonRecordDecls(RT->getDecl()->getDefinitionOrSelf(), Unit,
5999 LineNo, LinkageName, Var, DContext);
6003 GVE = DBuilder.createGlobalVariableExpression(
6004 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
6005 Var->hasLocalLinkage());
6006 Var->addDebugInfo(GVE);
6018 const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6023 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
6034 struct ReferencesAnonymous
6036 bool RefAnon =
false;
6037 bool VisitRecordType(RecordType *RT) {
6045 ReferencesAnonymous RT;
6058struct ReconstitutableType :
public RecursiveASTVisitor<ReconstitutableType> {
6059 bool Reconstitutable =
true;
6060 bool VisitVectorType(VectorType *FT) {
6061 Reconstitutable =
false;
6064 bool VisitAtomicType(AtomicType *FT) {
6065 Reconstitutable =
false;
6068 bool TraverseEnumType(EnumType *ET,
bool =
false) {
6071 const EnumDecl *ED = ET->getDecl();
6073 Reconstitutable =
false;
6077 Reconstitutable =
false;
6082 bool VisitFunctionProtoType(FunctionProtoType *FT) {
6086 return Reconstitutable;
6088 bool VisitRecordType(RecordType *RT,
bool =
false) {
6090 Reconstitutable =
false;
6100 ReconstitutableType
T;
6102 return T.Reconstitutable;
6105bool CGDebugInfo::HasReconstitutableArgs(
6106 ArrayRef<TemplateArgument> Args)
const {
6107 return llvm::all_of(Args, [&](
const TemplateArgument &TA) {
6147 llvm_unreachable(
"Other, unresolved, template arguments should "
6148 "not be seen here");
6153std::string CGDebugInfo::GetName(
const Decl *D,
bool Qualified,
6154 bool *NameIsSimplified)
const {
6156 llvm::raw_string_ostream
OS(Name);
6157 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
6160 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
6161 CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
6163 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6164 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
6166 std::optional<TemplateArgs> Args;
6168 bool IsOperatorOverload =
false;
6169 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
6170 Args = GetTemplateArgs(RD);
6171 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
6172 Args = GetTemplateArgs(FD);
6174 IsOperatorOverload |=
6177 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
6178 Args = GetTemplateArgs(VD);
6202 bool Reconstitutable =
6203 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
6205 PrintingPolicy PP = getPrintingPolicy();
6207 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
6212 if (NameIsSimplified)
6213 *NameIsSimplified =
true;
6214 bool Mangled = TemplateNamesKind ==
6215 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
6221 std::string EncodedOriginalName;
6222 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
6227 printTemplateArgumentList(OS, Args->Args, PP);
6228 printTemplateArgumentList(EncodedOriginalNameOS, Args->Args, PP);
6230 std::string CanonicalOriginalName;
6231 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
6233 assert(EncodedOriginalName == CanonicalOriginalName);
6242 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6243 if (D->
hasAttr<NoDebugAttr>())
6246 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
6247 return GetName(D,
true);
6253 if (Cached != DeclCache.end())
6254 return Var->addDebugInfo(
6258 llvm::DIFile *Unit =
nullptr;
6259 llvm::DIScope *DContext =
nullptr;
6261 StringRef DeclName, LinkageName;
6263 llvm::MDTuple *TemplateParameters =
nullptr;
6264 collectVarDeclProps(D, Unit, LineNo,
T, DeclName, LinkageName,
6265 TemplateParameters, DContext);
6269 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6274 if (
T->isUnionType() && DeclName.empty()) {
6275 const auto *RD =
T->castAsRecordDecl();
6277 "unnamed non-anonymous struct or union?");
6278 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
6283 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->
getType());
6284 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
6285 if (D->
hasAttr<CUDASharedAttr>())
6288 else if (D->
hasAttr<CUDAConstantAttr>())
6292 AppendAddressSpaceXDeref(AddressSpace,
Expr);
6294 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
6295 GVE = DBuilder.createGlobalVariableExpression(
6296 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(
T, Unit),
6297 Var->hasLocalLinkage(),
true,
6298 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
6299 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
6300 Align, Annotations);
6301 Var->addDebugInfo(GVE);
6307 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6308 if (VD->
hasAttr<NoDebugAttr>())
6310 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
6311 return GetName(VD,
true);
6316 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
6317 StringRef Name = VD->
getName();
6318 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
6320 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
6322 if (CGM.getCodeGenOpts().EmitCodeView) {
6333 CanQualType T = CGM.getContext().getCanonicalTagType(ED);
6334 [[maybe_unused]] llvm::DIType *EDTy = getOrCreateType(
T, Unit);
6335 assert(EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
6345 auto *VarD = dyn_cast<VarDecl>(VD);
6346 if (VarD && VarD->isStaticDataMember()) {
6348 getDeclContextDescriptor(VarD);
6353 RetainedTypes.push_back(
6354 CGM.getContext().getCanonicalTagType(RD).getAsOpaquePtr());
6358 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
6360 auto &GV = DeclCache[VD];
6364 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
6365 llvm::MDTuple *TemplateParameters =
nullptr;
6369 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
6370 TemplateParameters = parameterNodes.get();
6373 GV.reset(DBuilder.createGlobalVariableExpression(
6374 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
6375 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
6376 TemplateParameters, Align));
6381 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6382 if (D->
hasAttr<NoDebugAttr>())
6386 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
6387 StringRef Name = D->
getName();
6388 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
6390 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6391 llvm::DIGlobalVariableExpression *GVE =
6392 DBuilder.createGlobalVariableExpression(
6393 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
6394 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
6395 Var->addDebugInfo(GVE);
6402 if (CGM.getCodeGenOpts().getDebugInfo() <=
6403 llvm::codegenoptions::DebugLineTablesOnly)
6406 llvm::DILocation *DIL =
Value->getDebugLoc().get();
6410 llvm::DIFile *Unit = DIL->getFile();
6411 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
6416 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
6417 llvm::Value *Var = Load->getPointerOperand();
6422 auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
6423 return DbgDeclare->getVariable()->getType() ==
Type;
6425 if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6429 llvm::DILocalVariable *D =
6430 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
6431 Type,
false, llvm::DINode::FlagArtificial);
6433 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
6434 DBuilder.insertDbgValue(
Value, D, DBuilder.createExpression(), DIL,
6444 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6448 if (D->
hasAttr<NoDebugAttr>())
6451 auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
6466 if (!(DI = getDeclarationOrDefinition(
6467 AliaseeDecl.getCanonicalDecl().getDecl())))
6470 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6473 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
6474 DContext, DI, getOrCreateFile(Loc), getLineNumber(Loc), D->getName());
6488 llvm::DIFile *
File = getOrCreateFile(Loc);
6489 llvm::DIGlobalVariableExpression *Debug =
6490 DBuilder.createGlobalVariableExpression(
6491 nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
6492 getLineNumber(Loc), getOrCreateType(S->
getType(),
File),
true);
6493 GV->addDebugInfo(Debug);
6496llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
6497 if (!LexicalBlockStack.empty())
6498 return LexicalBlockStack.back();
6499 llvm::DIScope *Mod = getParentModuleOrNull(D);
6500 return getContextDescriptor(D, Mod ? Mod : TheCU);
6504 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6508 CGM.getCodeGenOpts().DebugExplicitImport) {
6512 DBuilder.createImportedModule(
6514 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
6519 if (llvm::DINode *
Target =
6522 DBuilder.createImportedDeclaration(
6524 getOrCreateFile(Loc), getLineNumber(Loc));
6529 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6532 "We shouldn't be codegening an invalid UsingDecl containing no decls");
6534 for (
const auto *USD : UD.
shadows()) {
6539 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
6540 if (
const auto *AT = FD->getType()
6543 if (AT->getDeducedType().isNull())
6554 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6557 "We shouldn't be codegening an invalid UsingEnumDecl"
6558 " containing no decls");
6560 for (
const auto *USD : UD.
shadows())
6565 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
6567 if (
Module *M = ID.getImportedModule()) {
6569 auto Loc = ID.getLocation();
6570 DBuilder.createImportedDeclaration(
6571 getCurrentContextDescriptor(
cast<Decl>(ID.getDeclContext())),
6572 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
6573 getLineNumber(Loc));
6577llvm::DIImportedEntity *
6579 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6581 auto &VH = NamespaceAliasCache[&NA];
6584 llvm::DIImportedEntity *R;
6586 if (
const auto *Underlying =
6589 R = DBuilder.createImportedDeclaration(
6592 getLineNumber(Loc), NA.
getName());
6594 R = DBuilder.createImportedDeclaration(
6597 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
6603CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6607 auto I = NamespaceCache.find(NSDecl);
6608 if (I != NamespaceCache.end())
6611 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6613 llvm::DINamespace *NS =
6614 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6615 NamespaceCache[NSDecl].reset(NS);
6620 assert(TheCU &&
"no main compile unit");
6621 TheCU->setDWOId(Signature);
6627 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6628 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
6630 ? CreateTypeDefinition(E.Type, E.Unit)
6632 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
6636 for (
const auto &P : ObjCMethodCache) {
6637 if (P.second.empty())
6640 QualType QTy(P.first->getTypeForDecl(), 0);
6642 assert(It != TypeCache.end());
6644 llvm::DICompositeType *InterfaceDecl =
6647 auto CurElts = InterfaceDecl->getElements();
6651 for (
auto &SubprogramDirect : P.second)
6652 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6653 EltTys.push_back(SubprogramDirect.getPointer());
6655 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6656 DBuilder.replaceArrays(InterfaceDecl, Elements);
6659 for (
const auto &P : ReplaceMap) {
6662 assert(Ty->isForwardDecl());
6664 auto It = TypeCache.find(P.first);
6665 assert(It != TypeCache.end());
6668 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6672 for (
const auto &P : FwdDeclReplaceMap) {
6675 llvm::Metadata *Repl;
6677 auto It = DeclCache.find(P.first);
6681 if (It == DeclCache.end())
6686 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6687 Repl = GVE->getVariable();
6693 for (
auto &RT : RetainedTypes)
6694 if (
auto MD = TypeCache[RT])
6697 DBuilder.finalize();
6702 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
6703 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6704 DBuilder.retainType(DieTy);
6708 if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
6709 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6710 DBuilder.retainType(DieTy);
6714 if (LexicalBlockStack.empty())
6715 return llvm::DebugLoc();
6717 llvm::MDNode *
Scope = LexicalBlockStack.back();
6718 return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
6719 getColumnNumber(Loc),
Scope);
6725 if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
6726 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6727 DebugKind == llvm::codegenoptions::LocTrackingOnly ||
6728 !CGM.getCodeGenOpts().DebugCallSiteInfo)
6729 return llvm::DINode::FlagZero;
6734 bool SupportsDWARFv4Ext =
6735 CGM.getCodeGenOpts().DwarfVersion == 4 &&
6736 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6737 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6739 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
6740 return llvm::DINode::FlagZero;
6742 return llvm::DINode::FlagAllCallsDescribed;
6753 return DBuilder.createConstantValueExpression(
6754 Val.
getFloat().bitcastToAPInt().getZExtValue());
6759 llvm::APSInt
const &ValInt = Val.
getInt();
6760 std::optional<uint64_t> ValIntOpt;
6761 if (ValInt.isUnsigned())
6762 ValIntOpt = ValInt.tryZExtValue();
6763 else if (
auto tmp = ValInt.trySExtValue())
6766 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6769 return DBuilder.createConstantValueExpression(ValIntOpt.value());
6774CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &
CGF,
6776 : RunCleanupsScope(
CGF), Range(Range), ParentScope(
CGF.CurLexicalScope) {
6777 CGF.CurLexicalScope =
this;
6779 DI->EmitLexicalBlockStart(
CGF.Builder, Range.getBegin());
6784 DI->EmitLexicalBlockEnd(
CGF.Builder, Range.getEnd());
6797#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
6799 Label = "__ubsan_check_" #Name; \
6803#undef SANITIZER_CHECK
6814#define SANITIZER(NAME, ID) \
6815 case SanitizerKind::SO_##ID: \
6816 Label = "__ubsan_check_" NAME; \
6818#include "clang/Basic/Sanitizers.def"
6820 llvm_unreachable(
"unexpected sanitizer kind");
6825 for (
unsigned int i = 0; i < Label.length(); i++)
6826 if (!std::isalpha(Label[i]))
6835 llvm::DILocation *CheckDebugLoc =
Builder.getCurrentDebugLocation();
6837 if (!DI || !CheckDebugLoc)
6838 return CheckDebugLoc;
6839 const auto &AnnotateDebugInfo =
6840 CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo;
6841 if (AnnotateDebugInfo.empty())
6842 return CheckDebugLoc;
6845 if (Ordinals.size() == 1)
6850 if (any_of(Ordinals, [&](
auto Ord) {
return AnnotateDebugInfo.has(Ord); })) {
6854 llvm::DIFile *
File = llvm::DIFile::get(
CGM.getLLVMContext(),
6855 "ubsan_interface.h",
6857 return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label,
File);
6860 return CheckDebugLoc;
6868 assert(!CGF->IsSanitizerScope);
6869 CGF->IsSanitizerScope =
true;
6873 assert(CGF->IsSanitizerScope);
6874 CGF->IsSanitizerScope =
false;
Defines the clang::ASTContext interface.
static bool IsReconstitutableType(QualType QT)
static void stripUnusedQualifiers(Qualifiers &Q)
static std::string SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal)
static llvm::Constant * buildConstantDataArrayFromElements(llvm::LLVMContext &Ctx, const APValue &Arr)
Build an llvm::ConstantDataArray from the initialized elements of an APValue array,...
static unsigned getDwarfCC(CallingConv CC, const llvm::Triple &T)
static std::string SanitizerHandlerToCheckLabel(SanitizerHandler Handler)
static bool IsObjCSynthesizedPropertyExplicitParameter(VarDecl const *VD)
Returns true if the specified variable VD is an explicit parameter of a synthesized Objective-C prope...
static bool IsArtificial(VarDecl const *VD)
Returns true if VD is a compiler-generated variable and should be treated as artificial for the purpo...
static bool needsTypeIdentifier(const TagDecl *TD, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static bool shouldOmitDefinition(llvm::codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access, const RecordDecl *RD)
Convert an AccessSpecifier into the corresponding DINode flag.
static 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 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.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
unsigned getNumElements() const
QualType getElementType() const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Default
Set to the current date and time.
@ Result
The result type of a method or function.
const FunctionProtoType * T
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Deleting
Deleting dtor.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ Generic
not a target-specific vector type
U cast(CodeGen::Address addr)
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ CXXThis
Parameter for C++ 'this' argument.
@ ObjCSelf
Parameter for Objective-C 'self' argument.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
__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.