diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 88cc5be4ded6..687aea5c0879 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -314,8 +314,9 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) { llvm::SmallVector EltTys; llvm::DIType FieldTy = - DBuilder.createMemberType("isa", getOrCreateMainFile(), - 0,Size, 0, 0, 0, ISATy); + DBuilder.createMemberType(getOrCreateMainFile(), "isa", + getOrCreateMainFile(), 0, Size, + 0, 0, 0, ISATy); EltTys.push_back(FieldTy); llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); @@ -529,7 +530,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty, FieldTy = DescTy; FieldSize = CGM.getContext().getTypeSize(Ty); FieldAlign = CGM.getContext().getTypeAlign(Ty); - FieldTy = DBuilder.createMemberType("__descriptor", Unit, + FieldTy = DBuilder.createMemberType(Unit, "__descriptor", Unit, LineNo, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -592,7 +593,8 @@ llvm::DIType CGDebugInfo::createFieldType(llvm::StringRef name, SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, - llvm::DIFile tunit) { + llvm::DIFile tunit, + llvm::DIDescriptor scope) { llvm::DIType debugType = getOrCreateType(type, tunit); // Get the location for the field. @@ -614,15 +616,16 @@ llvm::DIType CGDebugInfo::createFieldType(llvm::StringRef name, else if (AS == clang::AS_protected) flags |= llvm::DIDescriptor::FlagProtected; - return DBuilder.createMemberType(name, file, line, sizeInBits, alignInBits, - offsetInBits, flags, debugType); + return DBuilder.createMemberType(scope, name, file, line, sizeInBits, + alignInBits, offsetInBits, flags, debugType); } /// CollectRecordFields - A helper function to collect debug info for /// record fields. This is used while creating debug info entry for a Record. void CGDebugInfo:: CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit, - llvm::SmallVectorImpl &elements) { + llvm::SmallVectorImpl &elements, + llvm::DIType RecordTy) { unsigned fieldNo = 0; const FieldDecl *LastFD = 0; bool IsMsStruct = record->hasAttr(); @@ -653,7 +656,7 @@ CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit, llvm::DIType fieldType = createFieldType(name, type, field->getBitWidth(), field->getLocation(), field->getAccess(), - layout.getFieldOffset(fieldNo), tunit); + layout.getFieldOffset(fieldNo), tunit, RecordTy); elements.push_back(fieldType); } @@ -961,7 +964,7 @@ CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit, unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); llvm::DIType VPTR - = DBuilder.createMemberType(getVTableName(RD), Unit, + = DBuilder.createMemberType(Unit, getVTableName(RD), Unit, 0, Size, 0, 0, 0, getOrCreateVTablePtrType(Unit)); EltTys.push_back(VPTR); @@ -1049,7 +1052,7 @@ llvm::DIType CGDebugInfo::CreateType(const RecordType *Ty) { } } - CollectRecordFields(RD, Unit, EltTys); + CollectRecordFields(RD, Unit, EltTys, FwdDecl); llvm::DIArray TParamsArray; if (CXXDecl) { CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); @@ -1380,13 +1383,13 @@ llvm::DIType CGDebugInfo::CreateType(const MemberPointerType *Ty, // FIXME: This should probably be a function type instead. ElementTypes[0] = - DBuilder.createMemberType("ptr", U, 0, + DBuilder.createMemberType(U, "ptr", U, 0, Info.first, Info.second, FieldOffset, 0, PointerDiffDITy); FieldOffset += Info.first; ElementTypes[1] = - DBuilder.createMemberType("ptr", U, 0, + DBuilder.createMemberType(U, "ptr", U, 0, Info.first, Info.second, FieldOffset, 0, PointerDiffDITy); @@ -1587,7 +1590,7 @@ llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType, llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); uint64_t FieldSize = CGM.getContext().getTypeSize(FType); unsigned FieldAlign = CGM.getContext().getTypeAlign(FType); - llvm::DIType Ty = DBuilder.createMemberType(Name, Unit, 0, + llvm::DIType Ty = DBuilder.createMemberType(Unit, Name, Unit, 0, FieldSize, FieldAlign, *Offset, 0, FieldTy); *Offset += FieldSize; @@ -1898,7 +1901,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD, FieldAlign = CGM.getContext().toBits(Align); *XOffset = FieldOffset; - FieldTy = DBuilder.createMemberType(VD->getName(), Unit, + FieldTy = DBuilder.createMemberType(Unit, VD->getName(), Unit, 0, FieldSize, FieldAlign, FieldOffset, 0, FieldTy); EltTys.push_back(FieldTy); @@ -2134,23 +2137,23 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, llvm::SmallVector fields; fields.push_back(createFieldType("__isa", C.VoidPtrTy, 0, loc, AS_public, blockLayout->getElementOffsetInBits(0), - tunit)); + tunit, tunit)); fields.push_back(createFieldType("__flags", C.IntTy, 0, loc, AS_public, blockLayout->getElementOffsetInBits(1), - tunit)); + tunit, tunit)); fields.push_back(createFieldType("__reserved", C.IntTy, 0, loc, AS_public, blockLayout->getElementOffsetInBits(2), - tunit)); + tunit, tunit)); fields.push_back(createFieldType("__FuncPtr", C.VoidPtrTy, 0, loc, AS_public, blockLayout->getElementOffsetInBits(3), - tunit)); + tunit, tunit)); fields.push_back(createFieldType("__descriptor", C.getPointerType(block.NeedsCopyDispose ? C.getBlockDescriptorExtendedType() : C.getBlockDescriptorType()), 0, loc, AS_public, blockLayout->getElementOffsetInBits(4), - tunit)); + tunit, tunit)); // We want to sort the captures by offset, not because DWARF // requires this, but because we're paranoid about debuggers. @@ -2199,7 +2202,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, QualType type = method->getThisType(C); fields.push_back(createFieldType("this", type, 0, loc, AS_public, - offsetInBits, tunit)); + offsetInBits, tunit, tunit)); continue; } @@ -2214,12 +2217,12 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block, uint64_t xoffset; fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset); fieldType = DBuilder.createPointerType(fieldType, ptrInfo.first); - fieldType = DBuilder.createMemberType(name, tunit, line, + fieldType = DBuilder.createMemberType(tunit, name, tunit, line, ptrInfo.first, ptrInfo.second, offsetInBits, 0, fieldType); } else { fieldType = createFieldType(name, variable->getType(), 0, - loc, AS_public, offsetInBits, tunit); + loc, AS_public, offsetInBits, tunit, tunit); } fields.push_back(fieldType); } diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index eb1b22d90270..f87d0072e323 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -139,9 +139,11 @@ class CGDebugInfo { llvm::DIType createFieldType(llvm::StringRef name, QualType type, Expr *bitWidth, SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, - llvm::DIFile tunit); + llvm::DIFile tunit, + llvm::DIDescriptor scope); void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, - llvm::SmallVectorImpl &E); + llvm::SmallVectorImpl &E, + llvm::DIType RecordTy); void CollectVTableInfo(const CXXRecordDecl *Decl, llvm::DIFile F, diff --git a/clang/test/CodeGen/debug-info-member.c b/clang/test/CodeGen/debug-info-member.c new file mode 100644 index 000000000000..54066fa53060 --- /dev/null +++ b/clang/test/CodeGen/debug-info-member.c @@ -0,0 +1,3 @@ +// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3 + +struct A { int x; } a;