33 #include "llvm/ADT/SmallVector.h"
34 #include "llvm/ADT/StringExtras.h"
35 #include "llvm/IR/Constants.h"
36 #include "llvm/IR/DataLayout.h"
37 #include "llvm/IR/DerivedTypes.h"
38 #include "llvm/IR/Instructions.h"
39 #include "llvm/IR/Intrinsics.h"
40 #include "llvm/IR/Module.h"
41 #include "llvm/Support/FileSystem.h"
42 #include "llvm/Support/Path.h"
43 using namespace clang;
44 using namespace clang::CodeGen;
47 : CGM(CGM), DebugKind(CGM.getCodeGenOpts().getDebugInfo()),
48 DebugTypeExtRefs(CGM.getCodeGenOpts().DebugTypeExtRefs),
49 DBuilder(CGM.getModule()) {
51 DebugPrefixMap[KV.first] = KV.second;
56 assert(LexicalBlockStack.empty() &&
57 "Region stack mismatch, stack not empty!");
63 init(TemporaryLocation);
70 init(TemporaryLocation, DefaultToEmpty);
74 bool DefaultToEmpty) {
81 OriginalLocation = CGF->
Builder.getCurrentDebugLocation();
82 if (TemporaryLocation.
isValid()) {
83 DI->EmitLocation(CGF->
Builder, TemporaryLocation);
88 CGF->
Builder.SetCurrentDebugLocation(llvm::DebugLoc());
93 assert(!DI->LexicalBlockStack.empty());
94 CGF->
Builder.SetCurrentDebugLocation(
95 llvm::DebugLoc::get(0, 0, DI->LexicalBlockStack.back()));
109 OriginalLocation = CGF.
Builder.getCurrentDebugLocation();
111 CGF.
Builder.SetCurrentDebugLocation(std::move(Loc));
118 CGF->
Builder.SetCurrentDebugLocation(std::move(OriginalLocation));
131 if (LexicalBlockStack.empty())
135 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
138 if (PCLoc.isInvalid() ||
Scope->getFilename() == PCLoc.getFilename())
141 if (
auto *LBF = dyn_cast<llvm::DILexicalBlockFile>(
Scope)) {
142 LexicalBlockStack.pop_back();
143 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlockFile(
144 LBF->getScope(), getOrCreateFile(CurLoc)));
145 }
else if (isa<llvm::DILexicalBlock>(
Scope) ||
146 isa<llvm::DISubprogram>(
Scope)) {
147 LexicalBlockStack.pop_back();
148 LexicalBlockStack.emplace_back(
149 DBuilder.createLexicalBlockFile(
Scope, getOrCreateFile(CurLoc)));
153 llvm::DIScope *CGDebugInfo::getDeclContextDescriptor(
const Decl *D) {
154 llvm::DIScope *Mod = getParentModuleOrNull(D);
159 llvm::DIScope *CGDebugInfo::getContextDescriptor(
const Decl *
Context,
160 llvm::DIScope *Default) {
164 auto I = RegionMap.find(Context);
165 if (
I != RegionMap.end()) {
166 llvm::Metadata *V =
I->second;
167 return dyn_cast_or_null<llvm::DIScope>(V);
171 if (
const NamespaceDecl *NSDecl = dyn_cast<NamespaceDecl>(Context))
172 return getOrCreateNameSpace(NSDecl);
174 if (
const RecordDecl *RDecl = dyn_cast<RecordDecl>(Context))
175 if (!RDecl->isDependentType())
177 getOrCreateMainFile());
181 StringRef CGDebugInfo::getFunctionName(
const FunctionDecl *FD) {
182 assert(FD &&
"Invalid FunctionDecl!");
192 llvm::raw_svector_ostream OS(NS);
214 return internString(OS.str());
217 StringRef CGDebugInfo::getObjCMethodName(
const ObjCMethodDecl *OMD) {
218 SmallString<256> MethodName;
219 llvm::raw_svector_ostream OS(MethodName);
223 dyn_cast<const ObjCImplementationDecl>(DC)) {
224 OS << OID->getName();
226 dyn_cast<const ObjCInterfaceDecl>(DC)) {
227 OS << OID->getName();
229 if (OC->IsClassExtension()) {
230 OS << OC->getClassInterface()->getName();
232 OS << ((
const NamedDecl *)OC)->getIdentifier()->getNameStart() <<
'('
233 << OC->getIdentifier()->getNameStart() <<
')';
236 dyn_cast<const 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) {
259 if (!isa<ClassTemplateSpecializationDecl>(RD))
262 SmallString<128>
Name;
264 llvm::raw_svector_ostream OS(Name);
270 return internString(Name);
276 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
277 remapDIPath(TheCU->getDirectory()));
284 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
285 remapDIPath(TheCU->getDirectory()));
289 auto it = DIFileCache.find(fname);
291 if (it != DIFileCache.end()) {
293 if (llvm::Metadata *V = it->second)
294 return cast<llvm::DIFile>(V);
297 llvm::DIFile *F = DBuilder.createFile(remapDIPath(PLoc.
getFilename()),
298 remapDIPath(getCurrentDirname()));
300 DIFileCache[fname].reset(F);
304 llvm::DIFile *CGDebugInfo::getOrCreateMainFile() {
305 return DBuilder.createFile(remapDIPath(TheCU->getFilename()),
306 remapDIPath(TheCU->getDirectory()));
309 std::string CGDebugInfo::remapDIPath(StringRef Path)
const {
310 for (
const auto &Entry : DebugPrefixMap)
311 if (Path.startswith(Entry.first))
312 return (Twine(Entry.second) + Path.substr(Entry.first.size())).str();
324 unsigned CGDebugInfo::getColumnNumber(
SourceLocation Loc,
bool Force) {
337 StringRef CGDebugInfo::getCurrentDirname() {
341 if (!CWDName.empty())
343 SmallString<256> CWD;
344 llvm::sys::fs::current_path(CWD);
345 return CWDName = internString(CWD);
348 void CGDebugInfo::CreateCompileUnit() {
360 if (MainFileName.empty())
361 MainFileName =
"<stdin>";
367 std::string MainFileDir;
369 MainFileDir = remapDIPath(MainFile->getDir()->getName());
370 if (MainFileDir !=
".") {
372 llvm::sys::path::append(MainFileDirSS, MainFileName);
373 MainFileName = MainFileDirSS.str();
377 llvm::dwarf::SourceLanguage LangTag;
381 LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
383 LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
384 }
else if (LO.ObjC1) {
385 LangTag = llvm::dwarf::DW_LANG_ObjC;
387 LangTag = llvm::dwarf::DW_LANG_C99;
389 LangTag = llvm::dwarf::DW_LANG_C89;
395 unsigned RuntimeVers = 0;
401 TheCU = DBuilder.createCompileUnit(
402 LangTag, remapDIPath(MainFileName), remapDIPath(getCurrentDirname()),
406 ? llvm::DIBuilder::LineTablesOnly
407 : llvm::DIBuilder::FullDebug,
411 llvm::DIType *CGDebugInfo::CreateType(
const BuiltinType *BT) {
415 #define BUILTIN_TYPE(Id, SingletonId)
416 #define PLACEHOLDER_TYPE(Id, SingletonId) case BuiltinType::Id:
417 #include "clang/AST/BuiltinTypes.def"
418 case BuiltinType::Dependent:
419 llvm_unreachable(
"Unexpected builtin type");
420 case BuiltinType::NullPtr:
421 return DBuilder.createNullPtrType();
422 case BuiltinType::Void:
424 case BuiltinType::ObjCClass:
426 ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
428 getOrCreateMainFile(), 0);
430 case BuiltinType::ObjCId: {
440 ClassTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
442 getOrCreateMainFile(), 0);
446 auto *ISATy = DBuilder.createPointerType(ClassTy, Size);
449 DBuilder.createStructType(TheCU,
"objc_object", getOrCreateMainFile(),
450 0, 0, 0, 0,
nullptr, llvm::DINodeArray());
452 DBuilder.replaceArrays(
454 DBuilder.getOrCreateArray(&*DBuilder.createMemberType(
455 ObjTy,
"isa", getOrCreateMainFile(), 0, Size, 0, 0, 0, ISATy)));
458 case BuiltinType::ObjCSel: {
460 SelTy = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
461 "objc_selector", TheCU,
462 getOrCreateMainFile(), 0);
466 case BuiltinType::OCLImage1d:
467 return getOrCreateStructPtrType(
"opencl_image1d_t", OCLImage1dDITy);
468 case BuiltinType::OCLImage1dArray:
469 return getOrCreateStructPtrType(
"opencl_image1d_array_t",
470 OCLImage1dArrayDITy);
471 case BuiltinType::OCLImage1dBuffer:
472 return getOrCreateStructPtrType(
"opencl_image1d_buffer_t",
473 OCLImage1dBufferDITy);
474 case BuiltinType::OCLImage2d:
475 return getOrCreateStructPtrType(
"opencl_image2d_t", OCLImage2dDITy);
476 case BuiltinType::OCLImage2dArray:
477 return getOrCreateStructPtrType(
"opencl_image2d_array_t",
478 OCLImage2dArrayDITy);
479 case BuiltinType::OCLImage2dDepth:
480 return getOrCreateStructPtrType(
"opencl_image2d_depth_t",
481 OCLImage2dDepthDITy);
482 case BuiltinType::OCLImage2dArrayDepth:
483 return getOrCreateStructPtrType(
"opencl_image2d_array_depth_t",
484 OCLImage2dArrayDepthDITy);
485 case BuiltinType::OCLImage2dMSAA:
486 return getOrCreateStructPtrType(
"opencl_image2d_msaa_t",
488 case BuiltinType::OCLImage2dArrayMSAA:
489 return getOrCreateStructPtrType(
"opencl_image2d_array_msaa_t",
490 OCLImage2dArrayMSAADITy);
491 case BuiltinType::OCLImage2dMSAADepth:
492 return getOrCreateStructPtrType(
"opencl_image2d_msaa_depth_t",
493 OCLImage2dMSAADepthDITy);
494 case BuiltinType::OCLImage2dArrayMSAADepth:
495 return getOrCreateStructPtrType(
"opencl_image2d_array_msaa_depth_t",
496 OCLImage2dArrayMSAADepthDITy);
497 case BuiltinType::OCLImage3d:
498 return getOrCreateStructPtrType(
"opencl_image3d_t", OCLImage3dDITy);
499 case BuiltinType::OCLSampler:
500 return DBuilder.createBasicType(
503 case BuiltinType::OCLEvent:
504 return getOrCreateStructPtrType(
"opencl_event_t", OCLEventDITy);
505 case BuiltinType::OCLClkEvent:
506 return getOrCreateStructPtrType(
"opencl_clk_event_t", OCLClkEventDITy);
507 case BuiltinType::OCLQueue:
508 return getOrCreateStructPtrType(
"opencl_queue_t", OCLQueueDITy);
509 case BuiltinType::OCLNDRange:
510 return getOrCreateStructPtrType(
"opencl_ndrange_t", OCLNDRangeDITy);
511 case BuiltinType::OCLReserveID:
512 return getOrCreateStructPtrType(
"opencl_reserve_id_t", OCLReserveIDDITy);
514 case BuiltinType::UChar:
515 case BuiltinType::Char_U:
516 Encoding = llvm::dwarf::DW_ATE_unsigned_char;
518 case BuiltinType::Char_S:
519 case BuiltinType::SChar:
520 Encoding = llvm::dwarf::DW_ATE_signed_char;
522 case BuiltinType::Char16:
523 case BuiltinType::Char32:
524 Encoding = llvm::dwarf::DW_ATE_UTF;
526 case BuiltinType::UShort:
527 case BuiltinType::UInt:
528 case BuiltinType::UInt128:
529 case BuiltinType::ULong:
530 case BuiltinType::WChar_U:
531 case BuiltinType::ULongLong:
532 Encoding = llvm::dwarf::DW_ATE_unsigned;
534 case BuiltinType::Short:
535 case BuiltinType::Int:
536 case BuiltinType::Int128:
537 case BuiltinType::Long:
538 case BuiltinType::WChar_S:
539 case BuiltinType::LongLong:
540 Encoding = llvm::dwarf::DW_ATE_signed;
542 case BuiltinType::Bool:
543 Encoding = llvm::dwarf::DW_ATE_boolean;
545 case BuiltinType::Half:
546 case BuiltinType::Float:
547 case BuiltinType::LongDouble:
548 case BuiltinType::Double:
549 Encoding = llvm::dwarf::DW_ATE_float;
554 case BuiltinType::Long:
557 case BuiltinType::LongLong:
558 BTName =
"long long int";
560 case BuiltinType::ULong:
561 BTName =
"long unsigned int";
563 case BuiltinType::ULongLong:
564 BTName =
"long long unsigned int";
573 return DBuilder.createBasicType(BTName, Size, Align, Encoding);
576 llvm::DIType *CGDebugInfo::CreateType(
const ComplexType *Ty) {
578 llvm::dwarf::TypeKind Encoding = llvm::dwarf::DW_ATE_complex_float;
580 Encoding = llvm::dwarf::DW_ATE_lo_user;
584 return DBuilder.createBasicType(
"complex", Size, Align, Encoding);
587 llvm::DIType *CGDebugInfo::CreateQualifiedType(
QualType Ty,
588 llvm::DIFile *Unit) {
599 llvm::dwarf::Tag Tag;
601 Tag = llvm::dwarf::DW_TAG_const_type;
604 Tag = llvm::dwarf::DW_TAG_volatile_type;
607 Tag = llvm::dwarf::DW_TAG_restrict_type;
610 assert(Qc.
empty() &&
"Unknown type qualifier for debug info");
611 return getOrCreateType(
QualType(T, 0), Unit);
618 return DBuilder.createQualifiedType(Tag, FromTy);
622 llvm::DIFile *Unit) {
630 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
634 llvm::DIType *CGDebugInfo::CreateType(
const PointerType *Ty,
635 llvm::DIFile *Unit) {
636 return CreatePointerLikeType(llvm::dwarf::DW_TAG_pointer_type, Ty,
642 switch (TheCU->getSourceLanguage()) {
643 case llvm::dwarf::DW_LANG_C_plus_plus:
645 case llvm::dwarf::DW_LANG_ObjC_plus_plus:
646 return isa<CXXRecordDecl>(TD) || isa<EnumDecl>(TD);
656 llvm::DICompileUnit *TheCU) {
657 SmallString<256> FullName;
669 llvm::raw_svector_ostream Out(FullName);
676 llvm::dwarf::Tag Tag;
678 Tag = llvm::dwarf::DW_TAG_structure_type;
680 Tag = llvm::dwarf::DW_TAG_union_type;
685 Tag = llvm::dwarf::DW_TAG_class_type;
690 llvm::DICompositeType *
691 CGDebugInfo::getOrCreateRecordFwdDecl(
const RecordType *Ty,
692 llvm::DIScope *Ctx) {
695 return cast<llvm::DICompositeType>(T);
696 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
698 StringRef RDName = getClassName(RD);
711 llvm::DICompositeType *RetTy = DBuilder.createReplaceableCompositeType(
713 llvm::DINode::FlagFwdDecl, FullName);
714 ReplaceMap.emplace_back(
715 std::piecewise_construct, std::make_tuple(Ty),
716 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
720 llvm::DIType *CGDebugInfo::CreatePointerLikeType(llvm::dwarf::Tag Tag,
723 llvm::DIFile *Unit) {
731 if (Tag == llvm::dwarf::DW_TAG_reference_type ||
732 Tag == llvm::dwarf::DW_TAG_rvalue_reference_type)
733 return DBuilder.createReferenceType(Tag, getOrCreateType(PointeeTy, Unit),
736 return DBuilder.createPointerType(getOrCreateType(PointeeTy, Unit), Size,
740 llvm::DIType *CGDebugInfo::getOrCreateStructPtrType(StringRef Name,
741 llvm::DIType *&
Cache) {
744 Cache = DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type, Name,
745 TheCU, getOrCreateMainFile(), 0);
747 Cache = DBuilder.createPointerType(Cache, Size);
752 llvm::DIFile *Unit) {
755 uint64_t FieldSize, FieldOffset;
757 llvm::DINodeArray Elements;
761 EltTys.push_back(CreateMemberType(Unit, FType,
"reserved", &FieldOffset));
762 EltTys.push_back(CreateMemberType(Unit, FType,
"Size", &FieldOffset));
764 Elements = DBuilder.getOrCreateArray(EltTys);
767 unsigned Flags = llvm::DINode::FlagAppleBlock;
771 DBuilder.createStructType(Unit,
"__block_descriptor",
nullptr, LineNo,
772 FieldOffset, 0, Flags,
nullptr, Elements);
777 auto *DescTy = DBuilder.createPointerType(EltTy, Size);
781 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
783 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
784 EltTys.push_back(CreateMemberType(Unit, FType,
"__reserved", &FieldOffset));
786 EltTys.push_back(CreateMemberType(Unit, FType,
"__FuncPtr", &FieldOffset));
791 EltTys.push_back(DBuilder.createMemberType(Unit,
"__descriptor",
nullptr, LineNo,
792 FieldSize, FieldAlign, FieldOffset,
795 FieldOffset += FieldSize;
796 Elements = DBuilder.getOrCreateArray(EltTys);
803 DBuilder.createStructType(Unit,
"",
nullptr, LineNo,
804 FieldOffset, 0, Flags,
nullptr, Elements);
806 return DBuilder.createPointerType(EltTy, Size);
810 llvm::DIFile *Unit) {
811 assert(Ty->isTypeAlias());
812 llvm::DIType *Src = getOrCreateType(Ty->getAliasedType(), Unit);
815 llvm::raw_svector_ostream OS(NS);
820 OS, Ty->getArgs(), Ty->getNumArgs(),
824 Ty->getTemplateName().getAsTemplateDecl())->getTemplatedDecl();
827 return DBuilder.createTypedef(Src, OS.str(), getOrCreateFile(Loc),
829 getDeclContextDescriptor(AliasDecl));
832 llvm::DIType *CGDebugInfo::CreateType(
const TypedefType *Ty,
833 llvm::DIFile *Unit) {
839 return DBuilder.createTypedef(
841 Ty->
getDecl()->
getName(), getOrCreateFile(Loc), getLineNumber(Loc),
842 getDeclContextDescriptor(Ty->
getDecl()));
845 llvm::DIType *CGDebugInfo::CreateType(
const FunctionType *Ty,
846 llvm::DIFile *Unit) {
850 EltTys.push_back(getOrCreateType(Ty->
getReturnType(), Unit));
854 if (isa<FunctionNoProtoType>(Ty))
855 EltTys.push_back(DBuilder.createUnspecifiedParameter());
857 for (
unsigned i = 0, e = FPT->getNumParams(); i != e; ++i)
858 EltTys.push_back(getOrCreateType(FPT->getParamType(i), Unit));
859 if (FPT->isVariadic())
860 EltTys.push_back(DBuilder.createUnspecifiedParameter());
863 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
864 return DBuilder.createSubroutineType(EltTypeArray);
877 if (Access == Default)
882 return llvm::DINode::FlagPrivate;
884 return llvm::DINode::FlagProtected;
886 return llvm::DINode::FlagPublic;
890 llvm_unreachable(
"unexpected access enumerator");
893 llvm::DIType *CGDebugInfo::createFieldType(
894 StringRef name,
QualType type, uint64_t sizeInBitsOverride,
896 llvm::DIFile *tunit, llvm::DIScope *scope,
const RecordDecl *RD) {
897 llvm::DIType *debugType = getOrCreateType(type, tunit);
900 llvm::DIFile *file = getOrCreateFile(loc);
901 unsigned line = getLineNumber(loc);
903 uint64_t SizeInBits = 0;
904 unsigned AlignInBits = 0;
907 SizeInBits = TI.
Width;
908 AlignInBits = TI.
Align;
910 if (sizeInBitsOverride)
911 SizeInBits = sizeInBitsOverride;
915 return DBuilder.createMemberType(scope, name, file, line, SizeInBits,
916 AlignInBits, offsetInBits, flags, debugType);
919 void CGDebugInfo::CollectRecordLambdaFields(
921 llvm::DIType *RecordTy) {
927 unsigned fieldno = 0;
930 I !=
E; ++
I, ++Field, ++fieldno) {
934 llvm::DIFile *VUnit = getOrCreateFile(C.
getLocation());
935 StringRef VName = V->
getName();
936 uint64_t SizeInBitsOverride = 0;
937 if (Field->isBitField()) {
938 SizeInBitsOverride = Field->getBitWidthValue(CGM.
getContext());
939 assert(SizeInBitsOverride &&
"found named 0-width bitfield");
941 llvm::DIType *fieldType = createFieldType(
942 VName, Field->getType(), SizeInBitsOverride, C.
getLocation(),
943 Field->getAccess(), layout.
getFieldOffset(fieldno), VUnit, RecordTy,
945 elements.push_back(fieldType);
952 llvm::DIFile *VUnit = getOrCreateFile(f->
getLocation());
954 llvm::DIType *fieldType = createFieldType(
958 elements.push_back(fieldType);
963 llvm::DIDerivedType *
964 CGDebugInfo::CreateRecordStaticField(
const VarDecl *Var, llvm::DIType *RecordTy,
969 llvm::DIFile *VUnit = getOrCreateFile(Var->
getLocation());
970 llvm::DIType *VTy = getOrCreateType(Var->
getType(), VUnit);
972 unsigned LineNumber = getLineNumber(Var->
getLocation());
973 StringRef VName = Var->
getName();
974 llvm::Constant *C =
nullptr;
986 llvm::DIDerivedType *GV = DBuilder.createStaticMemberType(
987 RecordTy, VName, VUnit, LineNumber, VTy, Flags, C);
992 void CGDebugInfo::CollectRecordNormalField(
993 const FieldDecl *field, uint64_t OffsetInBits, llvm::DIFile *tunit,
996 StringRef name = field->
getName();
1003 uint64_t SizeInBitsOverride = 0;
1006 assert(SizeInBitsOverride &&
"found named 0-width bitfield");
1009 llvm::DIType *fieldType =
1010 createFieldType(name, type, SizeInBitsOverride, field->
getLocation(),
1011 field->
getAccess(), OffsetInBits, tunit, RecordTy, RD);
1013 elements.push_back(fieldType);
1016 void CGDebugInfo::CollectRecordFields(
1017 const RecordDecl *record, llvm::DIFile *tunit,
1019 llvm::DICompositeType *RecordTy) {
1022 if (CXXDecl && CXXDecl->
isLambda())
1023 CollectRecordLambdaFields(CXXDecl, elements, RecordTy);
1028 unsigned fieldNo = 0;
1032 for (
const auto *
I : record->
decls())
1033 if (
const auto *V = dyn_cast<VarDecl>(
I)) {
1036 if (MI != StaticDataMemberCache.end()) {
1037 assert(MI->second &&
1038 "Static data member declaration should still exist");
1039 elements.push_back(MI->second);
1041 auto Field = CreateRecordStaticField(V, RecordTy, record);
1042 elements.push_back(Field);
1044 }
else if (
const auto *field = dyn_cast<FieldDecl>(
I)) {
1045 CollectRecordNormalField(field, layout.
getFieldOffset(fieldNo), tunit,
1046 elements, RecordTy, record);
1054 llvm::DISubroutineType *
1055 CGDebugInfo::getOrCreateMethodType(
const CXXMethodDecl *Method,
1056 llvm::DIFile *Unit) {
1059 return cast_or_null<llvm::DISubroutineType>(
1060 getOrCreateType(
QualType(Func, 0), Unit));
1065 llvm::DISubroutineType *CGDebugInfo::getOrCreateInstanceMethodType(
1068 llvm::DITypeRefArray Args(
1069 cast<llvm::DISubroutineType>(getOrCreateType(
QualType(Func, 0), Unit))
1071 assert(Args.size() &&
"Invalid number of arguments!");
1076 Elts.push_back(Args[0]);
1080 if (isa<ClassTemplateSpecializationDecl>(RD)) {
1082 const PointerType *ThisPtrTy = cast<PointerType>(ThisPtr);
1087 llvm::DIType *PointeeType = getOrCreateType(PointeeTy, Unit);
1088 llvm::DIType *ThisPtrType =
1089 DBuilder.createPointerType(PointeeType, Size, Align);
1094 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1095 Elts.push_back(ThisPtrType);
1097 llvm::DIType *ThisPtrType = getOrCreateType(ThisPtr, Unit);
1099 ThisPtrType = DBuilder.createObjectPointerType(ThisPtrType);
1100 Elts.push_back(ThisPtrType);
1104 for (
unsigned i = 1, e = Args.size(); i != e; ++i)
1105 Elts.push_back(Args[i]);
1107 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
1111 Flags |= llvm::DINode::FlagLValueReference;
1113 Flags |= llvm::DINode::FlagRValueReference;
1115 return DBuilder.createSubroutineType(EltTypeArray, Flags);
1128 llvm::DISubprogram *CGDebugInfo::CreateCXXMemberFunction(
1129 const CXXMethodDecl *Method, llvm::DIFile *Unit, llvm::DIType *RecordTy) {
1131 isa<CXXConstructorDecl>(Method) || isa<CXXDestructorDecl>(Method);
1133 StringRef MethodName = getFunctionName(Method);
1134 llvm::DISubroutineType *MethodTy = getOrCreateMethodType(Method, Unit);
1138 StringRef MethodLinkageName;
1143 llvm::DIFile *MethodDefUnit =
nullptr;
1144 unsigned MethodLine = 0;
1146 MethodDefUnit = getOrCreateFile(Method->
getLocation());
1147 MethodLine = getLineNumber(Method->
getLocation());
1151 llvm::DIType *ContainingType =
nullptr;
1152 unsigned Virtuality = 0;
1153 unsigned VIndex = 0;
1157 Virtuality = llvm::dwarf::DW_VIRTUALITY_pure_virtual;
1159 Virtuality = llvm::dwarf::DW_VIRTUALITY_virtual;
1166 if (!isa<CXXDestructorDecl>(Method) &&
1169 ContainingType = RecordTy;
1174 Flags |= llvm::DINode::FlagArtificial;
1177 if (CXXC->isExplicit())
1178 Flags |= llvm::DINode::FlagExplicit;
1180 dyn_cast<CXXConversionDecl>(Method)) {
1181 if (CXXC->isExplicit())
1182 Flags |= llvm::DINode::FlagExplicit;
1185 Flags |= llvm::DINode::FlagPrototyped;
1187 Flags |= llvm::DINode::FlagLValueReference;
1189 Flags |= llvm::DINode::FlagRValueReference;
1191 llvm::DINodeArray TParamsArray = CollectFunctionTemplateParams(Method, Unit);
1192 llvm::DISubprogram *SP = DBuilder.createMethod(
1193 RecordTy, MethodName, MethodLinkageName, MethodDefUnit, MethodLine,
1195 false, Virtuality, VIndex, ContainingType, Flags,
1203 void CGDebugInfo::CollectCXXMemberFunctions(
1210 for (
const auto *
I : RD->
decls()) {
1235 EltTys.push_back(MI == SPCache.end()
1236 ? CreateCXXMemberFunction(Method, Unit, RecordTy)
1237 : static_cast<llvm::Metadata *>(MI->second));
1241 void CGDebugInfo::CollectCXXBases(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1243 llvm::DIType *RecordTy) {
1245 for (
const auto &BI : RD->
bases()) {
1246 unsigned BFlags = 0;
1247 uint64_t BaseOffset;
1250 cast<CXXRecordDecl>(BI.getType()->getAs<
RecordType>()->getDecl());
1252 if (BI.isVirtual()) {
1265 BFlags = llvm::DINode::FlagVirtual;
1272 llvm::DIType *DTy = DBuilder.createInheritance(
1273 RecordTy, getOrCreateType(BI.getType(), Unit), BaseOffset, BFlags);
1274 EltTys.push_back(DTy);
1281 llvm::DIFile *Unit) {
1283 for (
unsigned i = 0, e = TAList.size(); i != e; ++i) {
1290 llvm::DIType *TTy = getOrCreateType(TA.
getAsType(), Unit);
1291 TemplateParams.push_back(
1292 DBuilder.createTemplateTypeParameter(TheCU, Name, TTy));
1296 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1303 llvm::DIType *TTy = getOrCreateType(T, Unit);
1304 llvm::Constant *V =
nullptr;
1308 if (
const auto *VD = dyn_cast<VarDecl>(D))
1312 else if ((MD = dyn_cast<CXXMethodDecl>(D)) && MD->
isInstance())
1314 else if (
const auto *FD = dyn_cast<FunctionDecl>(D))
1318 else if (
const auto *MPT = dyn_cast<MemberPointerType>(T.
getTypePtr())) {
1327 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1329 cast_or_null<llvm::Constant>(V->stripPointerCasts())));
1333 llvm::DIType *TTy = getOrCreateType(T, Unit);
1334 llvm::Constant *V =
nullptr;
1344 if (MPT->isMemberDataPointer())
1347 V = llvm::ConstantInt::get(CGM.
Int8Ty, 0);
1348 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1349 TheCU, Name, TTy, cast<llvm::Constant>(V)));
1352 TemplateParams.push_back(DBuilder.createTemplateTemplateParameter(
1353 TheCU, Name,
nullptr,
1357 TemplateParams.push_back(DBuilder.createTemplateParameterPack(
1358 TheCU, Name,
nullptr,
1367 assert(V &&
"Expression in template argument isn't constant");
1368 llvm::DIType *TTy = getOrCreateType(T, Unit);
1369 TemplateParams.push_back(DBuilder.createTemplateValueParameter(
1370 TheCU, Name, TTy, cast<llvm::Constant>(V->stripPointerCasts())));
1376 "These argument types shouldn't exist in concrete types");
1379 return DBuilder.getOrCreateArray(TemplateParams);
1383 CGDebugInfo::CollectFunctionTemplateParams(
const FunctionDecl *FD,
1384 llvm::DIFile *Unit) {
1390 return CollectTemplateParams(
1393 return llvm::DINodeArray();
1396 llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams(
1403 return CollectTemplateParams(TPList, TAList.
asArray(), Unit);
1406 llvm::DIType *CGDebugInfo::getOrCreateVTablePtrType(llvm::DIFile *Unit) {
1408 return VTablePtrType;
1413 llvm::Metadata *STy = getOrCreateType(Context.
IntTy, Unit);
1414 llvm::DITypeRefArray SElements = DBuilder.getOrCreateTypeArray(STy);
1415 llvm::DIType *SubTy = DBuilder.createSubroutineType(SElements);
1417 llvm::DIType *vtbl_ptr_type =
1418 DBuilder.createPointerType(SubTy, Size, 0,
"__vtbl_ptr_type");
1419 VTablePtrType = DBuilder.createPointerType(vtbl_ptr_type, Size);
1420 return VTablePtrType;
1423 StringRef CGDebugInfo::getVTableName(
const CXXRecordDecl *RD) {
1428 void CGDebugInfo::CollectVTableInfo(
const CXXRecordDecl *RD, llvm::DIFile *Unit,
1441 llvm::DIType *VPTR = DBuilder.createMemberType(
1442 Unit, getVTableName(RD), Unit, 0, Size, 0, 0,
1443 llvm::DINode::FlagArtificial, getOrCreateVTablePtrType(Unit));
1444 EltTys.push_back(VPTR);
1450 llvm::DIType *T = getOrCreateType(RTy, getOrCreateFile(Loc));
1462 assert(!D.
isNull() &&
"null type");
1463 llvm::DIType *T = getOrCreateType(D, getOrCreateFile(Loc));
1464 assert(T &&
"could not create debug info for type");
1468 if (
auto *CTy = dyn_cast<llvm::DICompositeType>(T))
1469 if (!CTy->getIdentifier().empty())
1480 auto I = TypeCache.find(TyPtr);
1481 if (
I == TypeCache.end() || !cast<llvm::DIType>(
I->second)->isForwardDecl())
1483 llvm::DIType *Res = CreateTypeDefinition(Ty->
castAs<
EnumType>());
1484 assert(!Res->isForwardDecl());
1485 TypeCache[TyPtr].reset(Res);
1498 if (
const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
1506 llvm::DIType *T = getTypeOrNull(Ty);
1507 if (T && T->isForwardDecl())
1516 auto I = TypeCache.find(TyPtr);
1517 if (
I != TypeCache.end() && !cast<llvm::DIType>(
I->second)->isForwardDecl())
1520 assert(!Res->isForwardDecl());
1521 TypeCache[TyPtr].reset(Res);
1526 for (; I !=
End; ++
I)
1527 if (
FunctionDecl *Tmpl = I->getInstantiatedFromMemberFunction())
1528 if (!Tmpl->isImplicit() && Tmpl->isThisDeclarationADefinition() &&
1529 !I->getMemberSpecializationInfo()->isExplicitSpecialization())
1535 bool DebugTypeExtRefs,
1545 if (!LangOpts.CPlusPlus)
1561 dyn_cast<ClassTemplateSpecializationDecl>(RD))
1562 Spec = SD->getSpecializationKind();
1572 llvm::DIType *CGDebugInfo::CreateType(
const RecordType *Ty) {
1574 llvm::DIType *T = cast_or_null<llvm::DIType>(getTypeOrNull(
QualType(Ty, 0)));
1578 T = getOrCreateRecordFwdDecl(Ty, getDeclContextDescriptor(RD));
1582 return CreateTypeDefinition(Ty);
1585 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const RecordType *Ty) {
1589 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
1597 llvm::DICompositeType *FwdDecl = getOrCreateLimitedType(Ty, DefUnit);
1603 if (
const CXXRecordDecl *CXXDecl = dyn_cast<CXXRecordDecl>(RD))
1604 CollectContainingType(CXXDecl, FwdDecl);
1607 LexicalBlockStack.emplace_back(&*FwdDecl);
1608 RegionMap[Ty->
getDecl()].reset(FwdDecl);
1620 CollectCXXBases(CXXDecl, DefUnit, EltTys, FwdDecl);
1621 CollectVTableInfo(CXXDecl, DefUnit, EltTys);
1625 CollectRecordFields(RD, DefUnit, EltTys, FwdDecl);
1627 CollectCXXMemberFunctions(CXXDecl, DefUnit, EltTys, FwdDecl);
1629 LexicalBlockStack.pop_back();
1630 RegionMap.erase(Ty->
getDecl());
1632 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
1633 DBuilder.replaceArrays(FwdDecl, Elements);
1635 if (FwdDecl->isTemporary())
1637 llvm::MDNode::replaceWithPermanent(llvm::TempDICompositeType(FwdDecl));
1639 RegionMap[Ty->
getDecl()].reset(FwdDecl);
1644 llvm::DIFile *Unit) {
1674 llvm::DIFile *Unit) {
1681 return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
1683 getDeclContextDescriptor(ID), Unit, 0);
1686 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
1689 static_cast<llvm::dwarf::SourceLanguage
>(TheCU->getSourceLanguage());
1695 llvm::DIScope *Mod = getParentModuleOrNull(ID);
1696 llvm::DIType *FwdDecl = DBuilder.createReplaceableCompositeType(
1697 llvm::dwarf::DW_TAG_structure_type, ID->
getName(), Mod ? Mod : TheCU,
1698 DefUnit,
Line, RuntimeLang);
1699 ObjCInterfaceCache.push_back(ObjCInterfaceCacheEntry(Ty, FwdDecl, Unit));
1703 return CreateTypeDefinition(Ty, Unit);
1708 bool CreateSkeletonCU) {
1713 auto ModRef = ModuleCache.find(M);
1714 if (ModRef != ModuleCache.end())
1715 return cast<llvm::DIModule>(ModRef->second);
1718 SmallString<128> ConfigMacros;
1720 llvm::raw_svector_ostream OS(ConfigMacros);
1724 for (
auto &M : PPOpts.Macros) {
1727 const std::string &Macro = M.first;
1728 bool Undef = M.second;
1729 OS <<
"\"-" << (Undef ?
'U' :
'D');
1730 for (
char c : Macro)
1732 case '\\' : OS <<
"\\\\";
break;
1733 case '"' : OS <<
"\\\"";
break;
1740 bool IsRootModule = M ? !M->
Parent :
true;
1741 if (CreateSkeletonCU && IsRootModule) {
1743 DIB.createCompileUnit(TheCU->getSourceLanguage(), Mod.
getModuleName(),
1744 Mod.
getPath(), TheCU->getProducer(),
true,
1749 llvm::DIModule *Parent =
1750 IsRootModule ?
nullptr
1751 : getOrCreateModuleRef(
1754 llvm::DIModule *DIMod =
1755 DBuilder.createModule(Parent, Mod.
getModuleName(), ConfigMacros,
1757 ModuleCache[M].reset(DIMod);
1762 llvm::DIFile *Unit) {
1764 llvm::DIFile *DefUnit = getOrCreateFile(ID->
getLocation());
1766 unsigned RuntimeLang = TheCU->getSourceLanguage();
1774 Flags |= llvm::DINode::FlagObjcClassComplete;
1776 llvm::DIScope *Mod = getParentModuleOrNull(ID);
1777 llvm::DICompositeType *RealDecl = DBuilder.createStructType(
1778 Mod ? Mod : Unit, ID->
getName(), DefUnit,
Line, Size, Align, Flags,
1779 nullptr, llvm::DINodeArray(), RuntimeLang);
1782 TypeCache[QTy.getAsOpaquePtr()].reset(RealDecl);
1785 LexicalBlockStack.emplace_back(RealDecl);
1786 RegionMap[Ty->
getDecl()].reset(RealDecl);
1793 llvm::DIType *SClassTy =
1798 llvm::DIType *InhTag = DBuilder.createInheritance(RealDecl, SClassTy, 0, 0);
1799 EltTys.push_back(InhTag);
1805 llvm::DIFile *PUnit = getOrCreateFile(Loc);
1806 unsigned PLine = getLineNumber(Loc);
1809 llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(
1810 PD->getName(), PUnit, PLine,
1812 : getSelectorName(PD->getGetterName()),
1814 : getSelectorName(PD->getSetterName()),
1815 PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit));
1816 EltTys.push_back(PropertyNode);
1819 llvm::SmallPtrSet<const IdentifierInfo*, 16> PropertySet;
1821 for (
auto *PD : ClassExt->properties()) {
1822 PropertySet.insert(PD->getIdentifier());
1828 if (!PropertySet.insert(PD->getIdentifier()).second)
1835 unsigned FieldNo = 0;
1838 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
1842 StringRef FieldName = Field->getName();
1845 if (FieldName.empty())
1849 llvm::DIFile *FieldDefUnit = getOrCreateFile(Field->getLocation());
1850 unsigned FieldLine = getLineNumber(Field->getLocation());
1852 uint64_t FieldSize = 0;
1853 unsigned FieldAlign = 0;
1855 if (!FType->isIncompleteArrayType()) {
1858 FieldSize = Field->isBitField()
1864 uint64_t FieldOffset;
1869 if (Field->isBitField()) {
1882 Flags = llvm::DINode::FlagProtected;
1884 Flags = llvm::DINode::FlagPrivate;
1886 Flags = llvm::DINode::FlagPublic;
1888 llvm::MDNode *PropertyNode =
nullptr;
1891 ImpD->FindPropertyImplIvarDecl(Field->getIdentifier())) {
1894 llvm::DIFile *PUnit = getOrCreateFile(Loc);
1895 unsigned PLine = getLineNumber(Loc);
1898 PropertyNode = DBuilder.createObjCProperty(
1899 PD->getName(), PUnit, PLine,
1901 PD->getGetterName()),
1903 PD->getSetterName()),
1904 PD->getPropertyAttributes(),
1905 getOrCreateType(PD->getType(), PUnit));
1909 FieldTy = DBuilder.createObjCIVar(FieldName, FieldDefUnit, FieldLine,
1910 FieldSize, FieldAlign, FieldOffset, Flags,
1911 FieldTy, PropertyNode);
1912 EltTys.push_back(FieldTy);
1915 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
1916 DBuilder.replaceArrays(RealDecl, Elements);
1918 LexicalBlockStack.pop_back();
1922 llvm::DIType *CGDebugInfo::CreateType(
const VectorType *Ty,
1923 llvm::DIFile *Unit) {
1924 llvm::DIType *ElementTy = getOrCreateType(Ty->
getElementType(), Unit);
1931 llvm::Metadata *Subscript = DBuilder.getOrCreateSubrange(0, Count);
1932 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscript);
1937 return DBuilder.createVectorType(Size, Align, ElementTy, SubscriptArray);
1940 llvm::DIType *CGDebugInfo::CreateType(
const ArrayType *Ty, llvm::DIFile *Unit) {
1969 while ((Ty = dyn_cast<ArrayType>(EltTy))) {
1979 Count = CAT->getSize().getZExtValue();
1982 Subscripts.push_back(DBuilder.getOrCreateSubrange(0, Count));
1986 llvm::DINodeArray SubscriptArray = DBuilder.getOrCreateArray(Subscripts);
1988 return DBuilder.createArrayType(Size, Align, getOrCreateType(EltTy, Unit),
1993 llvm::DIFile *Unit) {
1994 return CreatePointerLikeType(llvm::dwarf::DW_TAG_reference_type, Ty,
1999 llvm::DIFile *Unit) {
2000 return CreatePointerLikeType(llvm::dwarf::DW_TAG_rvalue_reference_type, Ty,
2010 return DBuilder.createMemberPointerType(
2015 return DBuilder.createMemberPointerType(
2022 llvm::DIType *CGDebugInfo::CreateType(
const AtomicType *Ty, llvm::DIFile *U) {
2028 llvm::DIType* CGDebugInfo::CreateType(
const PipeType *Ty,
2033 llvm::DIType *CGDebugInfo::CreateEnumType(
const EnumType *Ty) {
2045 bool isImportedFromModule =
2051 llvm::DIScope *EDContext = getDeclContextDescriptor(ED);
2052 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2054 StringRef EDName = ED->
getName();
2055 llvm::DIType *RetTy = DBuilder.createReplaceableCompositeType(
2056 llvm::dwarf::DW_TAG_enumeration_type, EDName, EDContext, DefUnit, Line,
2057 0, Size, Align, llvm::DINode::FlagFwdDecl, FullName);
2058 ReplaceMap.emplace_back(
2059 std::piecewise_construct, std::make_tuple(Ty),
2060 std::make_tuple(static_cast<llvm::Metadata *>(RetTy)));
2064 return CreateTypeDefinition(Ty);
2067 llvm::DIType *CGDebugInfo::CreateTypeDefinition(
const EnumType *Ty) {
2082 Enumerators.push_back(DBuilder.createEnumerator(
2083 Enum->getName(), Enum->getInitVal().getSExtValue()));
2087 llvm::DINodeArray EltArray = DBuilder.getOrCreateArray(Enumerators);
2089 llvm::DIFile *DefUnit = getOrCreateFile(ED->
getLocation());
2091 llvm::DIScope *EnumContext = getDeclContextDescriptor(ED);
2092 llvm::DIType *ClassTy =
2094 return DBuilder.createEnumerationType(EnumContext, ED->
getName(), DefUnit,
2095 Line, Size, Align, EltArray, ClassTy,
2106 Quals += InnerQuals;
2111 case Type::TemplateSpecialization: {
2112 const auto *Spec = cast<TemplateSpecializationType>(T);
2113 if (Spec->isTypeAlias())
2115 T = Spec->desugar();
2118 case Type::TypeOfExpr:
2119 T = cast<TypeOfExprType>(T)->getUnderlyingExpr()->getType();
2124 case Type::Decltype:
2127 case Type::UnaryTransform:
2130 case Type::Attributed:
2131 T = cast<AttributedType>(T)->getEquivalentType();
2133 case Type::Elaborated:
2134 T = cast<ElaboratedType>(T)->getNamedType();
2137 T = cast<ParenType>(T)->getInnerType();
2139 case Type::SubstTemplateTypeParm:
2140 T = cast<SubstTemplateTypeParmType>(T)->getReplacementType();
2143 QualType DT = cast<AutoType>(T)->getDeducedType();
2144 assert(!DT.
isNull() &&
"Undeduced types shouldn't reach here.");
2149 assert(T != LastT &&
"Type unwrapping failed to unwrap!");
2154 llvm::DIType *CGDebugInfo::getTypeOrNull(
QualType Ty) {
2160 if (it != TypeCache.end()) {
2162 if (llvm::Metadata *V = it->second)
2163 return cast<llvm::DIType>(V);
2180 llvm::DIType *CGDebugInfo::getOrCreateType(
QualType Ty, llvm::DIFile *Unit) {
2187 if (
auto *T = getTypeOrNull(Ty))
2190 llvm::DIType *Res = CreateTypeNode(Ty, Unit);
2194 TypeCache[TyPtr].reset(Res);
2199 llvm::DIModule *CGDebugInfo::getParentModuleOrNull(
const Decl *D) {
2201 if (isa<RecordDecl>(D) && !cast<RecordDecl>(D)->
getDefinition())
2207 auto Info = Reader->getSourceDescriptor(Idx);
2209 return getOrCreateModuleRef(*Info,
true);
2210 }
else if (ClangModuleMap) {
2224 return getOrCreateModuleRef(Info,
false);
2231 llvm::DIType *CGDebugInfo::CreateTypeNode(
QualType Ty, llvm::DIFile *Unit) {
2234 return CreateQualifiedType(Ty, Unit);
2238 #define TYPE(Class, Base)
2239 #define ABSTRACT_TYPE(Class, Base)
2240 #define NON_CANONICAL_TYPE(Class, Base)
2241 #define DEPENDENT_TYPE(Class, Base) case Type::Class:
2242 #include "clang/AST/TypeNodes.def"
2243 llvm_unreachable(
"Dependent types cannot show up in debug information");
2245 case Type::ExtVector:
2247 return CreateType(cast<VectorType>(Ty), Unit);
2248 case Type::ObjCObjectPointer:
2249 return CreateType(cast<ObjCObjectPointerType>(Ty), Unit);
2250 case Type::ObjCObject:
2251 return CreateType(cast<ObjCObjectType>(Ty), Unit);
2252 case Type::ObjCInterface:
2253 return CreateType(cast<ObjCInterfaceType>(Ty), Unit);
2255 return CreateType(cast<BuiltinType>(Ty));
2257 return CreateType(cast<ComplexType>(Ty));
2259 return CreateType(cast<PointerType>(Ty), Unit);
2260 case Type::Adjusted:
2264 cast<PointerType>(cast<AdjustedType>(Ty)->getAdjustedType()), Unit);
2265 case Type::BlockPointer:
2266 return CreateType(cast<BlockPointerType>(Ty), Unit);
2268 return CreateType(cast<TypedefType>(Ty), Unit);
2270 return CreateType(cast<RecordType>(Ty));
2272 return CreateEnumType(cast<EnumType>(Ty));
2273 case Type::FunctionProto:
2274 case Type::FunctionNoProto:
2275 return CreateType(cast<FunctionType>(Ty), Unit);
2276 case Type::ConstantArray:
2277 case Type::VariableArray:
2278 case Type::IncompleteArray:
2279 return CreateType(cast<ArrayType>(Ty), Unit);
2281 case Type::LValueReference:
2282 return CreateType(cast<LValueReferenceType>(Ty), Unit);
2283 case Type::RValueReference:
2284 return CreateType(cast<RValueReferenceType>(Ty), Unit);
2286 case Type::MemberPointer:
2287 return CreateType(cast<MemberPointerType>(Ty), Unit);
2290 return CreateType(cast<AtomicType>(Ty), Unit);
2293 return CreateType(cast<PipeType>(Ty), Unit);
2295 case Type::TemplateSpecialization:
2296 return CreateType(cast<TemplateSpecializationType>(Ty), Unit);
2299 case Type::Attributed:
2300 case Type::Elaborated:
2302 case Type::SubstTemplateTypeParm:
2303 case Type::TypeOfExpr:
2305 case Type::Decltype:
2306 case Type::UnaryTransform:
2307 case Type::PackExpansion:
2311 llvm_unreachable(
"type should have been unwrapped!");
2314 llvm::DICompositeType *CGDebugInfo::getOrCreateLimitedType(
const RecordType *Ty,
2315 llvm::DIFile *Unit) {
2318 auto *T = cast_or_null<llvm::DICompositeType>(getTypeOrNull(QTy));
2323 if (T && !T->isForwardDecl())
2327 llvm::DICompositeType *Res = CreateLimitedType(Ty);
2332 DBuilder.replaceArrays(Res, T ? T->getElements() : llvm::DINodeArray());
2335 TypeCache[QTy.getAsOpaquePtr()].reset(Res);
2340 llvm::DICompositeType *CGDebugInfo::CreateLimitedType(
const RecordType *Ty) {
2344 llvm::DIFile *DefUnit = getOrCreateFile(RD->
getLocation());
2346 StringRef RDName = getClassName(RD);
2348 llvm::DIScope *RDContext = getDeclContextDescriptor(RD);
2352 auto *T = cast_or_null<llvm::DICompositeType>(
2361 return getOrCreateRecordFwdDecl(Ty, RDContext);
2368 llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType(
2369 getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align, 0,
2372 RegionMap[Ty->
getDecl()].reset(RealDecl);
2376 dyn_cast<ClassTemplateSpecializationDecl>(RD))
2377 DBuilder.replaceArrays(RealDecl, llvm::DINodeArray(),
2378 CollectCXXTemplateParams(TSpecial, DefUnit));
2382 void CGDebugInfo::CollectContainingType(
const CXXRecordDecl *RD,
2383 llvm::DICompositeType *RealDecl) {
2385 llvm::DICompositeType *ContainingType =
nullptr;
2397 ContainingType = cast<llvm::DICompositeType>(
2398 getOrCreateType(
QualType(PBase->getTypeForDecl(), 0),
2401 ContainingType = RealDecl;
2403 DBuilder.replaceVTableHolder(RealDecl, ContainingType);
2406 llvm::DIType *CGDebugInfo::CreateMemberType(llvm::DIFile *Unit,
QualType FType,
2407 StringRef Name, uint64_t *
Offset) {
2408 llvm::DIType *FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
2411 llvm::DIType *Ty = DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize,
2412 FieldAlign, *Offset, 0, FieldTy);
2413 *Offset += FieldSize;
2417 void CGDebugInfo::collectFunctionDeclProps(
GlobalDecl GD, llvm::DIFile *Unit,
2419 StringRef &LinkageName,
2420 llvm::DIScope *&FDContext,
2421 llvm::DINodeArray &TParamsArray,
2424 Name = getFunctionName(FD);
2428 Flags |= llvm::DINode::FlagPrototyped;
2433 if (LinkageName == Name ||
2437 LinkageName = StringRef();
2442 FDContext = getOrCreateNameSpace(NSDecl);
2445 llvm::DIScope *Mod = getParentModuleOrNull(RDecl);
2446 FDContext = getContextDescriptor(RDecl, Mod ? Mod : TheCU);
2449 TParamsArray = CollectFunctionTemplateParams(FD, Unit);
2453 void CGDebugInfo::collectVarDeclProps(
const VarDecl *VD, llvm::DIFile *&Unit,
2455 StringRef &Name, StringRef &LinkageName,
2456 llvm::DIScope *&VDContext) {
2463 if (T->isIncompleteArrayType()) {
2465 llvm::APInt ConstVal(32, 1);
2476 if (LinkageName == Name)
2477 LinkageName = StringRef();
2496 llvm::DIScope *Mod = getParentModuleOrNull(VD);
2497 VDContext = getContextDescriptor(cast<Decl>(DC), Mod ? Mod : TheCU);
2500 llvm::DISubprogram *
2501 CGDebugInfo::getFunctionForwardDeclaration(
const FunctionDecl *FD) {
2502 llvm::DINodeArray TParamsArray;
2503 StringRef
Name, LinkageName;
2506 llvm::DIFile *Unit = getOrCreateFile(Loc);
2507 llvm::DIScope *DContext = Unit;
2508 unsigned Line = getLineNumber(Loc);
2510 collectFunctionDeclProps(FD, Unit, Name, LinkageName, DContext,
2511 TParamsArray, Flags);
2515 ArgTypes.push_back(Parm->getType());
2519 llvm::DISubprogram *SP = DBuilder.createTempFunctionFwdDecl(
2520 DContext, Name, LinkageName, Unit, Line,
2523 TParamsArray.get(), getFunctionDeclaration(FD));
2525 FwdDeclReplaceMap.emplace_back(std::piecewise_construct,
2526 std::make_tuple(CanonDecl),
2527 std::make_tuple(SP));
2531 llvm::DIGlobalVariable *
2532 CGDebugInfo::getGlobalVariableForwardDeclaration(
const VarDecl *VD) {
2534 StringRef
Name, LinkageName;
2536 llvm::DIFile *Unit = getOrCreateFile(Loc);
2537 llvm::DIScope *DContext = Unit;
2538 unsigned Line = getLineNumber(Loc);
2540 collectVarDeclProps(VD, Unit, Line, T, Name, LinkageName, DContext);
2541 auto *GV = DBuilder.createTempGlobalVariableFwdDecl(
2542 DContext, Name, LinkageName, Unit, Line, getOrCreateType(T, Unit),
2544 FwdDeclReplaceMap.emplace_back(
2545 std::piecewise_construct,
2547 std::make_tuple(static_cast<llvm::Metadata *>(GV)));
2551 llvm::DINode *CGDebugInfo::getDeclarationOrDefinition(
const Decl *D) {
2556 if (
const TypeDecl *TD = dyn_cast<TypeDecl>(D))
2558 getOrCreateFile(TD->getLocation()));
2561 if (I != DeclCache.end())
2562 return dyn_cast_or_null<llvm::DINode>(I->second);
2566 if (
const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(D))
2567 return getFunctionForwardDeclaration(FD);
2568 else if (
const auto *VD = dyn_cast<VarDecl>(D))
2569 return getGlobalVariableForwardDeclaration(VD);
2574 llvm::DISubprogram *CGDebugInfo::getFunctionDeclaration(
const Decl *D) {
2583 auto *S = getDeclContextDescriptor(D);
2586 if (MI == SPCache.end()) {
2589 return CreateCXXMemberFunction(MD, getOrCreateFile(MD->
getLocation()),
2590 cast<llvm::DICompositeType>(S));
2593 if (MI != SPCache.end()) {
2594 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
2595 if (SP && !SP->isDefinition())
2599 for (
auto NextFD : FD->
redecls()) {
2600 auto MI = SPCache.find(NextFD->getCanonicalDecl());
2601 if (MI != SPCache.end()) {
2602 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(MI->second);
2603 if (SP && !SP->isDefinition())
2612 llvm::DISubroutineType *CGDebugInfo::getOrCreateFunctionType(
const Decl *D,
2618 return DBuilder.createSubroutineType(DBuilder.getOrCreateTypeArray(None));
2620 if (
const CXXMethodDecl *Method = dyn_cast<CXXMethodDecl>(D))
2621 return getOrCreateMethodType(Method, F);
2622 if (
const ObjCMethodDecl *OMethod = dyn_cast<ObjCMethodDecl>(D)) {
2627 QualType ResultTy = OMethod->getReturnType();
2632 QualType(OMethod->getClassInterface()->getTypeForDecl(), 0));
2634 Elts.push_back(getOrCreateType(ResultTy, F));
2637 if (
auto *SelfDecl = OMethod->getSelfDecl())
2638 SelfDeclTy = SelfDecl->getType();
2639 else if (
auto *FPT = dyn_cast<FunctionProtoType>(FnType))
2642 if (!SelfDeclTy.
isNull())
2643 Elts.push_back(CreateSelfType(SelfDeclTy, getOrCreateType(SelfDeclTy, F)));
2645 Elts.push_back(DBuilder.createArtificialType(
2648 for (
const auto *PI : OMethod->params())
2649 Elts.push_back(getOrCreateType(PI->getType(), F));
2651 if (OMethod->isVariadic())
2652 Elts.push_back(DBuilder.createUnspecifiedParameter());
2654 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(Elts);
2655 return DBuilder.createSubroutineType(EltTypeArray);
2660 if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D))
2665 for (
unsigned i = 0, e = FPT->
getNumParams(); i != e; ++i)
2666 EltTys.push_back(getOrCreateType(FPT->
getParamType(i), F));
2667 EltTys.push_back(DBuilder.createUnspecifiedParameter());
2668 llvm::DITypeRefArray EltTypeArray = DBuilder.getOrCreateTypeArray(EltTys);
2669 return DBuilder.createSubroutineType(EltTypeArray);
2672 return cast<llvm::DISubroutineType>(getOrCreateType(FnType, F));
2680 StringRef LinkageName;
2682 FnBeginRegionCount.push_back(LexicalBlockStack.size());
2685 bool HasDecl = (D !=
nullptr);
2688 llvm::DIFile *Unit = getOrCreateFile(Loc);
2689 llvm::DIScope *FDContext = Unit;
2690 llvm::DINodeArray TParamsArray;
2693 LinkageName = Fn->getName();
2694 }
else if (
const FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
2697 if (FI != SPCache.end()) {
2698 auto *SP = dyn_cast_or_null<llvm::DISubprogram>(FI->second);
2699 if (SP && SP->isDefinition()) {
2700 LexicalBlockStack.emplace_back(SP);
2701 RegionMap[D].reset(SP);
2705 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
2706 TParamsArray, Flags);
2707 }
else if (
const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
2708 Name = getObjCMethodName(OMD);
2709 Flags |= llvm::DINode::FlagPrototyped;
2712 Name = Fn->getName();
2713 Flags |= llvm::DINode::FlagPrototyped;
2715 if (!Name.empty() && Name[0] ==
'\01')
2716 Name = Name.substr(1);
2719 Flags |= llvm::DINode::FlagArtificial;
2724 unsigned LineNo = getLineNumber(Loc);
2725 unsigned ScopeLine = getLineNumber(ScopeLoc);
2732 llvm::DISubprogram *SP = DBuilder.createFunction(
2733 FDContext, Name, LinkageName, Unit, LineNo,
2734 getOrCreateFunctionType(D, FnType, Unit), Fn->hasInternalLinkage(),
2735 true , ScopeLine, Flags, CGM.
getLangOpts().Optimize,
2736 TParamsArray.get(), getFunctionDeclaration(D));
2737 Fn->setSubprogram(SP);
2741 if (HasDecl && isa<FunctionDecl>(D))
2745 LexicalBlockStack.emplace_back(SP);
2748 RegionMap[D].reset(SP);
2754 StringRef LinkageName;
2761 llvm::DIFile *Unit = getOrCreateFile(Loc);
2762 llvm::DIScope *FDContext = getDeclContextDescriptor(D);
2763 llvm::DINodeArray TParamsArray;
2764 if (isa<FunctionDecl>(D)) {
2766 collectFunctionDeclProps(GD, Unit, Name, LinkageName, FDContext,
2767 TParamsArray, Flags);
2768 }
else if (
const ObjCMethodDecl *OMD = dyn_cast<ObjCMethodDecl>(D)) {
2769 Name = getObjCMethodName(OMD);
2770 Flags |= llvm::DINode::FlagPrototyped;
2772 llvm_unreachable(
"not a function or ObjC method");
2774 if (!Name.empty() && Name[0] ==
'\01')
2775 Name = Name.substr(1);
2778 Flags |= llvm::DINode::FlagArtificial;
2783 unsigned LineNo = getLineNumber(Loc);
2784 unsigned ScopeLine = 0;
2786 DBuilder.createFunction(FDContext, Name, LinkageName, Unit, LineNo,
2787 getOrCreateFunctionType(D, FnType, Unit),
2790 TParamsArray.get(), getFunctionDeclaration(D));
2800 llvm::MDNode *
Scope = LexicalBlockStack.back();
2801 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
2802 getLineNumber(CurLoc), getColumnNumber(CurLoc), Scope));
2806 llvm::MDNode *Back =
nullptr;
2807 if (!LexicalBlockStack.empty())
2808 Back = LexicalBlockStack.back().get();
2809 LexicalBlockStack.emplace_back(DBuilder.createLexicalBlock(
2810 cast<llvm::DIScope>(Back), getOrCreateFile(CurLoc), getLineNumber(CurLoc),
2811 getColumnNumber(CurLoc)));
2820 Builder.SetCurrentDebugLocation(llvm::DebugLoc::get(
2821 getLineNumber(Loc), getColumnNumber(Loc), LexicalBlockStack.back()));
2827 CreateLexicalBlock(Loc);
2832 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
2840 LexicalBlockStack.pop_back();
2844 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
2845 unsigned RCount = FnBeginRegionCount.back();
2846 assert(RCount <= LexicalBlockStack.size() &&
"Region stack mismatch");
2849 while (LexicalBlockStack.size() != RCount) {
2852 LexicalBlockStack.pop_back();
2854 FnBeginRegionCount.pop_back();
2857 llvm::DIType *CGDebugInfo::EmitTypeForVarWithBlocksAttr(
const VarDecl *VD,
2858 uint64_t *XOffset) {
2862 uint64_t FieldSize, FieldOffset;
2863 unsigned FieldAlign;
2865 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
2870 EltTys.push_back(CreateMemberType(Unit, FType,
"__isa", &FieldOffset));
2871 EltTys.push_back(CreateMemberType(Unit, FType,
"__forwarding", &FieldOffset));
2873 EltTys.push_back(CreateMemberType(Unit, FType,
"__flags", &FieldOffset));
2874 EltTys.push_back(CreateMemberType(Unit, FType,
"__size", &FieldOffset));
2877 if (HasCopyAndDispose) {
2880 CreateMemberType(Unit, FType,
"__copy_helper", &FieldOffset));
2882 CreateMemberType(Unit, FType,
"__destroy_helper", &FieldOffset));
2884 bool HasByrefExtendedLayout;
2887 HasByrefExtendedLayout) &&
2888 HasByrefExtendedLayout) {
2891 CreateMemberType(Unit, FType,
"__byref_variable_layout", &FieldOffset));
2901 CharUnits NumPaddingBytes = AlignedOffsetInBytes - FieldOffsetInBytes;
2904 llvm::APInt pad(32, NumPaddingBytes.
getQuantity());
2907 EltTys.push_back(CreateMemberType(Unit, FType,
"", &FieldOffset));
2912 llvm::DIType *FieldTy = getOrCreateType(FType, Unit);
2916 *XOffset = FieldOffset;
2917 FieldTy = DBuilder.createMemberType(Unit, VD->
getName(), Unit, 0, FieldSize,
2918 FieldAlign, FieldOffset, 0, FieldTy);
2919 EltTys.push_back(FieldTy);
2920 FieldOffset += FieldSize;
2922 llvm::DINodeArray Elements = DBuilder.getOrCreateArray(EltTys);
2924 unsigned Flags = llvm::DINode::FlagBlockByrefStruct;
2926 return DBuilder.createStructType(Unit,
"", Unit, 0, FieldOffset, 0, Flags,
2934 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
2939 llvm::DIFile *Unit =
nullptr;
2943 uint64_t XOffset = 0;
2944 if (VD->
hasAttr<BlocksAttr>())
2945 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
2947 Ty = getOrCreateType(VD->
getType(), Unit);
2964 Flags |= llvm::DINode::FlagArtificial;
2970 if (isa<ImplicitParamDecl>(VD) && ArgNo && *ArgNo == 1)
2971 Flags |= llvm::DINode::FlagObjectPointer;
2972 if (llvm::Argument *Arg = dyn_cast<llvm::Argument>(Storage))
2973 if (Arg->getType()->isPointerTy() && !Arg->hasByValAttr() &&
2975 Expr.push_back(llvm::dwarf::DW_OP_deref);
2977 auto *
Scope = cast<llvm::DIScope>(LexicalBlockStack.back());
2979 StringRef Name = VD->
getName();
2980 if (!Name.empty()) {
2981 if (VD->
hasAttr<BlocksAttr>()) {
2983 Expr.push_back(llvm::dwarf::DW_OP_plus);
2988 Expr.push_back(llvm::dwarf::DW_OP_deref);
2989 Expr.push_back(llvm::dwarf::DW_OP_plus);
2996 ? DBuilder.createParameterVariable(
Scope, VD->
getName(),
2997 *ArgNo, Unit,
Line, Ty)
2998 : DBuilder.createAutoVariable(
Scope, VD->
getName(), Unit,
3002 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3003 llvm::DebugLoc::get(Line, Column,
Scope),
3004 Builder.GetInsertBlock());
3006 }
else if (isa<VariableArrayType>(VD->
getType()))
3007 Expr.push_back(llvm::dwarf::DW_OP_deref);
3011 const RecordDecl *RD = cast<RecordDecl>(RT->getDecl());
3020 for (
const auto *Field : RD->
fields()) {
3021 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
3022 StringRef FieldName = Field->getName();
3025 if (FieldName.empty() && !isa<RecordType>(Field->getType()))
3029 auto *D = DBuilder.createAutoVariable(
3031 Flags | llvm::DINode::FlagArtificial);
3034 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3035 llvm::DebugLoc::get(Line, Column,
Scope),
3036 Builder.GetInsertBlock());
3044 ? DBuilder.createParameterVariable(
Scope, Name, *ArgNo, Unit, Line,
3047 : DBuilder.createAutoVariable(
Scope, Name, Unit, Line, Ty,
3051 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(Expr),
3052 llvm::DebugLoc::get(Line, Column,
Scope),
3053 Builder.GetInsertBlock());
3060 EmitDeclare(VD, Storage,
llvm::None, Builder);
3063 llvm::DIType *CGDebugInfo::CreateSelfType(
const QualType &QualTy,
3065 llvm::DIType *CachedTy = getTypeOrNull(QualTy);
3068 return DBuilder.createObjectPointerType(Ty);
3073 const CGBlockInfo &blockInfo, llvm::Instruction *InsertPoint) {
3075 assert(!LexicalBlockStack.empty() &&
"Region stack mismatch, stack empty!");
3077 if (Builder.GetInsertBlock() ==
nullptr)
3080 bool isByRef = VD->
hasAttr<BlocksAttr>();
3082 uint64_t XOffset = 0;
3083 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
3086 Ty = EmitTypeForVarWithBlocksAttr(VD, &XOffset);
3088 Ty = getOrCreateType(VD->
getType(), Unit);
3092 if (isa<ImplicitParamDecl>(VD) && VD->
getName() ==
"self")
3093 Ty = CreateSelfType(VD->
getType(), Ty);
3097 unsigned Column = getColumnNumber(VD->
getLocation());
3106 if (isa<llvm::AllocaInst>(Storage))
3107 addr.push_back(llvm::dwarf::DW_OP_deref);
3108 addr.push_back(llvm::dwarf::DW_OP_plus);
3111 addr.push_back(llvm::dwarf::DW_OP_deref);
3112 addr.push_back(llvm::dwarf::DW_OP_plus);
3117 addr.push_back(llvm::dwarf::DW_OP_deref);
3118 addr.push_back(llvm::dwarf::DW_OP_plus);
3125 auto *D = DBuilder.createAutoVariable(
3126 cast<llvm::DILocalScope>(LexicalBlockStack.back()), VD->
getName(), Unit,
3130 auto DL = llvm::DebugLoc::get(Line, Column, LexicalBlockStack.back());
3132 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,
3135 DBuilder.insertDeclare(Storage, D, DBuilder.createExpression(addr), DL,
3136 Builder.GetInsertBlock());
3143 EmitDeclare(VD, AI, ArgNo, Builder);
3147 struct BlockLayoutChunk {
3148 uint64_t OffsetInBits;
3151 bool operator<(
const BlockLayoutChunk &l,
const BlockLayoutChunk &r) {
3152 return l.OffsetInBits < r.OffsetInBits;
3167 llvm::DIFile *tunit = getOrCreateFile(loc);
3168 unsigned line = getLineNumber(loc);
3169 unsigned column = getColumnNumber(loc);
3172 getDeclContextDescriptor(blockDecl);
3174 const llvm::StructLayout *blockLayout =
3179 blockLayout->getElementOffsetInBits(0),
3181 fields.push_back(createFieldType(
"__flags", C.
IntTy, 0, loc,
AS_public,
3182 blockLayout->getElementOffsetInBits(1),
3184 fields.push_back(createFieldType(
"__reserved", C.
IntTy, 0, loc,
AS_public,
3185 blockLayout->getElementOffsetInBits(2),
3189 fields.push_back(createFieldType(
"__FuncPtr", FnPtrType, 0, loc,
AS_public,
3190 blockLayout->getElementOffsetInBits(3),
3192 fields.push_back(createFieldType(
3196 0, loc,
AS_public, blockLayout->getElementOffsetInBits(4), tunit, tunit));
3204 BlockLayoutChunk chunk;
3205 chunk.OffsetInBits =
3206 blockLayout->getElementOffsetInBits(block.
CXXThisIndex);
3207 chunk.Capture =
nullptr;
3208 chunks.push_back(chunk);
3212 for (
const auto &capture : blockDecl->
captures()) {
3213 const VarDecl *variable = capture.getVariable();
3220 BlockLayoutChunk chunk;
3221 chunk.OffsetInBits =
3222 blockLayout->getElementOffsetInBits(captureInfo.
getIndex());
3223 chunk.Capture = &capture;
3224 chunks.push_back(chunk);
3228 llvm::array_pod_sort(chunks.begin(), chunks.end());
3233 uint64_t offsetInBits = i->OffsetInBits;
3242 fields.push_back(createFieldType(
"this", type, 0, loc,
AS_public,
3243 offsetInBits, tunit, tunit));
3248 StringRef name = variable->
getName();
3250 llvm::DIType *fieldType;
3256 fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset);
3257 fieldType = DBuilder.createPointerType(fieldType, PtrInfo.
Width);
3259 DBuilder.createMemberType(tunit, name, tunit, line, PtrInfo.
Width,
3260 PtrInfo.
Align, offsetInBits, 0, fieldType);
3263 offsetInBits, tunit, tunit);
3265 fields.push_back(fieldType);
3269 llvm::raw_svector_ostream(typeName) <<
"__block_literal_"
3272 llvm::DINodeArray fieldsArray = DBuilder.getOrCreateArray(fields);
3274 llvm::DIType *type = DBuilder.createStructType(
3275 tunit, typeName.str(), tunit, line,
3281 unsigned flags = llvm::DINode::FlagArtificial;
3282 auto *scope = cast<llvm::DILocalScope>(LexicalBlockStack.back());
3285 auto *debugVar = DBuilder.createParameterVariable(
3286 scope, Arg->getName(), ArgNo, tunit, line,
type,
3291 DBuilder.insertDbgValueIntrinsic(
3292 LocalAddr, 0, debugVar, DBuilder.createExpression(),
3293 llvm::DebugLoc::get(line, column, scope), Builder.GetInsertBlock());
3297 DBuilder.insertDeclare(Arg, debugVar, DBuilder.createExpression(),
3298 llvm::DebugLoc::get(line, column, scope),
3299 Builder.GetInsertBlock());
3302 llvm::DIDerivedType *
3303 CGDebugInfo::getOrCreateStaticDataMemberDeclarationOrNull(
const VarDecl *D) {
3308 if (MI != StaticDataMemberCache.end()) {
3309 assert(MI->second &&
"Static data member declaration should still exist");
3316 auto *Ctxt = cast<llvm::DICompositeType>(getDeclContextDescriptor(D));
3317 return CreateRecordStaticField(D, Ctxt, cast<RecordDecl>(DC));
3320 llvm::DIGlobalVariable *CGDebugInfo::CollectAnonRecordDecls(
3321 const RecordDecl *RD, llvm::DIFile *Unit,
unsigned LineNo,
3322 StringRef LinkageName, llvm::GlobalVariable *Var, llvm::DIScope *DContext) {
3323 llvm::DIGlobalVariable *GV =
nullptr;
3325 for (
const auto *Field : RD->
fields()) {
3326 llvm::DIType *FieldTy = getOrCreateType(Field->getType(), Unit);
3327 StringRef FieldName = Field->getName();
3330 if (FieldName.empty()) {
3333 GV = CollectAnonRecordDecls(RT->
getDecl(), Unit, LineNo, LinkageName,
3338 GV = DBuilder.createGlobalVariable(DContext, FieldName, LinkageName, Unit,
3340 Var->hasInternalLinkage(), Var,
nullptr);
3349 llvm::DIFile *Unit =
nullptr;
3350 llvm::DIScope *DContext =
nullptr;
3352 StringRef DeclName, LinkageName;
3354 collectVarDeclProps(D, Unit, LineNo, T, DeclName, LinkageName, DContext);
3358 llvm::DIGlobalVariable *GV =
nullptr;
3366 "unnamed non-anonymous struct or union?");
3367 GV = CollectAnonRecordDecls(RD, Unit, LineNo, LinkageName, Var, DContext);
3369 GV = DBuilder.createGlobalVariable(
3370 DContext, DeclName, LinkageName, Unit, LineNo, getOrCreateType(T, Unit),
3371 Var->hasInternalLinkage(), Var,
3372 getOrCreateStaticDataMemberDeclarationOrNull(D));
3378 llvm::Constant *Init) {
3381 llvm::DIFile *Unit = getOrCreateFile(VD->
getLocation());
3382 StringRef Name = VD->
getName();
3383 llvm::DIType *Ty = getOrCreateType(VD->
getType(), Unit);
3385 const EnumDecl *ED = cast<EnumDecl>(ECD->getDeclContext());
3386 assert(isa<EnumType>(ED->
getTypeForDecl()) &&
"Enum without EnumType?");
3392 if (Ty->getTag() == llvm::dwarf::DW_TAG_enumeration_type)
3398 auto *VarD = cast<VarDecl>(VD);
3399 if (VarD->isStaticDataMember()) {
3400 auto *RD = cast<RecordDecl>(VarD->getDeclContext());
3401 getDeclContextDescriptor(VarD);
3403 RetainedTypes.push_back(
3408 llvm::DIScope *DContext = getDeclContextDescriptor(VD);
3410 auto &GV = DeclCache[VD];
3413 GV.reset(DBuilder.createGlobalVariable(
3414 DContext, Name, StringRef(), Unit, getLineNumber(VD->
getLocation()), Ty,
3415 true, Init, getOrCreateStaticDataMemberDeclarationOrNull(VarD)));
3418 llvm::DIScope *CGDebugInfo::getCurrentContextDescriptor(
const Decl *D) {
3419 if (!LexicalBlockStack.empty())
3420 return LexicalBlockStack.back();
3421 llvm::DIScope *Mod = getParentModuleOrNull(D);
3422 return getContextDescriptor(D, Mod ? Mod : TheCU);
3431 DBuilder.createImportedModule(
3433 getOrCreateNameSpace(NSDecl),
3442 "We shouldn't be codegening an invalid UsingDecl containing no decls");
3446 if (llvm::DINode *Target =
3447 getDeclarationOrDefinition(USD.getUnderlyingDecl()))
3448 DBuilder.createImportedDeclaration(
3449 getCurrentContextDescriptor(cast<Decl>(USD.getDeclContext())), Target,
3450 getLineNumber(USD.getLocation()));
3456 DBuilder.createImportedDeclaration(
3458 getOrCreateModuleRef(Info, DebugTypeExtRefs),
3463 llvm::DIImportedEntity *
3467 auto &VH = NamespaceAliasCache[&NA];
3469 return cast<llvm::DIImportedEntity>(VH);
3470 llvm::DIImportedEntity *R;
3474 R = DBuilder.createImportedDeclaration(
3479 R = DBuilder.createImportedDeclaration(
3488 CGDebugInfo::getOrCreateNameSpace(
const NamespaceDecl *NSDecl) {
3490 auto I = NameSpaceCache.find(NSDecl);
3491 if (I != NameSpaceCache.end())
3492 return cast<llvm::DINamespace>(I->second);
3494 unsigned LineNo = getLineNumber(NSDecl->
getLocation());
3495 llvm::DIFile *FileD = getOrCreateFile(NSDecl->
getLocation());
3496 llvm::DIScope *Context = getDeclContextDescriptor(NSDecl);
3497 llvm::DINamespace *NS =
3498 DBuilder.createNameSpace(Context, NSDecl->
getName(), FileD, LineNo);
3499 NameSpaceCache[NSDecl].reset(NS);
3504 assert(TheCU &&
"no main compile unit");
3505 TheCU->setDWOId(Signature);
3512 for (
size_t i = 0; i != ObjCInterfaceCache.size(); ++i) {
3513 ObjCInterfaceCacheEntry E = ObjCInterfaceCache[i];
3514 llvm::DIType *Ty = E.Type->getDecl()->getDefinition()
3515 ? CreateTypeDefinition(E.Type, E.Unit)
3517 DBuilder.replaceTemporary(llvm::TempDIType(E.Decl), Ty);
3520 for (
auto p : ReplaceMap) {
3522 auto *Ty = cast<llvm::DIType>(
p.second);
3523 assert(Ty->isForwardDecl());
3525 auto it = TypeCache.find(
p.first);
3526 assert(it != TypeCache.end());
3529 DBuilder.replaceTemporary(llvm::TempDIType(Ty),
3530 cast<llvm::DIType>(it->second));
3533 for (
const auto &
p : FwdDeclReplaceMap) {
3535 llvm::TempMDNode FwdDecl(cast<llvm::MDNode>(
p.second));
3536 llvm::Metadata *Repl;
3538 auto it = DeclCache.find(
p.first);
3542 if (it == DeclCache.end())
3547 DBuilder.replaceTemporary(std::move(FwdDecl), cast<llvm::MDNode>(Repl));
3552 for (
auto &RT : RetainedTypes)
3553 if (
auto MD = TypeCache[RT])
3554 DBuilder.retainType(cast<llvm::DIType>(MD));
3556 DBuilder.finalize();
3563 if (
auto *DieTy = getOrCreateType(Ty, getOrCreateMainFile()))
3565 DBuilder.retainType(DieTy);
unsigned getNumElements() const
ArrayRef< ParmVarDecl * > parameters() 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.
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.
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.
EnumConstantDecl - An instance of this object exists for each enum constant that is defined...
Defines the SourceManager interface.
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
Decl - This represents one declaration (or definition), e.g.
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.
TemplateSpecializationType(TemplateName T, const TemplateArgument *Args, unsigned NumArgs, QualType Canon, QualType Aliased)
QualType getPointeeType() const
The base class of the type hierarchy.
Emit only debug info necessary for generating line number tables (-gline-tables-only).
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.
Describes the capture of a variable or of this, or of a C++1y init-capture.
llvm::IntegerType * Int8Ty
i8, i16, i32, and i64
Represents a C++ constructor within a class.
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.
AccessSpecifier getAccess() const
field_iterator field_begin() const
const FunctionProtoType * getFunctionType() const
getFunctionType - Return the underlying function type for this block.
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.
llvm::Constant * GetAddrOfGlobalVar(const VarDecl *D, llvm::Type *Ty=nullptr)
Return the llvm::Constant for the address of the given global variable.
NamespaceDecl * getCanonicalDecl() override
Retrieves the canonical declaration of this namespace.
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
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.
Don't generate debug info.
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
Retrieves the "canonical" declaration of the given declaration.
const CXXRecordDecl * getPointeeCXXRecordDecl() const
If this is a pointer or reference to a RecordType, return the CXXRecordDecl that that type refers to...
unsigned size() const
Retrieve the number of template arguments in this template argument list.
unsigned shadow_size() const
Return the number of shadowed declarations associated with this using declaration.
void completeClassData(const RecordDecl *RD)
Emit location information but do not generate debug info in the output.
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.
An rvalue reference type, per C++11 [dcl.ref].
An lvalue ref-qualifier was provided (&).
bool isImplicit() const
isImplicit - Indicates whether the declaration was implicitly generated by the implementation.
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...
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.
TypeDecl - Represents a declaration of a type.
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.
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.
bool isIncompleteType(NamedDecl **Def=nullptr) const
Types are partitioned into 3 broad categories (C99 6.2.5p1): object types, function types...
DeclContext * getLexicalDeclContext()
getLexicalDeclContext - The declaration context where this Decl was lexically declared (LexicalDC)...
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.
static void PrintTemplateArgumentList(raw_ostream &OS, const TemplateArgument *Args, unsigned NumArgs, const PrintingPolicy &Policy, bool SkipBrackets=false)
Print a template argument list, including the '<' and '>' enclosing the template arguments...
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...
virtual Decl * getCanonicalDecl()
Retrieves the "canonical" declaration of the given declaration.
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...
const HeaderSearchOptions & getHeaderSearchOpts() const
TypeAliasDecl - Represents the declaration of a typedef-name via a C++0x alias-declaration.
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
unsigned getOwningModuleID() const
Retrieve the global ID of the module that owns this particular declaration.
void setDwoId(uint64_t Signature)
Set the main CU's DwoId field to Signature.
ArrayRef< TemplateArgument > asArray() const
Produce this as an array ref.
ID
Defines the set of possible language-specific address spaces.
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.
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...
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
DeclContext * getDeclContext()
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.
void print(raw_ostream &OS, const PrintingPolicy &Policy, const Twine &PlaceHolder=Twine()) const
bool isInstanceMethod() const
clang::ObjCRuntime ObjCRuntime
virtual llvm::Constant * EmitMemberFunctionPointer(const CXXMethodDecl *MD)
Create a member pointer for the given method.
bool isObjCQualifiedIdType() const
True if this is equivalent to 'id.
bool isFromASTFile() const
Determine whether this declaration came from an AST file (such as a precompiled header or module) rat...
QualType getObjCIdType() const
Represents the Objective-CC id type.
const TemplateArgument * data() const
Retrieve a pointer to the template argument list.
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.
class LLVM_ALIGNAS(8) TemplateSpecializationType unsigned NumArgs
Represents a type template specialization; the template must be a class template, a type alias templa...
QualType getElementType() const
Represents a C++ conversion function within a class.
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.
VarDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
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.
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
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.
unsigned getBitWidthValue(const ASTContext &Ctx) 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)
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.
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.
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()
bool isAnonymousStructOrUnion() const
isAnonymousStructOrUnion - Whether this is an anonymous struct or union.
Represents a template argument.
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...
static __inline__ uint32_t volatile uint32_t * p
ObjCInterfaceDecl * getDefinition()
Retrieve the definition of this class, or NULL if this class has been forward-declared (with @class) ...
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.
Decl * getNonClosureContext()
Find the innermost non-closure ancestor of this declaration, walking up through blocks, lambdas, etc.
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.
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.
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
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
SourceLocation getLocation() const
FunctionDecl * getCanonicalDecl() override
Retrieves the "canonical" declaration of the given declaration.
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...
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
Represents a C array with a specified size that is not an integer-constant-expression.
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.
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.
CharUnits RoundUpToAlignment(const CharUnits &Align) const
RoundUpToAlignment - Returns the next integer (mod 2**64) that is greater than or equal to this quant...
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()
ObjCCategoryImplDecl - An object of this class encapsulates a category @implementation declaration...
Represents the canonical version of C arrays with a specified constant size.
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.
Represents a shadow declaration introduced into a scope by a (resolved) using declaration.
bool capturesVariable() const
Determine whether this capture handles a variable.
bool isPointerType() const
static bool shouldOmitDefinition(CodeGenOptions::DebugInfoKind DebugKind, bool DebugTypeExtRefs, const RecordDecl *RD, const LangOptions &LangOpts)
PresumedLoc getPresumedLoc(SourceLocation Loc, bool UseLineDirectives=true) const
Returns the "presumed" location of a SourceLocation specifies.