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) {
432 PP.MSVCFormatting =
true;
442 PP.PrintAsCanonical =
true;
443 PP.UsePreferredNames =
false;
444 PP.AlwaysIncludeTypeForTemplateArgument =
true;
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);
675 return CGM.getCodeGenOpts().remapDebugPathPrefix(Path);
683 if (DebugLoc == CurLoc)
698 if (DebugLoc == CurLoc)
704StringRef CGDebugInfo::getCurrentDirname() {
712 assert(CGO.DwarfVersion <= 5);
714 llvm::dwarf::SourceLanguage LangTag;
717 LangTag = llvm::dwarf::DW_LANG_HLSL;
719 LangTag = llvm::dwarf::DW_LANG_HIP;
721 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
722 else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
723 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
724 else if (LO.CPlusPlus14)
725 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
726 else if (LO.CPlusPlus11)
727 LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
729 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
730 }
else if (LO.ObjC) {
731 LangTag = llvm::dwarf::DW_LANG_ObjC;
732 }
else if (LO.OpenCL && (!CGO.DebugStrictDwarf || CGO.DwarfVersion >= 5)) {
733 LangTag = llvm::dwarf::DW_LANG_OpenCL;
734 }
else if (LO.C11 && !(CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)) {
735 LangTag = llvm::dwarf::DW_LANG_C11;
737 LangTag = llvm::dwarf::DW_LANG_C99;
739 LangTag = llvm::dwarf::DW_LANG_C89;
745static llvm::DISourceLanguageName
754 llvm::dwarf::SourceLanguageName LangTag;
757 LangTag = llvm::dwarf::DW_LNAME_HLSL;
759 LangTag = llvm::dwarf::DW_LNAME_HIP;
760 }
else if (LO.ObjC) {
761 LangTag = llvm::dwarf::DW_LNAME_ObjC_plus_plus;
763 LangTag = llvm::dwarf::DW_LNAME_C_plus_plus;
766 }
else if (LO.ObjC) {
767 LangTag = llvm::dwarf::DW_LNAME_ObjC;
768 }
else if (LO.OpenCL) {
769 LangTag = llvm::dwarf::DW_LNAME_OpenCL_C;
771 LangTag = llvm::dwarf::DW_LNAME_C;
775 return llvm::DISourceLanguageName(LangTag, LangVersion);
778void CGDebugInfo::CreateCompileUnit() {
779 SmallString<64> Checksum;
780 std::optional<llvm::DIFile::ChecksumKind> CSKind;
781 std::optional<llvm::DIFile::ChecksumInfo<StringRef>> CSInfo;
791 SourceManager &SM = CGM.getContext().getSourceManager();
792 auto &CGO = CGM.getCodeGenOpts();
793 const LangOptions &LO = CGM.getLangOpts();
794 std::string MainFileName = CGO.MainFileName;
795 if (MainFileName.empty())
796 MainFileName =
"<stdin>";
802 std::string MainFileDir;
805 MainFileDir = std::string(MainFile->getDir().getName());
806 if (!llvm::sys::path::is_absolute(MainFileName)) {
807 llvm::SmallString<1024> MainFileDirSS(MainFileDir);
808 llvm::sys::path::Style Style =
810 ? (CGM.getTarget().
getTriple().isOSWindows()
811 ? llvm::sys::path::Style::windows_backslash
812 : llvm::sys::path::Style::posix)
813 : llvm::sys::path::Style::native;
814 llvm::sys::path::append(MainFileDirSS, Style, MainFileName);
815 MainFileName = std::string(
816 llvm::sys::path::remove_leading_dotslash(MainFileDirSS, Style));
823 if (MainFile->getName() == MainFileName &&
825 MainFile->getName().rsplit(
'.').second)
827 MainFileName = CGM.getModule().getName().str();
836 unsigned RuntimeVers = 0;
840 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
842 case llvm::codegenoptions::NoDebugInfo:
843 case llvm::codegenoptions::LocTrackingOnly:
844 EmissionKind = llvm::DICompileUnit::NoDebug;
846 case llvm::codegenoptions::DebugLineTablesOnly:
847 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
849 case llvm::codegenoptions::DebugDirectivesOnly:
850 EmissionKind = llvm::DICompileUnit::DebugDirectivesOnly;
852 case llvm::codegenoptions::DebugInfoConstructor:
853 case llvm::codegenoptions::LimitedDebugInfo:
854 case llvm::codegenoptions::FullDebugInfo:
855 case llvm::codegenoptions::UnusedTypeInfo:
856 EmissionKind = llvm::DICompileUnit::FullDebug;
861 auto &CGOpts = CGM.getCodeGenOpts();
867 CSInfo.emplace(*CSKind, Checksum);
868 llvm::DIFile *CUFile = DBuilder.createFile(
872 StringRef Sysroot, SDK;
873 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB) {
874 StringRef FullSysroot = CGM.getHeaderSearchOpts().Sysroot;
875 if (CGM.getCodeGenOpts().DebugRecordSysroot)
876 Sysroot = FullSysroot;
877 auto B = llvm::sys::path::rbegin(FullSysroot);
878 auto E = llvm::sys::path::rend(FullSysroot);
880 std::find_if(B, E, [](
auto SDK) {
return SDK.ends_with(
".sdk"); });
885 llvm::DICompileUnit::DebugNameTableKind NameTableKind =
886 static_cast<llvm::DICompileUnit::DebugNameTableKind
>(
887 CGOpts.DebugNameTable);
888 if (CGM.getTarget().getTriple().isNVPTX())
889 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::None;
890 else if (CGM.getTarget().getTriple().getVendor() == llvm::Triple::Apple)
891 NameTableKind = llvm::DICompileUnit::DebugNameTableKind::Apple;
894 TheCU = DBuilder.createCompileUnit(
896 CGOpts.EmitVersionIdentMetadata ? Producer :
"",
897 CGOpts.OptimizationLevel != 0 || CGOpts.PrepareForLTO ||
898 CGOpts.PrepareForThinLTO,
899 CGOpts.DwarfDebugFlags, RuntimeVers, CGOpts.SplitDwarfFile, EmissionKind,
900 DwoId, CGOpts.SplitDwarfInlining, CGOpts.DebugInfoForProfiling,
901 NameTableKind, CGOpts.DebugRangesBaseAddress,
remapDIPath(Sysroot), SDK);
904llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
908#define BUILTIN_TYPE(Id, SingletonId)
909#define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
910#include "clang/AST/BuiltinTypes.def"
911 case BuiltinType::Dependent:
912 llvm_unreachable(
"Unexpected builtin type");
913 case BuiltinType::NullPtr:
914 return DBuilder.createNullPtrType();
915 case BuiltinType::Void:
917 case BuiltinType::ObjCClass:
920 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
921 "objc_class", TheCU, TheCU->getFile(), 0);
923 case BuiltinType::ObjCId: {
934 DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
935 "objc_class", TheCU, TheCU->getFile(), 0);
937 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
939 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
941 ObjTy = DBuilder.createStructType(TheCU,
"objc_object", TheCU->getFile(), 0,
942 (uint64_t)0, 0, llvm::DINode::FlagZero,
943 nullptr, llvm::DINodeArray());
945 DBuilder.replaceArrays(
946 ObjTy, DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
947 ObjTy,
"isa", TheCU->getFile(), 0, Size, 0, 0,
948 llvm::DINode::FlagZero, ISATy)));
951 case BuiltinType::ObjCSel: {
953 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
954 "objc_selector", TheCU,
955 TheCU->getFile(), 0);
959#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
960 case BuiltinType::Id: \
961 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
963#include "clang/Basic/OpenCLImageTypes.def"
964 case BuiltinType::OCLSampler:
965 return getOrCreateStructPtrType(
"opencl_sampler_t", OCLSamplerDITy);
966 case BuiltinType::OCLEvent:
967 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
968 case BuiltinType::OCLClkEvent:
969 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
970 case BuiltinType::OCLQueue:
971 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
972 case BuiltinType::OCLReserveID:
973 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
974#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \
975 case BuiltinType::Id: \
976 return getOrCreateStructPtrType("opencl_" #ExtType, Id##Ty);
977#include "clang/Basic/OpenCLExtensionTypes.def"
978#define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) \
979 case BuiltinType::Id: \
980 return getOrCreateStructPtrType(#Name, SingletonId);
981#include "clang/Basic/HLSLIntangibleTypes.def"
982#define HLSL_PACKED_TYPE(Name, Id, SingletonId) \
983 case BuiltinType::Id: \
984 return DBuilder.createBasicType(#Name, 32, llvm::dwarf::DW_ATE_unsigned);
985#include "clang/Basic/HLSLPackedTypes.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;
1224 case BuiltinType::MetaInfo:
1225 llvm_unreachable(
"std::meta::info is consteval-only type");
1228 BTName = BT->
getName(CGM.getLangOpts());
1231 return DBuilder.createBasicType(BTName, Size, Encoding);
1234llvm::DIType *CGDebugInfo::CreateType(
const BitIntType *Ty) {
1235 SmallString<32> Name;
1236 llvm::raw_svector_ostream
OS(Name);
1237 OS << (Ty->
isUnsigned() ?
"unsigned _BitInt(" :
"_BitInt(")
1240 ? llvm::dwarf::DW_ATE_unsigned
1241 : llvm::dwarf::DW_ATE_signed;
1242 return DBuilder.createBasicType(Name, CGM.getContext().getTypeSize(Ty),
1243 Encoding, llvm::DINode::FlagZero, 0,
1247llvm::DIType *CGDebugInfo::CreateType(
const OverflowBehaviorType *Ty,
1249 return getOrCreateType(Ty->getUnderlyingType(), U);
1252llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
1254 llvm::dwarf::TypeKind
Encoding = llvm::dwarf::DW_ATE_complex_float;
1256 Encoding = llvm::dwarf::DW_ATE_lo_user;
1259 return DBuilder.createBasicType(
"complex", Size, Encoding);
1273 return llvm::dwarf::DW_TAG_const_type;
1277 return llvm::dwarf::DW_TAG_volatile_type;
1281 return llvm::dwarf::DW_TAG_restrict_type;
1283 return (llvm::dwarf::Tag)0;
1286llvm::DIType *CGDebugInfo::CreateQualifiedType(QualType Ty,
1287 llvm::DIFile *Unit) {
1288 QualifierCollector Qc;
1302 bool AuthenticatesNullValues =
1305 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1306 llvm::DIType *FromTy = getOrCreateType(QualType(
T, 0), Unit);
1307 return DBuilder.createPtrAuthQualifiedType(FromTy, Key, IsDiscr,
1308 ExtraDiscr, IsaPointer,
1309 AuthenticatesNullValues);
1311 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
1312 return getOrCreateType(QualType(
T, 0), Unit);
1316 auto *FromTy = getOrCreateType(Qc.
apply(CGM.getContext(),
T), Unit);
1320 return DBuilder.createQualifiedType(Tag, FromTy);
1323llvm::DIType *CGDebugInfo::CreateQualifiedType(
const FunctionProtoType *F,
1324 llvm::DIFile *Unit) {
1333 assert(Q.
empty() &&
"Unknown type qualifier for debug info");
1338 getOrCreateType(CGM.getContext().getFunctionType(F->
getReturnType(),
1344 return DBuilder.createQualifiedType(Tag, FromTy);
1347llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectPointerType *Ty,
1348 llvm::DIFile *Unit) {
1354 return getOrCreateType(CGM.getContext().getObjCIdType(), Unit);
1356 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1360llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
1361 llvm::DIFile *Unit) {
1362 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
1368 case llvm::dwarf::DW_LANG_C_plus_plus:
1369 case llvm::dwarf::DW_LANG_C_plus_plus_11:
1370 case llvm::dwarf::DW_LANG_C_plus_plus_14:
1371 case llvm::dwarf::DW_LANG_HIP:
1373 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
1383 case llvm::dwarf::DW_LNAME_C_plus_plus:
1384 case llvm::dwarf::DW_LNAME_HIP:
1386 case llvm::dwarf::DW_LNAME_ObjC_plus_plus:
1397 if (llvm::DISourceLanguageName SourceLang = TheCU->getSourceLanguage();
1398 SourceLang.hasVersionedName())
1400 static_cast<llvm::dwarf::SourceLanguageName
>(SourceLang.getName()),
1404 static_cast<llvm::dwarf::SourceLanguage
>(SourceLang.getName()),
1430 llvm::DICompileUnit *TheCU) {
1448 llvm::DICompileUnit *TheCU) {
1454 if (
const auto *RD = dyn_cast<CXXRecordDecl>(TD))
1456 if (RD->isDynamicClass() &&
1462 llvm::raw_svector_ostream Out(Identifier);
1469 llvm::dwarf::Tag Tag;
1471 Tag = llvm::dwarf::DW_TAG_structure_type;
1473 Tag = llvm::dwarf::DW_TAG_union_type;
1478 Tag = llvm::dwarf::DW_TAG_class_type;
1483llvm::DICompositeType *
1484CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
1485 llvm::DIScope *Ctx) {
1487 if (llvm::DIType *
T = getTypeOrNull(QualType(Ty, 0)))
1489 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
1490 const unsigned Line =
1492 StringRef RDName = getClassName(RD);
1499 Size = CGM.getContext().getTypeSize(Ty);
1501 llvm::DINode::DIFlags Flags = llvm::DINode::FlagFwdDecl;
1506 if (
const CXXRecordDecl *CXXRD = dyn_cast<CXXRecordDecl>(RD))
1507 if (!CXXRD->hasDefinition() ||
1508 (CXXRD->hasDefinition() && !CXXRD->isTrivial()))
1509 Flags |= llvm::DINode::FlagNonTrivial;
1512 SmallString<256> Identifier;
1514 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
1516 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
1519 if (CGM.getCodeGenOpts().DebugFwdTemplateParams)
1520 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
1521 DBuilder.replaceArrays(RetTy, llvm::DINodeArray(),
1522 CollectCXXTemplateParams(TSpecial, DefUnit));
1523 ReplaceMap.emplace_back(
1524 std::piecewise_construct, std::make_tuple(Ty),
1525 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
1529llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
1532 llvm::DIFile *Unit) {
1537 std::optional<unsigned> DWARFAddressSpace =
1538 CGM.getTarget().getDWARFAddressSpace(
1539 CGM.getTypes().getTargetAddressSpace(PointeeTy));
1541 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
1542 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type) {
1543 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
1544 Size, Align, DWARFAddressSpace);
1546 SmallVector<llvm::Metadata *, 4> Annots;
1547 CollectBTFTypeTagAnnotations(PointeeTy, Annots);
1549 llvm::DINodeArray Annotations =
nullptr;
1550 if (Annots.size() > 0)
1551 Annotations = DBuilder.getOrCreateArray(Annots);
1552 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
1553 Align, DWARFAddressSpace, StringRef(),
1558llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
1559 llvm::DIType *&
Cache) {
1562 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
1563 TheCU, TheCU->getFile(), 0);
1564 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
1565 Cache = DBuilder.createPointerType(
Cache, Size);
1569uint64_t CGDebugInfo::collectDefaultElementTypesForBlockPointer(
1570 const BlockPointerType *Ty, llvm::DIFile *Unit, llvm::DIDerivedType *DescTy,
1571 unsigned LineNo, SmallVectorImpl<llvm::Metadata *> &EltTys) {
1581 if (CGM.getLangOpts().OpenCL) {
1582 FType = CGM.getContext().IntTy;
1583 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
1584 EltTys.push_back(CreateMemberType(Unit, FType,
"__align", &FieldOffset));
1586 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1587 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
1588 FType = CGM.getContext().IntTy;
1589 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
1590 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
1592 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
1593 FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
1594 uint64_t FieldSize = CGM.getContext().getTypeSize(Ty);
1595 uint32_t FieldAlign = CGM.getContext().getTypeAlign(Ty);
1596 EltTys.push_back(DBuilder.createMemberType(
1597 Unit,
"__descriptor",
nullptr, LineNo, FieldSize, FieldAlign,
1598 FieldOffset, llvm::DINode::FlagZero, DescTy));
1599 FieldOffset += FieldSize;
1605llvm::DIType *CGDebugInfo::CreateType(
const BlockPointerType *Ty,
1606 llvm::DIFile *Unit) {
1607 SmallVector<llvm::Metadata *, 8> EltTys;
1610 llvm::DINodeArray Elements;
1613 FType = CGM.getContext().UnsignedLongTy;
1614 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
1615 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
1617 Elements = DBuilder.getOrCreateArray(EltTys);
1620 llvm::DINode::DIFlags Flags = llvm::DINode::FlagAppleBlock;
1623 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, 0,
1624 FieldOffset, 0, Flags,
nullptr, Elements);
1629 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
1631 FieldOffset = collectDefaultElementTypesForBlockPointer(Ty, Unit, DescTy,
1634 Elements = DBuilder.getOrCreateArray(EltTys);
1640 EltTy = DBuilder.createStructType(Unit,
"",
nullptr, 0, FieldOffset, 0,
1641 Flags,
nullptr, Elements);
1643 return DBuilder.createPointerType(EltTy, Size);
1646static llvm::SmallVector<TemplateArgument>
1648 assert(Ty->isTypeAlias());
1657 ArrayRef SubstArgs = Ty->template_arguments();
1660 if (Param->isParameterPack()) {
1669 if (SubstArgs.empty()) {
1678 SpecArgs.push_back(SubstArgs.front());
1679 SubstArgs = SubstArgs.drop_front();
1684llvm::DIType *CGDebugInfo::CreateType(
const TemplateSpecializationType *Ty,
1685 llvm::DIFile *Unit) {
1686 assert(Ty->isTypeAlias());
1687 llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
1689 const TemplateDecl *TD = Ty->getTemplateName().getAsTemplateDecl();
1697 SmallString<128> NS;
1698 llvm::raw_svector_ostream
OS(NS);
1700 auto PP = getPrintingPolicy();
1703 SourceLocation Loc =
AliasDecl->getLocation();
1705 if (CGM.getCodeGenOpts().DebugTemplateAlias) {
1706 auto ArgVector = ::GetTemplateArgs(TD, Ty);
1715 llvm::raw_string_ostream
OS(Name);
1717 if (CGM.getCodeGenOpts().getDebugSimpleTemplateNames() !=
1718 llvm::codegenoptions::DebugTemplateNamesKind::Simple ||
1719 !HasReconstitutableArgs(Args.Args))
1720 printTemplateArgumentList(OS, Args.Args, PP);
1722 llvm::DIDerivedType *AliasTy = DBuilder.createTemplateAlias(
1723 Src, Name, getOrCreateFile(Loc), getLineNumber(Loc),
1724 getDeclContextDescriptor(
AliasDecl), CollectTemplateParams(Args, Unit));
1728 printTemplateArgumentList(OS, Ty->template_arguments(), PP,
1730 return DBuilder.createTypedef(Src,
OS.str(), getOrCreateFile(Loc),
1747 return llvm::DINode::FlagZero;
1751 return llvm::DINode::FlagPrivate;
1753 return llvm::DINode::FlagProtected;
1755 return llvm::DINode::FlagPublic;
1757 return llvm::DINode::FlagZero;
1759 llvm_unreachable(
"unexpected access enumerator");
1762llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
1763 llvm::DIFile *Unit) {
1764 llvm::DIType *Underlying =
1780 SmallVector<llvm::Metadata *, 4> Annots;
1781 llvm::DINodeArray Annotations;
1783 CollectBTFDeclTagAnnotations(Ty->
getDecl(), Annots);
1784 if (!Annots.empty())
1785 Annotations = DBuilder.getOrCreateArray(Annots);
1787 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1792 return DBuilder.createTypedef(Underlying, Ty->
getDecl()->
getName(),
1793 getOrCreateFile(Loc), getLineNumber(Loc),
1794 getDeclContextDescriptor(Ty->
getDecl()), Align,
1795 Flags, Annotations);
1803 if (
T.isSPIROrSPIRV())
1804 return llvm::dwarf::DW_CC_LLVM_SpirFunction;
1809 return llvm::dwarf::DW_CC_BORLAND_stdcall;
1811 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
1813 return llvm::dwarf::DW_CC_BORLAND_thiscall;
1815 return llvm::dwarf::DW_CC_LLVM_vectorcall;
1817 return llvm::dwarf::DW_CC_BORLAND_pascal;
1819 return llvm::dwarf::DW_CC_LLVM_Win64;
1821 return llvm::dwarf::DW_CC_LLVM_X86_64SysV;
1825 return llvm::dwarf::DW_CC_LLVM_AAPCS;
1827 return llvm::dwarf::DW_CC_LLVM_AAPCS_VFP;
1829 return llvm::dwarf::DW_CC_LLVM_IntelOclBicc;
1831 return llvm::dwarf::DW_CC_LLVM_DeviceKernel;
1833 return llvm::dwarf::DW_CC_LLVM_Swift;
1835 return llvm::dwarf::DW_CC_LLVM_SwiftTail;
1837 return llvm::dwarf::DW_CC_LLVM_PreserveMost;
1839 return llvm::dwarf::DW_CC_LLVM_PreserveAll;
1841 return llvm::dwarf::DW_CC_LLVM_X86RegCall;
1843 return llvm::dwarf::DW_CC_LLVM_M68kRTD;
1845 return llvm::dwarf::DW_CC_LLVM_PreserveNone;
1847 return llvm::dwarf::DW_CC_LLVM_RISCVVectorCall;
1848#define CC_VLS_CASE(ABI_VLEN) case CC_RISCVVLSCall_##ABI_VLEN:
1862 return llvm::dwarf::DW_CC_LLVM_RISCVVLSCall;
1868 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1870 Flags |= llvm::DINode::FlagLValueReference;
1872 Flags |= llvm::DINode::FlagRValueReference;
1876llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
1877 llvm::DIFile *Unit) {
1878 const auto *FPT = dyn_cast<FunctionProtoType>(Ty);
1880 if (llvm::DIType *QTy = CreateQualifiedType(FPT, Unit))
1886 SmallVector<llvm::Metadata *, 16> EltTys;
1889 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
1891 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1895 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1898 for (
const QualType &ParamType : FPT->param_types())
1899 EltTys.push_back(getOrCreateType(ParamType, Unit));
1900 if (FPT->isVariadic())
1901 EltTys.push_back(DBuilder.createUnspecifiedParameter());
1904 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
1905 llvm::DIType *F = DBuilder.createSubroutineType(
1906 EltTypeArray, Flags,
1911llvm::DIDerivedType *
1912CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
1913 llvm::DIScope *RecordTy,
const RecordDecl *RD) {
1914 StringRef Name = BitFieldDecl->
getName();
1915 QualType Ty = BitFieldDecl->
getType();
1916 if (BitFieldDecl->
hasAttr<PreferredTypeAttr>())
1919 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1920 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1923 llvm::DIFile *
File = getOrCreateFile(Loc);
1924 unsigned Line = getLineNumber(Loc);
1926 const CGBitFieldInfo &BitFieldInfo =
1927 CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl);
1929 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
1936 if (CGM.getDataLayout().isBigEndian())
1938 uint64_t OffsetInBits = StorageOffsetInBits + Offset;
1940 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(BitFieldDecl);
1941 return DBuilder.createBitFieldMemberType(
1942 RecordTy, Name,
File,
Line, SizeInBits, OffsetInBits, StorageOffsetInBits,
1943 Flags, DebugType, Annotations);
1946llvm::DIDerivedType *CGDebugInfo::createBitFieldSeparatorIfNeeded(
1947 const FieldDecl *BitFieldDecl,
const llvm::DIDerivedType *BitFieldDI,
1948 llvm::ArrayRef<llvm::Metadata *> PreviousFieldsDI,
const RecordDecl *RD) {
1950 if (!CGM.getTargetCodeGenInfo().shouldEmitDWARFBitFieldSeparators())
1975 if (PreviousFieldsDI.empty())
1979 auto *PreviousMDEntry =
1980 PreviousFieldsDI.empty() ?
nullptr : PreviousFieldsDI.back();
1981 auto *PreviousMDField =
1982 dyn_cast_or_null<llvm::DIDerivedType>(PreviousMDEntry);
1983 if (!PreviousMDField || !PreviousMDField->isBitField() ||
1984 PreviousMDField->getSizeInBits() == 0)
1988 std::advance(PreviousBitfield, BitFieldDecl->
getFieldIndex() - 1);
1990 assert(PreviousBitfield->isBitField());
1992 if (!PreviousBitfield->isZeroLengthBitField())
1995 QualType Ty = PreviousBitfield->getType();
1996 SourceLocation Loc = PreviousBitfield->getLocation();
1997 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1998 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
1999 llvm::DIScope *RecordTy = BitFieldDI->getScope();
2001 llvm::DIFile *
File = getOrCreateFile(Loc);
2002 unsigned Line = getLineNumber(Loc);
2008 llvm::DINode::DIFlags Flags =
2010 llvm::DINodeArray Annotations =
2011 CollectBTFDeclTagAnnotations(*PreviousBitfield);
2012 return DBuilder.createBitFieldMemberType(
2013 RecordTy,
"",
File,
Line, 0, StorageOffsetInBits, StorageOffsetInBits,
2014 Flags, DebugType, Annotations);
2017llvm::DIType *CGDebugInfo::createFieldType(
2019 uint64_t offsetInBits,
uint32_t AlignInBits, llvm::DIFile *tunit,
2020 llvm::DIScope *scope,
const RecordDecl *RD, llvm::DINodeArray Annotations) {
2021 llvm::DIType *debugType = getOrCreateType(
type, tunit);
2024 llvm::DIFile *file = getOrCreateFile(loc);
2025 const unsigned line = getLineNumber(loc.
isValid() ? loc : CurLoc);
2028 auto Align = AlignInBits;
2029 if (!
type->isIncompleteArrayType()) {
2030 TypeInfo TI = CGM.getContext().getTypeInfo(
type);
2031 SizeInBits = TI.
Width;
2037 return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align,
2038 offsetInBits, flags, debugType, Annotations);
2042CGDebugInfo::createInlinedSubprogram(StringRef FuncName,
2043 llvm::DIFile *FileScope) {
2047 llvm::DISubprogram *&SP = InlinedSubprogramMap[FuncName];
2050 llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(
nullptr);
2051 SP = DBuilder.createFunction(
2052 FileScope, FuncName, StringRef(),
2053 FileScope, 0, DIFnTy,
2055 llvm::DINode::FlagArtificial,
2056 llvm::DISubprogram::SPFlagDefinition,
2057 nullptr,
nullptr,
nullptr,
2058 nullptr, StringRef(),
2059 CGM.getCodeGenOpts().DebugKeyInstructions);
2066CGDebugInfo::GetLambdaCaptureName(
const LambdaCapture &
Capture) {
2068 return CGM.getCodeGenOpts().EmitCodeView ?
"__this" :
"this";
2070 assert(
Capture.capturesVariable());
2072 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2073 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2075 return CaptureDecl->
getName();
2078void CGDebugInfo::CollectRecordLambdaFields(
2079 const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements,
2080 llvm::DIType *RecordTy) {
2085 unsigned fieldno = 0;
2088 I != E; ++I, ++Field, ++fieldno) {
2089 const LambdaCapture &
Capture = *I;
2091 CGM.getContext().getASTRecordLayout(CXXDecl).getFieldOffset(fieldno);
2093 assert(!
Field->isBitField() &&
"lambdas don't have bitfield members!");
2103 Loc =
Field->getLocation();
2104 }
else if (
Capture.capturesVariable()) {
2107 const ValueDecl *CaptureDecl =
Capture.getCapturedVar();
2108 assert(CaptureDecl &&
"Expected valid decl for captured variable.");
2115 llvm::DIFile *VUnit = getOrCreateFile(Loc);
2117 elements.push_back(createFieldType(
2119 Field->getAccess(), FieldOffset, Align, VUnit, RecordTy, CXXDecl));
2125template <
typename T>
2126static llvm::Constant *
2137 return llvm::ConstantDataArray::get(Ctx, Vals);
2150 const QualType ElemQTy = ArrayTy->getElementType();
2157 switch (ElemBitWidth) {
2173llvm::DIDerivedType *
2174CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
2175 const RecordDecl *RD) {
2179 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
2180 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
2182 unsigned LineNumber = getLineNumber(Var->
getLocation());
2183 StringRef VName = Var->
getName();
2187 llvm::Constant *
C =
nullptr;
2192 C = llvm::ConstantInt::get(CGM.getLLVMContext(),
Value->getInt());
2193 if (
Value->isFloat())
2194 C = llvm::ConstantFP::get(CGM.getLLVMContext(),
Value->getFloat());
2195 if (
Value->isArray())
2201 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2202 ? llvm::dwarf::DW_TAG_variable
2203 : llvm::dwarf::DW_TAG_member;
2205 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
2206 RecordTy, VName, VUnit, LineNumber, VTy, Flags,
C, Tag, Align);
2211void CGDebugInfo::CollectRecordNormalField(
2212 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
2213 SmallVectorImpl<llvm::Metadata *> &elements, llvm::DIType *RecordTy,
2214 const RecordDecl *RD) {
2219 if (
name.empty() && !
type->isRecordType())
2222 llvm::DIType *FieldType;
2224 llvm::DIDerivedType *BitFieldType;
2225 FieldType = BitFieldType = createBitFieldType(field, RecordTy, RD);
2226 if (llvm::DIType *Separator =
2227 createBitFieldSeparatorIfNeeded(field, BitFieldType, elements, RD))
2228 elements.push_back(Separator);
2231 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(field);
2234 OffsetInBits, Align, tunit, RecordTy, RD, Annotations);
2237 elements.push_back(FieldType);
2240void CGDebugInfo::CollectRecordNestedType(
2241 const TypeDecl *TD, SmallVectorImpl<llvm::Metadata *> &elements) {
2242 QualType Ty = CGM.getContext().getTypeDeclType(TD);
2249 if (llvm::DIType *nestedType = getOrCreateType(Ty, getOrCreateFile(Loc)))
2250 elements.push_back(nestedType);
2253void CGDebugInfo::CollectRecordFields(
2254 const RecordDecl *record, llvm::DIFile *tunit,
2255 SmallVectorImpl<llvm::Metadata *> &elements,
2256 llvm::DICompositeType *RecordTy) {
2257 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(record);
2259 if (CXXDecl && CXXDecl->
isLambda())
2260 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
2262 const ASTRecordLayout &layout = CGM.getContext().getASTRecordLayout(record);
2265 unsigned fieldNo = 0;
2269 for (
const auto *I : record->
decls())
2270 if (
const auto *
V = dyn_cast<VarDecl>(I)) {
2271 if (
V->hasAttr<NoDebugAttr>())
2276 if (CGM.getCodeGenOpts().EmitCodeView &&
2284 auto MI = StaticDataMemberCache.find(
V->getCanonicalDecl());
2285 if (MI != StaticDataMemberCache.end()) {
2286 assert(MI->second &&
2287 "Static data member declaration should still exist");
2288 elements.push_back(MI->second);
2290 auto Field = CreateRecordStaticField(
V, RecordTy, record);
2291 elements.push_back(Field);
2293 }
else if (
const auto *field = dyn_cast<FieldDecl>(I)) {
2294 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
2295 elements, RecordTy, record);
2299 }
else if (CGM.getCodeGenOpts().EmitCodeView) {
2302 if (
const auto *nestedType = dyn_cast<TypeDecl>(I)) {
2307 if (!nestedType->isImplicit() &&
2308 nestedType->getDeclContext() == record)
2309 CollectRecordNestedType(nestedType, elements);
2315llvm::DISubroutineType *
2316CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *
Method,
2317 llvm::DIFile *Unit) {
2318 const FunctionProtoType *
Func =
Method->getType()->getAs<FunctionProtoType>();
2320 return cast_or_null<llvm::DISubroutineType>(
2321 getOrCreateType(QualType(
Func, 0), Unit));
2324 if (!
Method->hasCXXExplicitFunctionObjectParameter())
2325 ThisType =
Method->getThisType();
2327 return getOrCreateInstanceMethodType(ThisType,
Func, Unit);
2330llvm::DISubroutineType *CGDebugInfo::getOrCreateMethodTypeForDestructor(
2331 const CXXMethodDecl *
Method, llvm::DIFile *Unit, QualType FNType) {
2332 const FunctionProtoType *
Func = FNType->
getAs<FunctionProtoType>();
2334 return getOrCreateInstanceMethodType(
Method->getThisType(),
Func, Unit,
true);
2337llvm::DISubroutineType *
2338CGDebugInfo::getOrCreateInstanceMethodType(QualType ThisPtr,
2339 const FunctionProtoType *
Func,
2340 llvm::DIFile *Unit,
bool SkipFirst) {
2341 FunctionProtoType::ExtProtoInfo EPI =
Func->getExtProtoInfo();
2356 getOrCreateType(CGM.getContext().getFunctionType(
2357 Func->getReturnType(),
Func->getParamTypes(), EPI),
2359 llvm::DITypeArray Args = OriginalFunc->getTypeArray();
2360 assert(Args.size() &&
"Invalid number of arguments!");
2362 SmallVector<llvm::Metadata *, 16> Elts;
2365 Elts.push_back(Args[0]);
2367 const bool HasExplicitObjectParameter = ThisPtr.
isNull();
2371 if (!HasExplicitObjectParameter) {
2372 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
2375 DBuilder.createObjectPointerType(ThisPtrType,
true);
2376 Elts.push_back(ThisPtrType);
2380 for (
unsigned i = (SkipFirst ? 2 : 1), e = Args.size(); i < e; ++i)
2381 Elts.push_back(Args[i]);
2384 if (HasExplicitObjectParameter) {
2385 assert(Elts.size() >= 2 && Args.size() >= 2 &&
2386 "Expected at least return type and object parameter.");
2387 Elts[1] = DBuilder.createObjectPointerType(Args[1],
false);
2390 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2392 return DBuilder.createSubroutineType(
2393 EltTypeArray, OriginalFunc->getFlags(),
2400 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->
getDeclContext()))
2408CGDebugInfo::GetMethodLinkageName(
const CXXMethodDecl *
Method)
const {
2411 const bool IsCtorOrDtor =
2414 if (IsCtorOrDtor && !CGM.getCodeGenOpts().DebugStructorDeclLinkageNames)
2421 if (IsCtorOrDtor && !CGM.getTarget().getCXXABI().hasConstructorVariants())
2424 if (
const auto *Ctor = llvm::dyn_cast<CXXConstructorDecl>(
Method))
2427 if (
const auto *Dtor = llvm::dyn_cast<CXXDestructorDecl>(
Method))
2430 return CGM.getMangledName(
Method);
2433bool CGDebugInfo::shouldGenerateVirtualCallSite()
const {
2436 (CGM.getCodeGenOpts().DwarfVersion >= 5));
2439llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
2440 const CXXMethodDecl *
Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
2443 StringRef MethodName = getFunctionName(
Method);
2444 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(
Method, Unit);
2446 StringRef MethodLinkageName;
2453 MethodLinkageName = GetMethodLinkageName(
Method);
2456 llvm::DIFile *MethodDefUnit =
nullptr;
2457 unsigned MethodLine = 0;
2458 if (!
Method->isImplicit()) {
2459 MethodDefUnit = getOrCreateFile(
Method->getLocation());
2460 MethodLine = getLineNumber(
Method->getLocation());
2464 llvm::DIType *ContainingType =
nullptr;
2465 unsigned VIndex = 0;
2466 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
2467 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
2468 int ThisAdjustment = 0;
2471 if (
Method->isPureVirtual())
2472 SPFlags |= llvm::DISubprogram::SPFlagPureVirtual;
2474 SPFlags |= llvm::DISubprogram::SPFlagVirtual;
2476 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2480 VIndex = CGM.getItaniumVTableContext().getMethodVTableIndex(
Method);
2484 const auto *DD = dyn_cast<CXXDestructorDecl>(
Method);
2487 DD, CGM.getContext().getTargetInfo().emitVectorDeletingDtors(
2488 CGM.getContext().getLangOpts())
2492 MethodVFTableLocation ML =
2493 CGM.getMicrosoftVTableContext().getMethodVFTableLocation(GD);
2501 if (
Method->size_overridden_methods() == 0)
2502 Flags |= llvm::DINode::FlagIntroducedVirtual;
2507 ThisAdjustment = CGM.getCXXABI()
2508 .getVirtualFunctionPrologueThisAdjustment(GD)
2511 ContainingType = RecordTy;
2514 if (
Method->getCanonicalDecl()->isDeleted())
2515 SPFlags |= llvm::DISubprogram::SPFlagDeleted;
2517 if (
Method->isNoReturn())
2518 Flags |= llvm::DINode::FlagNoReturn;
2521 Flags |= llvm::DINode::FlagStaticMember;
2522 if (
Method->isImplicit())
2523 Flags |= llvm::DINode::FlagArtificial;
2525 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(
Method)) {
2526 if (CXXC->isExplicit())
2527 Flags |= llvm::DINode::FlagExplicit;
2528 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(
Method)) {
2529 if (CXXC->isExplicit())
2530 Flags |= llvm::DINode::FlagExplicit;
2532 if (
Method->hasPrototype())
2533 Flags |= llvm::DINode::FlagPrototyped;
2535 Flags |= llvm::DINode::FlagLValueReference;
2537 Flags |= llvm::DINode::FlagRValueReference;
2538 if (!
Method->isExternallyVisible())
2539 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
2540 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
2541 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
2546 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor) {
2547 if (
const auto *CD = dyn_cast<CXXConstructorDecl>(
Method)) {
2548 if (
const auto *Def =
2549 dyn_cast_or_null<CXXConstructorDecl>(CD->getDefinition());
2550 Def && !Def->isDelegatingConstructor()) {
2556 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(
Method, Unit);
2557 llvm::DISubprogram *SP = DBuilder.createMethod(
2558 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
2559 MethodTy, VIndex, ThisAdjustment, ContainingType, Flags, SPFlags,
2560 TParamsArray.get(),
nullptr,
2561 CGM.getCodeGenOpts().DebugKeyInstructions);
2563 SPCache[
Method->getCanonicalDecl()].reset(SP);
2568void CGDebugInfo::CollectCXXMemberFunctions(
2569 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2570 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy) {
2575 for (
const auto *I : RD->
decls()) {
2576 const auto *
Method = dyn_cast<CXXMethodDecl>(I);
2590 if (
Method->getType()->castAs<FunctionProtoType>()->getContainedAutoType())
2599 auto MI = SPCache.find(
Method->getCanonicalDecl());
2600 EltTys.push_back(MI == SPCache.end()
2601 ? CreateCXXMemberFunction(
Method, Unit, RecordTy)
2602 :
static_cast<llvm::Metadata *
>(MI->second));
2606void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
2607 SmallVectorImpl<llvm::Metadata *> &EltTys,
2608 llvm::DIType *RecordTy) {
2609 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> SeenTypes;
2610 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
bases(), SeenTypes,
2611 llvm::DINode::FlagZero);
2615 if (CGM.getCodeGenOpts().EmitCodeView) {
2616 CollectCXXBasesAux(RD, Unit, EltTys, RecordTy, RD->
vbases(), SeenTypes,
2617 llvm::DINode::FlagIndirectVirtualBase);
2621void CGDebugInfo::CollectCXXBasesAux(
2622 const CXXRecordDecl *RD, llvm::DIFile *Unit,
2623 SmallVectorImpl<llvm::Metadata *> &EltTys, llvm::DIType *RecordTy,
2625 llvm::DenseSet<CanonicalDeclPtr<const CXXRecordDecl>> &SeenTypes,
2626 llvm::DINode::DIFlags StartingFlags) {
2627 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
2628 for (
const auto &BI : Bases) {
2631 BI.getType()->castAsCanonical<RecordType>()->getDecl())
2633 if (!SeenTypes.insert(Base).second)
2635 auto *BaseTy = getOrCreateType(BI.getType(), Unit);
2636 llvm::DINode::DIFlags BFlags = StartingFlags;
2640 if (BI.isVirtual()) {
2641 if (CGM.getTarget().getCXXABI().isItaniumFamily()) {
2644 BaseOffset = 0 - CGM.getItaniumVTableContext()
2645 .getVirtualBaseOffsetOffset(RD, Base)
2651 4 * CGM.getMicrosoftVTableContext().getVBTableIndex(RD, Base);
2652 VBPtrOffset = CGM.getContext()
2653 .getASTRecordLayout(RD)
2657 BFlags |= llvm::DINode::FlagVirtual;
2664 llvm::DIType *DTy = DBuilder.createInheritance(RecordTy, BaseTy, BaseOffset,
2665 VBPtrOffset, BFlags);
2666 EltTys.push_back(DTy);
2671CGDebugInfo::CollectTemplateParams(std::optional<TemplateArgs> OArgs,
2672 llvm::DIFile *Unit) {
2674 return llvm::DINodeArray();
2675 TemplateArgs &Args = *OArgs;
2676 SmallVector<llvm::Metadata *, 16> TemplateParams;
2677 for (
unsigned i = 0, e = Args.Args.size(); i != e; ++i) {
2678 const TemplateArgument &TA = Args.Args[i];
2682 Name = Args.TList->getParam(i)->getName();
2686 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
2687 TemplateParams.push_back(DBuilder.createTemplateTypeParameter(
2688 TheCU, Name, TTy, defaultParameter));
2693 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2694 TheCU, Name, TTy, defaultParameter,
2695 llvm::ConstantInt::get(CGM.getLLVMContext(), TA.
getAsIntegral())));
2700 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2701 llvm::Constant *
V =
nullptr;
2704 if (!CGM.getLangOpts().CUDA || CGM.getLangOpts().CUDAIsDevice ||
2705 !D->
hasAttr<CUDADeviceAttr>()) {
2708 if (
const auto *VD = dyn_cast<VarDecl>(D))
2709 V = CGM.GetAddrOfGlobalVar(VD);
2712 else if (
const auto *MD = dyn_cast<CXXMethodDecl>(D);
2713 MD && MD->isImplicitObjectMemberFunction())
2714 V = CGM.getCXXABI().EmitMemberFunctionPointer(MD);
2715 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2716 V = CGM.GetAddrOfFunction(FD);
2719 else if (
const auto *MPT =
2720 dyn_cast<MemberPointerType>(
T.getTypePtr())) {
2724 uint64_t fieldOffset = CGM.getContext().getFieldOffset(D);
2726 CGM.getContext().toCharUnitsFromBits((int64_t)fieldOffset);
2727 V = CGM.getCXXABI().EmitMemberDataPointer(MPT, chars);
2728 }
else if (
const auto *GD = dyn_cast<MSGuidDecl>(D)) {
2729 V = CGM.GetAddrOfMSGuidDecl(GD).getPointer();
2730 }
else if (
const auto *TPO = dyn_cast<TemplateParamObjectDecl>(D)) {
2732 V = ConstantEmitter(CGM).emitAbstract(
2733 SourceLocation(), TPO->getValue(), TPO->getType());
2735 V = CGM.GetAddrOfTemplateParamObject(TPO).getPointer();
2737 assert(
V &&
"Failed to find template parameter pointer");
2738 V =
V->stripPointerCasts();
2740 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2741 TheCU, Name, TTy, defaultParameter, cast_or_null<llvm::Constant>(
V)));
2745 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2746 llvm::Constant *
V =
nullptr;
2749 if (
const auto *MPT = dyn_cast<MemberPointerType>(
T.getTypePtr()))
2755 if (MPT->isMemberDataPointer())
2756 V = CGM.getCXXABI().EmitNullMemberPointer(MPT);
2758 V = llvm::ConstantInt::get(CGM.Int8Ty, 0);
2759 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2760 TheCU, Name, TTy, defaultParameter,
V));
2764 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2765 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(
2767 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2768 TheCU, Name, TTy, defaultParameter,
V));
2771 std::string QualName;
2772 llvm::raw_string_ostream
OS(QualName);
2774 OS, getPrintingPolicy());
2775 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
2776 TheCU, Name,
nullptr, QualName, defaultParameter));
2780 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
2781 TheCU, Name,
nullptr,
2788 T = CGM.getContext().getLValueReferenceType(
T);
2789 llvm::Constant *
V = ConstantEmitter(CGM).emitAbstract(E,
T);
2790 assert(
V &&
"Expression in template argument isn't constant");
2791 llvm::DIType *TTy = getOrCreateType(
T, Unit);
2792 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
2793 TheCU, Name, TTy, defaultParameter,
V->stripPointerCasts()));
2799 "These argument types shouldn't exist in concrete types");
2802 return DBuilder.getOrCreateArray(TemplateParams);
2805std::optional<CGDebugInfo::TemplateArgs>
2806CGDebugInfo::GetTemplateArgs(
const FunctionDecl *FD)
const {
2814 return std::nullopt;
2816std::optional<CGDebugInfo::TemplateArgs>
2817CGDebugInfo::GetTemplateArgs(
const VarDecl *VD)
const {
2821 auto *TS = dyn_cast<VarTemplateSpecializationDecl>(VD);
2823 return std::nullopt;
2824 VarTemplateDecl *
T = TS->getSpecializedTemplate();
2825 const TemplateParameterList *TList =
T->getTemplateParameters();
2826 auto TA = TS->getTemplateArgs().asArray();
2827 return {{TList, TA}};
2829std::optional<CGDebugInfo::TemplateArgs>
2830CGDebugInfo::GetTemplateArgs(
const RecordDecl *RD)
const {
2831 if (
auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD)) {
2835 TemplateParameterList *TPList =
2836 TSpecial->getSpecializedTemplate()->getTemplateParameters();
2837 const TemplateArgumentList &TAList = TSpecial->getTemplateArgs();
2838 return {{TPList, TAList.
asArray()}};
2840 return std::nullopt;
2844CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
2845 llvm::DIFile *Unit) {
2846 return CollectTemplateParams(GetTemplateArgs(FD), Unit);
2849llvm::DINodeArray CGDebugInfo::CollectVarTemplateParams(
const VarDecl *VL,
2850 llvm::DIFile *Unit) {
2851 return CollectTemplateParams(GetTemplateArgs(VL), Unit);
2854llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
const RecordDecl *RD,
2855 llvm::DIFile *Unit) {
2856 return CollectTemplateParams(GetTemplateArgs(RD), Unit);
2859void CGDebugInfo::CollectBTFDeclTagAnnotations(
2860 const Decl *D, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2862 llvm::Metadata *Ops[2] = {
2863 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_decl_tag")),
2864 llvm::MDString::get(CGM.getLLVMContext(), I->getBTFDeclTag())};
2865 Annotations.push_back(llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2869llvm::DINodeArray CGDebugInfo::CollectBTFDeclTagAnnotations(
const Decl *D) {
2870 if (!D->
hasAttr<BTFDeclTagAttr>())
2873 SmallVector<llvm::Metadata *, 4> Annotations;
2874 CollectBTFDeclTagAnnotations(D, Annotations);
2875 return DBuilder.getOrCreateArray(Annotations);
2878void CGDebugInfo::CollectBTFTypeTagAnnotations(
2879 QualType Ty, SmallVectorImpl<llvm::Metadata *> &Annotations) {
2880 const BTFTagAttributedType *BTFAttrTy;
2882 BTFAttrTy = dyn_cast<BTFTagAttributedType>(
Atomic->getValueType());
2884 BTFAttrTy = dyn_cast<BTFTagAttributedType>(Ty);
2887 StringRef
Tag = BTFAttrTy->getAttr()->getBTFTypeTag();
2889 llvm::Metadata *Ops[2] = {
2890 llvm::MDString::get(CGM.getLLVMContext(), StringRef(
"btf_type_tag")),
2891 llvm::MDString::get(CGM.getLLVMContext(), Tag)};
2892 Annotations.insert(Annotations.begin(),
2893 llvm::MDNode::get(CGM.getLLVMContext(), Ops));
2895 BTFAttrTy = dyn_cast<BTFTagAttributedType>(BTFAttrTy->getWrappedType());
2899llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
2901 return VTablePtrType;
2903 ASTContext &Context = CGM.getContext();
2906 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
2907 llvm::DITypeArray SElements = DBuilder.getOrCreateTypeArray(STy);
2908 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
2910 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
2911 std::optional<unsigned> DWARFAddressSpace =
2912 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
2914 llvm::DIType *vtbl_ptr_type = DBuilder.createPointerType(
2915 SubTy, Size, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
2916 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
2917 return VTablePtrType;
2920StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
2932 if (!CGM.getTarget().getCXXABI().isItaniumFamily())
2934 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
2944 if (CGM.getTarget().getTriple().isOSBinFormatCOFF() &&
2945 VTable->isDeclarationForLinker())
2949 StringRef SymbolName =
"__clang_vtable";
2951 QualType VoidPtr = Context.getPointerType(Context.VoidTy);
2960 llvm::DIScope *DContext = getContextDescriptor(RD, TheCU);
2962 llvm::DIFile *Unit = getOrCreateFile(Loc);
2963 llvm::DIType *VTy = getOrCreateType(VoidPtr, Unit);
2965 llvm::DINode::FlagArtificial;
2966 auto Tag = CGM.getCodeGenOpts().DwarfVersion >= 5
2967 ? llvm::dwarf::DW_TAG_variable
2968 : llvm::dwarf::DW_TAG_member;
2969 llvm::DIDerivedType *DT = DBuilder.createStaticMemberType(
2970 Ctxt, SymbolName, Unit, 0, VTy, Flags,
2974 unsigned PAlign = CGM.getVtableGlobalVarAlignment();
2978 llvm::DIGlobalVariableExpression *GVE =
2979 DBuilder.createGlobalVariableExpression(
2980 TheCU, SymbolName, VTable->getName(), Unit, 0,
2981 getOrCreateType(VoidPtr, Unit), VTable->hasLocalLinkage(),
2982 true,
nullptr, DT,
nullptr,
2984 VTable->addDebugInfo(GVE);
2987StringRef CGDebugInfo::getDynamicInitializerName(
const VarDecl *VD,
2989 llvm::Function *InitFn) {
2994 return InitFn->getName();
3004 llvm::raw_svector_ostream OS(QualifiedGV);
3006 std::tie(Quals, GVName) = OS.str().rsplit(
"::");
3008 std::swap(Quals, GVName);
3012 llvm::raw_svector_ostream OS(InitName);
3014 OS << Quals <<
"::";
3019 llvm_unreachable(
"not an initializer");
3021 OS <<
"`dynamic initializer for '";
3024 OS <<
"`dynamic atexit destructor for '";
3031 if (
const auto *VTpl = dyn_cast<VarTemplateSpecializationDecl>(VD)) {
3032 printTemplateArgumentList(OS, VTpl->getTemplateArgs().asArray(),
3033 getPrintingPolicy());
3038 return internString(
OS.str());
3041void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
3042 SmallVectorImpl<llvm::Metadata *> &EltTys) {
3051 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
3058 llvm::DIType *VPtrTy =
nullptr;
3059 bool NeedVTableShape = CGM.getCodeGenOpts().EmitCodeView &&
3060 CGM.getTarget().getCXXABI().isMicrosoft();
3061 if (NeedVTableShape) {
3063 CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3064 const VTableLayout &VFTLayout =
3065 CGM.getMicrosoftVTableContext().getVFTableLayout(RD,
CharUnits::Zero());
3066 unsigned VSlotCount =
3068 unsigned VTableWidth = PtrWidth * VSlotCount;
3069 unsigned VtblPtrAddressSpace = CGM.getTarget().getVtblPtrAddressSpace();
3070 std::optional<unsigned> DWARFAddressSpace =
3071 CGM.getTarget().getDWARFAddressSpace(VtblPtrAddressSpace);
3074 llvm::DIType *VTableType = DBuilder.createPointerType(
3075 nullptr, VTableWidth, 0, DWARFAddressSpace,
"__vtbl_ptr_type");
3076 EltTys.push_back(VTableType);
3079 VPtrTy = DBuilder.createPointerType(VTableType, PtrWidth);
3087 VPtrTy = getOrCreateVTablePtrType(Unit);
3089 unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
3090 llvm::DIType *VPtrMember =
3091 DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
3092 llvm::DINode::FlagArtificial, VPtrTy);
3093 EltTys.push_back(VPtrMember);
3098 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3099 llvm::DIType *
T = getOrCreateType(RTy, getOrCreateFile(Loc));
3110 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
3111 assert(!D.
isNull() &&
"null type");
3112 llvm::DIType *
T = getOrCreateType(D, getOrCreateFile(Loc));
3113 assert(
T &&
"could not create debug info for type");
3122 if (CGM.getCodeGenOpts().getDebugInfo() <=
3123 llvm::codegenoptions::DebugLineTablesOnly)
3127 node = llvm::MDNode::get(CGM.getLLVMContext(), {});
3129 node = getOrCreateType(AllocatedTy, getOrCreateFile(Loc));
3131 CI->setMetadata(
"heapallocsite", node);
3135 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3137 CanQualType Ty = CGM.getContext().getCanonicalTagType(ED);
3139 auto I = TypeCache.find(TyPtr);
3142 llvm::DIType *Res = CreateTypeDefinition(dyn_cast<EnumType>(Ty));
3143 assert(!Res->isForwardDecl());
3144 TypeCache[TyPtr].reset(Res);
3148 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3149 !CGM.getLangOpts().CPlusPlus)
3155 if (RD->
hasAttr<DLLImportAttr>())
3158 if (MD->hasAttr<DLLImportAttr>())
3171 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
3181 if (
auto *TD = dyn_cast<ClassTemplateSpecializationDecl>(CXXDecl))
3182 Explicit = TD->isExplicitInstantiationOrSpecialization();
3186 if (CXXDecl->
fields().empty())
3196 if (
auto *CXXRD = dyn_cast<CXXRecordDecl>(RD))
3197 if (CXXRD->isDynamicClass() &&
3198 CGM.getVTableLinkage(CXXRD) ==
3199 llvm::GlobalValue::AvailableExternallyLinkage &&
3210 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
3212 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3214 auto I = TypeCache.find(TyPtr);
3221 auto [Res, PrefRes] = CreateTypeDefinition(dyn_cast<RecordType>(Ty));
3222 assert(!Res->isForwardDecl());
3223 TypeCache[TyPtr].reset(Res);
3230 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
3231 !MD->getMemberSpecializationInfo()->isExplicitSpecialization())
3258 bool HasNonDeletedCtor =
false;
3260 if (Ctor->isCopyOrMoveConstructor())
3267 if (CtorDef->isDelegatingConstructor())
3271 if (Ctor->isConstexpr() && !Ctor->isDeleted())
3274 if (!Ctor->isDeleted())
3275 HasNonDeletedCtor =
true;
3277 return HasNonDeletedCtor;
3293 if (DebugKind == llvm::codegenoptions::DebugLineTablesOnly)
3296 if (DebugKind > llvm::codegenoptions::LimitedDebugInfo ||
3297 RD->
hasAttr<StandaloneDebugAttr>())
3300 if (!LangOpts.CPlusPlus)
3306 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3322 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
3323 Spec = SD->getSpecializationKind();
3332 if ((DebugKind == llvm::codegenoptions::DebugInfoConstructor) &&
3343 CanQualType Ty = CGM.getContext().getCanonicalTagType(RD);
3344 llvm::DIType *
T = getTypeOrNull(Ty);
3345 if (
T &&
T->isForwardDecl())
3349llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
3351 llvm::DIType *
T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
3355 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
3359 auto [Def, Pref] = CreateTypeDefinition(Ty);
3361 return Pref ? Pref : Def;
3364llvm::DIType *CGDebugInfo::GetPreferredNameType(
const CXXRecordDecl *RD,
3365 llvm::DIFile *Unit) {
3369 auto const *PNA = RD->
getAttr<PreferredNameAttr>();
3373 return getOrCreateType(PNA->getTypedefType(), Unit);
3400 const auto *RT = QT->
getAs<RecordType>();
3404 auto *CRD = dyn_cast<CXXRecordDecl>(RT->getDecl()->getDefinitionOrSelf());
3405 if (!CRD || !CRD->hasDefinition())
3410 assert(CRD->isStandardLayout());
3416std::pair<llvm::DIType *, llvm::DIType *>
3417CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
3421 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
3429 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty);
3433 return {FwdDecl,
nullptr};
3435 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
3436 CollectContainingType(CXXDecl, FwdDecl);
3439 LexicalBlockStack.emplace_back(&*FwdDecl);
3440 RegionMap[RD].reset(FwdDecl);
3443 SmallVector<llvm::Metadata *, 16> EltTys;
3450 const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD);
3452 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
3453 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
3457 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
3458 if (CXXDecl && !CGM.getCodeGenOpts().DebugOmitUnreferencedMethods)
3459 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
3461 LexicalBlockStack.pop_back();
3462 RegionMap.erase(RD);
3464 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3465 DBuilder.replaceArrays(FwdDecl, Elements);
3467 if (FwdDecl->isTemporary())
3469 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
3471 RegionMap[RD].reset(FwdDecl);
3473 if (DebugKind == llvm::codegenoptions::DebugInfoConstructor) {
3488 if (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB)
3489 if (
auto *PrefDI = GetPreferredNameType(CXXDecl, DefUnit))
3490 return {FwdDecl, PrefDI};
3492 return {FwdDecl,
nullptr};
3495llvm::DIType *CGDebugInfo::CreateType(
const ObjCObjectType *Ty,
3496 llvm::DIFile *Unit) {
3498 return getOrCreateType(Ty->getBaseType(), Unit);
3501llvm::DIType *CGDebugInfo::CreateType(
const ObjCTypeParamType *Ty,
3502 llvm::DIFile *Unit) {
3504 SourceLocation Loc = Ty->getDecl()->getLocation();
3507 return DBuilder.createTypedef(
3508 getOrCreateType(Ty->getDecl()->getUnderlyingType(), Unit),
3509 Ty->getDecl()->getName(), getOrCreateFile(Loc), getLineNumber(Loc),
3510 getDeclContextDescriptor(Ty->getDecl()));
3537llvm::DIType *CGDebugInfo::CreateType(
const ObjCInterfaceType *Ty,
3538 llvm::DIFile *Unit) {
3543 auto RuntimeLang =
static_cast<llvm::dwarf::SourceLanguage
>(
3544 TheCU->getSourceLanguage().getUnversionedName());
3549 if (DebugTypeExtRefs &&
ID->isFromASTFile() &&
ID->getDefinition() &&
3550 !
ID->getImplementation())
3551 return DBuilder.createForwardDecl(
3552 llvm::dwarf::DW_TAG_structure_type,
ID->getName(),
3553 getDeclContextDescriptor(ID), Unit, 0, RuntimeLang);
3556 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3557 unsigned Line = getLineNumber(
ID->getLocation());
3561 ObjCInterfaceDecl *Def =
ID->getDefinition();
3563 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3564 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
3565 llvm::dwarf::DW_TAG_structure_type,
ID->getName(), Mod ? Mod : TheCU,
3566 DefUnit,
Line, RuntimeLang);
3567 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
3571 return CreateTypeDefinition(Ty, Unit);
3574llvm::DIModule *CGDebugInfo::getOrCreateModuleRef(ASTSourceDescriptor Mod,
3575 bool CreateSkeletonCU) {
3580 auto ModRef = ModuleCache.find(M);
3581 if (ModRef != ModuleCache.end())
3585 SmallString<128> ConfigMacros;
3587 llvm::raw_svector_ostream
OS(ConfigMacros);
3588 const auto &PPOpts = CGM.getPreprocessorOpts();
3591 for (
auto &M : PPOpts.Macros) {
3594 const std::string &
Macro = M.first;
3595 bool Undef = M.second;
3596 OS <<
"\"-" << (Undef ?
'U' :
'D');
3597 for (
char c :
Macro)
3612 bool IsRootModule = M ? !M->
Parent :
true;
3616 if (CreateSkeletonCU && IsRootModule && Mod.
getASTFile().empty() && M)
3617 assert(StringRef(M->
Name).starts_with(CGM.getLangOpts().ModuleName) &&
3618 "clang module without ASTFile must be specified by -fmodule-name");
3621 auto RemapPath = [
this](StringRef Path) -> std::string {
3623 StringRef Relative(Remapped);
3624 StringRef CompDir = TheCU->getDirectory();
3625 if (CompDir.empty())
3628 if (Relative.consume_front(CompDir))
3629 Relative.consume_front(llvm::sys::path::get_separator());
3631 return Relative.str();
3634 if (CreateSkeletonCU && IsRootModule && !Mod.
getASTFile().empty()) {
3641 Signature = ModSig.truncatedValue();
3645 llvm::DIBuilder DIB(CGM.getModule());
3647 if (!llvm::sys::path::is_absolute(Mod.
getASTFile())) {
3648 if (CGM.getHeaderSearchOpts().ModuleFileHomeIsCwd)
3649 PCM = getCurrentDirname();
3653 llvm::sys::path::append(PCM, Mod.
getASTFile());
3654 DIB.createCompileUnit(
3655 TheCU->getSourceLanguage(),
3658 TheCU->getProducer(),
false, StringRef(), 0, RemapPath(PCM),
3659 llvm::DICompileUnit::FullDebug, Signature);
3663 llvm::DIModule *Parent =
3665 : getOrCreateModuleRef(ASTSourceDescriptor(*M->
Parent),
3667 StringRef IncludePath = Mod.
getPath();
3668 if (!CGM.getCodeGenOpts().DebugRecordSysroot) {
3669 StringRef Sysroot = CGM.getHeaderSearchOpts().Sysroot;
3670 if (!Sysroot.empty() && IncludePath.starts_with(Sysroot))
3673 llvm::DIModule *DIMod =
3674 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
3675 RemapPath(IncludePath));
3676 ModuleCache[M].reset(DIMod);
3680llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const ObjCInterfaceType *Ty,
3681 llvm::DIFile *Unit) {
3683 llvm::DIFile *DefUnit = getOrCreateFile(
ID->getLocation());
3684 unsigned Line = getLineNumber(
ID->getLocation());
3686 unsigned RuntimeLang = TheCU->getSourceLanguage().getUnversionedName();
3692 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3693 if (
ID->getImplementation())
3694 Flags |= llvm::DINode::FlagObjcClassComplete;
3696 llvm::DIScope *Mod = getParentModuleOrNull(ID);
3697 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
3698 Mod ? Mod : Unit,
ID->getName(), DefUnit,
Line, Size, Align, Flags,
3699 nullptr, llvm::DINodeArray(), RuntimeLang);
3701 QualType QTy(Ty, 0);
3702 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
3705 LexicalBlockStack.emplace_back(RealDecl);
3706 RegionMap[Ty->
getDecl()].reset(RealDecl);
3709 SmallVector<llvm::Metadata *, 16> EltTys;
3711 ObjCInterfaceDecl *SClass =
ID->getSuperClass();
3713 llvm::DIType *SClassTy =
3714 getOrCreateType(CGM.getContext().getObjCInterfaceType(SClass), Unit);
3718 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0,
3719 llvm::DINode::FlagZero);
3720 EltTys.push_back(InhTag);
3724 auto AddProperty = [&](
const ObjCPropertyDecl *PD) {
3725 SourceLocation Loc = PD->getLocation();
3726 llvm::DIFile *PUnit = getOrCreateFile(Loc);
3727 unsigned PLine = getLineNumber(Loc);
3728 ObjCMethodDecl *Getter = PD->getGetterMethodDecl();
3729 ObjCMethodDecl *Setter = PD->getSetterMethodDecl();
3730 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
3731 PD->getName(), PUnit, PLine,
3733 : getSelectorName(PD->getGetterName()),
3735 : getSelectorName(PD->getSetterName()),
3736 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
3737 EltTys.push_back(PropertyNode);
3742 typedef std::pair<char, const IdentifierInfo *> IsClassAndIdent;
3746 llvm::DenseSet<IsClassAndIdent> PropertySet;
3748 auto GetIsClassAndIdent = [](
const ObjCPropertyDecl *PD) {
3749 return std::make_pair(PD->isClassProperty(), PD->getIdentifier());
3751 for (
const ObjCCategoryDecl *ClassExt :
ID->known_extensions())
3752 for (
auto *PD : ClassExt->properties()) {
3753 PropertySet.insert(GetIsClassAndIdent(PD));
3756 for (
const auto *PD :
ID->properties()) {
3759 if (!PropertySet.insert(GetIsClassAndIdent(PD)).second)
3765 const ASTRecordLayout &RL = CGM.getContext().getASTObjCInterfaceLayout(ID);
3766 unsigned FieldNo = 0;
3767 for (ObjCIvarDecl *Field =
ID->all_declared_ivar_begin(); Field;
3768 Field =
Field->getNextIvar(), ++FieldNo) {
3769 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
3773 StringRef FieldName =
Field->getName();
3776 if (FieldName.empty())
3780 llvm::DIFile *FieldDefUnit = getOrCreateFile(
Field->getLocation());
3781 unsigned FieldLine = getLineNumber(
Field->getLocation());
3782 QualType FType =
Field->getType();
3789 FieldSize =
Field->isBitField() ?
Field->getBitWidthValue()
3790 : CGM.getContext().getTypeSize(FType);
3795 if (CGM.getLangOpts().ObjCRuntime.isNonFragile()) {
3799 if (
Field->isBitField()) {
3801 CGM.getObjCRuntime().ComputeBitfieldBitOffset(CGM, ID, Field);
3802 FieldOffset %= CGM.getContext().getCharWidth();
3810 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3812 Flags = llvm::DINode::FlagProtected;
3814 Flags = llvm::DINode::FlagPrivate;
3816 Flags = llvm::DINode::FlagPublic;
3818 if (
Field->isBitField())
3819 Flags |= llvm::DINode::FlagBitField;
3821 llvm::MDNode *PropertyNode =
nullptr;
3822 ObjCPropertyDecl *SynthesizedProperty =
nullptr;
3823 llvm::DIFile *PUnit =
nullptr;
3825 if (ObjCImplementationDecl *ImpD =
ID->getImplementation()) {
3826 if (ObjCPropertyImplDecl *PImpD =
3827 ImpD->FindPropertyImplIvarDecl(
Field->getIdentifier())) {
3828 if (ObjCPropertyDecl *PD = PImpD->getPropertyDecl()) {
3829 SynthesizedProperty = PD;
3830 SourceLocation Loc = PD->getLocation();
3831 PUnit = getOrCreateFile(Loc);
3832 PLine = getLineNumber(Loc);
3833 ObjCMethodDecl *Getter = PImpD->getGetterMethodDecl();
3834 ObjCMethodDecl *Setter = PImpD->getSetterMethodDecl();
3835 PropertyNode = DBuilder.createObjCProperty(
3836 PD->getName(), PUnit, PLine,
3839 : getSelectorName(PD->getGetterName()),
3842 : getSelectorName(PD->getSetterName()),
3843 PD->getPropertyAttributes(),
3844 getOrCreateType(PD->getType(), PUnit));
3848 auto *IvarTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
3849 FieldSize, FieldAlign, FieldOffset,
3850 Flags, FieldTy, PropertyNode);
3851 EltTys.push_back(IvarTy);
3853 if (SynthesizedProperty) {
3854 assert(PUnit &&
"SynthesizedProperty implies PUnit");
3855 EltTys.push_back(DBuilder.createProperty(
3856 SynthesizedProperty->
getName(), PUnit, PLine,
3857 getOrCreateType(SynthesizedProperty->
getType(), PUnit), IvarTy));
3861 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3862 DBuilder.replaceArrays(RealDecl, Elements);
3864 LexicalBlockStack.pop_back();
3868llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
3869 llvm::DIFile *Unit) {
3877 auto &Ctx = CGM.getContext();
3882 QualType CharVecTy =
3884 return CreateType(CharVecTy->
getAs<VectorType>(), Unit);
3887 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3890 llvm::Metadata *Subscript;
3891 QualType QTy(Ty, 0);
3892 auto SizeExpr = SizeExprCache.find(QTy);
3893 if (SizeExpr != SizeExprCache.end())
3894 Subscript = DBuilder.getOrCreateSubrange(
3895 SizeExpr->getSecond() ,
nullptr ,
3896 nullptr ,
nullptr );
3899 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3900 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count ? Count : -1));
3901 Subscript = DBuilder.getOrCreateSubrange(
3902 CountNode ,
nullptr ,
nullptr ,
3905 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
3910 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
3913llvm::DIType *CGDebugInfo::CreateType(
const ConstantMatrixType *Ty,
3914 llvm::DIFile *Unit) {
3918 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
3923 llvm::SmallVector<llvm::Metadata *, 2> Subscripts;
3924 auto *ColumnCountNode =
3925 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3926 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumColumns()));
3927 auto *RowCountNode =
3928 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3929 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Ty->
getNumRows()));
3930 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3931 ColumnCountNode ,
nullptr ,
nullptr ,
3933 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3934 RowCountNode ,
nullptr ,
nullptr ,
3936 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
3937 return DBuilder.createArrayType(Size, Align, ElementTy, SubscriptArray);
3940llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
3945 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3960 Size = CGM.getContext().getTypeSize(Ty);
3967 SmallVector<llvm::Metadata *, 8> Subscripts;
3968 QualType EltTy(Ty, 0);
3969 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
3978 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
3979 Count = CAT->getZExtSize();
3980 else if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
3981 if (Expr *Size = VAT->getSizeExpr()) {
3983 if (
Size->EvaluateAsInt(
Result, CGM.getContext()))
3984 Count =
Result.Val.getInt().getExtValue();
3988 auto SizeNode = SizeExprCache.find(EltTy);
3989 if (SizeNode != SizeExprCache.end())
3990 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3991 SizeNode->getSecond() ,
nullptr ,
3992 nullptr ,
nullptr ));
3995 llvm::ConstantAsMetadata::get(llvm::ConstantInt::getSigned(
3996 llvm::Type::getInt64Ty(CGM.getLLVMContext()), Count));
3997 Subscripts.push_back(DBuilder.getOrCreateSubrange(
3998 CountNode ,
nullptr ,
nullptr ,
4004 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
4006 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
4010llvm::DIType *CGDebugInfo::CreateType(
const LValueReferenceType *Ty,
4011 llvm::DIFile *Unit) {
4012 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
4016llvm::DIType *CGDebugInfo::CreateType(
const RValueReferenceType *Ty,
4017 llvm::DIFile *Unit) {
4018 llvm::dwarf::Tag
Tag = llvm::dwarf::DW_TAG_rvalue_reference_type;
4020 if (CGM.getCodeGenOpts().DebugStrictDwarf &&
4021 CGM.getCodeGenOpts().DwarfVersion < 4)
4022 Tag = llvm::dwarf::DW_TAG_reference_type;
4024 return CreatePointerLikeType(Tag, Ty, Ty->
getPointeeType(), Unit);
4027llvm::DIType *CGDebugInfo::CreateType(
const MemberPointerType *Ty,
4029 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4033 Size = CGM.getContext().getTypeSize(Ty);
4036 if (CGM.getTarget().getCXXABI().isMicrosoft()) {
4039 Flags |= llvm::DINode::FlagSingleInheritance;
4042 Flags |= llvm::DINode::FlagMultipleInheritance;
4045 Flags |= llvm::DINode::FlagVirtualInheritance;
4055 llvm::DIType *ClassType = getOrCreateType(
T, U);
4057 return DBuilder.createMemberPointerType(
4061 const FunctionProtoType *FPT =
4063 return DBuilder.createMemberPointerType(
4064 getOrCreateInstanceMethodType(
4067 ClassType, Size, 0, Flags);
4070llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
4072 return DBuilder.createQualifiedType(llvm::dwarf::DW_TAG_atomic_type, FromTy);
4075llvm::DIType *CGDebugInfo::CreateType(
const PipeType *Ty, llvm::DIFile *U) {
4079llvm::DIType *CGDebugInfo::CreateType(
const HLSLAttributedResourceType *Ty,
4081 return getOrCreateType(Ty->getWrappedType(), U);
4084llvm::DIType *CGDebugInfo::CreateType(
const HLSLInlineSpirvType *Ty,
4091 const EnumType *Ty) {
4103llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
4106 bool isImportedFromModule =
4107 DebugTypeExtRefs && ED->isFromASTFile() && ED->getDefinition();
4111 if (isImportedFromModule || !ED->getDefinition()) {
4118 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
4119 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4120 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
4121 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
4123 unsigned Line = getLineNumber(ED->getLocation());
4124 StringRef EDName = ED->getName();
4125 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
4126 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit,
Line,
4127 0, Size, Align, llvm::DINode::FlagFwdDecl, Identifier);
4129 ReplaceMap.emplace_back(
4130 std::piecewise_construct, std::make_tuple(Ty),
4131 std::make_tuple(
static_cast<llvm::Metadata *
>(RetTy)));
4135 return CreateTypeDefinition(Ty);
4138llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
4141 SmallVector<llvm::Metadata *, 16> Enumerators;
4142 ED = ED->getDefinition();
4143 assert(ED &&
"An enumeration definition is required");
4144 for (
const auto *
Enum : ED->enumerators()) {
4145 Enumerators.push_back(
4146 DBuilder.createEnumerator(
Enum->getName(),
Enum->getInitVal()));
4149 std::optional<EnumExtensibilityAttr::Kind> EnumKind;
4150 if (
auto *Attr = ED->getAttr<EnumExtensibilityAttr>())
4151 EnumKind = Attr->getExtensibility();
4154 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
4156 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
4157 unsigned Line = getLineNumber(ED->getLocation());
4158 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
4159 llvm::DIType *ClassTy = getOrCreateType(ED->getIntegerType(), DefUnit);
4160 return DBuilder.createEnumerationType(
4161 EnumContext, ED->getName(), DefUnit,
Line, Size, Align, EltArray, ClassTy,
4162 0, Identifier, ED->isScoped(), EnumKind);
4167 StringRef Name, StringRef
Value) {
4168 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4169 return DBuilder.createMacro(Parent,
Line, MType, Name,
Value);
4175 llvm::DIFile *FName = getOrCreateFile(FileLoc);
4176 unsigned Line = LineLoc.
isInvalid() ? 0 : getLineNumber(LineLoc);
4177 return DBuilder.createTempMacroFile(Parent,
Line, FName);
4182 llvm::DISubprogram *SynthSubprogram) {
4183 return llvm::DILocation::get(CGM.getLLVMContext(), 0, 0,
4184 SynthSubprogram, ParentLocation);
4189 StringRef SynthFuncName,
4190 llvm::DIFile *SynthFile) {
4191 llvm::DISubprogram *SP = createInlinedSubprogram(SynthFuncName, SynthFile);
4196 llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) {
4202 FuncName += Category;
4204 FuncName += FailureMsg;
4207 TrapLocation->getFile());
4217 Quals += InnerQuals;
4219 switch (
T->getTypeClass()) {
4221 return C.getQualifiedType(
T.getTypePtr(), Quals);
4224 case Type::InjectedClassName:
4225 return C.getQualifiedType(
T->getCanonicalTypeUnqualified().getTypePtr(),
4227 case Type::TemplateSpecialization: {
4229 if (Spec->isTypeAlias())
4230 return C.getQualifiedType(
T.getTypePtr(), Quals);
4231 T = Spec->desugar();
4234 case Type::TypeOfExpr:
4240 case Type::Decltype:
4243 case Type::UnaryTransform:
4246 case Type::Attributed:
4249 case Type::BTFTagAttributed:
4252 case Type::CountAttributed:
4261 case Type::MacroQualified:
4264 case Type::SubstTemplateTypeParm:
4268 case Type::DeducedTemplateSpecialization: {
4270 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
4274 case Type::PackIndexing: {
4278 case Type::Adjusted:
4285 assert(
T != LastT &&
"Type unwrapping failed to unwrap!");
4290llvm::DIType *CGDebugInfo::getTypeOrNull(QualType Ty) {
4293 if (It != TypeCache.end()) {
4295 if (llvm::Metadata *
V = It->second)
4308 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly ||
4315 RetainedTypes.push_back(
4316 CGM.getContext().getCanonicalTagType(&D).getAsOpaquePtr());
4319llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
4323 llvm::TimeTraceScope TimeScope(
"DebugType", [&]() {
4325 llvm::raw_string_ostream OS(Name);
4326 Ty.
print(OS, getPrintingPolicy());
4333 if (
auto *
T = getTypeOrNull(Ty))
4336 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
4337 void *TyPtr = Ty.getAsOpaquePtr();
4340 TypeCache[TyPtr].reset(Res);
4345llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
4353 auto Info = Reader->getSourceDescriptor(Idx);
4355 return getOrCreateModuleRef(*Info,
true);
4356 }
else if (ClangModuleMap) {
4369 auto Info = ASTSourceDescriptor(*M);
4370 return getOrCreateModuleRef(Info,
false);
4373 return getOrCreateModuleRef(PCHDescriptor,
false);
4380llvm::DIType *CGDebugInfo::CreateTypeNode(QualType Ty, llvm::DIFile *Unit) {
4383 return CreateQualifiedType(Ty, Unit);
4387#define TYPE(Class, Base)
4388#define ABSTRACT_TYPE(Class, Base)
4389#define NON_CANONICAL_TYPE(Class, Base)
4390#define DEPENDENT_TYPE(Class, Base) case Type::Class:
4391#include "clang/AST/TypeNodes.inc"
4392 llvm_unreachable(
"Dependent types cannot show up in debug information");
4394 case Type::ExtVector:
4397 case Type::ConstantMatrix:
4399 case Type::ObjCObjectPointer:
4401 case Type::ObjCObject:
4403 case Type::ObjCTypeParam:
4405 case Type::ObjCInterface:
4413 case Type::BlockPointer:
4421 case Type::FunctionProto:
4422 case Type::FunctionNoProto:
4424 case Type::ConstantArray:
4425 case Type::VariableArray:
4426 case Type::IncompleteArray:
4427 case Type::ArrayParameter:
4430 case Type::LValueReference:
4432 case Type::RValueReference:
4435 case Type::MemberPointer:
4443 case Type::OverflowBehavior:
4448 case Type::TemplateSpecialization:
4450 case Type::HLSLAttributedResource:
4452 case Type::HLSLInlineSpirv:
4454 case Type::PredefinedSugar:
4456 case Type::CountAttributed:
4457 case Type::LateParsedAttr:
4459 case Type::Attributed:
4460 case Type::BTFTagAttributed:
4461 case Type::Adjusted:
4463 case Type::DeducedTemplateSpecialization:
4466 case Type::MacroQualified:
4467 case Type::SubstTemplateTypeParm:
4468 case Type::TypeOfExpr:
4470 case Type::Decltype:
4471 case Type::PackIndexing:
4472 case Type::UnaryTransform:
4476 llvm_unreachable(
"type should have been unwrapped!");
4479llvm::DICompositeType *
4480CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty) {
4481 QualType QTy(Ty, 0);
4483 auto *
T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
4488 if (
T && !
T->isForwardDecl())
4492 llvm::DICompositeType *Res = CreateLimitedType(Ty);
4497 DBuilder.replaceArrays(Res,
T ?
T->getElements() : llvm::DINodeArray());
4500 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
4505llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
4507 bool NameIsSimplified =
false;
4510 StringRef RDName = getClassName(RD, &NameIsSimplified);
4512 llvm::DIFile *DefUnit =
nullptr;
4515 DefUnit = getOrCreateFile(Loc);
4516 Line = getLineNumber(Loc);
4519 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
4523 auto *
T = cast_or_null<llvm::DICompositeType>(
4524 getTypeOrNull(CGM.getContext().getCanonicalTagType(RD)));
4532 return getOrCreateRecordFwdDecl(Ty, RDContext);
4545 auto Flags = llvm::DINode::FlagZero;
4546 if (NameIsSimplified)
4547 Flags |= llvm::DINode::FlagNameIsSimplified;
4548 if (
auto CXXRD = dyn_cast<CXXRecordDecl>(RD)) {
4550 Flags |= llvm::DINode::FlagTypePassByReference;
4552 Flags |= llvm::DINode::FlagTypePassByValue;
4555 if (!CXXRD->isTrivial())
4556 Flags |= llvm::DINode::FlagNonTrivial;
4559 if (CXXRD->isAnonymousStructOrUnion())
4560 Flags |= llvm::DINode::FlagExportSymbols;
4563 dyn_cast<CXXRecordDecl>(CXXRD->getDeclContext()));
4566 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
4567 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
4569 Flags, Identifier, Annotations);
4573 switch (RealDecl->getTag()) {
4575 llvm_unreachable(
"invalid composite type tag");
4577 case llvm::dwarf::DW_TAG_array_type:
4578 case llvm::dwarf::DW_TAG_enumeration_type:
4583 if (Identifier.empty())
4587 case llvm::dwarf::DW_TAG_structure_type:
4588 case llvm::dwarf::DW_TAG_union_type:
4589 case llvm::dwarf::DW_TAG_class_type:
4592 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
4596 if (
auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Ty->getDecl())) {
4597 CXXRecordDecl *TemplateDecl =
4598 CTSD->getSpecializedTemplate()->getTemplatedDecl();
4599 RegionMap[TemplateDecl].reset(RealDecl);
4601 RegionMap[RD].reset(RealDecl);
4603 TypeCache[QualType(Ty, 0).getAsOpaquePtr()].reset(RealDecl);
4605 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
4606 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
4607 CollectCXXTemplateParams(TSpecial, DefUnit));
4611void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
4612 llvm::DICompositeType *RealDecl) {
4614 llvm::DIType *ContainingType =
nullptr;
4615 const ASTRecordLayout &RL = CGM.getContext().getASTRecordLayout(RD);
4619 const ASTRecordLayout &BRL = CGM.getContext().getASTRecordLayout(PBase);
4626 CanQualType T = CGM.getContext().getCanonicalTagType(PBase);
4627 ContainingType = getOrCreateType(
T, getOrCreateFile(RD->
getLocation()));
4629 ContainingType = RealDecl;
4631 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
4634llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit, QualType FType,
4635 StringRef Name, uint64_t *Offset) {
4636 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
4637 uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
4640 DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign,
4641 *Offset, llvm::DINode::FlagZero, FieldTy);
4642 *Offset += FieldSize;
4646void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
4648 StringRef &LinkageName,
4649 llvm::DIScope *&FDContext,
4650 llvm::DINodeArray &TParamsArray,
4651 llvm::DINode::DIFlags &Flags) {
4653 bool NameIsSimplified =
false;
4654 Name = getFunctionName(FD, &NameIsSimplified);
4655 if (NameIsSimplified)
4656 Flags |= llvm::DINode::FlagNameIsSimplified;
4657 Name = getFunctionName(FD);
4660 LinkageName = CGM.getMangledName(GD);
4662 Flags |= llvm::DINode::FlagPrototyped;
4666 if (LinkageName == Name ||
4667 (CGM.getCodeGenOpts().CoverageNotesFile.empty() &&
4668 CGM.getCodeGenOpts().CoverageDataFile.empty() &&
4669 !CGM.getCodeGenOpts().DebugInfoForProfiling &&
4670 !CGM.getCodeGenOpts().PseudoProbeForProfiling &&
4671 DebugKind <= llvm::codegenoptions::DebugLineTablesOnly))
4672 LinkageName = StringRef();
4676 if (CGM.getCodeGenOpts().hasReducedDebugInfo() ||
4677 (DebugKind == llvm::codegenoptions::DebugLineTablesOnly &&
4678 CGM.getCodeGenOpts().EmitCodeView)) {
4679 if (
const NamespaceDecl *NSDecl =
4681 FDContext = getOrCreateNamespace(NSDecl);
4682 else if (
const RecordDecl *RDecl =
4684 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
4685 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
4688 if (CGM.getCodeGenOpts().hasReducedDebugInfo()) {
4691 Flags |= llvm::DINode::FlagNoReturn;
4693 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
4697void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
4698 unsigned &LineNo, QualType &
T,
4699 StringRef &Name, StringRef &LinkageName,
4700 llvm::MDTuple *&TemplateParameters,
4701 llvm::DIScope *&VDContext) {
4710 llvm::APInt ConstVal(32, 1);
4711 QualType ET = CGM.getContext().getAsArrayType(
T)->getElementType();
4713 T = CGM.getContext().getConstantArrayType(ET, ConstVal,
nullptr,
4720 LinkageName = CGM.getMangledName(VD);
4721 if (LinkageName == Name)
4722 LinkageName = StringRef();
4725 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VD, &*Unit);
4726 TemplateParameters = parameterNodes.get();
4728 TemplateParameters =
nullptr;
4734 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
4735 VDContext = LexicalBlockStack.back();
4754 DC = CGM.getContext().getTranslationUnitDecl();
4756 llvm::DIScope *Mod = getParentModuleOrNull(VD);
4757 VDContext = getContextDescriptor(
cast<Decl>(DC), Mod ? Mod : TheCU);
4760llvm::DISubprogram *CGDebugInfo::getFunctionFwdDeclOrStub(GlobalDecl GD,
4762 llvm::DINodeArray TParamsArray;
4763 StringRef Name, LinkageName;
4764 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
4765 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
4767 llvm::DIFile *Unit = getOrCreateFile(Loc);
4768 llvm::DIScope *DContext = Unit;
4769 unsigned Line = getLineNumber(Loc);
4770 collectFunctionDeclProps(GD, Unit, Name, LinkageName, DContext, TParamsArray,
4775 SmallVector<QualType, 16> ArgTypes;
4776 for (
const ParmVarDecl *Parm : FD->
parameters())
4777 ArgTypes.push_back(Parm->getType());
4780 QualType FnType = CGM.getContext().getFunctionType(
4781 FD->
getReturnType(), ArgTypes, FunctionProtoType::ExtProtoInfo(CC));
4783 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
4784 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
4785 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
4789 SPFlags |= llvm::DISubprogram::SPFlagDefinition;
4790 return DBuilder.createFunction(
4791 DContext, Name, LinkageName, Unit,
Line,
4792 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4793 TParamsArray.get(), getFunctionDeclaration(FD),
nullptr,
4795 CGM.getCodeGenOpts().DebugKeyInstructions);
4798 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
4799 DContext, Name, LinkageName, Unit,
Line,
4800 getOrCreateFunctionType(GD.
getDecl(), FnType, Unit), 0, Flags, SPFlags,
4801 TParamsArray.get(), getFunctionDeclaration(FD));
4803 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
4804 std::make_tuple(CanonDecl),
4805 std::make_tuple(SP));
4809llvm::DISubprogram *CGDebugInfo::getFunctionForwardDeclaration(GlobalDecl GD) {
4810 return getFunctionFwdDeclOrStub(GD,
false);
4813llvm::DISubprogram *CGDebugInfo::getFunctionStub(GlobalDecl GD) {
4814 return getFunctionFwdDeclOrStub(GD,
true);
4817llvm::DIGlobalVariable *
4818CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
4820 StringRef Name, LinkageName;
4822 llvm::DIFile *Unit = getOrCreateFile(Loc);
4823 llvm::DIScope *DContext = Unit;
4824 unsigned Line = getLineNumber(Loc);
4825 llvm::MDTuple *TemplateParameters =
nullptr;
4827 collectVarDeclProps(VD, Unit,
Line,
T, Name, LinkageName, TemplateParameters,
4830 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
4831 DContext, Name, LinkageName, Unit,
Line, getOrCreateType(
T, Unit),
4833 FwdDeclReplaceMap.emplace_back(
4834 std::piecewise_construct,
4836 std::make_tuple(
static_cast<llvm::Metadata *
>(GV)));
4840llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
4845 if (
const auto *TD = dyn_cast<TypeDecl>(D)) {
4846 QualType Ty = CGM.getContext().getTypeDeclType(TD);
4847 return getOrCreateType(Ty, getOrCreateFile(TD->
getLocation()));
4851 if (I != DeclCache.end()) {
4853 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(N))
4854 return GVE->getVariable();
4862 if (IE != ImportedDeclCache.end()) {
4863 auto N = IE->second;
4864 if (
auto *GVE = dyn_cast_or_null<llvm::DIImportedEntity>(N))
4866 return dyn_cast_or_null<llvm::DINode>(N);
4871 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
4872 return getFunctionForwardDeclaration(FD);
4873 else if (
const auto *VD = dyn_cast<VarDecl>(D))
4874 return getGlobalVariableForwardDeclaration(VD);
4879llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
4880 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4883 const auto *FD = dyn_cast<FunctionDecl>(D);
4888 auto *S = getDeclContextDescriptor(D);
4891 if (MI == SPCache.end()) {
4893 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
4897 if (MI != SPCache.end()) {
4898 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4899 if (SP && !SP->isDefinition())
4903 for (
auto *NextFD : FD->
redecls()) {
4904 auto MI = SPCache.find(NextFD->getCanonicalDecl());
4905 if (MI != SPCache.end()) {
4906 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
4907 if (SP && !SP->isDefinition())
4914llvm::DISubprogram *CGDebugInfo::getObjCMethodDeclaration(
4915 const Decl *D, llvm::DISubroutineType *FnType,
unsigned LineNo,
4916 llvm::DINode::DIFlags Flags, llvm::DISubprogram::DISPFlags SPFlags) {
4917 if (!D || DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
4920 const auto *OMD = dyn_cast<ObjCMethodDecl>(D);
4924 if (CGM.getCodeGenOpts().DwarfVersion < 5 && !OMD->
isDirectMethod())
4928 SPFlags |= llvm::DISubprogram::SPFlagObjCDirect;
4937 QualType QTy(
ID->getTypeForDecl(), 0);
4938 auto It = TypeCache.find(QTy.getAsOpaquePtr());
4939 if (It == TypeCache.end())
4942 llvm::DISubprogram *FD = DBuilder.createFunction(
4943 InterfaceType, getObjCMethodName(OMD), StringRef(),
4944 InterfaceType->getFile(), LineNo, FnType, LineNo, Flags, SPFlags);
4945 DBuilder.finalizeSubprogram(FD);
4952llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
4957 if (!D || (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly &&
4958 !CGM.getCodeGenOpts().EmitCodeView))
4961 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray({}));
4963 if (
const auto *
Method = dyn_cast<CXXDestructorDecl>(D)) {
4966 return getOrCreateMethodTypeForDestructor(
Method, F, FnType);
4969 if (
const auto *
Method = dyn_cast<CXXMethodDecl>(D))
4970 return getOrCreateMethodType(
Method, F);
4972 const auto *FTy = FnType->
getAs<FunctionType>();
4975 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
4977 SmallVector<llvm::Metadata *, 16> Elts;
4980 QualType ResultTy = OMethod->getReturnType();
4983 if (ResultTy == CGM.getContext().getObjCInstanceType())
4984 ResultTy = CGM.getContext().getPointerType(
4985 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
4987 Elts.push_back(getOrCreateType(ResultTy, F));
4989 QualType SelfDeclTy;
4990 if (
auto *SelfDecl = OMethod->getSelfDecl())
4991 SelfDeclTy = SelfDecl->getType();
4992 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
4995 if (!SelfDeclTy.
isNull())
4997 CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
4999 Elts.push_back(DBuilder.createArtificialType(
5000 getOrCreateType(CGM.getContext().getObjCSelType(), F)));
5002 for (
const auto *PI : OMethod->parameters())
5003 Elts.push_back(getOrCreateType(PI->getType(), F));
5005 if (OMethod->isVariadic())
5006 Elts.push_back(DBuilder.createUnspecifiedParameter());
5008 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
5009 return DBuilder.createSubroutineType(
5010 EltTypeArray, llvm::DINode::FlagZero,
5011 getDwarfCC(CC, CGM.getTarget().getTriple()));
5016 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
5017 if (FD->isVariadic()) {
5018 SmallVector<llvm::Metadata *, 16> EltTys;
5019 EltTys.push_back(getOrCreateType(FD->getReturnType(), F));
5020 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
5022 EltTys.push_back(getOrCreateType(ParamType, F));
5023 EltTys.push_back(DBuilder.createUnspecifiedParameter());
5024 llvm::DITypeArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
5025 return DBuilder.createSubroutineType(
5026 EltTypeArray, llvm::DINode::FlagZero,
5027 getDwarfCC(CC, CGM.getTarget().getTriple()));
5039 CC = SrcFnTy->getCallConv();
5041 for (
const VarDecl *VD : Args)
5042 ArgTypes.push_back(VD->
getType());
5043 return CGM.getContext().getFunctionType(RetTy, ArgTypes,
5049 llvm::Function *Fn,
bool CurFuncIsThunk) {
5051 StringRef LinkageName;
5053 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5056 bool HasDecl = (D !=
nullptr);
5058 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5059 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5060 llvm::DIFile *Unit = getOrCreateFile(Loc);
5061 llvm::DIScope *FDContext = Unit;
5062 llvm::DINodeArray TParamsArray;
5063 bool KeyInstructions = CGM.getCodeGenOpts().DebugKeyInstructions;
5066 LinkageName = Fn->getName();
5067 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
5069 auto FI = SPCache.find(FD->getCanonicalDecl());
5070 if (FI != SPCache.end()) {
5071 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5072 if (SP && SP->isDefinition()) {
5073 LexicalBlockStack.emplace_back(SP);
5074 RegionMap[D].reset(SP);
5078 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5079 TParamsArray, Flags);
5082 KeyInstructions && !isa_and_present<CoroutineBodyStmt>(FD->getBody());
5083 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5084 Name = getObjCMethodName(OMD);
5085 Flags |= llvm::DINode::FlagPrototyped;
5091 if (Name != Fn->getName())
5092 LinkageName = Fn->getName();
5094 Name = Fn->getName();
5099 Flags |= llvm::DINode::FlagPrototyped;
5101 Name.consume_front(
"\01");
5105 "Unexpected DynamicInitKind !");
5109 Flags |= llvm::DINode::FlagArtificial;
5115 Flags |= llvm::DINode::FlagThunk;
5117 if (Fn->hasLocalLinkage())
5118 SPFlags |= llvm::DISubprogram::SPFlagLocalToUnit;
5119 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5120 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5123 llvm::DISubprogram::DISPFlags SPFlagsForDef =
5124 SPFlags | llvm::DISubprogram::SPFlagDefinition;
5126 const unsigned LineNo = getLineNumber(Loc.
isValid() ? Loc : CurLoc);
5127 unsigned ScopeLine = getLineNumber(ScopeLoc);
5128 llvm::DISubroutineType *DIFnType = getOrCreateFunctionType(D, FnType, Unit);
5129 llvm::DISubprogram *
Decl =
nullptr;
5130 llvm::DINodeArray Annotations =
nullptr;
5133 ? getObjCMethodDeclaration(D, DIFnType, LineNo, Flags, SPFlags)
5134 : getFunctionDeclaration(D);
5135 Annotations = CollectBTFDeclTagAnnotations(D);
5143 llvm::DISubprogram *SP = DBuilder.createFunction(
5144 FDContext, Name, LinkageName, Unit, LineNo, DIFnType, ScopeLine,
5145 FlagsForDef, SPFlagsForDef, TParamsArray.get(),
Decl,
nullptr,
5146 Annotations,
"", KeyInstructions);
5147 Fn->setSubprogram(SP);
5156 LexicalBlockStack.emplace_back(SP);
5159 RegionMap[D].reset(SP);
5163 QualType FnType, llvm::Function *Fn) {
5165 StringRef LinkageName;
5171 llvm::TimeTraceScope TimeScope(
"DebugFunction", [&]() {
5172 return GetName(D,
true);
5175 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5176 llvm::DIFile *Unit = getOrCreateFile(Loc);
5177 bool IsDeclForCallSite = Fn ?
true :
false;
5178 llvm::DIScope *FDContext =
5179 IsDeclForCallSite ? Unit : getDeclContextDescriptor(D);
5180 llvm::DINodeArray TParamsArray;
5183 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
5184 TParamsArray, Flags);
5185 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
5186 Name = getObjCMethodName(OMD);
5187 Flags |= llvm::DINode::FlagPrototyped;
5189 llvm_unreachable(
"not a function or ObjC method");
5191 Name.consume_front(
"\01");
5194 Flags |= llvm::DINode::FlagArtificial;
5199 unsigned LineNo = getLineNumber(Loc);
5200 unsigned ScopeLine = 0;
5201 llvm::DISubprogram::DISPFlags SPFlags = llvm::DISubprogram::SPFlagZero;
5202 if (CGM.getCodeGenOpts().OptimizationLevel != 0)
5203 SPFlags |= llvm::DISubprogram::SPFlagOptimized;
5205 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
5206 llvm::DISubroutineType *STy = getOrCreateFunctionType(D, FnType, Unit);
5208 assert(~SPFlags & llvm::DISubprogram::SPFlagDefinition);
5209 llvm::DISubprogram *SP = DBuilder.createFunction(
5210 FDContext, Name, LinkageName, Unit, LineNo, STy, ScopeLine, Flags,
5211 SPFlags, TParamsArray.get(),
nullptr,
nullptr, Annotations,
5217 if (IsDeclForCallSite && CGM.getTarget().getTriple().isBPF()) {
5218 if (
auto *FD = dyn_cast<FunctionDecl>(D)) {
5219 llvm::DITypeArray ParamTypes = STy->getTypeArray();
5222 llvm::DINodeArray ParamAnnotations = CollectBTFDeclTagAnnotations(PD);
5223 DBuilder.createParameterVariable(
5224 SP, PD->getName(), ArgNo, Unit, LineNo, ParamTypes[ArgNo],
true,
5225 llvm::DINode::FlagZero, ParamAnnotations);
5231 if (IsDeclForCallSite)
5232 Fn->setSubprogram(SP);
5236 llvm::CallBase *CI) {
5237 if (!shouldGenerateVirtualCallSite())
5243 assert(CI &&
"Invalid Call Instruction.");
5244 if (!CI->isIndirectCall())
5248 if (llvm::DISubprogram *MD = getFunctionDeclaration(FD))
5249 CI->setMetadata(llvm::LLVMContext::MD_call_target, MD);
5257 auto *
Func = dyn_cast<llvm::Function>(CallOrInvoke->getCalledOperand());
5260 if (
Func->getSubprogram())
5264 if (!
Func->isDeclaration())
5288 auto FI = SPCache.find(FD->getCanonicalDecl());
5289 llvm::DISubprogram *SP =
nullptr;
5290 if (FI != SPCache.end())
5291 SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
5292 if (!SP || !SP->isDefinition())
5293 SP = getFunctionStub(GD);
5294 FnBeginRegionCount.push_back(LexicalBlockStack.size());
5295 LexicalBlockStack.emplace_back(SP);
5301 assert(CurInlinedAt &&
"unbalanced inline scope stack");
5310 if (CurLoc.isInvalid() ||
5311 (CGM.getCodeGenOpts().DebugInfoMacroExpansionLoc && CurLoc.isMacroID()) ||
5312 LexicalBlockStack.empty())
5315 llvm::MDNode *
Scope = LexicalBlockStack.back();
5316 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5317 CGM.getLLVMContext(), CurLocLine, CurLocColumn,
Scope, CurInlinedAt));
5321 llvm::MDNode *Back =
nullptr;
5322 if (!LexicalBlockStack.empty())
5323 Back = LexicalBlockStack.back().get();
5326 unsigned Line = getLineNumber(CurLoc);
5327 unsigned Column =
Line ? getColumnNumber(CurLoc) : 0;
5328 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
5332void CGDebugInfo::AppendAddressSpaceXDeref(
5334 std::optional<unsigned> DWARFAddressSpace =
5336 if (!DWARFAddressSpace)
5339 Expr.push_back(llvm::dwarf::DW_OP_constu);
5340 Expr.push_back(*DWARFAddressSpace);
5341 Expr.push_back(llvm::dwarf::DW_OP_swap);
5342 Expr.push_back(llvm::dwarf::DW_OP_xderef);
5351 Builder.SetCurrentDebugLocation(llvm::DILocation::get(
5352 CGM.getLLVMContext(), getLineNumber(Loc), getColumnNumber(Loc),
5353 LexicalBlockStack.back(), CurInlinedAt));
5355 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5359 CreateLexicalBlock(Loc);
5364 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5369 if (DebugKind <= llvm::codegenoptions::DebugLineTablesOnly)
5372 LexicalBlockStack.pop_back();
5376 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5377 unsigned RCount = FnBeginRegionCount.back();
5378 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
5381 while (LexicalBlockStack.size() != RCount) {
5384 LexicalBlockStack.pop_back();
5386 FnBeginRegionCount.pop_back();
5388 if (Fn && Fn->getSubprogram())
5389 DBuilder.finalizeSubprogram(Fn->getSubprogram());
5392CGDebugInfo::BlockByRefType
5393CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
5394 uint64_t *XOffset) {
5397 uint64_t FieldSize, FieldOffset;
5398 uint32_t FieldAlign;
5400 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5405 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
5406 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
5408 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
5409 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
5412 if (HasCopyAndDispose) {
5415 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
5417 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
5419 bool HasByrefExtendedLayout;
5422 HasByrefExtendedLayout) &&
5423 HasByrefExtendedLayout) {
5426 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
5435 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
5438 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
5441 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
5446 llvm::DIType *WrappedTy = getOrCreateType(FType, Unit);
5447 FieldSize = CGM.getContext().getTypeSize(FType);
5448 FieldAlign = CGM.getContext().toBits(Align);
5450 *XOffset = FieldOffset;
5451 llvm::DIType *FieldTy = DBuilder.createMemberType(
5452 Unit, VD->
getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset,
5453 llvm::DINode::FlagZero, WrappedTy);
5454 EltTys.push_back(FieldTy);
5455 FieldOffset += FieldSize;
5457 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
5458 return {DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0,
5459 llvm::DINode::FlagZero,
nullptr, Elements),
5463llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const VarDecl *VD,
5464 llvm::Value *Storage,
5465 std::optional<unsigned> ArgNo,
5467 const bool UsePointerValue) {
5468 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5469 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5470 if (VD->
hasAttr<NoDebugAttr>())
5475 llvm::DIFile *Unit =
nullptr;
5476 if (!VarIsArtificial)
5480 if (VD->
hasAttr<BlocksAttr>())
5481 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5483 Ty = getOrCreateType(VD->
getType(), Unit);
5493 if (!VarIsArtificial) {
5497 SmallVector<uint64_t, 13> Expr;
5498 llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
5505 Flags |= llvm::DINode::FlagArtificial;
5509 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(VD->
getType());
5510 AppendAddressSpaceXDeref(AddressSpace, Expr);
5514 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD)) {
5517 Flags |= llvm::DINode::FlagObjectPointer;
5518 }
else if (
const auto *PVD = dyn_cast<ParmVarDecl>(VD)) {
5519 if (PVD->isExplicitObjectParameter())
5520 Flags |= llvm::DINode::FlagObjectPointer;
5528 StringRef Name = VD->
getName();
5529 if (!Name.empty()) {
5535 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5537 offset = CGM.getContext().toCharUnitsFromBits(
5540 Expr.push_back(llvm::dwarf::DW_OP_deref);
5541 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5543 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5546 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
5558 for (
const auto *Field : RD->
fields()) {
5559 llvm::DIType *FieldTy = getOrCreateType(
Field->getType(), Unit);
5560 StringRef FieldName =
Field->getName();
5568 auto *D = DBuilder.createAutoVariable(
5569 Scope, FieldName, Unit,
Line, FieldTy,
5570 CGM.getCodeGenOpts().OptimizationLevel != 0,
5571 Flags | llvm::DINode::FlagArtificial, FieldAlign);
5574 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5575 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5578 Builder.GetInsertBlock());
5586 if (UsePointerValue) {
5587 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5588 "Debug info already contains DW_OP_deref.");
5589 Expr.push_back(llvm::dwarf::DW_OP_deref);
5593 llvm::DILocalVariable *D =
nullptr;
5595 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(VD);
5596 D = DBuilder.createParameterVariable(
5597 Scope, Name, *ArgNo, Unit,
Line, Ty,
5598 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Annotations);
5607 auto RemapCoroArgToLocalVar = [&]() -> llvm::DILocalVariable * {
5613 auto Iter = llvm::find_if(CoroutineParameterMappings, [&](
auto &Pair) {
5614 Stmt *StmtPtr =
const_cast<Stmt *
>(Pair.second);
5615 if (DeclStmt *DeclStmtPtr = dyn_cast<DeclStmt>(StmtPtr)) {
5616 DeclGroupRef DeclGroup = DeclStmtPtr->getDeclGroup();
5618 if (VD == dyn_cast_or_null<VarDecl>(
Decl))
5624 if (Iter != CoroutineParameterMappings.end()) {
5625 ParmVarDecl *PD =
const_cast<ParmVarDecl *
>(Iter->first);
5626 auto Iter2 = llvm::find_if(ParamDbgMappings, [&](
auto &DbgPair) {
5627 return DbgPair.first == PD && DbgPair.second->getScope() == Scope;
5629 if (Iter2 != ParamDbgMappings.end())
5630 return const_cast<llvm::DILocalVariable *
>(Iter2->second);
5636 D = RemapCoroArgToLocalVar();
5639 D = DBuilder.createAutoVariable(
5640 Scope, Name, Unit,
Line, Ty,
5641 CGM.getCodeGenOpts().OptimizationLevel != 0, Flags, Align);
5644 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5645 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5646 Column, Scope, CurInlinedAt),
5647 Builder.GetInsertBlock());
5652llvm::DILocalVariable *CGDebugInfo::EmitDeclare(
const BindingDecl *BD,
5653 llvm::Value *Storage,
5654 std::optional<unsigned> ArgNo,
5656 const bool UsePointerValue) {
5657 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5658 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5659 if (BD->
hasAttr<NoDebugAttr>())
5666 llvm::DIFile *Unit = getOrCreateFile(BD->
getLocation());
5667 llvm::DIType *Ty = getOrCreateType(BD->
getType(), Unit);
5675 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(BD->
getType());
5677 SmallVector<uint64_t, 3> Expr;
5678 AppendAddressSpaceXDeref(AddressSpace, Expr);
5683 if (UsePointerValue) {
5684 assert(!llvm::is_contained(Expr, llvm::dwarf::DW_OP_deref) &&
5685 "Debug info already contains DW_OP_deref.");
5686 Expr.push_back(llvm::dwarf::DW_OP_deref);
5691 StringRef Name = BD->
getName();
5694 llvm::DILocalVariable *D = DBuilder.createAutoVariable(
5695 Scope, Name, Unit,
Line, Ty, CGM.getCodeGenOpts().OptimizationLevel != 0,
5696 llvm::DINode::FlagZero, Align);
5698 if (
const MemberExpr *ME = dyn_cast<MemberExpr>(BD->
getBinding())) {
5699 if (
const FieldDecl *FD = dyn_cast<FieldDecl>(ME->getMemberDecl())) {
5700 const unsigned fieldIndex = FD->getFieldIndex();
5701 const clang::CXXRecordDecl *parent =
5702 (
const CXXRecordDecl *)FD->getParent();
5703 const ASTRecordLayout &layout =
5704 CGM.getContext().getASTRecordLayout(parent);
5706 if (FD->isBitField()) {
5707 const CGRecordLayout &RL =
5708 CGM.getTypes().getCGRecordLayout(FD->getParent());
5713 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5719 ? llvm::dwarf::DW_OP_LLVM_extract_bits_sext
5720 : llvm::dwarf::DW_OP_LLVM_extract_bits_zext);
5721 Expr.push_back(Info.
Offset);
5724 const uint64_t TypeSize = CGM.getContext().getTypeSize(BD->
getType());
5725 Expr.push_back(std::min((uint64_t)Info.
Size, TypeSize));
5726 }
else if (fieldOffset != 0) {
5727 assert(fieldOffset % CGM.getContext().getCharWidth() == 0 &&
5728 "Unexpected non-bitfield with non-byte-aligned offset");
5729 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5731 CGM.getContext().toCharUnitsFromBits(fieldOffset).getQuantity());
5734 }
else if (
const ArraySubscriptExpr *ASE =
5735 dyn_cast<ArraySubscriptExpr>(BD->
getBinding())) {
5736 if (
const IntegerLiteral *IL = dyn_cast<IntegerLiteral>(ASE->getIdx())) {
5737 const uint64_t value = IL->getValue().getZExtValue();
5738 const uint64_t typeSize = CGM.getContext().getTypeSize(BD->
getType());
5741 Expr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5742 Expr.push_back(CGM.getContext()
5743 .toCharUnitsFromBits(value * typeSize)
5750 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
5751 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
5752 Column, Scope, CurInlinedAt),
5753 Builder.GetInsertBlock());
5758llvm::DILocalVariable *
5761 const bool UsePointerValue) {
5762 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5764 if (
auto *DD = dyn_cast<DecompositionDecl>(VD)) {
5766 EmitDeclare(B, Storage, std::nullopt, Builder,
5773 return EmitDeclare(VD, Storage, std::nullopt, Builder, UsePointerValue);
5777 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5778 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5780 if (D->
hasAttr<NoDebugAttr>())
5784 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
5790 StringRef Name = D->
getName();
5796 CGM.getCodeGenOpts().OptimizationLevel != 0);
5799 DBuilder.insertLabel(L,
5800 llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5801 Scope, CurInlinedAt),
5802 Builder.GetInsertBlock()->end());
5805llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
5807 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
5810 return DBuilder.createObjectPointerType(Ty,
true);
5815 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
5816 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5817 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
5819 if (Builder.GetInsertBlock() ==
nullptr)
5821 if (VD->
hasAttr<NoDebugAttr>())
5824 bool isByRef = VD->
hasAttr<BlocksAttr>();
5826 uint64_t XOffset = 0;
5827 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
5830 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset).WrappedType;
5832 Ty = getOrCreateType(VD->
getType(), Unit);
5836 if (
const auto *IPD = dyn_cast<ImplicitParamDecl>(VD))
5838 Ty = CreateSelfType(VD->
getType(), Ty);
5841 const unsigned Line =
5845 const llvm::DataLayout &target = CGM.getDataLayout();
5852 addr.push_back(llvm::dwarf::DW_OP_deref);
5853 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5856 addr.push_back(llvm::dwarf::DW_OP_deref);
5857 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5860 CGM.getContext().toCharUnitsFromBits(target.getPointerSizeInBits(0));
5862 addr.push_back(llvm::dwarf::DW_OP_deref);
5863 addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
5865 offset = CGM.getContext().toCharUnitsFromBits(XOffset);
5871 auto *D = DBuilder.createAutoVariable(
5873 Line, Ty,
false, llvm::DINode::FlagZero, Align);
5876 auto DL = llvm::DILocation::get(CGM.getLLVMContext(),
Line,
Column,
5877 LexicalBlockStack.back(), CurInlinedAt);
5878 auto *
Expr = DBuilder.createExpression(addr);
5880 DBuilder.insertDeclare(Storage, D,
Expr, DL, InsertPoint->getIterator());
5882 DBuilder.insertDeclare(Storage, D,
Expr, DL, Builder.GetInsertBlock());
5885llvm::DILocalVariable *
5888 bool UsePointerValue) {
5889 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5890 return EmitDeclare(VD, AI, ArgNo, Builder, UsePointerValue);
5894struct BlockLayoutChunk {
5895 uint64_t OffsetInBits;
5898bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
5899 return l.OffsetInBits < r.OffsetInBits;
5903void CGDebugInfo::collectDefaultFieldsForBlockLiteralDeclare(
5905 const llvm::StructLayout &BlockLayout, llvm::DIFile *Unit,
5906 SmallVectorImpl<llvm::Metadata *> &Fields) {
5910 if (CGM.getLangOpts().OpenCL) {
5911 Fields.push_back(createFieldType(
"__size", Context.
IntTy, Loc,
AS_public,
5912 BlockLayout.getElementOffsetInBits(0),
5914 Fields.push_back(createFieldType(
"__align", Context.
IntTy, Loc,
AS_public,
5915 BlockLayout.getElementOffsetInBits(1),
5919 BlockLayout.getElementOffsetInBits(0),
5921 Fields.push_back(createFieldType(
"__flags", Context.
IntTy, Loc,
AS_public,
5922 BlockLayout.getElementOffsetInBits(1),
5926 BlockLayout.getElementOffsetInBits(2), Unit, Unit));
5927 auto *FnTy =
Block.getBlockExpr()->getFunctionType();
5928 auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
5929 Fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, Loc,
AS_public,
5930 BlockLayout.getElementOffsetInBits(3),
5932 Fields.push_back(createFieldType(
5937 Loc,
AS_public, BlockLayout.getElementOffsetInBits(4), Unit, Unit));
5944 llvm::AllocaInst *Alloca,
5946 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
5952 llvm::DIFile *tunit = getOrCreateFile(loc);
5953 unsigned line = getLineNumber(loc);
5954 unsigned column = getColumnNumber(loc);
5959 const llvm::StructLayout *blockLayout =
5963 collectDefaultFieldsForBlockLiteralDeclare(block,
C, loc, *blockLayout, tunit,
5972 BlockLayoutChunk chunk;
5973 chunk.OffsetInBits =
5974 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
5975 chunk.Capture =
nullptr;
5976 chunks.push_back(chunk);
5980 for (
const auto &capture :
blockDecl->captures()) {
5981 const VarDecl *variable = capture.getVariable();
5988 BlockLayoutChunk chunk;
5989 chunk.OffsetInBits =
5990 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
5991 chunk.Capture = &capture;
5992 chunks.push_back(chunk);
5996 llvm::array_pod_sort(chunks.begin(), chunks.end());
5998 for (
const BlockLayoutChunk &Chunk : chunks) {
5999 uint64_t offsetInBits = Chunk.OffsetInBits;
6006 cast_or_null<CXXMethodDecl>(
blockDecl->getNonClosureContext()))
6008 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(
blockDecl->getParent()))
6009 type = CGM.getContext().getCanonicalTagType(RDecl);
6011 llvm_unreachable(
"unexpected block declcontext");
6013 fields.push_back(createFieldType(
"this",
type, loc,
AS_public,
6014 offsetInBits, tunit, tunit));
6019 StringRef name = variable->
getName();
6021 llvm::DIType *fieldType;
6023 TypeInfo PtrInfo =
C.getTypeInfo(
C.VoidPtrTy);
6028 EmitTypeForVarWithBlocksAttr(variable, &xoffset).BlockByRefWrapper;
6029 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
6030 fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
6031 PtrInfo.
Width, Align, offsetInBits,
6032 llvm::DINode::FlagZero, fieldType);
6036 offsetInBits, Align, tunit, tunit);
6038 fields.push_back(fieldType);
6042 llvm::raw_svector_ostream(typeName)
6043 <<
"__block_literal_" << CGM.getUniqueBlockCount();
6045 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
6047 llvm::DIType *
type =
6048 DBuilder.createStructType(tunit, typeName.str(), tunit, line,
6049 CGM.getContext().toBits(block.
BlockSize), 0,
6050 llvm::DINode::FlagZero,
nullptr, fieldsArray);
6051 type = DBuilder.createPointerType(
type, CGM.PointerWidthInBits);
6054 llvm::DINode::DIFlags flags = llvm::DINode::FlagArtificial;
6058 auto *debugVar = DBuilder.createParameterVariable(
6059 scope, Name, ArgNo, tunit, line,
type,
6060 CGM.getCodeGenOpts().OptimizationLevel != 0, flags);
6063 DBuilder.insertDeclare(Alloca, debugVar, DBuilder.createExpression(),
6064 llvm::DILocation::get(CGM.getLLVMContext(), line,
6065 column, scope, CurInlinedAt),
6066 Builder.GetInsertBlock());
6069llvm::DIDerivedType *
6070CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
6075 if (MI != StaticDataMemberCache.end()) {
6076 assert(MI->second &&
"Static data member declaration should still exist");
6087llvm::DIGlobalVariableExpression *CGDebugInfo::CollectAnonRecordDecls(
6088 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
6089 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
6090 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6092 for (
const auto *Field : RD->
fields()) {
6093 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
6094 StringRef FieldName = Field->getName();
6097 if (FieldName.empty()) {
6098 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
6099 GVE = CollectAnonRecordDecls(RT->getDecl()->getDefinitionOrSelf(), Unit,
6100 LineNo, LinkageName, Var, DContext);
6104 GVE = DBuilder.createGlobalVariableExpression(
6105 DContext, FieldName, LinkageName, Unit, LineNo, FieldTy,
6106 Var->hasLocalLinkage());
6107 Var->addDebugInfo(GVE);
6119 const auto *RD = dyn_cast<CXXRecordDecl>(RT->getDecl());
6124 auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD);
6135 struct ReferencesAnonymous
6137 bool RefAnon =
false;
6138 bool VisitRecordType(RecordType *RT) {
6146 ReferencesAnonymous RT;
6159struct ReconstitutableType :
public RecursiveASTVisitor<ReconstitutableType> {
6160 bool Reconstitutable =
true;
6161 bool VisitVectorType(VectorType *FT) {
6162 Reconstitutable =
false;
6165 bool VisitAtomicType(AtomicType *FT) {
6166 Reconstitutable =
false;
6169 bool TraverseEnumType(EnumType *ET,
bool =
false) {
6172 const EnumDecl *ED = ET->getDecl();
6174 Reconstitutable =
false;
6178 Reconstitutable =
false;
6183 bool VisitFunctionProtoType(FunctionProtoType *FT) {
6187 return Reconstitutable;
6189 bool VisitRecordType(RecordType *RT,
bool =
false) {
6191 Reconstitutable =
false;
6201 ReconstitutableType
T;
6203 return T.Reconstitutable;
6206bool CGDebugInfo::HasReconstitutableArgs(
6207 ArrayRef<TemplateArgument> Args)
const {
6208 return llvm::all_of(Args, [&](
const TemplateArgument &TA) {
6248 llvm_unreachable(
"Other, unresolved, template arguments should "
6249 "not be seen here");
6254std::string CGDebugInfo::GetName(
const Decl *D,
bool Qualified,
6255 bool *NameIsSimplified)
const {
6257 llvm::raw_string_ostream
OS(Name);
6258 const NamedDecl *ND = dyn_cast<NamedDecl>(D);
6261 llvm::codegenoptions::DebugTemplateNamesKind TemplateNamesKind =
6262 CGM.getCodeGenOpts().getDebugSimpleTemplateNames();
6264 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6265 TemplateNamesKind = llvm::codegenoptions::DebugTemplateNamesKind::Full;
6267 std::optional<TemplateArgs> Args;
6269 bool IsOperatorOverload =
false;
6270 if (
auto *RD = dyn_cast<CXXRecordDecl>(ND)) {
6271 Args = GetTemplateArgs(RD);
6272 }
else if (
auto *FD = dyn_cast<FunctionDecl>(ND)) {
6273 Args = GetTemplateArgs(FD);
6275 IsOperatorOverload |=
6278 }
else if (
auto *VD = dyn_cast<VarDecl>(ND)) {
6279 Args = GetTemplateArgs(VD);
6303 bool Reconstitutable =
6304 Args && HasReconstitutableArgs(Args->Args) && !IsOperatorOverload;
6306 PrintingPolicy PP = getPrintingPolicy();
6308 if (TemplateNamesKind == llvm::codegenoptions::DebugTemplateNamesKind::Full ||
6313 if (NameIsSimplified)
6314 *NameIsSimplified =
true;
6315 bool Mangled = TemplateNamesKind ==
6316 llvm::codegenoptions::DebugTemplateNamesKind::Mangled;
6322 std::string EncodedOriginalName;
6323 llvm::raw_string_ostream EncodedOriginalNameOS(EncodedOriginalName);
6328 printTemplateArgumentList(OS, Args->Args, PP);
6329 printTemplateArgumentList(EncodedOriginalNameOS, Args->Args, PP);
6331 std::string CanonicalOriginalName;
6332 llvm::raw_string_ostream OriginalOS(CanonicalOriginalName);
6334 assert(EncodedOriginalName == CanonicalOriginalName);
6343 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6344 if (D->
hasAttr<NoDebugAttr>())
6347 llvm::TimeTraceScope TimeScope(
"DebugGlobalVariable", [&]() {
6348 return GetName(D,
true);
6354 if (Cached != DeclCache.end())
6355 return Var->addDebugInfo(
6359 llvm::DIFile *Unit =
nullptr;
6360 llvm::DIScope *DContext =
nullptr;
6362 StringRef DeclName, LinkageName;
6364 llvm::MDTuple *TemplateParameters =
nullptr;
6365 collectVarDeclProps(D, Unit, LineNo,
T, DeclName, LinkageName,
6366 TemplateParameters, DContext);
6370 llvm::DIGlobalVariableExpression *GVE =
nullptr;
6375 if (
T->isUnionType() && DeclName.empty()) {
6376 const auto *RD =
T->castAsRecordDecl();
6378 "unnamed non-anonymous struct or union?");
6379 GVE = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
6384 unsigned AddressSpace = CGM.getTypes().getTargetAddressSpace(D->
getType());
6385 if (CGM.getLangOpts().CUDA && CGM.getLangOpts().CUDAIsDevice) {
6386 if (D->
hasAttr<CUDASharedAttr>())
6389 else if (D->
hasAttr<CUDAConstantAttr>())
6393 AppendAddressSpaceXDeref(AddressSpace,
Expr);
6395 llvm::DINodeArray Annotations = CollectBTFDeclTagAnnotations(D);
6396 GVE = DBuilder.createGlobalVariableExpression(
6397 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(
T, Unit),
6398 Var->hasLocalLinkage(),
true,
6399 Expr.empty() ?
nullptr : DBuilder.createExpression(
Expr),
6400 getOrCreateStaticDataMemberDeclarationOrNull(D), TemplateParameters,
6401 Align, Annotations);
6402 Var->addDebugInfo(GVE);
6408 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6409 if (VD->
hasAttr<NoDebugAttr>())
6411 llvm::TimeTraceScope TimeScope(
"DebugConstGlobalVariable", [&]() {
6412 return GetName(VD,
true);
6417 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
6418 StringRef Name = VD->
getName();
6419 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
6421 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
6423 if (CGM.getCodeGenOpts().EmitCodeView) {
6434 CanQualType T = CGM.getContext().getCanonicalTagType(ED);
6435 [[maybe_unused]] llvm::DIType *EDTy = getOrCreateType(
T, Unit);
6436 assert(EDTy->getTag() == llvm::dwarf::DW_TAG_enumeration_type);
6446 auto *VarD = dyn_cast<VarDecl>(VD);
6447 if (VarD && VarD->isStaticDataMember()) {
6449 getDeclContextDescriptor(VarD);
6454 RetainedTypes.push_back(
6455 CGM.getContext().getCanonicalTagType(RD).getAsOpaquePtr());
6459 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
6461 auto &GV = DeclCache[VD];
6465 llvm::DIExpression *InitExpr = createConstantValueExpression(VD,
Init);
6466 llvm::MDTuple *TemplateParameters =
nullptr;
6470 llvm::DINodeArray parameterNodes = CollectVarTemplateParams(VarD, &*Unit);
6471 TemplateParameters = parameterNodes.get();
6474 GV.reset(DBuilder.createGlobalVariableExpression(
6475 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
6476 true,
true, InitExpr, getOrCreateStaticDataMemberDeclarationOrNull(VarD),
6477 TemplateParameters, Align));
6482 assert(CGM.getCodeGenOpts().hasReducedDebugInfo());
6483 if (D->
hasAttr<NoDebugAttr>())
6487 llvm::DIFile *Unit = getOrCreateFile(D->
getLocation());
6488 StringRef Name = D->
getName();
6489 llvm::DIType *Ty = getOrCreateType(D->
getType(), Unit);
6491 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6492 llvm::DIGlobalVariableExpression *GVE =
6493 DBuilder.createGlobalVariableExpression(
6494 DContext, Name, StringRef(), Unit, getLineNumber(D->
getLocation()),
6495 Ty,
false,
false,
nullptr,
nullptr,
nullptr, Align);
6496 Var->addDebugInfo(GVE);
6503 if (CGM.getCodeGenOpts().getDebugInfo() <=
6504 llvm::codegenoptions::DebugLineTablesOnly)
6507 llvm::DILocation *DIL =
Value->getDebugLoc().get();
6511 llvm::DIFile *Unit = DIL->getFile();
6512 llvm::DIType *
Type = getOrCreateType(Ty, Unit);
6517 if (llvm::LoadInst *Load = dyn_cast<llvm::LoadInst>(
Value)) {
6518 llvm::Value *Var = Load->getPointerOperand();
6523 auto DeclareTypeMatches = [&](llvm::DbgVariableRecord *DbgDeclare) {
6524 return DbgDeclare->getVariable()->getType() ==
Type;
6526 if (any_of(llvm::findDVRDeclares(Var), DeclareTypeMatches))
6530 llvm::DILocalVariable *D =
6531 DBuilder.createAutoVariable(LexicalBlockStack.back(),
"",
nullptr, 0,
6532 Type,
false, llvm::DINode::FlagArtificial);
6534 if (
auto InsertPoint =
Value->getInsertionPointAfterDef()) {
6535 DBuilder.insertDbgValue(
Value, D, DBuilder.createExpression(), DIL,
6545 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6549 if (D->
hasAttr<NoDebugAttr>())
6552 auto AliaseeDecl = CGM.getMangledNameDecl(GV->getName());
6567 if (!(DI = getDeclarationOrDefinition(
6568 AliaseeDecl.getCanonicalDecl().getDecl())))
6571 llvm::DIScope *DContext = getDeclContextDescriptor(D);
6574 llvm::DIImportedEntity *ImportDI = DBuilder.createImportedDeclaration(
6575 DContext, DI, getOrCreateFile(Loc), getLineNumber(Loc), D->getName());
6589 llvm::DIFile *
File = getOrCreateFile(Loc);
6590 llvm::DIGlobalVariableExpression *Debug =
6591 DBuilder.createGlobalVariableExpression(
6592 nullptr, StringRef(), StringRef(), getOrCreateFile(Loc),
6593 getLineNumber(Loc), getOrCreateType(S->
getType(),
File),
true);
6594 GV->addDebugInfo(Debug);
6597llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
6598 if (!LexicalBlockStack.empty())
6599 return LexicalBlockStack.back();
6600 llvm::DIScope *Mod = getParentModuleOrNull(D);
6601 return getContextDescriptor(D, Mod ? Mod : TheCU);
6605 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6609 CGM.getCodeGenOpts().DebugExplicitImport) {
6613 DBuilder.createImportedModule(
6615 getOrCreateNamespace(NSDecl), getOrCreateFile(Loc), getLineNumber(Loc));
6620 if (llvm::DINode *
Target =
6623 DBuilder.createImportedDeclaration(
6625 getOrCreateFile(Loc), getLineNumber(Loc));
6630 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6633 "We shouldn't be codegening an invalid UsingDecl containing no decls");
6635 for (
const auto *USD : UD.
shadows()) {
6640 if (
const auto *FD = dyn_cast<FunctionDecl>(USD->getUnderlyingDecl()))
6641 if (
const auto *AT = FD->getType()
6644 if (AT->getDeducedType().isNull())
6655 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6658 "We shouldn't be codegening an invalid UsingEnumDecl"
6659 " containing no decls");
6661 for (
const auto *USD : UD.
shadows())
6666 if (CGM.getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
6668 if (
Module *M = ID.getImportedModule()) {
6670 auto Loc = ID.getLocation();
6671 DBuilder.createImportedDeclaration(
6672 getCurrentContextDescriptor(
cast<Decl>(ID.getDeclContext())),
6673 getOrCreateModuleRef(Info, DebugTypeExtRefs), getOrCreateFile(Loc),
6674 getLineNumber(Loc));
6678llvm::DIImportedEntity *
6680 if (!CGM.getCodeGenOpts().hasReducedDebugInfo())
6682 auto &VH = NamespaceAliasCache[&NA];
6685 llvm::DIImportedEntity *R;
6687 if (
const auto *Underlying =
6690 R = DBuilder.createImportedDeclaration(
6693 getLineNumber(Loc), NA.
getName());
6695 R = DBuilder.createImportedDeclaration(
6698 getOrCreateFile(Loc), getLineNumber(Loc), NA.
getName());
6704CGDebugInfo::getOrCreateNamespace(
const NamespaceDecl *NSDecl) {
6708 auto I = NamespaceCache.find(NSDecl);
6709 if (I != NamespaceCache.end())
6712 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
6714 llvm::DINamespace *NS =
6715 DBuilder.createNameSpace(Context, NSDecl->
getName(), NSDecl->
isInline());
6716 NamespaceCache[NSDecl].reset(NS);
6721 assert(TheCU &&
"no main compile unit");
6722 TheCU->setDWOId(Signature);
6728 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
6729 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
6731 ? CreateTypeDefinition(E.Type, E.Unit)
6733 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
6737 for (
const auto &P : ObjCMethodCache) {
6738 if (P.second.empty())
6741 QualType QTy(P.first->getTypeForDecl(), 0);
6743 assert(It != TypeCache.end());
6745 llvm::DICompositeType *InterfaceDecl =
6748 auto CurElts = InterfaceDecl->getElements();
6752 for (
auto &SubprogramDirect : P.second)
6753 if (CGM.getCodeGenOpts().DwarfVersion >= 5 || SubprogramDirect.getInt())
6754 EltTys.push_back(SubprogramDirect.getPointer());
6756 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
6757 DBuilder.replaceArrays(InterfaceDecl, Elements);
6760 for (
const auto &P : ReplaceMap) {
6763 assert(Ty->isForwardDecl());
6765 auto It = TypeCache.find(P.first);
6766 assert(It != TypeCache.end());
6769 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
6773 for (
const auto &P : FwdDeclReplaceMap) {
6776 llvm::Metadata *Repl;
6778 auto It = DeclCache.find(P.first);
6782 if (It == DeclCache.end())
6787 if (
auto *GVE = dyn_cast_or_null<llvm::DIGlobalVariableExpression>(Repl))
6788 Repl = GVE->getVariable();
6794 for (
auto &RT : RetainedTypes)
6795 if (
auto MD = TypeCache[RT])
6798 DBuilder.finalize();
6803 if (CGM.getCodeGenOpts().hasReducedDebugInfo())
6804 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6805 DBuilder.retainType(DieTy);
6809 if (CGM.getCodeGenOpts().hasMaybeUnusedDebugInfo())
6810 if (
auto *DieTy = getOrCreateType(Ty, TheCU->getFile()))
6811 DBuilder.retainType(DieTy);
6815 if (LexicalBlockStack.empty())
6816 return llvm::DebugLoc();
6818 llvm::MDNode *
Scope = LexicalBlockStack.back();
6819 return llvm::DILocation::get(CGM.getLLVMContext(), getLineNumber(Loc),
6820 getColumnNumber(Loc),
Scope);
6826 if (CGM.getCodeGenOpts().OptimizationLevel == 0 ||
6827 DebugKind == llvm::codegenoptions::NoDebugInfo ||
6828 DebugKind == llvm::codegenoptions::LocTrackingOnly ||
6829 !CGM.getCodeGenOpts().DebugCallSiteInfo)
6830 return llvm::DINode::FlagZero;
6835 bool SupportsDWARFv4Ext =
6836 CGM.getCodeGenOpts().DwarfVersion == 4 &&
6837 (CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::LLDB ||
6838 CGM.getCodeGenOpts().getDebuggerTuning() == llvm::DebuggerKind::GDB);
6840 if (!SupportsDWARFv4Ext && CGM.getCodeGenOpts().DwarfVersion < 5)
6841 return llvm::DINode::FlagZero;
6843 return llvm::DINode::FlagAllCallsDescribed;
6854 return DBuilder.createConstantValueExpression(
6855 Val.
getFloat().bitcastToAPInt().getZExtValue());
6860 llvm::APSInt
const &ValInt = Val.
getInt();
6861 std::optional<uint64_t> ValIntOpt;
6862 if (ValInt.isUnsigned())
6863 ValIntOpt = ValInt.tryZExtValue();
6864 else if (
auto tmp = ValInt.trySExtValue())
6867 ValIntOpt =
static_cast<uint64_t
>(*tmp);
6870 return DBuilder.createConstantValueExpression(ValIntOpt.value());
6875CodeGenFunction::LexicalScope::LexicalScope(CodeGenFunction &
CGF,
6877 : RunCleanupsScope(
CGF), Range(Range), ParentScope(
CGF.CurLexicalScope) {
6878 CGF.CurLexicalScope =
this;
6880 DI->EmitLexicalBlockStart(
CGF.Builder, Range.getBegin());
6885 DI->EmitLexicalBlockEnd(
CGF.Builder, Range.getEnd());
6898#define SANITIZER_CHECK(Enum, Name, Version, Msg) \
6900 Label = "__ubsan_check_" #Name; \
6904#undef SANITIZER_CHECK
6915#define SANITIZER(NAME, ID) \
6916 case SanitizerKind::SO_##ID: \
6917 Label = "__ubsan_check_" NAME; \
6919#include "clang/Basic/Sanitizers.def"
6921 llvm_unreachable(
"unexpected sanitizer kind");
6926 for (
unsigned int i = 0; i < Label.length(); i++)
6927 if (!std::isalpha(Label[i]))
6936 llvm::DILocation *CheckDebugLoc =
Builder.getCurrentDebugLocation();
6938 if (!DI || !CheckDebugLoc)
6939 return CheckDebugLoc;
6940 const auto &AnnotateDebugInfo =
6941 CGM.getCodeGenOpts().SanitizeAnnotateDebugInfo;
6942 if (AnnotateDebugInfo.empty())
6943 return CheckDebugLoc;
6946 if (Ordinals.size() == 1)
6951 if (any_of(Ordinals, [&](
auto Ord) {
return AnnotateDebugInfo.has(Ord); })) {
6955 llvm::DIFile *
File = llvm::DIFile::get(
CGM.getLLVMContext(),
6956 "ubsan_interface.h",
6958 return DI->CreateSyntheticInlineAt(CheckDebugLoc, Label,
File);
6961 return CheckDebugLoc;
6969 assert(!CGF->IsSanitizerScope);
6970 CGF->IsSanitizerScope =
true;
6974 assert(CGF->IsSanitizerScope);
6975 CGF->IsSanitizerScope =
false;
Defines the clang::ASTContext interface.
static bool IsReconstitutableType(QualType QT)
static void stripUnusedQualifiers(Qualifiers &Q)
static std::string SanitizerOrdinalToCheckLabel(SanitizerKind::SanitizerOrdinal Ordinal)
static llvm::Constant * buildConstantDataArrayFromElements(llvm::LLVMContext &Ctx, const APValue &Arr)
Build an llvm::ConstantDataArray from the initialized elements of an APValue array,...
static unsigned getDwarfCC(CallingConv CC, const llvm::Triple &T)
static std::string SanitizerHandlerToCheckLabel(SanitizerHandler Handler)
static bool IsObjCSynthesizedPropertyExplicitParameter(VarDecl const *VD)
Returns true if the specified variable VD is an explicit parameter of a synthesized Objective-C prope...
static bool IsArtificial(VarDecl const *VD)
Returns true if VD is a compiler-generated variable and should be treated as artificial for the purpo...
static bool needsTypeIdentifier(const TagDecl *TD, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static bool shouldOmitDefinition(llvm::codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
static llvm::DINode::DIFlags getAccessFlag(AccessSpecifier Access, const RecordDecl *RD)
Convert an AccessSpecifier into the corresponding DINode flag.
static void completeStandardLayoutUnionType(CGDebugInfo &DebugInfo, QualType QT)
static llvm::DINode::DIFlags getRefFlags(const FunctionProtoType *Func)
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C)
static SourceLocation getMacroDebugLoc(const CodeGenModule &CGM, SourceLocation Loc)
static llvm::dwarf::Tag getTagForRecord(const RecordDecl *RD)
static llvm::SmallVector< TemplateArgument > GetTemplateArgs(const TemplateDecl *TD, const TemplateSpecializationType *Ty)
static bool isFunctionLocalClass(const CXXRecordDecl *RD)
isFunctionLocalClass - Return true if CXXRecordDecl is defined inside a function.
static bool hasCXXMangling(llvm::dwarf::SourceLanguage Lang, bool IsTagDecl)
static uint32_t getDeclAlignIfRequired(const Decl *D, const ASTContext &Ctx)
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, CXXRecordDecl::method_iterator End)
static auto getEnumInfo(CodeGenModule &CGM, llvm::DICompileUnit *TheCU, const EnumType *Ty)
static bool canUseCtorHoming(const CXXRecordDecl *RD)
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Getter)
static llvm::Constant * tryEmitConstexprArrayAsConstant(CodeGenModule &CGM, const VarDecl *Var, const APValue *Value)
Try to create an llvm::Constant for a constexpr array of integer elements.
static bool isClassOrMethodDLLImport(const CXXRecordDecl *RD)
Return true if the class or any of its methods are marked dllimport.
static llvm::DISourceLanguageName GetDISourceLanguageName(const CodeGenModule &CGM)
static uint32_t getTypeAlignIfRequired(const Type *Ty, const ASTContext &Ctx)
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Setter)
static bool isDefinedInClangModule(const RecordDecl *RD)
Does a type definition exist in an imported clang module?
static void completeStandardLayoutUnionMembers(CGDebugInfo &DebugInfo, const CXXRecordDecl *RD)
static llvm::dwarf::Tag getNextQualifier(Qualifiers &Q)
static bool IsDecomposedVarDecl(VarDecl const *VD)
Returns true if VD is a a holding variable (aka a VarDecl retrieved using BindingDecl::getHoldingVar)...
static SmallString< 256 > getTypeIdentifier(const TagType *Ty, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
static bool ReferencesAnonymousEntity(ArrayRef< TemplateArgument > Args)
static llvm::dwarf::SourceLanguage GetSourceLanguage(const CodeGenModule &CGM)
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
#define CC_VLS_CASE(ABI_VLEN)
Defines the LambdaCapture class.
constexpr llvm::StringRef ClangTrapPrefix
static StringRef getTriple(const Command &Job)
#define LIST_SANITIZER_CHECKS
static const NamedDecl * getDefinition(const Decl *D)
Defines the SourceManager interface.
Defines version macros and version-related utility functions for Clang.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat],...
bool hasArrayFiller() const
APValue & getArrayInitializedElt(unsigned I)
unsigned getArrayInitializedElts() const
APValue & getArrayFiller()
unsigned getArraySize() const
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
bool getByrefLifetime(QualType Ty, Qualifiers::ObjCLifetime &Lifetime, bool &HasByrefExtendedLayout) const
Returns true, if given type has a known lifetime.
SourceManager & getSourceManager()
const ConstantArrayType * getAsConstantArrayType(QualType T) const
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, const Expr *SizeExpr, ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type.
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
QualType getBlockDescriptorType() const
Gets the struct used to keep track of the descriptor for pointer to blocks.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any.
CanQualType getCanonicalTagType(const TagDecl *TD) const
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
bool hasExtendableVFPtr() const
hasVFPtr - Does this class have a virtual function table pointer that can be extended by a derived cl...
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not.
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
Module * getModuleOrNull() const
ASTFileSignature getSignature() const
StringRef getASTFile() const
StringRef getPath() const
std::string getModuleName() const
QualType getElementType() const
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
shadow_range shadows() const
A binding in a decomposition declaration.
Expr * getBinding() const
Get the expression to which this declaration is bound.
unsigned getNumBits() const
A class which contains all the information about a particular captured value.
bool isByRef() const
Whether this is a "by ref" capture, i.e.
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
VarDecl * getVariable() const
The variable being captured.
Represents a block literal declaration, which is like an unnamed FunctionDecl.
QualType getPointeeType() const
StringRef getName(const PrintingPolicy &Policy) const
Represents a base class of a C++ class.
Represents a C++ constructor within a class.
Represents a static or instance method of a struct/union/class.
QualType getThisType() const
Return the type of the this pointer.
Represents a C++ struct/union/class.
bool isAggregate() const
Determine whether this class is an aggregate (C++ [dcl.init.aggr]), which is a class with no user-dec...
bool hasTrivialDefaultConstructor() const
Determine whether this class has a trivial default constructor (C++11 [class.ctor]p5).
bool isStandardLayout() const
Determine whether this class is standard-layout per C++ [class]p7.
llvm::iterator_range< base_class_const_iterator > base_class_const_range
specific_decl_iterator< CXXMethodDecl > method_iterator
Iterator access to method members.
bool isLambda() const
Determine whether this class describes a lambda function object.
bool needsImplicitDefaultConstructor() const
Determine if we need to declare a default constructor for this class.
capture_const_iterator captures_end() const
method_range methods() const
bool defaultedDefaultConstructorIsConstexpr() const
Determine whether a defaulted default constructor for this class would be constexpr.
method_iterator method_begin() const
Method begin iterator.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
base_class_range vbases()
bool isDynamicClass() const
const LambdaCapture * capture_const_iterator
MSInheritanceModel getMSInheritanceModel() const
Returns the inheritance model used for this record.
bool hasDefinition() const
method_iterator method_end() const
Method past-the-end iterator.
capture_const_iterator captures_begin() const
CXXRecordDecl * getDefinitionOrSelf() const
void * getAsOpaquePtr() const
Retrieve the internal representation of this canonical type.
This is an opaque type for sizes expressed in character units.
bool isPositive() const
Test whether the quantity is greater than zero.
bool isZero() const
Test whether the quantity equals zero.
CharUnits alignTo(CharUnits Align) const
Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is a multiple...
QuantityType getQuantity() const
Get the raw integer representation of this quantity.
static CharUnits fromQuantity(QuantityType Quantity)
Construct a CharUnits quantity from a raw integer type.
static CharUnits Zero()
Construct a CharUnits quantity of zero.
Represents a class template specialization, which refers to a class template with a given set of temp...
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
A scoped helper to set the current debug location to the specified location or preferred location of ...
ApplyInlineDebugLocation(CodeGenFunction &CGF, GlobalDecl InlinedFn)
Set up the CodeGenFunction's DebugInfo to produce inline locations for the function InlinedFn.
~ApplyInlineDebugLocation()
Restore everything back to the original state.
unsigned getIndex() const
CGBlockInfo - Information to generate a block literal.
unsigned CXXThisIndex
The field index of 'this' within the block, if there is one.
const BlockDecl * getBlockDecl() const
llvm::StructType * StructureType
const Capture & getCapture(const VarDecl *var) const
@ RAA_Indirect
Pass it as a pointer to temporary memory.
MangleContext & getMangleContext()
Gets the mangle context.
This class gathers all debug information during compilation and is responsible for emitting to llvm g...
void addInstToCurrentSourceAtom(llvm::Instruction *KeyInstruction, llvm::Value *Backup)
Add KeyInstruction and an optional Backup instruction to the current atom group, created using ApplyA...
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file.
void completeFunction()
Reset internal state.
void EmitGlobalAlias(const llvm::GlobalValue *GV, const GlobalDecl Decl)
Emit information about global variable alias.
void EmitLabel(const LabelDecl *D, CGBuilderTy &Builder)
Emit call to llvm.dbg.label for an label.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
void completeUnusedClass(const CXXRecordDecl &D)
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...
bool isInvalidDecl() const
llvm::iterator_range< specific_attr_iterator< T > > specific_attrs() const
SourceLocation getLocation() const
DeclContext * getDeclContext()
AccessSpecifier getAccess() const
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC).
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
const LangOptions & getLangOpts() const LLVM_READONLY
Helper to get the language options from the ASTContext.
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
bool isObjCZeroArgSelector() const
@ CXXConversionFunctionName
Selector getObjCSelector() const
Get the Objective-C selector stored in this declaration name.
bool isObjCOneArgSelector() const
NameKind getNameKind() const
Determine what kind of name this is.
bool isComplete() const
Returns true if this can be considered a complete type.
EnumDecl * getDefinitionOrSelf() const
This represents one expression.
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
Represents a member of a struct/union/class.
bool isBitField() const
Determines whether this field is a bitfield.
unsigned getFieldIndex() const
Returns the index of this field within its record, as appropriate for passing to ASTRecordLayout::get...
static InputKind getInputKindForExtension(StringRef Extension)
getInputKindForExtension - Return the appropriate input kind for a file extension.
Represents a function declaration or definition.
bool isInlined() const
Determine whether this function should be inlined, because it is either marked "inline" or "constexpr...
bool isNoReturn() const
Determines whether this function is known to be 'noreturn', through an attribute on its declaration o...
QualType getReturnType() const
ArrayRef< ParmVarDecl * > parameters() const
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
@ TK_FunctionTemplateSpecialization
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
FunctionDecl * getMostRecentDecl()
Returns the most recent (re)declaration of this declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
FunctionDecl * getDefinition()
Get the definition for this declaration.
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization,...
Represents a prototype with parameter type info, e.g.
ExceptionSpecificationType getExceptionSpecType() const
Get the kind of exception specification on this function.
unsigned getNumParams() const
QualType getParamType(unsigned i) const
ExtProtoInfo getExtProtoInfo() const
ArrayRef< QualType > getParamTypes() const
ArrayRef< QualType > param_types() const
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
FunctionType - C99 6.7.5.3 - Function Declarators.
bool getNoReturnAttr() const
Determine whether this function type includes the GNU noreturn attribute.
CallingConv getCallConv() const
QualType getReturnType() const
GlobalDecl - represents a global declaration.
GlobalDecl getCanonicalDecl() const
DynamicInitKind getDynamicInitKind() const
const Decl * getDecl() const
Describes a module import declaration, which makes the contents of the named module visible in the cu...
Represents the declaration of a label.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
clang::ObjCRuntime ObjCRuntime
bool UseTargetPathSeparator
Indicates whether to use target's platform-specific file separator when FILE macro is used and when c...
std::optional< uint32_t > getCPlusPlusLangStd() const
Returns the most applicable C++ standard-compliant language version code.
std::optional< uint32_t > getCLangStd() const
Returns the most applicable C standard-compliant language version code.
virtual void mangleCXXRTTIName(QualType T, raw_ostream &, bool NormalizeIntegers=false)=0
QualType getElementType() const
Returns type of the elements being stored in the matrix.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
Note: this can trigger extra deserialization when external AST sources are used.
QualType getPointeeType() const
Describes a module or submodule.
Module * Parent
The parent of this module.
std::string Name
The name of this module.
This represents a decl that may have a name.
NamedDecl * getUnderlyingDecl()
Looks through UsingDecls and ObjCCompatibleAliasDecls for the underlying named decl.
IdentifierInfo * getIdentifier() const
Get the identifier that names this declaration, if there is one.
StringRef getName() const
Get the name of identifier for this declaration as a StringRef.
DeclarationName getDeclName() const
Get the actual, stored name of the declaration, which may be a special name.
std::string getNameAsString() const
Get a human-readable name for the declaration, even if it is one of the special kinds of names (C++ c...
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
Appends a human-readable name for this declaration into the given stream.
void printQualifiedName(raw_ostream &OS) const
Returns a human-readable qualified name for this declaration, like A::B::i, for i being member of nam...
bool isExternallyVisible() const
Represents a C++ namespace alias.
NamespaceBaseDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
Represent a C++ namespace.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
bool isInline() const
Returns true if this is an inline namespace declaration.
ObjCImplementationDecl * getImplementation() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
ObjCMethodDecl - Represents an instance or class method declaration.
bool isDirectMethod() const
True if the method is tagged as objc_direct.
Selector getSelector() const
bool isInstanceMethod() const
ObjCInterfaceDecl * getClassInterface()
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
Represents one property declaration in an Objective-C interface.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
Represents a parameter to a function.
QualType getElementType() const
bool isIsaPointer() const
bool authenticatesNullValues() const
bool isAddressDiscriminated() const
unsigned getExtraDiscriminator() const
QualType getPointeeType() const
Represents an unpacked "presumed" location which can be presented to the user.
unsigned getColumn() const
Return the presumed column number of this location.
const char * getFilename() const
Return the presumed filename of this location.
unsigned getLine() const
Return the presumed line number of this location.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
A (possibly-)qualified type.
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
bool isNull() const
Return true if this QualType doesn't point to a type yet.
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
void * getAsOpaquePtr() const
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
The collection of all-type qualifiers we support.
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
void removeObjCLifetime()
void removeAddressSpace()
PointerAuthQualifier getPointerAuth() const
Represents a struct/union/class.
field_range fields() const
RecordDecl * getDefinition() const
Returns the RecordDecl that actually defines this struct/union/class.
specific_decl_iterator< FieldDecl > field_iterator
RecordDecl * getDefinitionOrSelf() const
bool isAnonymousStructOrUnion() const
Whether this is an anonymous struct or union.
field_iterator field_begin() const
A class that does preorder or postorder depth-first traversal on the entire Clang AST and visits each...
QualType getPointeeType() const
Scope - A scope is a transient data structure that is used while parsing the program.
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
std::string getAsString() const
Derive the full selector name (e.g.
Encodes a location in the source.
bool isValid() const
Return true if this is a valid SourceLocation object.
This class handles loading and caching of source files into memory.
FileID getFileID(SourceLocation SpellingLoc) const
Return the FileID for a SourceLocation.
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.
OptionalFileEntryRef getFileEntryRefForID(FileID FID) const
Returns the FileEntryRef for the provided FileID.
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.
CanQualType getCanonicalTypeUnqualified() const
bool isIntegerType() const
isIntegerType() does not include complex integers (a GCC extension).
const T * castAs() const
Member-template castAs<specific type>.
bool isReferenceType() const
AutoType * getContainedAutoType() const
Get the AutoType whose type will be deduced for a variable with an initializer of this type.
bool isMemberDataPointerType() const
const Type * getBaseElementTypeUnsafe() const
Get the base element type of this type, potentially discarding type qualifiers.
bool isComplexIntegerType() const
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types,...
TypeClass getTypeClass() const
const T * getAs() const
Member-template getAs<specific type>'.
bool isRecordType() const
QualType getUnderlyingType() const
TypedefNameDecl * getDecl() const
Represents a C++ using-declaration.
Represents C++ using-directive.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
Represents a C++ using-enum-declaration.
Represents a shadow declaration implicitly introduced into a scope by a (resolved) using-declaration ...
static bool hasVtableSlot(const CXXMethodDecl *MD)
Determine whether this function should be assigned a vtable slot.
ArrayRef< VTableComponent > vtable_components() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
Represents a variable declaration or definition.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
bool isStaticDataMember() const
Determines whether this is a static data member.
bool isStaticLocal() const
Returns true if a variable with function scope is a static local variable.
const Expr * getInit() const
const APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
bool isEscapingByref() const
Indicates the capture is a __block variable that is captured by a block that can potentially escape (...
unsigned getNumElements() const
QualType getElementType() const
@ Type
The l-value was considered opaque, so the alignment was determined from a type.
@ Decl
The l-value was an access to a declared entity or something equivalently strong, like the address of ...
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
const internal::VariadicDynCastAllOfMatcher< Decl, BlockDecl > blockDecl
Matches block declarations.
@ OS
Indicates that the tracking object is a descendant of a referenced-counted OSObject,...
Top level wrappers for InstallAPI frontend operations.
CanQual< Type > CanQualType
Represents a canonical, potentially-qualified type.
@ Ctor_Unified
GCC-style unified dtor.
bool isa(CodeGen::Address addr)
CustomizableOptional< FileEntryRef > OptionalFileEntryRef
if(T->getSizeExpr()) TRY_TO(TraverseStmt(const_cast< Expr * >(T -> getSizeExpr())))
@ RQ_LValue
An lvalue ref-qualifier was provided (&).
@ RQ_RValue
An rvalue ref-qualifier was provided (&&).
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
@ Module
Module linkage, which indicates that the entity can be referred to from other translation units withi...
@ Default
Set to the current date and time.
@ Result
The result type of a method or function.
const FunctionProtoType * T
bool isNoexceptExceptionSpec(ExceptionSpecificationType ESpecType)
@ Dtor_VectorDeleting
Vector deleting dtor.
@ Dtor_Unified
GCC-style unified dtor.
@ Dtor_Deleting
Deleting dtor.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
@ TSK_ExplicitInstantiationDeclaration
This template specialization was instantiated from a template due to an explicit instantiation declar...
@ TSK_Undeclared
This template specialization was formed from a template-id but has not yet been declared,...
CallingConv
CallingConv - Specifies the calling convention that a function uses.
@ Generic
not a target-specific vector type
U cast(CodeGen::Address addr)
@ Enum
The "enum" keyword introduces the elaborated-type-specifier.
@ CXXThis
Parameter for C++ 'this' argument.
@ ObjCSelf
Parameter for Objective-C 'self' argument.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number,...
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 SplitTemplateClosers
Whether nested templates must be closed like 'a<b<c> >' rather than 'a<b<c>>'.
unsigned UseEnumerators
Whether to print enumerator non-type template parameters with a matching enumerator name or via cast ...
unsigned SuppressInlineNamespace
Suppress printing parts of scope specifiers that correspond to inline namespaces.
const PrintingCallbacks * Callbacks
Callbacks to use to allow the behavior of printing to be customized.