34 #include "llvm/ADT/SmallVector.h"
35 #include "llvm/ADT/StringExtras.h"
36 #include "llvm/IR/Constants.h"
37 #include "llvm/IR/DataLayout.h"
38 #include "llvm/IR/DerivedTypes.h"
39 #include "llvm/IR/Instructions.h"
40 #include "llvm/IR/Intrinsics.h"
41 #include "llvm/IR/Module.h"
42 #include "llvm/Support/FileSystem.h"
43 #include "llvm/Support/Path.h"
44 using namespace clang;
45 using namespace clang::CodeGen;
48 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
49 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
50 DBuilder(CGM.getModule()) {
52 DebugPrefixMap[KV.first] = KV.second;
57 assert(LexicalBlockStack.empty() &&
58 "Region stack mismatch, stack not empty!");
64 init(TemporaryLocation);
71 init(TemporaryLocation, DefaultToEmpty);
75 bool DefaultToEmpty) {
82 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
83 if (TemporaryLocation.
isValid()) {
84 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
89 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
94 assert(!DI->LexicalBlockStack.empty());
95 CGF->
Builder.SetCurrentDebugLocation(
96 llvm::DebugLoc::get(0, 0, DI->LexicalBlockStack.back()));
110 OriginalLocation = CGF.
Builder.getCurrentDebugLocation();
112 CGF.
Builder.SetCurrentDebugLocation(std::move(Loc));
119 CGF->
Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
132 if (LexicalBlockStack.empty())
136 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
139 if (PCLoc.isInvalid() ||
Scope->getFilename() == PCLoc.getFilename())
142 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
143 LexicalBlockStack.pop_back();
144 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
145 LBF->getScope(), getOrCreateFile(CurLoc)));
146 }
else if (isa<llvm::DILexicalBlock>(
Scope) ||
147 isa<llvm::DISubprogram>(
Scope)) {
148 LexicalBlockStack.pop_back();
149 LexicalBlockStack.emplace_back(
150 DBuilder.createLexicalBlockFile(
Scope, getOrCreateFile(CurLoc)));
154 llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
155 llvm::DIScope *Mod = getParentModuleOrNull(D);
156 return getContextDescriptor(cast<Decl>(D->getDeclContext()),
160 llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *
Context,
161 llvm::DIScope *Default) {
165 auto I = RegionMap.find(Context);
166 if (
I != RegionMap.end()) {
167 llvm::Metadata *V =
I->second;
168 return dyn_cast_or_null<llvm::DIScope>(V);
172 if (
const auto *NSDecl = dyn_cast<NamespaceDecl>(Context))
173 return getOrCreateNameSpace(NSDecl);
175 if (
const auto *RDecl = dyn_cast<RecordDecl>(Context))
176 if (!RDecl->isDependentType())
178 getOrCreateMainFile());
182 StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD) {
183 assert(FD &&
"Invalid FunctionDecl!");
197 if (!Info && FII && !UseQualifiedName)
201 llvm::raw_svector_ostream OS(NS);
204 if (!UseQualifiedName)
217 return internString(OS.str());
220 StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
221 SmallString<256> MethodName;
222 llvm::raw_svector_ostream OS(MethodName);
225 if (
const auto *OID = dyn_cast<ObjCImplementationDecl>(DC)) {
227 }
else if (
const auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) {
228 OS << OID->getName();
229 }
else if (
const auto *OC = dyn_cast<ObjCCategoryDecl>(DC)) {
230 if (OC->IsClassExtension()) {
231 OS << OC->getClassInterface()->getName();
233 OS << OC->getIdentifier()->getNameStart() <<
'('
234 << OC->getIdentifier()->getNameStart() <<
')';
236 }
else if (
const auto *OCD = dyn_cast<ObjCCategoryImplDecl>(DC)) {
237 OS << ((
const NamedDecl *)OCD)->getIdentifier()->getNameStart() <<
'('
238 << OCD->getIdentifier()->getNameStart() <<
')';
239 }
else if (isa<ObjCProtocolDecl>(DC)) {
243 cast<ObjCObjectPointerType>(SelfDecl->getType())->getPointeeType();
249 return internString(OS.str());
252 StringRef CGDebugInfo::getSelectorName(
Selector S) {
256 StringRef CGDebugInfo::getClassName(
const RecordDecl *RD) {
257 if (isa<ClassTemplateSpecializationDecl>(RD)) {
258 SmallString<128>
Name;
259 llvm::raw_svector_ostream OS(Name);
264 return internString(Name);
270 return II->getName();
276 assert(RD->getDeclContext() == D->getDeclContext() &&
277 "Typedef should not be in another decl context!");
278 assert(D->getDeclName().getAsIdentifierInfo() &&
279 "Typedef was not named!");
280 return D->getDeclName().getAsIdentifierInfo()->getName();
290 Name = DD->getName();
295 Name = TND->getName();
298 SmallString<256> UnnamedType(
"<unnamed-type-");
301 return internString(UnnamedType);
312 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
313 remapDIPath(TheCU->getDirectory()));
320 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
321 remapDIPath(TheCU->getDirectory()));
325 auto it = DIFileCache.find(fname);
327 if (it != DIFileCache.end()) {
329 if (llvm::Metadata *V = it->second)
330 return cast<llvm::DIFile>(V);
333 llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.
getFilename()),
334 remapDIPath(getCurrentDirname()));
336 DIFileCache[fname].reset(F);
340 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
341 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
342 remapDIPath(TheCU->getDirectory()));
345 std::string CGDebugInfo::remapDIPath(StringRef Path)
const {
346 for (
const auto &Entry : DebugPrefixMap)
347 if (Path.startswith(Entry.first))
348 return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
360 unsigned CGDebugInfo::getColumnNumber(
SourceLocation Loc,
bool Force) {
373 StringRef CGDebugInfo::getCurrentDirname() {
377 if (!CWDName.empty())
379 SmallString<256> CWD;
380 llvm::sys::fs::current_path(CWD);
381 return CWDName = internString(CWD);
384 void CGDebugInfo::CreateCompileUnit() {
396 if (MainFileName.empty())
397 MainFileName =
"<stdin>";
403 std::string MainFileDir;
405 MainFileDir = remapDIPath(MainFile->getDir()->getName());
406 if (MainFileDir !=
".") {
408 llvm::sys::path::append(MainFileDirSS, MainFileName);
409 MainFileName = MainFileDirSS.str();
413 llvm::dwarf::SourceLanguage LangTag;
417 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
419 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
420 }
else if (LO.ObjC1) {
421 LangTag = llvm::dwarf::DW_LANG_ObjC;
422 }
else if (LO.RenderScript) {
423 LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
425 LangTag = llvm::dwarf::DW_LANG_C99;
427 LangTag = llvm::dwarf::DW_LANG_C89;
433 unsigned RuntimeVers = 0;
437 llvm::DICompileUnit::DebugEmissionKind EmissionKind;
441 EmissionKind = llvm::DICompileUnit::NoDebug;
444 EmissionKind = llvm::DICompileUnit::LineTablesOnly;
448 EmissionKind = llvm::DICompileUnit::FullDebug;
454 TheCU = DBuilder.createCompileUnit(
455 LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
460 llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
464 #define BUILTIN_TYPE(Id, SingletonId)
465 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
466 #include "clang/AST/BuiltinTypes.def"
467 case BuiltinType::Dependent:
468 llvm_unreachable(
"Unexpected builtin type");
469 case BuiltinType::NullPtr:
470 return DBuilder.createNullPtrType();
471 case BuiltinType::Void:
473 case BuiltinType::ObjCClass:
475 ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
477 getOrCreateMainFile(), 0);
479 case BuiltinType::ObjCId: {
489 ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
491 getOrCreateMainFile(), 0);
495 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
498 DBuilder.createStructType(TheCU,
"objc_object", getOrCreateMainFile(),
499 0, 0, 0, 0,
nullptr, llvm::DINodeArray());
501 DBuilder.replaceArrays(
503 DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
504 ObjTy,
"isa", getOrCreateMainFile(), 0, Size, 0, 0, 0, ISATy)));
507 case BuiltinType::ObjCSel: {
509 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
510 "objc_selector", TheCU,
511 getOrCreateMainFile(), 0);
515 #define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \
516 case BuiltinType::Id: \
517 return getOrCreateStructPtrType("opencl_" #ImgType "_" #Suffix "_t", \
519 #include "clang/Basic/OpenCLImageTypes.def"
520 case BuiltinType::OCLSampler:
521 return DBuilder.createBasicType(
524 case BuiltinType::OCLEvent:
525 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
526 case BuiltinType::OCLClkEvent:
527 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
528 case BuiltinType::OCLQueue:
529 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
530 case BuiltinType::OCLNDRange:
531 return getOrCreateStructPtrType(
"opencl_ndrange_t", OCLNDRangeDITy);
532 case BuiltinType::OCLReserveID:
533 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
535 case BuiltinType::UChar:
536 case BuiltinType::Char_U:
537 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
539 case BuiltinType::Char_S:
540 case BuiltinType::SChar:
541 Encoding = llvm::dwarf::DW_ATE_signed_char;
543 case BuiltinType::Char16:
544 case BuiltinType::Char32:
545 Encoding = llvm::dwarf::DW_ATE_UTF;
547 case BuiltinType::UShort:
548 case BuiltinType::UInt:
549 case BuiltinType::UInt128:
550 case BuiltinType::ULong:
551 case BuiltinType::WChar_U:
552 case BuiltinType::ULongLong:
553 Encoding = llvm::dwarf::DW_ATE_unsigned;
555 case BuiltinType::Short:
556 case BuiltinType::Int:
557 case BuiltinType::Int128:
558 case BuiltinType::Long:
559 case BuiltinType::WChar_S:
560 case BuiltinType::LongLong:
561 Encoding = llvm::dwarf::DW_ATE_signed;
563 case BuiltinType::Bool:
564 Encoding = llvm::dwarf::DW_ATE_boolean;
566 case BuiltinType::Half:
567 case BuiltinType::Float:
568 case BuiltinType::LongDouble:
569 case BuiltinType::Float128:
570 case BuiltinType::Double:
576 Encoding = llvm::dwarf::DW_ATE_float;
581 case BuiltinType::Long:
584 case BuiltinType::LongLong:
585 BTName =
"long long int";
587 case BuiltinType::ULong:
588 BTName =
"long unsigned int";
590 case BuiltinType::ULongLong:
591 BTName =
"long long unsigned int";
600 return DBuilder.createBasicType(BTName, Size, Align, Encoding);
603 llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
605 llvm::dwarf::TypeKind Encoding = llvm::dwarf::DW_ATE_complex_float;
607 Encoding = llvm::dwarf::DW_ATE_lo_user;
611 return DBuilder.createBasicType(
"complex", Size, Align, Encoding);
614 llvm::DIType *CGDebugInfo::CreateQualifiedType(
QualType Ty,
615 llvm::DIFile *Unit) {
626 llvm::dwarf::Tag Tag;
628 Tag = llvm::dwarf::DW_TAG_const_type;
631 Tag = llvm::dwarf::DW_TAG_volatile_type;
634 Tag = llvm::dwarf::DW_TAG_restrict_type;
637 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
638 return getOrCreateType(
QualType(T, 0), Unit);
645 return DBuilder.createQualifiedType(Tag, FromTy);
649 llvm::DIFile *Unit) {
657 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
661 llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
662 llvm::DIFile *Unit) {
663 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
669 switch (TheCU->getSourceLanguage()) {
670 case llvm::dwarf::DW_LANG_C_plus_plus:
672 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
673 return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
683 llvm::DICompileUnit *TheCU) {
684 SmallString<256> FullName;
692 llvm::raw_svector_ostream Out(FullName);
699 llvm::dwarf::Tag Tag;
701 Tag = llvm::dwarf::DW_TAG_structure_type;
703 Tag = llvm::dwarf::DW_TAG_union_type;
708 Tag = llvm::dwarf::DW_TAG_class_type;
713 llvm::DICompositeType *
714 CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
715 llvm::DIScope *Ctx) {
718 return cast<llvm::DICompositeType>(T);
719 llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
720 unsigned Line = getLineNumber(RD->getLocation());
721 StringRef RDName = getClassName(RD);
734 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
736 llvm::DINode::FlagFwdDecl, FullName);
737 ReplaceMap.emplace_back(
738 std::piecewise_construct, std::make_tuple(Ty),
739 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
743 llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
746 llvm::DIFile *Unit) {
754 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
755 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
756 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
759 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
763 llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
764 llvm::DIType *&
Cache) {
767 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
768 TheCU, getOrCreateMainFile(), 0);
770 Cache = DBuilder.createPointerType(Cache, Size);
775 llvm::DIFile *Unit) {
778 uint64_t FieldSize, FieldOffset;
780 llvm::DINodeArray Elements;
784 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
785 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
787 Elements = DBuilder.getOrCreateArray(EltTys);
790 unsigned Flags = llvm::DINode::FlagAppleBlock;
794 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, LineNo,
795 FieldOffset, 0, Flags,
nullptr, Elements);
800 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
804 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
806 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
807 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
809 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
814 EltTys.push_back(DBuilder.createMemberType(Unit,
"__descriptor",
nullptr, LineNo,
815 FieldSize, FieldAlign, FieldOffset,
818 FieldOffset += FieldSize;
819 Elements = DBuilder.getOrCreateArray(EltTys);
826 DBuilder.createStructType(Unit,
"",
nullptr, LineNo,
827 FieldOffset, 0, Flags,
nullptr, Elements);
829 return DBuilder.createPointerType(EltTy, Size);
833 llvm::DIFile *Unit) {
834 assert(Ty->isTypeAlias());
835 llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
838 llvm::raw_svector_ostream OS(NS);
843 OS, Ty->template_arguments(),
846 auto *AliasDecl = cast<TypeAliasTemplateDecl>(
847 Ty->getTemplateName().getAsTemplateDecl())->getTemplatedDecl();
850 return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
852 getDeclContextDescriptor(AliasDecl));
855 llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
856 llvm::DIFile *Unit) {
862 return DBuilder.createTypedef(
864 Ty->
getDecl()->
getName(), getOrCreateFile(Loc), getLineNumber(Loc),
865 getDeclContextDescriptor(Ty->
getDecl()));
875 return llvm::dwarf::DW_CC_BORLAND_stdcall;
877 return llvm::dwarf::DW_CC_BORLAND_msfastcall;
879 return llvm::dwarf::DW_CC_BORLAND_thiscall;
881 return llvm::dwarf::DW_CC_LLVM_vectorcall;
883 return llvm::dwarf::DW_CC_BORLAND_pascal;
901 llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
902 llvm::DIFile *Unit) {
906 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
910 if (isa<FunctionNoProtoType>(Ty))
911 EltTys.push_back(DBuilder.createUnspecifiedParameter());
912 else if (
const auto *FPT = dyn_cast<FunctionProtoType>(Ty)) {
913 for (
const QualType &ParamType : FPT->param_types())
914 EltTys.push_back(getOrCreateType(ParamType, Unit));
915 if (FPT->isVariadic())
916 EltTys.push_back(DBuilder.createUnspecifiedParameter());
919 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
920 return DBuilder.createSubroutineType(EltTypeArray, 0,
934 if (Access == Default)
939 return llvm::DINode::FlagPrivate;
941 return llvm::DINode::FlagProtected;
943 return llvm::DINode::FlagPublic;
947 llvm_unreachable(
"unexpected access enumerator");
950 llvm::DIType *CGDebugInfo::createBitFieldType(
const FieldDecl *BitFieldDecl,
951 llvm::DIScope *RecordTy,
953 StringRef Name = BitFieldDecl->
getName();
956 llvm::DIFile *VUnit = getOrCreateFile(Loc);
957 llvm::DIType *DebugType = getOrCreateType(Ty, VUnit);
960 llvm::DIFile *File = getOrCreateFile(Loc);
961 unsigned Line = getLineNumber(Loc);
965 uint64_t SizeInBits = BitFieldInfo.
Size;
966 assert(SizeInBits > 0 &&
"found named 0-width bitfield");
968 uint64_t StorageOffsetInBits =
970 uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.
Offset;
971 unsigned Flags =
getAccessFlag(BitFieldDecl->getAccess(), RD);
972 return DBuilder.createBitFieldMemberType(
973 RecordTy, Name, File, Line, SizeInBits, AlignInBits, OffsetInBits,
974 StorageOffsetInBits, Flags, DebugType);
980 llvm::DIFile *tunit, llvm::DIScope *scope,
982 llvm::DIType *debugType = getOrCreateType(type, tunit);
985 llvm::DIFile *file = getOrCreateFile(loc);
986 unsigned line = getLineNumber(loc);
988 uint64_t SizeInBits = 0;
989 unsigned AlignInBits = 0;
992 SizeInBits = TI.
Width;
993 AlignInBits = TI.
Align;
997 return DBuilder.createMemberType(scope, name, file, line, SizeInBits,
998 AlignInBits, offsetInBits, flags, debugType);
1001 void CGDebugInfo::CollectRecordLambdaFields(
1003 llvm::DIType *RecordTy) {
1009 unsigned fieldno = 0;
1012 I !=
E; ++
I, ++Field, ++fieldno) {
1016 assert(!Field->isBitField() &&
"lambdas don't have bitfield members!");
1018 StringRef VName = V->
getName();
1019 llvm::DIFile *VUnit = getOrCreateFile(Loc);
1020 llvm::DIType *FieldType = createFieldType(
1021 VName, Field->getType(), Loc, Field->getAccess(),
1023 elements.push_back(FieldType);
1030 llvm::DIFile *VUnit = getOrCreateFile(f->getLocation());
1032 llvm::DIType *fieldType = createFieldType(
1033 "this", type, f->getLocation(), f->getAccess(),
1036 elements.push_back(fieldType);
1041 llvm::DIDerivedType *
1042 CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
1047 llvm::DIFile *VUnit = getOrCreateFile(Var->getLocation());
1048 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
1050 unsigned LineNumber = getLineNumber(Var->getLocation());
1051 StringRef VName = Var->
getName();
1052 llvm::Constant *C =
nullptr;
1064 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
1065 RecordTy, VName, VUnit, LineNumber, VTy, Flags, C);
1070 void CGDebugInfo::CollectRecordNormalField(
1071 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
1074 StringRef name = field->
getName();
1081 llvm::DIType *FieldType;
1083 FieldType = createBitFieldType(field, RecordTy, RD);
1086 createFieldType(name, type, field->getLocation(), field->getAccess(),
1087 OffsetInBits, tunit, RecordTy, RD);
1090 elements.push_back(FieldType);
1093 void CGDebugInfo::CollectRecordFields(
1094 const RecordDecl *record, llvm::DIFile *tunit,
1096 llvm::DICompositeType *RecordTy) {
1099 if (CXXDecl && CXXDecl->
isLambda())
1100 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
1105 unsigned fieldNo = 0;
1109 for (
const auto *
I : record->
decls())
1110 if (
const auto *V = dyn_cast<VarDecl>(
I)) {
1111 if (V->hasAttr<NoDebugAttr>())
1114 auto MI = StaticDataMemberCache.find(V->getCanonicalDecl());
1115 if (MI != StaticDataMemberCache.end()) {
1116 assert(MI->second &&
1117 "Static data member declaration should still exist");
1118 elements.push_back(MI->second);
1120 auto Field = CreateRecordStaticField(V, RecordTy, record);
1121 elements.push_back(Field);
1123 }
else if (
const auto *field = dyn_cast<FieldDecl>(
I)) {
1124 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
1125 elements, RecordTy, record);
1133 llvm::DISubroutineType *
1134 CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *Method,
1135 llvm::DIFile *Unit) {
1138 return cast_or_null<llvm::DISubroutineType>(
1139 getOrCreateType(
QualType(Func, 0), Unit));
1144 llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
1147 llvm::DITypeRefArray Args(
1148 cast<llvm::DISubroutineType>(getOrCreateType(
QualType(Func, 0), Unit))
1150 assert(Args.size() &&
"Invalid number of arguments!");
1155 Elts.push_back(Args[0]);
1159 if (isa<ClassTemplateSpecializationDecl>(RD)) {
1161 const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
1166 llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
1167 llvm::DIType *ThisPtrType =
1168 DBuilder.createPointerType(PointeeType, Size, Align);
1173 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1174 Elts.push_back(ThisPtrType);
1176 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
1178 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1179 Elts.push_back(ThisPtrType);
1183 for (
unsigned i = 1, e = Args.size(); i != e; ++i)
1184 Elts.push_back(Args[i]);
1186 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
1190 Flags |= llvm::DINode::FlagLValueReference;
1192 Flags |= llvm::DINode::FlagRValueReference;
1194 return DBuilder.createSubroutineType(EltTypeArray, Flags,
1201 if (
const auto *NRD = dyn_cast<CXXRecordDecl>(RD->getDeclContext()))
1203 if (isa<FunctionDecl>(RD->getDeclContext()))
1208 llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
1209 const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
1211 isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
1213 StringRef MethodName = getFunctionName(Method);
1214 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
1218 StringRef MethodLinkageName;
1228 llvm::DIFile *MethodDefUnit =
nullptr;
1229 unsigned MethodLine = 0;
1230 if (!Method->isImplicit()) {
1231 MethodDefUnit = getOrCreateFile(Method->getLocation());
1232 MethodLine = getLineNumber(Method->getLocation());
1236 llvm::DIType *ContainingType =
nullptr;
1237 unsigned Virtuality = 0;
1238 unsigned VIndex = 0;
1244 Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual;
1246 Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual;
1251 if (!isa<CXXDestructorDecl>(Method))
1268 Flags |= llvm::DINode::FlagIntroducedVirtual;
1277 ContainingType = RecordTy;
1280 if (Method->isImplicit())
1281 Flags |= llvm::DINode::FlagArtificial;
1283 if (
const auto *CXXC = dyn_cast<CXXConstructorDecl>(Method)) {
1284 if (CXXC->isExplicit())
1285 Flags |= llvm::DINode::FlagExplicit;
1286 }
else if (
const auto *CXXC = dyn_cast<CXXConversionDecl>(Method)) {
1287 if (CXXC->isExplicit())
1288 Flags |= llvm::DINode::FlagExplicit;
1291 Flags |= llvm::DINode::FlagPrototyped;
1293 Flags |= llvm::DINode::FlagLValueReference;
1295 Flags |= llvm::DINode::FlagRValueReference;
1297 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
1298 llvm::DISubprogram *SP = DBuilder.createMethod(
1299 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
1300 MethodTy,
false,
false, Virtuality,
1301 VIndex, ThisAdjustment, ContainingType, Flags, CGM.
getLangOpts().Optimize,
1302 TParamsArray.get());
1309 void CGDebugInfo::CollectCXXMemberFunctions(
1316 for (
const auto *
I : RD->
decls()) {
1328 if (!Method || Method->isImplicit() || Method->hasAttr<NoDebugAttr>())
1341 EltTys.push_back(MI == SPCache.end()
1342 ? CreateCXXMemberFunction(Method, Unit, RecordTy)
1343 : static_cast<llvm::Metadata *>(MI->second));
1347 void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1349 llvm::DIType *RecordTy) {
1351 for (
const auto &BI : RD->
bases()) {
1352 unsigned BFlags = 0;
1353 uint64_t BaseOffset;
1356 cast<CXXRecordDecl>(BI.getType()->getAs<
RecordType>()->getDecl());
1358 if (BI.isVirtual()) {
1371 BFlags = llvm::DINode::FlagVirtual;
1378 llvm::DIType *DTy = DBuilder.createInheritance(
1379 RecordTy, getOrCreateType(BI.getType(), Unit), BaseOffset, BFlags);
1380 EltTys.push_back(DTy);
1387 llvm::DIFile *Unit) {
1389 for (
unsigned i = 0, e = TAList.size(); i != e; ++i) {
1396 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
1397 TemplateParams.push_back(
1398 DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
1402 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1409 llvm::DIType *TTy = getOrCreateType(T, Unit);
1410 llvm::Constant *V =
nullptr;
1414 if (
const auto *VD = dyn_cast<VarDecl>(D))
1418 else if ((MD = dyn_cast<CXXMethodDecl>(D)) && MD->
isInstance())
1420 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1424 else if (
const auto *MPT = dyn_cast<MemberPointerType>(T.
getTypePtr())) {
1433 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1435 cast_or_null<llvm::Constant>(V->stripPointerCasts())));
1439 llvm::DIType *TTy = getOrCreateType(T, Unit);
1440 llvm::Constant *V =
nullptr;
1443 if (
const auto *MPT = dyn_cast<MemberPointerType>(T.
getTypePtr()))
1449 if (MPT->isMemberDataPointer())
1452 V = llvm::ConstantInt::get(CGM.
Int8Ty, 0);
1453 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1454 TheCU, Name, TTy, V));
1457 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
1458 TheCU, Name,
nullptr,
1462 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
1463 TheCU, Name,
nullptr,
1472 assert(V &&
"Expression in template argument isn't constant");
1473 llvm::DIType *TTy = getOrCreateType(T, Unit);
1474 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1475 TheCU, Name, TTy, V->stripPointerCasts()));
1481 "These argument types shouldn't exist in concrete types");
1484 return DBuilder.getOrCreateArray(TemplateParams);
1488 CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
1489 llvm::DIFile *Unit) {
1495 return CollectTemplateParams(
1498 return llvm::DINodeArray();
1501 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
1508 return CollectTemplateParams(TPList, TAList.
asArray(), Unit);
1511 llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
1513 return VTablePtrType;
1518 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
1519 llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
1520 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
1522 llvm::DIType *vtbl_ptr_type =
1523 DBuilder.createPointerType(SubTy, Size, 0,
"__vtbl_ptr_type");
1524 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
1525 return VTablePtrType;
1528 StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
1533 void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1546 llvm::DIType *VPTR = DBuilder.createMemberType(
1547 Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
1548 llvm::DINode::FlagArtificial, getOrCreateVTablePtrType(Unit));
1549 EltTys.push_back(VPTR);
1555 llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
1567 assert(!D.
isNull() &&
"null type");
1568 llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
1569 assert(T &&
"could not create debug info for type");
1580 auto I = TypeCache.find(TyPtr);
1581 if (
I == TypeCache.end() || !cast<llvm::DIType>(
I->second)->isForwardDecl())
1583 llvm::DIType *Res = CreateTypeDefinition(Ty->
castAs<
EnumType>());
1584 assert(!Res->isForwardDecl());
1585 TypeCache[TyPtr].reset(Res);
1598 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
1602 if (DebugTypeExtRefs && RD->isFromASTFile())
1606 llvm::DIType *T = getTypeOrNull(Ty);
1607 if (T && T->isForwardDecl())
1616 auto I = TypeCache.find(TyPtr);
1617 if (
I != TypeCache.end() && !cast<llvm::DIType>(
I->second)->isForwardDecl())
1620 assert(!Res->isForwardDecl());
1621 TypeCache[TyPtr].reset(Res);
1628 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
1636 if (!RD || !RD->isFromASTFile())
1640 if (
auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD)) {
1660 if (!LangOpts.CPlusPlus)
1675 if (
const auto *SD = dyn_cast<ClassTemplateSpecializationDecl>(RD))
1676 Spec = SD->getSpecializationKind();
1686 llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
1688 llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
1692 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
1696 return CreateTypeDefinition(Ty);
1699 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
1703 llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
1711 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
1717 if (
const auto *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
1718 CollectContainingType(CXXDecl, FwdDecl);
1721 LexicalBlockStack.emplace_back(&*FwdDecl);
1722 RegionMap[Ty->
getDecl()].reset(FwdDecl);
1734 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
1735 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
1739 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
1741 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
1743 LexicalBlockStack.pop_back();
1744 RegionMap.erase(Ty->
getDecl());
1746 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
1747 DBuilder.replaceArrays(FwdDecl, Elements);
1749 if (FwdDecl->isTemporary())
1751 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
1753 RegionMap[Ty->
getDecl()].reset(FwdDecl);
1758 llvm::DIFile *Unit) {
1788 llvm::DIFile *Unit) {
1796 if (DebugTypeExtRefs && ID->isFromASTFile() && ID->
getDefinition() &&
1798 return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
1800 getDeclContextDescriptor(ID), Unit, 0);
1803 llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
1804 unsigned Line = getLineNumber(ID->getLocation());
1806 static_cast<llvm::dwarf::SourceLanguage
>(TheCU->getSourceLanguage());
1812 llvm::DIScope *Mod = getParentModuleOrNull(ID);
1813 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
1814 llvm::dwarf::DW_TAG_structure_type, ID->
getName(), Mod ? Mod : TheCU,
1815 DefUnit,
Line, RuntimeLang);
1816 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
1820 return CreateTypeDefinition(Ty, Unit);
1825 bool CreateSkeletonCU) {
1830 auto ModRef = ModuleCache.find(M);
1831 if (ModRef != ModuleCache.end())
1832 return cast<llvm::DIModule>(ModRef->second);
1835 SmallString<128> ConfigMacros;
1837 llvm::raw_svector_ostream OS(ConfigMacros);
1841 for (
auto &M : PPOpts.Macros) {
1844 const std::string &
Macro = M.first;
1845 bool Undef = M.second;
1846 OS <<
"\"-" << (Undef ?
'U' :
'D');
1847 for (
char c : Macro)
1849 case '\\' : OS <<
"\\\\";
break;
1850 case '"' : OS <<
"\\\"";
break;
1857 bool IsRootModule = M ? !M->
Parent :
true;
1858 if (CreateSkeletonCU && IsRootModule) {
1863 DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.
getModuleName(),
1864 Mod.
getPath(), TheCU->getProducer(),
true,
1866 llvm::DICompileUnit::FullDebug, Signature);
1869 llvm::DIModule *Parent =
1870 IsRootModule ?
nullptr
1871 : getOrCreateModuleRef(
1874 llvm::DIModule *DIMod =
1875 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
1877 ModuleCache[M].reset(DIMod);
1882 llvm::DIFile *Unit) {
1884 llvm::DIFile *DefUnit = getOrCreateFile(ID->getLocation());
1885 unsigned Line = getLineNumber(ID->getLocation());
1886 unsigned RuntimeLang = TheCU->getSourceLanguage();
1894 Flags |= llvm::DINode::FlagObjcClassComplete;
1896 llvm::DIScope *Mod = getParentModuleOrNull(ID);
1897 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
1898 Mod ? Mod : Unit, ID->
getName(), DefUnit,
Line, Size, Align, Flags,
1899 nullptr, llvm::DINodeArray(), RuntimeLang);
1902 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
1905 LexicalBlockStack.emplace_back(RealDecl);
1906 RegionMap[Ty->
getDecl()].reset(RealDecl);
1913 llvm::DIType *SClassTy =
1918 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0);
1919 EltTys.push_back(InhTag);
1925 llvm::DIFile *PUnit = getOrCreateFile(Loc);
1926 unsigned PLine = getLineNumber(Loc);
1929 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
1930 PD->getName(), PUnit, PLine,
1932 : getSelectorName(PD->getGetterName()),
1934 : getSelectorName(PD->getSetterName()),
1935 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
1936 EltTys.push_back(PropertyNode);
1939 llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
1941 for (
auto *PD : ClassExt->properties()) {
1942 PropertySet.insert(PD->getIdentifier());
1948 if (!PropertySet.insert(PD->getIdentifier()).second)
1955 unsigned FieldNo = 0;
1958 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
1962 StringRef FieldName = Field->getName();
1965 if (FieldName.empty())
1969 llvm::DIFile *FieldDefUnit = getOrCreateFile(Field->getLocation());
1970 unsigned FieldLine = getLineNumber(Field->getLocation());
1972 uint64_t FieldSize = 0;
1973 unsigned FieldAlign = 0;
1975 if (!FType->isIncompleteArrayType()) {
1978 FieldSize = Field->isBitField()
1984 uint64_t FieldOffset;
1989 if (Field->isBitField()) {
2002 Flags = llvm::DINode::FlagProtected;
2004 Flags = llvm::DINode::FlagPrivate;
2006 Flags = llvm::DINode::FlagPublic;
2008 llvm::MDNode *PropertyNode =
nullptr;
2011 ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
2014 llvm::DIFile *PUnit = getOrCreateFile(Loc);
2015 unsigned PLine = getLineNumber(Loc);
2018 PropertyNode = DBuilder.createObjCProperty(
2019 PD->getName(), PUnit, PLine,
2021 PD->getGetterName()),
2023 PD->getSetterName()),
2024 PD->getPropertyAttributes(),
2025 getOrCreateType(PD->getType(), PUnit));
2029 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
2030 FieldSize, FieldAlign, FieldOffset, Flags,
2031 FieldTy, PropertyNode);
2032 EltTys.push_back(FieldTy);
2035 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2036 DBuilder.replaceArrays(RealDecl, Elements);
2038 LexicalBlockStack.pop_back();
2042 llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
2043 llvm::DIFile *Unit) {
2044 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
2051 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(0, Count);
2052 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
2057 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
2060 llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
2065 if (
const auto *VAT = dyn_cast<VariableArrayType>(Ty)) {
2089 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
2098 if (
const auto *CAT = dyn_cast<ConstantArrayType>(Ty))
2099 Count = CAT->getSize().getZExtValue();
2102 Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
2106 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
2108 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
2113 llvm::DIFile *Unit) {
2114 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
2119 llvm::DIFile *Unit) {
2120 return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
2135 case MSInheritanceAttr::Keyword_single_inheritance:
2136 Flags |= llvm::DINode::FlagSingleInheritance;
2138 case MSInheritanceAttr::Keyword_multiple_inheritance:
2139 Flags |= llvm::DINode::FlagMultipleInheritance;
2141 case MSInheritanceAttr::Keyword_virtual_inheritance:
2142 Flags |= llvm::DINode::FlagVirtualInheritance;
2144 case MSInheritanceAttr::Keyword_unspecified_inheritance:
2152 return DBuilder.createMemberPointerType(
2158 return DBuilder.createMemberPointerType(
2162 ClassType, Size, 0, Flags);
2165 llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
2171 llvm::DIType* CGDebugInfo::CreateType(
const PipeType *Ty,
2176 llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
2188 bool isImportedFromModule =
2189 DebugTypeExtRefs && ED->isFromASTFile() && ED->
getDefinition();
2200 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
2201 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
2202 llvm::TempDIScope TmpContext(DBuilder.createReplaceableCompositeType(
2203 llvm::dwarf::DW_TAG_enumeration_type,
"", TheCU, DefUnit, 0));
2205 unsigned Line = getLineNumber(ED->getLocation());
2206 StringRef EDName = ED->
getName();
2207 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
2208 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
2209 0, Size, Align, llvm::DINode::FlagFwdDecl, FullName);
2211 ReplaceMap.emplace_back(
2212 std::piecewise_construct, std::make_tuple(Ty),
2213 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
2217 return CreateTypeDefinition(Ty);
2220 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
2235 Enumerators.push_back(DBuilder.createEnumerator(
2236 Enum->getName(),
Enum->getInitVal().getSExtValue()));
2240 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
2242 llvm::DIFile *DefUnit = getOrCreateFile(ED->getLocation());
2243 unsigned Line = getLineNumber(ED->getLocation());
2244 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
2245 llvm::DIType *ClassTy =
2247 return DBuilder.createEnumerationType(EnumContext, ED->
getName(), DefUnit,
2248 Line, Size, Align, EltArray, ClassTy,
2259 Quals += InnerQuals;
2264 case Type::TemplateSpecialization: {
2265 const auto *Spec = cast<TemplateSpecializationType>(T);
2266 if (Spec->isTypeAlias())
2268 T = Spec->desugar();
2271 case Type::TypeOfExpr:
2272 T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
2277 case Type::Decltype:
2280 case Type::UnaryTransform:
2283 case Type::Attributed:
2284 T = cast<AttributedType>(T)->getEquivalentType();
2286 case Type::Elaborated:
2287 T = cast<ElaboratedType>(T)->getNamedType();
2290 T = cast<ParenType>(T)->getInnerType();
2292 case Type::SubstTemplateTypeParm:
2293 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
2296 QualType DT = cast<AutoType>(T)->getDeducedType();
2297 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
2302 assert(T != LastT &&
"Type unwrapping failed to unwrap!");
2307 llvm::DIType *CGDebugInfo::getTypeOrNull(
QualType Ty) {
2313 if (it != TypeCache.end()) {
2315 if (llvm::Metadata *V = it->second)
2316 return cast<llvm::DIType>(V);
2333 llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
2340 if (
auto *T = getTypeOrNull(Ty))
2343 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
2347 TypeCache[TyPtr].reset(Res);
2352 llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
2354 if (isa<RecordDecl>(D) && !cast<RecordDecl>(D)->
getDefinition())
2356 if (DebugTypeExtRefs && D->isFromASTFile()) {
2359 auto Idx = D->getOwningModuleID();
2360 auto Info = Reader->getSourceDescriptor(Idx);
2362 return getOrCreateModuleRef(*Info,
true);
2363 }
else if (ClangModuleMap) {
2378 return getOrCreateModuleRef(Info,
false);
2381 return getOrCreateModuleRef(PCHDescriptor,
false);
2388 llvm::DIType *CGDebugInfo::CreateTypeNode(
QualType Ty, llvm::DIFile *Unit) {
2391 return CreateQualifiedType(Ty, Unit);
2395 #define TYPE(Class, Base)
2396 #define ABSTRACT_TYPE(Class, Base)
2397 #define NON_CANONICAL_TYPE(Class, Base)
2398 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
2399 #include "clang/AST/TypeNodes.def"
2400 llvm_unreachable(
"Dependent types cannot show up in debug information");
2402 case Type::ExtVector:
2404 return CreateType(cast<VectorType>(Ty), Unit);
2405 case Type::ObjCObjectPointer:
2406 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
2407 case Type::ObjCObject:
2408 return CreateType(cast<ObjCObjectType>(Ty), Unit);
2409 case Type::ObjCInterface:
2410 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
2412 return CreateType(cast<BuiltinType>(Ty));
2414 return CreateType(cast<ComplexType>(Ty));
2416 return CreateType(cast<PointerType>(Ty), Unit);
2417 case Type::Adjusted:
2421 cast<PointerType>(cast<AdjustedType>(Ty)->getAdjustedType()), Unit);
2422 case Type::BlockPointer:
2423 return CreateType(cast<BlockPointerType>(Ty), Unit);
2425 return CreateType(cast<TypedefType>(Ty), Unit);
2427 return CreateType(cast<RecordType>(Ty));
2429 return CreateEnumType(cast<EnumType>(Ty));
2430 case Type::FunctionProto:
2431 case Type::FunctionNoProto:
2432 return CreateType(cast<FunctionType>(Ty), Unit);
2433 case Type::ConstantArray:
2434 case Type::VariableArray:
2435 case Type::IncompleteArray:
2436 return CreateType(cast<ArrayType>(Ty), Unit);
2438 case Type::LValueReference:
2439 return CreateType(cast<LValueReferenceType>(Ty), Unit);
2440 case Type::RValueReference:
2441 return CreateType(cast<RValueReferenceType>(Ty), Unit);
2443 case Type::MemberPointer:
2444 return CreateType(cast<MemberPointerType>(Ty), Unit);
2447 return CreateType(cast<AtomicType>(Ty), Unit);
2450 return CreateType(cast<PipeType>(Ty), Unit);
2452 case Type::TemplateSpecialization:
2453 return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
2456 case Type::Attributed:
2457 case Type::Elaborated:
2459 case Type::SubstTemplateTypeParm:
2460 case Type::TypeOfExpr:
2462 case Type::Decltype:
2463 case Type::UnaryTransform:
2464 case Type::PackExpansion:
2468 llvm_unreachable(
"type should have been unwrapped!");
2471 llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty,
2472 llvm::DIFile *Unit) {
2475 auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
2480 if (T && !T->isForwardDecl())
2484 llvm::DICompositeType *Res = CreateLimitedType(Ty);
2489 DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
2492 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
2497 llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
2501 llvm::DIFile *DefUnit = getOrCreateFile(RD->getLocation());
2502 unsigned Line = getLineNumber(RD->getLocation());
2503 StringRef RDName = getClassName(RD);
2505 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
2509 auto *T = cast_or_null<llvm::DICompositeType>(
2518 return getOrCreateRecordFwdDecl(Ty, RDContext);
2525 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
2526 getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align, 0,
2531 switch (RealDecl->getTag()) {
2533 llvm_unreachable(
"invalid composite type tag");
2535 case llvm::dwarf::DW_TAG_array_type:
2536 case llvm::dwarf::DW_TAG_enumeration_type:
2541 if (FullName.empty())
2544 case llvm::dwarf::DW_TAG_structure_type:
2545 case llvm::dwarf::DW_TAG_union_type:
2546 case llvm::dwarf::DW_TAG_class_type:
2549 llvm::MDNode::replaceWithDistinct(llvm::TempDICompositeType(RealDecl));
2553 RegionMap[Ty->
getDecl()].reset(RealDecl);
2556 if (
const auto *TSpecial = dyn_cast<ClassTemplateSpecializationDecl>(RD))
2557 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
2558 CollectCXXTemplateParams(TSpecial, DefUnit));
2562 void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
2563 llvm::DICompositeType *RealDecl) {
2565 llvm::DICompositeType *ContainingType =
nullptr;
2577 ContainingType = cast<llvm::DICompositeType>(
2578 getOrCreateType(
QualType(PBase->getTypeForDecl(), 0),
2579 getOrCreateFile(RD->getLocation())));
2581 ContainingType = RealDecl;
2583 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
2586 llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit,
QualType FType,
2587 StringRef Name, uint64_t *
Offset) {
2588 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
2591 llvm::DIType *Ty = DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize,
2592 FieldAlign, *Offset, 0, FieldTy);
2593 *Offset += FieldSize;
2597 void CGDebugInfo::collectFunctionDeclProps(GlobalDecl GD, llvm::DIFile *Unit,
2599 StringRef &LinkageName,
2600 llvm::DIScope *&FDContext,
2601 llvm::DINodeArray &TParamsArray,
2603 const auto *FD = cast<FunctionDecl>(GD.
getDecl());
2604 Name = getFunctionName(FD);
2608 Flags |= llvm::DINode::FlagPrototyped;
2613 if (LinkageName == Name || (!CGM.
getCodeGenOpts().EmitGcovArcs &&
2616 LinkageName = StringRef();
2620 dyn_cast_or_null<NamespaceDecl>(FD->getDeclContext()))
2621 FDContext = getOrCreateNameSpace(NSDecl);
2623 dyn_cast_or_null<RecordDecl>(FD->getDeclContext())) {
2624 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
2625 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
2628 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
2632 void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
2634 StringRef &Name, StringRef &LinkageName,
2635 llvm::DIScope *&VDContext) {
2636 Unit = getOrCreateFile(VD->getLocation());
2637 LineNo = getLineNumber(VD->getLocation());
2642 if (T->isIncompleteArrayType()) {
2644 llvm::APInt ConstVal(32, 1);
2652 if (VD->getDeclContext() && !isa<FunctionDecl>(VD->getDeclContext()) &&
2653 !isa<ObjCMethodDecl>(VD->getDeclContext()))
2655 if (LinkageName == Name)
2656 LinkageName = StringRef();
2665 : VD->getDeclContext();
2675 llvm::DIScope *Mod = getParentModuleOrNull(VD);
2676 VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
2679 llvm::DISubprogram *
2680 CGDebugInfo::getFunctionForwardDeclaration(
const FunctionDecl *FD) {
2681 llvm::DINodeArray TParamsArray;
2682 StringRef
Name, LinkageName;
2685 llvm::DIFile *Unit = getOrCreateFile(Loc);
2686 llvm::DIScope *DContext = Unit;
2687 unsigned Line = getLineNumber(Loc);
2689 collectFunctionDeclProps(FD, Unit, Name, LinkageName, DContext,
2690 TParamsArray, Flags);
2694 ArgTypes.push_back(Parm->getType());
2698 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
2699 DContext, Name, LinkageName, Unit, Line,
2702 TParamsArray.get(), getFunctionDeclaration(FD));
2704 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
2705 std::make_tuple(CanonDecl),
2706 std::make_tuple(SP));
2710 llvm::DIGlobalVariable *
2711 CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
2713 StringRef
Name, LinkageName;
2715 llvm::DIFile *Unit = getOrCreateFile(Loc);
2716 llvm::DIScope *DContext = Unit;
2717 unsigned Line = getLineNumber(Loc);
2719 collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, DContext);
2720 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
2721 DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
2723 FwdDeclReplaceMap.emplace_back(
2724 std::piecewise_construct,
2726 std::make_tuple(static_cast<llvm::Metadata *>(GV)));
2730 llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
2735 if (
const auto *TD = dyn_cast<TypeDecl>(D))
2737 getOrCreateFile(TD->getLocation()));
2738 auto I = DeclCache.find(D->getCanonicalDecl());
2740 if (I != DeclCache.end())
2741 return dyn_cast_or_null<llvm::DINode>(I->second);
2745 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2746 return getFunctionForwardDeclaration(FD);
2747 else if (
const auto *VD = dyn_cast<VarDecl>(D))
2748 return getGlobalVariableForwardDeclaration(VD);
2753 llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
2762 auto *S = getDeclContextDescriptor(D);
2765 if (MI == SPCache.end()) {
2767 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->getLocation()),
2768 cast<llvm::DICompositeType>(S));
2771 if (MI != SPCache.end()) {
2772 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
2773 if (SP && !SP->isDefinition())
2777 for (
auto NextFD : FD->
redecls()) {
2778 auto MI = SPCache.find(NextFD->getCanonicalDecl());
2779 if (MI != SPCache.end()) {
2780 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
2781 if (SP && !SP->isDefinition())
2790 llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
2796 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
2798 if (
const auto *Method = dyn_cast<CXXMethodDecl>(D))
2799 return getOrCreateMethodType(Method, F);
2804 if (
const auto *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
2809 QualType ResultTy = OMethod->getReturnType();
2814 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
2816 Elts.push_back(getOrCreateType(ResultTy, F));
2819 if (
auto *SelfDecl = OMethod->getSelfDecl())
2820 SelfDeclTy = SelfDecl->getType();
2821 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
2824 if (!SelfDeclTy.
isNull())
2825 Elts.push_back(CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
2827 Elts.push_back(DBuilder.createArtificialType(
2830 for (
const auto *PI : OMethod->parameters())
2831 Elts.push_back(getOrCreateType(PI->getType(), F));
2833 if (OMethod->isVariadic())
2834 Elts.push_back(DBuilder.createUnspecifiedParameter());
2836 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2837 return DBuilder.createSubroutineType(EltTypeArray, 0,
getDwarfCC(CC));
2842 if (
const auto *FD = dyn_cast<FunctionDecl>(D))
2846 if (
const auto *FPT = dyn_cast<FunctionProtoType>(FnType))
2848 EltTys.push_back(getOrCreateType(ParamType, F));
2849 EltTys.push_back(DBuilder.createUnspecifiedParameter());
2850 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
2851 return DBuilder.createSubroutineType(EltTypeArray, 0,
getDwarfCC(CC));
2854 return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
2862 StringRef LinkageName;
2864 FnBeginRegionCount.push_back(LexicalBlockStack.size());
2867 bool HasDecl = (D !=
nullptr);
2870 llvm::DIFile *Unit = getOrCreateFile(Loc);
2871 llvm::DIScope *FDContext = Unit;
2872 llvm::DINodeArray TParamsArray;
2875 LinkageName = Fn->getName();
2876 }
else if (
const auto *FD = dyn_cast<FunctionDecl>(D)) {
2879 if (FI != SPCache.end()) {
2880 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
2881 if (SP && SP->isDefinition()) {
2882 LexicalBlockStack.emplace_back(SP);
2883 RegionMap[D].reset(SP);
2887 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
2888 TParamsArray, Flags);
2889 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
2890 Name = getObjCMethodName(OMD);
2891 Flags |= llvm::DINode::FlagPrototyped;
2894 Name = Fn->getName();
2895 Flags |= llvm::DINode::FlagPrototyped;
2897 if (Name.startswith(
"\01"))
2898 Name = Name.substr(1);
2900 if (!HasDecl || D->isImplicit()) {
2901 Flags |= llvm::DINode::FlagArtificial;
2906 unsigned LineNo = getLineNumber(Loc);
2907 unsigned ScopeLine = getLineNumber(ScopeLoc);
2914 llvm::DISubprogram *SP = DBuilder.createFunction(
2915 FDContext, Name, LinkageName, Unit, LineNo,
2916 getOrCreateFunctionType(D, FnType, Unit), Fn->hasLocalLinkage(),
2917 true , ScopeLine, Flags, CGM.
getLangOpts().Optimize,
2918 TParamsArray.get(), getFunctionDeclaration(D));
2919 Fn->setSubprogram(SP);
2923 if (HasDecl && isa<FunctionDecl>(D))
2924 DeclCache[D->getCanonicalDecl()].reset(SP);
2927 LexicalBlockStack.emplace_back(SP);
2930 RegionMap[D].reset(SP);
2936 StringRef LinkageName;
2943 llvm::DIFile *Unit = getOrCreateFile(Loc);
2944 llvm::DIScope *FDContext = getDeclContextDescriptor(D);
2945 llvm::DINodeArray TParamsArray;
2946 if (isa<FunctionDecl>(D)) {
2948 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
2949 TParamsArray, Flags);
2950 }
else if (
const auto *OMD = dyn_cast<ObjCMethodDecl>(D)) {
2951 Name = getObjCMethodName(OMD);
2952 Flags |= llvm::DINode::FlagPrototyped;
2954 llvm_unreachable(
"not a function or ObjC method");
2956 if (!Name.empty() && Name[0] ==
'\01')
2957 Name = Name.substr(1);
2959 if (D->isImplicit()) {
2960 Flags |= llvm::DINode::FlagArtificial;
2965 unsigned LineNo = getLineNumber(Loc);
2966 unsigned ScopeLine = 0;
2968 DBuilder.retainType(DBuilder.createFunction(
2969 FDContext, Name, LinkageName, Unit, LineNo,
2970 getOrCreateFunctionType(D, FnType, Unit),
false ,
2971 false , ScopeLine, Flags, CGM.
getLangOpts().Optimize,
2972 TParamsArray.get(), getFunctionDeclaration(D)));
2982 llvm::MDNode *
Scope = LexicalBlockStack.back();
2983 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
2984 getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope));
2988 llvm::MDNode *Back =
nullptr;
2989 if (!LexicalBlockStack.empty())
2990 Back = LexicalBlockStack.back().get();
2991 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
2992 cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
2993 getColumnNumber(CurLoc)));
3002 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
3003 getLineNumber(Loc), getColumnNumber(Loc), LexicalBlockStack.back()));
3009 CreateLexicalBlock(Loc);
3014 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3022 LexicalBlockStack.pop_back();
3026 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3027 unsigned RCount = FnBeginRegionCount.back();
3028 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
3031 while (LexicalBlockStack.size() != RCount) {
3034 LexicalBlockStack.pop_back();
3036 FnBeginRegionCount.pop_back();
3039 llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
3040 uint64_t *XOffset) {
3044 uint64_t FieldSize, FieldOffset;
3045 unsigned FieldAlign;
3047 llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
3052 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
3053 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
3055 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
3056 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
3059 if (HasCopyAndDispose) {
3062 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
3064 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
3066 bool HasByrefExtendedLayout;
3069 HasByrefExtendedLayout) &&
3070 HasByrefExtendedLayout) {
3073 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
3082 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
3085 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
3088 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
3093 llvm::DIType *FieldTy = getOrCreateType(FType, Unit);
3097 *XOffset = FieldOffset;
3098 FieldTy = DBuilder.createMemberType(Unit, VD->
getName(), Unit, 0, FieldSize,
3099 FieldAlign, FieldOffset, 0, FieldTy);
3100 EltTys.push_back(FieldTy);
3101 FieldOffset += FieldSize;
3103 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
3105 unsigned Flags = llvm::DINode::FlagBlockByrefStruct;
3107 return DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0, Flags,
3115 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3116 if (VD->hasAttr<NoDebugAttr>())
3120 VD->isImplicit() || (isa<Decl>(VD->getDeclContext()) &&
3121 cast<Decl>(VD->getDeclContext())->isImplicit());
3122 llvm::DIFile *Unit =
nullptr;
3124 Unit = getOrCreateFile(VD->getLocation());
3126 uint64_t XOffset = 0;
3127 if (VD->hasAttr<BlocksAttr>())
3128 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
3130 Ty = getOrCreateType(VD->
getType(), Unit);
3139 unsigned Column = 0;
3141 Line = getLineNumber(VD->getLocation());
3142 Column = getColumnNumber(VD->getLocation());
3146 if (VD->isImplicit())
3147 Flags |= llvm::DINode::FlagArtificial;
3153 if (isa<ImplicitParamDecl>(VD) && ArgNo && *ArgNo == 1)
3154 Flags |= llvm::DINode::FlagObjectPointer;
3155 if (
auto *Arg = dyn_cast<llvm::Argument>(Storage))
3156 if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
3158 Expr.push_back(llvm::dwarf::DW_OP_deref);
3160 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
3162 StringRef Name = VD->
getName();
3163 if (!Name.empty()) {
3164 if (VD->hasAttr<BlocksAttr>()) {
3166 Expr.push_back(llvm::dwarf::DW_OP_plus);
3171 Expr.push_back(llvm::dwarf::DW_OP_deref);
3172 Expr.push_back(llvm::dwarf::DW_OP_plus);
3179 ? DBuilder.createParameterVariable(
Scope, VD->
getName(),
3180 *ArgNo, Unit,
Line, Ty)
3181 : DBuilder.createAutoVariable(
Scope, VD->
getName(), Unit,
3185 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3186 llvm::DebugLoc::get(Line, Column,
Scope),
3187 Builder.GetInsertBlock());
3189 }
else if (isa<VariableArrayType>(VD->
getType()))
3190 Expr.push_back(llvm::dwarf::DW_OP_deref);
3191 }
else if (
const auto *RT = dyn_cast<RecordType>(VD->
getType())) {
3194 const auto *RD = cast<RecordDecl>(RT->getDecl());
3203 for (
const auto *Field : RD->
fields()) {
3204 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
3205 StringRef FieldName = Field->getName();
3208 if (FieldName.empty() && !isa<RecordType>(Field->getType()))
3212 auto *D = DBuilder.createAutoVariable(
3214 Flags | llvm::DINode::FlagArtificial);
3217 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3218 llvm::DebugLoc::get(Line, Column,
Scope),
3219 Builder.GetInsertBlock());
3227 ? DBuilder.createParameterVariable(
Scope, Name, *ArgNo, Unit, Line,
3230 : DBuilder.createAutoVariable(
Scope, Name, Unit, Line, Ty,
3234 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3235 llvm::DebugLoc::get(Line, Column,
Scope),
3236 Builder.GetInsertBlock());
3243 EmitDeclare(VD, Storage,
llvm::None, Builder);
3246 llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
3248 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
3251 return DBuilder.createObjectPointerType(Ty);
3256 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
3258 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3260 if (Builder.GetInsertBlock() ==
nullptr)
3262 if (VD->hasAttr<NoDebugAttr>())
3265 bool isByRef = VD->hasAttr<BlocksAttr>();
3267 uint64_t XOffset = 0;
3268 llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
3271 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
3273 Ty = getOrCreateType(VD->
getType(), Unit);
3277 if (isa<ImplicitParamDecl>(VD) && VD->
getName() ==
"self")
3278 Ty = CreateSelfType(VD->
getType(), Ty);
3281 unsigned Line = getLineNumber(VD->getLocation());
3282 unsigned Column = getColumnNumber(VD->getLocation());
3291 if (isa<llvm::AllocaInst>(Storage))
3292 addr.push_back(llvm::dwarf::DW_OP_deref);
3293 addr.push_back(llvm::dwarf::DW_OP_plus);
3296 addr.push_back(llvm::dwarf::DW_OP_deref);
3297 addr.push_back(llvm::dwarf::DW_OP_plus);
3302 addr.push_back(llvm::dwarf::DW_OP_deref);
3303 addr.push_back(llvm::dwarf::DW_OP_plus);
3310 auto *D = DBuilder.createAutoVariable(
3311 cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->
getName(), Unit,
3315 auto DL = llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back());
3317 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,
3320 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,
3321 Builder.GetInsertBlock());
3328 EmitDeclare(VD, AI, ArgNo, Builder);
3332 struct BlockLayoutChunk {
3333 uint64_t OffsetInBits;
3336 bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
3337 return l.OffsetInBits < r.OffsetInBits;
3352 llvm::DIFile *tunit = getOrCreateFile(loc);
3353 unsigned line = getLineNumber(loc);
3354 unsigned column = getColumnNumber(loc);
3357 getDeclContextDescriptor(blockDecl);
3359 const llvm::StructLayout *blockLayout =
3364 blockLayout->getElementOffsetInBits(0),
3366 fields.push_back(createFieldType(
"__flags", C.
IntTy, loc,
AS_public,
3367 blockLayout->getElementOffsetInBits(1),
3369 fields.push_back(createFieldType(
"__reserved", C.
IntTy, loc,
AS_public,
3370 blockLayout->getElementOffsetInBits(2),
3374 fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, loc,
AS_public,
3375 blockLayout->getElementOffsetInBits(3),
3377 fields.push_back(createFieldType(
3381 loc,
AS_public, blockLayout->getElementOffsetInBits(4), tunit, tunit));
3389 BlockLayoutChunk chunk;
3390 chunk.OffsetInBits =
3391 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
3392 chunk.Capture =
nullptr;
3393 chunks.push_back(chunk);
3397 for (
const auto &capture : blockDecl->
captures()) {
3398 const VarDecl *variable = capture.getVariable();
3405 BlockLayoutChunk chunk;
3406 chunk.OffsetInBits =
3407 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
3408 chunk.Capture = &capture;
3409 chunks.push_back(chunk);
3413 llvm::array_pod_sort(chunks.begin(), chunks.end());
3415 for (
const BlockLayoutChunk &Chunk : chunks) {
3416 uint64_t offsetInBits = Chunk.OffsetInBits;
3423 cast_or_null<CXXMethodDecl>(blockDecl->getNonClosureContext()))
3425 else if (
auto *RDecl = dyn_cast<CXXRecordDecl>(blockDecl->
getParent()))
3426 type =
QualType(RDecl->getTypeForDecl(), 0);
3428 llvm_unreachable(
"unexpected block declcontext");
3430 fields.push_back(createFieldType(
"this", type, loc,
AS_public,
3431 offsetInBits, tunit, tunit));
3436 StringRef name = variable->
getName();
3438 llvm::DIType *fieldType;
3444 fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset);
3445 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
3447 DBuilder.createMemberType(tunit, name, tunit, line, PtrInfo.
Width,
3448 PtrInfo.
Align, offsetInBits, 0, fieldType);
3451 offsetInBits, tunit, tunit);
3453 fields.push_back(fieldType);
3457 llvm::raw_svector_ostream(typeName) <<
"__block_literal_"
3460 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
3462 llvm::DIType *type = DBuilder.createStructType(
3463 tunit, typeName.str(), tunit, line,
3469 unsigned flags = llvm::DINode::FlagArtificial;
3470 auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
3473 auto *debugVar = DBuilder.createParameterVariable(
3474 scope, Arg->getName(), ArgNo, tunit, line,
type,
3479 DBuilder.insertDbgValueIntrinsic(
3480 LocalAddr, 0, debugVar, DBuilder.createExpression(),
3481 llvm::DebugLoc::get(line, column, scope), Builder.GetInsertBlock());
3485 DBuilder.insertDeclare(Arg, debugVar, DBuilder.createExpression(),
3486 llvm::DebugLoc::get(line, column, scope),
3487 Builder.GetInsertBlock());
3490 llvm::DIDerivedType *
3491 CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
3496 if (MI != StaticDataMemberCache.end()) {
3497 assert(MI->second &&
"Static data member declaration should still exist");
3503 auto DC = D->getDeclContext();
3504 auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D));
3505 return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC));
3508 llvm::DIGlobalVariable *CGDebugInfo::CollectAnonRecordDecls(
3509 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
3510 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
3511 llvm::DIGlobalVariable *GV =
nullptr;
3513 for (
const auto *Field : RD->
fields()) {
3514 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
3515 StringRef FieldName = Field->getName();
3518 if (FieldName.empty()) {
3519 if (
const auto *RT = dyn_cast<RecordType>(Field->getType()))
3520 GV = CollectAnonRecordDecls(RT->getDecl(), Unit, LineNo, LinkageName,
3525 GV = DBuilder.createGlobalVariable(DContext, FieldName, LinkageName, Unit,
3527 Var->hasLocalLinkage(), Var,
nullptr);
3535 if (D->hasAttr<NoDebugAttr>())
3538 llvm::DIFile *Unit =
nullptr;
3539 llvm::DIScope *DContext =
nullptr;
3541 StringRef DeclName, LinkageName;
3543 collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, DContext);
3547 llvm::DIGlobalVariable *GV =
nullptr;
3555 "unnamed non-anonymous struct or union?");
3556 GV = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
3558 GV = DBuilder.createGlobalVariable(
3559 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
3560 Var->hasLocalLinkage(), Var,
3561 getOrCreateStaticDataMemberDeclarationOrNull(D));
3567 llvm::Constant *Init) {
3569 if (VD->hasAttr<NoDebugAttr>())
3572 llvm::DIFile *Unit = getOrCreateFile(VD->getLocation());
3573 StringRef Name = VD->
getName();
3574 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
3575 if (
const auto *ECD = dyn_cast<EnumConstantDecl>(VD)) {
3576 const auto *ED = cast<EnumDecl>(ECD->getDeclContext());
3577 assert(isa<EnumType>(ED->
getTypeForDecl()) &&
"Enum without EnumType?");
3583 if (Ty->getTag() == llvm::dwarf::DW_TAG_enumeration_type)
3586 if (isa<FunctionDecl>(VD->getDeclContext()))
3588 VD = cast<ValueDecl>(VD->getCanonicalDecl());
3589 auto *VarD = cast<VarDecl>(VD);
3590 if (VarD->isStaticDataMember()) {
3591 auto *RD = cast<RecordDecl>(VarD->getDeclContext());
3592 getDeclContextDescriptor(VarD);
3597 RetainedTypes.push_back(
3602 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
3604 auto &GV = DeclCache[VD];
3607 GV.reset(DBuilder.createGlobalVariable(
3608 DContext, Name, StringRef(), Unit, getLineNumber(VD->getLocation()), Ty,
3609 true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
3612 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
3613 if (!LexicalBlockStack.empty())
3614 return LexicalBlockStack.back();
3615 llvm::DIScope *Mod = getParentModuleOrNull(D);
3616 return getContextDescriptor(D, Mod ? Mod : TheCU);
3625 DBuilder.createImportedModule(
3626 getCurrentContextDescriptor(cast<Decl>(UD.getDeclContext())),
3627 getOrCreateNameSpace(NSDecl),
3628 getLineNumber(UD.getLocation()));
3636 "We shouldn't be codegening an invalid UsingDecl containing no decls");
3645 if (
const auto *FD = dyn_cast<FunctionDecl>(USD.getUnderlyingDecl()))
3646 if (
const auto *AT =
3648 if (AT->getDeducedType().isNull())
3650 if (llvm::DINode *Target =
3651 getDeclarationOrDefinition(USD.getUnderlyingDecl()))
3652 DBuilder.createImportedDeclaration(
3653 getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())), Target,
3654 getLineNumber(USD.getLocation()));
3658 if (CGM.
getCodeGenOpts().getDebuggerTuning() != llvm::DebuggerKind::LLDB)
3662 DBuilder.createImportedDeclaration(
3663 getCurrentContextDescriptor(cast<Decl>(ID.getDeclContext())),
3664 getOrCreateModuleRef(Info, DebugTypeExtRefs),
3665 getLineNumber(ID.getLocation()));
3669 llvm::DIImportedEntity *
3673 auto &VH = NamespaceAliasCache[&NA];
3675 return cast<llvm::DIImportedEntity>(VH);
3676 llvm::DIImportedEntity *R;
3677 if (
const auto *Underlying =
3680 R = DBuilder.createImportedDeclaration(
3681 getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
3685 R = DBuilder.createImportedDeclaration(
3686 getCurrentContextDescriptor(cast<Decl>(NA.getDeclContext())),
3688 getLineNumber(NA.getLocation()), NA.
getName());
3694 CGDebugInfo::getOrCreateNameSpace(
const NamespaceDecl *NSDecl) {
3696 auto I = NameSpaceCache.find(NSDecl);
3697 if (I != NameSpaceCache.end())
3698 return cast<llvm::DINamespace>(I->second);
3700 unsigned LineNo = getLineNumber(NSDecl->getLocation());
3701 llvm::DIFile *FileD = getOrCreateFile(NSDecl->getLocation());
3702 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
3703 llvm::DINamespace *NS =
3704 DBuilder.createNameSpace(Context, NSDecl->
getName(), FileD, LineNo);
3705 NameSpaceCache[NSDecl].reset(NS);
3710 assert(TheCU &&
"no main compile unit");
3711 TheCU->setDWOId(Signature);
3718 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
3719 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
3720 llvm::DIType *Ty = E.Type->getDecl()->getDefinition()
3721 ? CreateTypeDefinition(E.Type, E.Unit)
3723 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
3726 for (
auto p : ReplaceMap) {
3728 auto *Ty = cast<llvm::DIType>(p.second);
3729 assert(Ty->isForwardDecl());
3731 auto it = TypeCache.find(p.first);
3732 assert(it != TypeCache.end());
3735 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
3736 cast<llvm::DIType>(it->second));
3739 for (
const auto &p : FwdDeclReplaceMap) {
3741 llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(p.second));
3742 llvm::Metadata *Repl;
3744 auto it = DeclCache.find(p.first);
3748 if (it == DeclCache.end())
3753 DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
3758 for (
auto &RT : RetainedTypes)
3759 if (
auto MD = TypeCache[RT])
3760 DBuilder.retainType(cast<llvm::DIType>(MD));
3762 DBuilder.finalize();
3769 if (
auto *DieTy = getOrCreateType(Ty, getOrCreateMainFile()))
3771 DBuilder.retainType(DieTy);
unsigned getNumElements() const
Defines the clang::ASTContext interface.
bool isObjCOneArgSelector() const
Qualifiers getLocalQualifiers() const
Retrieve the set of qualifiers local to this particular QualType instance, not including any qualifie...
ObjCInterfaceDecl * getDecl() const
Get the declaration of this interface.
FunctionDecl - An instance of this class is created to represent a function declaration or definition...
static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Setter)
StringRef getName() const
getName - Get the name of identifier for this declaration as a StringRef.
void EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, llvm::Value *Arg, unsigned ArgNo, llvm::Value *LocalAddr, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for the block-literal argument to a block invocation function...
Smart pointer class that efficiently represents Objective-C method names.
std::string DwarfDebugFlags
The string to embed in the debug information for the compile unit, if non-empty.
A class which contains all the information about a particular captured value.
PointerType - C99 6.7.5.1 - Pointer Declarators.
APValue * evaluateValue() const
Attempt to evaluate the value of the initializer attached to this declaration, and produce notes expl...
A (possibly-)qualified type.
ArrayRef< Capture > captures() const
CodeGenTypes & getTypes()
static unsigned getAccessFlag(AccessSpecifier Access, const RecordDecl *RD)
Convert an AccessSpecifier into the corresponding DINode flag.
unsigned getColumn() const
Return the presumed column number of this location.
llvm::APSInt getAsIntegral() const
Retrieve the template argument as an integral value.
CharUnits getDeclAlign(const Decl *D, bool ForAlignof=false) const
Return a conservative estimate of the alignment of the specified decl D.
bool isBitField() const
Determines whether this field is a bitfield.
bool isByRef() const
Whether this is a "by ref" capture, i.e.
void EmitExplicitCastType(QualType Ty)
Emit the type explicitly casted to.
llvm::Module & getModule() const
Defines the clang::FileManager interface and associated types.
llvm::LLVMContext & getLLVMContext()
IdentifierInfo * getIdentifier() const
getIdentifier - Get the identifier that names this declaration, if there is one.
std::string getClangFullVersion()
Retrieves a string representing the complete clang version, which includes the clang version number...
QualType getQualifiedType(SplitQualType split) const
Un-split a SplitQualType.
MSInheritanceAttr::Spelling getMSInheritanceModel() const
Returns the inheritance model used for this record.
bool isFixed() const
Returns true if this is an Objective-C, C++11, or Microsoft-style enumeration with a fixed underlying...
decl_range decls() const
decls_begin/decls_end - Iterate over the declarations stored in this context.
llvm::DIType * getOrCreateRecordType(QualType Ty, SourceLocation L)
Emit record type's standalone debug info.
FunctionType - C99 6.7.5.3 - Function Declarators.
bool isInvalid() const
Return true if this object is invalid or uninitialized.
TemplateDecl * getAsTemplateDecl() const
Retrieve the underlying template declaration that this template name refers to, if known...
void EmitLexicalBlockEnd(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the end of a new lexical block and pop the current block.
Defines the SourceManager interface.
static bool shouldOmitDefinition(codegenoptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
QuantityType getQuantity() const
getQuantity - Get the raw integer representation of this quantity.
The template argument is an expression, and we've not resolved it to one of the other forms yet...
bool isRecordType() const
QualType getUnderlyingType() const
MemberSpecializationInfo * getMemberSpecializationInfo() const
If this function is an instantiation of a member function of a class template specialization, retrieves the member specialization information.
capture_const_iterator captures_begin() const
Defines the C++ template declaration subclasses.
method_iterator method_begin() const
Method begin iterator.
static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C)
TypePropertyCache< Private > Cache
bool hasDefinition() const
const llvm::DataLayout & getDataLayout() const
static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, const ObjCMethodDecl *Getter)
QualType getLValueReferenceType(QualType T, bool SpelledAsLValue=true) const
Return the uniqued reference to the type for an lvalue reference to the specified type...
RefQualifierKind getRefQualifier() const
Retrieve the ref-qualifier associated with this method.
QualType getPointeeType() const
The base class of the type hierarchy.
QualType getRecordType(const RecordDecl *Decl) const
Represents an array type, per C99 6.7.5.2 - Array Declarators.
const Expr * getInit() const
The template argument is a declaration that was provided for a pointer, reference, or pointer to member non-type template parameter.
NamespaceDecl - Represent a C++ namespace.
bool isPrimaryBaseVirtual() const
isPrimaryBaseVirtual - Get whether the primary base for this record is virtual or not...
NamedDecl * getParam(unsigned Idx)
const PreprocessorOptions & getPreprocessorOpts() const
AccessSpecifier
A C++ access specifier (public, private, protected), plus the special value "none" which means differ...
RefQualifierKind RefQualifier
Expr * getAsExpr() const
Retrieve the template argument as an expression.
CharUnits alignTo(const CharUnits &Align) const
alignTo - Returns the next integer (mod 2**64) that is greater than or equal to this quantity and is ...
Describes the capture of a variable or of this, or of a C++1y init-capture.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
void * getAsOpaquePtr() const
VarDecl - An instance of this class is created to represent a variable declaration or definition...
void removeObjCLifetime()
bool capturesCXXThis() const
Represents an empty template argument, e.g., one that has not been deduced.
Extra information about a function prototype.
CallingConv getCallConv() const
field_iterator field_begin() const
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
A this pointer adjustment.
uint64_t getTypeSize(QualType T) const
Return the size of the specified (complete) type T, in bits.
void EmitDeclareOfAutoVariable(const VarDecl *Decl, llvm::Value *AI, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an automatic variable declaration.
ObjCMethodDecl - Represents an instance or class method declaration.
QualType getThisType(ASTContext &C) const
Returns the type of the this pointer.
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
const CGBitFieldInfo & getBitFieldInfo(const FieldDecl *FD) const
Return the BitFieldInfo that corresponds to the field FD.
std::string SplitDwarfFile
The name for the split debug info file that we'll break out.
Stores a list of template parameters for a TemplateDecl and its derived classes.
bool isMemberDataPointerType() const
Describes how types, statements, expressions, and declarations should be printed. ...
void completeTemplateDefinition(const ClassTemplateSpecializationDecl &SD)
ParmVarDecl - Represents a parameter to a function.
static llvm::dwarf::Tag getTagForRecord(const RecordDecl *RD)
The collection of all-type qualifiers we support.
unsigned getNumParams() const
RecordDecl - Represents a struct/union/class.
Represents a class template specialization, which refers to a class template with a given set of temp...
One of these records is kept for each identifier that is lexed.
StringRef getPath() const
method_iterator end_overridden_methods() const
std::map< std::string, std::string > DebugPrefixMap
QualType apply(const ASTContext &Context, QualType QT) const
Apply the collected qualifiers to the given type.
class LLVM_ALIGNAS(8) DependentTemplateSpecializationType const IdentifierInfo * Name
Represents a template specialization type whose template cannot be resolved, e.g. ...
Represents a class type in Objective C.
CGDebugInfo * getDebugInfo()
CodeGenFunction - This class organizes the per-function state that is used while generating LLVM code...
const TemplateArgumentList * getTemplateSpecializationArgs() const
Retrieve the template arguments used to produce this function template specialization from the primar...
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
The template argument is an integral value stored in an llvm::APSInt that was provided for an integra...
static bool isFunctionLocalClass(const CXXRecordDecl *RD)
isFunctionLocalClass - Return true if CXXRecordDecl is defined inside a function. ...
void EmitImportDecl(const ImportDecl &ID)
Emit an declaration.
QualType getReturnType() const
FieldDecl - An instance of this class is created by Sema::ActOnField to represent a member of a struc...
bool isCompleteDefinition() const
isCompleteDefinition - Return true if this decl has its body fully specified.
bool isAnonymousNamespace() const
Returns true if this is an anonymous namespace declaration.
bool isPure() const
Whether this virtual function is pure, i.e.
QualType getBlockDescriptorType() const
Gets the struct used to keep track of the descriptor for pointer to blocks.
CXXMethodDecl * getCanonicalDecl() override
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
void completeClassData(const RecordDecl *RD)
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
QualType getTypeDeclType(const TypeDecl *Decl, const TypeDecl *PrevDecl=nullptr) const
Return the unique reference to the type for the specified type declaration.
const Decl * getDecl() const
Describes a module or submodule.
virtual void getNameForDiagnostic(raw_ostream &OS, const PrintingPolicy &Policy, bool Qualified) const
getNameForDiagnostic - Appends a human-readable name for this declaration into the given stream...
Provides information about a function template specialization, which is a FunctionDecl that has been ...
const Capture & getCapture(const VarDecl *var) const
Represents a C++ using-declaration.
const TemplateArgumentList * TemplateArguments
The template arguments used to produce the function template specialization from the function templat...
static SmallString< 64 > constructSetterName(StringRef Name)
Return the default setter name for the given identifier.
unsigned Size
The total size of the bit-field, in bits.
An rvalue reference type, per C++11 [dcl.ref].
param_type_range param_types() const
An lvalue ref-qualifier was provided (&).
CharUnits - This is an opaque type for sizes expressed in character units.
QualType getBaseType() const
Gets the base type of this object type.
NamedDecl * getAliasedNamespace() const
Retrieve the namespace that this alias refers to, which may either be a NamespaceDecl or a NamespaceA...
QualType getReturnType() const
const CXXRecordDecl * getParent() const
Returns the parent of this method declaration, which is the class in which this method is defined...
CharUnits StorageOffset
The offset of the bitfield storage from the start of the struct.
shadow_iterator shadow_begin() const
unsigned char PointerWidthInBits
The width of a pointer into the generic address space.
void EmitGlobalVariable(llvm::GlobalVariable *GV, const VarDecl *Decl)
Emit information about a global variable.
field_range fields() const
const ArrayType * getAsArrayType(QualType T) const
Type Query functions.
bool getByrefLifetime(QualType Ty, Qualifiers::ObjCLifetime &Lifetime, bool &HasByrefExtendedLayout) const
Returns true, if given type has a known lifetime.
RecordDecl * getDecl() const
static bool hasCXXMangling(const TagDecl *TD, llvm::DICompileUnit *TheCU)
Module * Parent
The parent of this module.
std::string getNameAsString() const
getNameAsString - Get a human-readable name for the declaration, even if it is one of the special kin...
bool isVariadic() const
Whether this function is variadic.
Scope - A scope is a transient data structure that is used while parsing the program.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine(), unsigned Indentation=0) const
static Qualifiers removeCommonQualifiers(Qualifiers &L, Qualifiers &R)
Returns the common set of qualifiers while removing them from the given sets.
llvm::DIType * getOrCreateInterfaceType(QualType Ty, SourceLocation Loc)
Emit an Objective-C interface type standalone debug info.
const ASTRecordLayout & getASTRecordLayout(const RecordDecl *D) const
Get or compute information about the layout of the specified record (struct/union/class) D...
uint64_t getFieldOffset(unsigned FieldNo) const
getFieldOffset - Get the offset of the given field index, in bits.
TypeClass getTypeClass() const
VarDecl * getCapturedVar() const
Retrieve the declaration of the local variable being captured.
unsigned Offset
The offset within a contiguous run of bitfields that are represented as a single "field" within the L...
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
llvm::DIImportedEntity * EmitNamespaceAlias(const NamespaceAliasDecl &NA)
Emit C++ namespace alias.
unsigned getLine() const
Return the presumed line number of this location.
Represents an ObjC class declaration.
uint64_t getMethodVTableIndex(GlobalDecl GD)
Locate a virtual function in the vtable.
detail::InMemoryDirectory::const_iterator I
CharUnits getVirtualBaseOffsetOffset(const CXXRecordDecl *RD, const CXXRecordDecl *VBase)
Return the offset in chars (relative to the vtable address point) where the offset of the virtual bas...
field_iterator field_end() const
bool NeedsCopyDispose
True if the block needs a custom copy or dispose function.
bool hasPrototype() const
Whether this function has a prototype, either because one was explicitly written or because it was "i...
bool isPositive() const
isPositive - Test whether the quantity is greater than zero.
EnumDecl * getDecl() const
static const Decl * getDefinition(const Decl *D)
ObjCPropertyImplDecl - Represents implementation declaration of a property in a class or category imp...
QualType getValueType() const
Gets the type contained by this atomic type, i.e.
FunctionTemplateSpecializationInfo * getTemplateSpecializationInfo() const
If this function is actually a function template specialization, retrieve information about this func...
static unsigned getDwarfCC(CallingConv CC)
const HeaderSearchOptions & getHeaderSearchOpts() const
const FileEntry * getFileEntryForID(FileID FID) const
Returns the FileEntry record for the provided FileID.
QualType getParamType(unsigned i) const
Represents a prototype with parameter type info, e.g.
CGBlockInfo - Information to generate a block literal.
const TargetInfo & getTarget() const
Represents a ValueDecl that came out of a declarator.
void setDwoId(uint64_t Signature)
Module debugging: Support for building PCMs.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
QualType getObjCInterfaceType(const ObjCInterfaceDecl *Decl, ObjCInterfaceDecl *PrevDecl=nullptr) const
getObjCInterfaceType - Return the unique reference to the type for the specified ObjC interface decl...
bool hasLocalQualifiers() const
Determine whether this particular QualType instance has any qualifiers, without looking through any t...
ASTRecordLayout - This class contains layout information for one RecordDecl, which is a struct/union/...
CGObjCRuntime & getObjCRuntime()
Return a reference to the configured Objective-C runtime.
void EmitLocation(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate a change in line/column information in the source file. ...
bool isMicrosoft() const
Is this ABI an MSVC-compatible ABI?
const Type * getTypeForDecl() const
BlockDecl - This represents a block literal declaration, which is like an unnamed FunctionDecl...
QualType getPointeeType() const
ValueDecl - Represent the declaration of a variable (in which case it is an lvalue) a function (in wh...
unsigned getIndex() const
Expr - This represents one expression.
QualType getBlockDescriptorExtendedType() const
Gets the struct used to keep track of the extended descriptor for pointer to blocks.
StringRef getName() const
Return the actual identifier string.
Emit only debug info necessary for generating line number tables (-gline-tables-only).
CGCXXABI & getCXXABI() const
VarDecl * getVariable() const
The variable being captured.
The template argument is a null pointer or null pointer to member that was provided for a non-type te...
Represents a C++ destructor within a class.
virtual CharUnits getVirtualFunctionPrologueThisAdjustment(GlobalDecl GD)
Get the ABI-specific "this" parameter adjustment to apply in the prologue of a virtual function...
TranslationUnitDecl * getTranslationUnitDecl() const
Defines version macros and version-related utility functions for Clang.
ArgKind getKind() const
Return the kind of stored template argument.
ExtProtoInfo getExtProtoInfo() const
CharUnits getBaseClassOffset(const CXXRecordDecl *Base) const
getBaseClassOffset - Get the offset, in chars, for the given base class.
ASTContext & getContext() const
SourceLocation getLocation() const
Retrieve the source location of the capture.
static CharUnits fromQuantity(QuantityType Quantity)
fromQuantity - Construct a CharUnits quantity from a raw integer type.
MicrosoftVTableContext & getMicrosoftVTableContext()
ImplicitParamDecl * getSelfDecl() const
QualType getDesugaredType(const ASTContext &Context) const
Return the specified type with any "sugar" removed from the type.
CharUnits toCharUnitsFromBits(int64_t BitSize) const
Convert a size in bits to a size in characters.
bool isInstanceMethod() const
clang::ObjCRuntime ObjCRuntime
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
DeclContext * getParent()
getParent - Returns the containing DeclContext.
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
QualType getObjCIdType() const
Represents the Objective-CC id type.
unsigned ComputeBitfieldBitOffset(CodeGen::CodeGenModule &CGM, const ObjCInterfaceDecl *ID, const ObjCIvarDecl *Ivar)
Represents an unpacked "presumed" location which can be presented to the user.
bool isExternallyVisible() const
Represents a GCC generic vector type.
An lvalue reference type, per C++11 [dcl.ref].
DeclarationName getDeclName() const
getDeclName - Get the actual, stored name of the declaration, which may be a special name...
ClassTemplateDecl * getSpecializedTemplate() const
Retrieve the template that this specialization specializes.
QualType getElementType() const
bool isComplexIntegerType() const
RecordDecl * getDefinition() const
getDefinition - Returns the RecordDecl that actually defines this struct/union/class.
const Module * getModuleOrNull() const
FunctionTemplateDecl * getTemplate() const
Retrieve the template from which this function was specialized.
CallingConv
CallingConv - Specifies the calling convention that a function uses.
TypedefNameDecl * getTypedefNameForAnonDecl() const
VarDecl * getCanonicalDecl() override
GlobalDecl - represents a global declaration.
const clang::PrintingPolicy & getPrintingPolicy() const
The l-value was considered opaque, so the alignment was determined from a type.
void EmitDeclareOfArgVariable(const VarDecl *Decl, llvm::Value *AI, unsigned ArgNo, CGBuilderTy &Builder)
Emit call to llvm.dbg.declare for an argument variable declaration.
uint64_t getFieldOffset(const ValueDecl *FD) const
Get the offset of a FieldDecl or IndirectFieldDecl, in bits.
unsigned getVBTableIndex(const CXXRecordDecl *Derived, const CXXRecordDecl *VBase)
Returns the index of VBase in the vbtable of Derived.
CXXRecordDecl * getMostRecentCXXRecordDecl() const
void EmitFunctionDecl(GlobalDecl GD, SourceLocation Loc, QualType FnType)
Emit debug info for a function declaration.
redecl_range redecls() const
Returns an iterator range for all the redeclarations of the same decl.
unsigned getTypeAlign(QualType T) const
Return the ABI-specified alignment of a (complete) type T, in bits.
TypeInfo getTypeInfo(const Type *T) const
Get the size and alignment of the specified complete type in bits.
bool isNonFragile() const
Does this runtime follow the set of implied behaviors for a "non-fragile" ABI?
uint64_t getPointerAlign(unsigned AddrSpace) const
virtual void mangleCXXRTTIName(QualType T, raw_ostream &)=0
const char * getFilename() const
Return the presumed filename of this location.
llvm::Constant * EmitConstantExpr(const Expr *E, QualType DestType, CodeGenFunction *CGF=nullptr)
Try to emit the given expression as a constant; returns 0 if the expression cannot be emitted as a co...
Encodes a location in the source.
enumerator_range enumerators() const
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr, bool IsForDefinition=false)
Return the llvm::Constant for the address of the given global variable.
ExternalASTSource * getExternalSource() const
Retrieve a pointer to the external AST source associated with this AST context, if any...
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of enums...
const Type * getTypePtr() const
Retrieves a pointer to the underlying (unqualified) type.
TemplateName getAsTemplate() const
Retrieve the template name for a template name argument.
method_iterator begin_overridden_methods() const
Interfaces are the core concept in Objective-C for object oriented design.
const CXXRecordDecl * getPrimaryBase() const
getPrimaryBase - Get the primary base for this record.
llvm::StructType * StructureType
void completeRequiredType(const RecordDecl *RD)
Limit generated debug info to reduce size (-fno-standalone-debug).
bool isValid() const
Return true if this is a valid SourceLocation object.
TagDecl - Represents the declaration of a struct/union/class/enum.
StringRef getNameForSlot(unsigned argIndex) const
Retrieve the name at a given position in the selector.
static QualType getUnderlyingType(const SubRegion *R)
Cached information about one file (either on disk or in the virtual file system). ...
void printName(raw_ostream &os) const
Represents a static or instance method of a struct/union/class.
TypedefNameDecl * getTypedefNameForUnnamedTagDecl(const TagDecl *TD)
ArrayRef< ParmVarDecl * > parameters() const
ObjCCategoryDecl - Represents a category declaration.
Module * getImportedModule() const
Retrieve the module that was imported by the import declaration.
Capture(VarDecl *variable, bool byRef, bool nested, Expr *copy)
const CodeGenOptions & getCodeGenOpts() const
const LangOptions & getLangOpts() const
Represents one property declaration in an Objective-C interface.
std::string getAsString() const
Derive the full selector name (e.g.
TypedefNameDecl * getDecl() const
const T * castAs() const
Member-template castAs<specific type>.
MangleContext & getMangleContext()
Gets the mangle context.
This template specialization was formed from a template-id but has not yet been declared, defined, or instantiated.
FileID getMainFileID() const
Returns the FileID of the main source file.
static void PrintTemplateArgumentList(raw_ostream &OS, ArrayRef< TemplateArgument > Args, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
method_iterator method_end() const
Method past-the-end iterator.
ItaniumVTableContext & getItaniumVTableContext()
unsigned CXXThisIndex
The field index of 'this' within the block, if there is one.
An rvalue ref-qualifier was provided (&&).
virtual llvm::Constant * EmitNullMemberPointer(const MemberPointerType *MPT)
Create a null member pointer of the given type.
static bool hasExplicitMemberDefinition(CXXRecordDecl::method_iterator I, CXXRecordDecl::method_iterator End)
void printQualifiedName(raw_ostream &OS) const
printQualifiedName - Returns human-readable qualified name for declaration, like A::B::i, for i being member of namespace A::B.
bool isDynamicClass() const
ValueDecl * getAsDecl() const
Retrieve the declaration for a declaration non-type template argument.
Describes a module import declaration, which makes the contents of the named module visible in the cu...
SourceLocation getExprLoc() const LLVM_READONLY
getExprLoc - Return the preferred location for the arrow when diagnosing a problem with a generic exp...
QualType getObjCInstanceType()
Retrieve the Objective-C "instancetype" type, if already known; otherwise, returns a NULL type;...
QualType getPointeeType() const
QualType getFunctionType(QualType ResultTy, ArrayRef< QualType > Args, const FunctionProtoType::ExtProtoInfo &EPI) const
Return a normal function type with a typed argument list.
QualType getObjCSelType() const
Retrieve the type that corresponds to the predefined Objective-C 'SEL' type.
ObjCIvarDecl * getNextIvar()
Base class for declarations which introduce a typedef-name.
bool isAnonymousStructOrUnion() const
isAnonymousStructOrUnion - Whether this is an anonymous struct or union.
Represents a template argument.
TemplateSpecializationKind getTemplateSpecializationKind() const
Determine whether this particular class is a specialization or instantiation of a class template or m...
QualType getAsType() const
Retrieve the type for a type template argument.
This class organizes the cross-function state that is used while generating LLVM code.
Selector getObjCSelector() const
getObjCSelector - Get the Objective-C selector stored in this declaration name.
NamespaceDecl * getNominatedNamespace()
Returns the namespace nominated by this using-directive.
TemplatedKind getTemplatedKind() const
What kind of templated function this is.
A qualifier set is used to build a set of qualifiers.
DeclContext - This is used only as base class of specific decl types that can act as declaration cont...
int getUniqueBlockCount()
Fetches the global unique block count.
StringRef getASTFile() const
prop_range properties() const
Module * inferModuleFromLocation(FullSourceLoc Loc)
Infers the (sub)module based on the given source location and source manager.
const internal::VariadicAllOfMatcher< Type > type
Matches Types in the clang AST.
The template argument is a pack expansion of a template name that was provided for a template templat...
bool isExplicitSpecialization() const
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
Emit location information but do not generate debug info in the output.
This template specialization was instantiated from a template due to an explicit instantiation declar...
QualType getEnumType(const EnumDecl *Decl) const
QualType getPointerType(QualType T) const
Return the uniqued reference to the type for a pointer to the specified type.
std::string getModuleName() const
const Type * strip(QualType type)
Collect any qualifiers on the given type and return an unqualified type.
CGDebugInfo(CodeGenModule &CGM)
std::string DebugCompilationDir
The string to embed in debug information as the current working directory.
EnumDecl - Represents an enum.
Selector getSelector() const
detail::InMemoryDirectory::const_iterator E
A pointer to member type per C++ 8.3.3 - Pointers to members.
TemplateSpecializationKind
Describes the kind of template specialization that a particular template specialization declaration r...
bool isLambda() const
Determine whether this class describes a lambda function object.
specific_decl_iterator - Iterates over a subrange of declarations stored in a DeclContext, providing only those that are of type SpecificDecl (or a class derived from it).
known_extensions_range known_extensions() const
QualType getPointeeType() const
Gets the type pointed to by this ObjC pointer.
bool isCompleteDefinitionRequired() const
Return true if this complete decl is required to be complete for some existing use.
Represents a pointer to an Objective C object.
ObjCImplementationDecl - Represents a class definition - this is where method definitions are specifi...
uint64_t getSignature() const
A helper class that allows the use of isa/cast/dyncast to detect TagType objects of structs/unions/cl...
Complex values, per C99 6.2.5p11.
Don't generate debug info.
SourceLocation getCaretLocation() const
const T * getAs() const
Member-template getAs<specific type>'.
unsigned getTypeQuals() const
CanQualType UnsignedLongTy
llvm::DIType * getOrCreateStandaloneType(QualType Ty, SourceLocation Loc)
Emit standalone debug info for a type.
QualType getIntegralType() const
Retrieve the type of the integral value.
void completeType(const EnumDecl *ED)
QualType getIntegerType() const
getIntegerType - Return the integer type this enum decl corresponds to.
virtual llvm::Constant * EmitMemberDataPointer(const MemberPointerType *MPT, CharUnits offset)
Create a member pointer for the given field.
DeclaratorDecl * getDeclaratorForUnnamedTagDecl(const TagDecl *TD)
StringRef getMangledName(GlobalDecl GD)
uint64_t getCharWidth() const
Return the size of the character type, in bits.
The template argument is a type.
ObjCImplementationDecl * getImplementation() const
The template argument is actually a parameter pack.
APValue - This class implements a discriminated union of [uninitialized] [APSInt] [APFloat]...
bool isStaticDataMember() const
Determines whether this is a static data member.
bool isObjCZeroArgSelector() const
QualType getPointeeType() const
SourceManager & getSourceManager()
uint64_t getPointerWidth(unsigned AddrSpace) const
Return the width of pointers on this target, for the specified address space.
std::string getQualifiedNameAsString() const
A template argument list.
const TemplateArgumentList & getTemplateArgs() const
Retrieve the template arguments of the class template specialization.
const Type * getClass() const
void EmitUsingDecl(const UsingDecl &UD)
Emit C++ using declaration.
QualType getNullPtrType() const
Retrieve the type for null non-type template argument.
void EmitUsingDirective(const UsingDirectiveDecl &UD)
Emit C++ using directive.
void EmitLexicalBlockStart(CGBuilderTy &Builder, SourceLocation Loc)
Emit metadata to indicate the beginning of a new lexical block and push the block onto the stack...
ArrayRef< TemplateArgument > getPackAsArray() const
Return the array of arguments in this template argument pack.
Represents a C++ struct/union/class.
BoundNodesTreeBuilder *const Builder
TargetCXXABI getCXXABI() const
Get the C++ ABI currently in use.
The template argument is a template name that was provided for a template template parameter...
std::string MainFileName
The user provided name for the "main file", if non-empty.
ObjCIvarDecl - Represents an ObjC instance variable.
bool isItaniumFamily() const
Does this ABI generally fall into the Itanium family of ABIs?
const BlockDecl * getBlockDecl() const
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.
void EmitFunctionStart(GlobalDecl GD, SourceLocation Loc, SourceLocation ScopeLoc, QualType FnType, llvm::Function *Fn, CGBuilderTy &Builder)
Emit a call to llvm.dbg.function.start to indicate start of a new function.
This class is used for builtin types like 'int'.
TemplateParameterList * getTemplateParameters() const
Get the list of template parameters.
QualType getParamTypeForDecl() const
capture_const_iterator captures_end() const
A SourceLocation and its associated SourceManager.
ObjCInterfaceDecl * getSuperClass() const
uint64_t Index
Method's index in the vftable.
void setLocation(SourceLocation Loc)
Update the current source location.
TagDecl * getDecl() const
bool isIncompleteArrayType() const
Abstracts clang modules and precompiled header files and holds everything needed to generate debug in...
unsigned getTargetAddressSpace(QualType T) const
QualType getConstantArrayType(QualType EltTy, const llvm::APInt &ArySize, ArrayType::ArraySizeModifier ASM, unsigned IndexTypeQuals) const
Return the unique reference to the type for a constant array of the specified element type...
QualType getElementType() const
QualType getElementType() const
bool MSVCFormatting
Use whitespace and punctuation like MSVC does.
bool capturesThis() const
Determine whether this capture handles the C++ this pointer.
int64_t toBits(CharUnits CharSize) const
Convert a size in characters to a size in bits.
const BlockExpr * getBlockExpr() const
FunctionDecl * getCanonicalDecl() override
NamedDecl - This represents a decl with a name.
ObjCIvarDecl * all_declared_ivar_begin()
all_declared_ivar_begin - return first ivar declared in this class, its extensions and its implementa...
FunctionDecl * getInstantiatedFromMemberFunction() const
If this function is an instantiation of a member function of a class template specialization, retrieves the function from which it was instantiated.
static SmallString< 256 > getUniqueTagTypeName(const TagType *Ty, CodeGenModule &CGM, llvm::DICompileUnit *TheCU)
In C++ mode, types have linkage, so we can rely on the ODR and on their mangled names, if they're external.
StringRef getName(const PrintingPolicy &Policy) const
SourceLocation getExpansionLoc(SourceLocation Loc) const
Given a SourceLocation object Loc, return the expansion location referenced by the ID...
EnumDecl * getDefinition() const
Represents a C++ namespace alias.
const ASTRecordLayout & getASTObjCInterfaceLayout(const ObjCInterfaceDecl *D) const
Get or compute information about the layout of the specified Objective-C interface.
static bool isDefinedInClangModule(const RecordDecl *RD)
Does a type definition exist in an imported clang module?
Represents C++ using-directive.
bool isNull() const
Return true if this QualType doesn't point to a type yet.
void EmitFunctionEnd(CGBuilderTy &Builder)
Constructs the debug code for exiting a function.
llvm::Constant * GetAddrOfFunction(GlobalDecl GD, llvm::Type *Ty=nullptr, bool ForVTable=false, bool DontDefer=false, bool IsForDefinition=false)
Return the address of the given function.
void removeAddressSpace()
const CGRecordLayout & getCGRecordLayout(const RecordDecl *)
getCGRecordLayout - Return record layout info for the given record decl.
TemplateSpecializationType(TemplateName T, ArrayRef< TemplateArgument > Args, QualType Canon, QualType Aliased)
This class handles loading and caching of source files into memory.
QualType getBaseElementType(const ArrayType *VAT) const
Return the innermost element type of an array type.
bool BlockRequiresCopying(QualType Ty, const VarDecl *D)
Returns true iff we need copy/dispose helpers for the given type.
const MethodVFTableLocation & getMethodVFTableLocation(GlobalDecl GD)
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
Structure with information about how a bitfield should be accessed.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPointerType() const
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.