Fix struct member's scope. Patch by Xi Wang.

llvm-svn: 133829
This commit is contained in:
Devang Patel 2011-06-24 22:00:59 +00:00
parent 503c3998f3
commit 15013e78c3
3 changed files with 32 additions and 24 deletions

View File

@ -314,8 +314,9 @@ llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) {
llvm::SmallVector<llvm::Value *, 16> EltTys; llvm::SmallVector<llvm::Value *, 16> EltTys;
llvm::DIType FieldTy = llvm::DIType FieldTy =
DBuilder.createMemberType("isa", getOrCreateMainFile(), DBuilder.createMemberType(getOrCreateMainFile(), "isa",
0,Size, 0, 0, 0, ISATy); getOrCreateMainFile(), 0, Size,
0, 0, 0, ISATy);
EltTys.push_back(FieldTy); EltTys.push_back(FieldTy);
llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys); llvm::DIArray Elements = DBuilder.getOrCreateArray(EltTys);
@ -529,7 +530,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
FieldTy = DescTy; FieldTy = DescTy;
FieldSize = CGM.getContext().getTypeSize(Ty); FieldSize = CGM.getContext().getTypeSize(Ty);
FieldAlign = CGM.getContext().getTypeAlign(Ty); FieldAlign = CGM.getContext().getTypeAlign(Ty);
FieldTy = DBuilder.createMemberType("__descriptor", Unit, FieldTy = DBuilder.createMemberType(Unit, "__descriptor", Unit,
LineNo, FieldSize, FieldAlign, LineNo, FieldSize, FieldAlign,
FieldOffset, 0, FieldTy); FieldOffset, 0, FieldTy);
EltTys.push_back(FieldTy); EltTys.push_back(FieldTy);
@ -592,7 +593,8 @@ llvm::DIType CGDebugInfo::createFieldType(llvm::StringRef name,
SourceLocation loc, SourceLocation loc,
AccessSpecifier AS, AccessSpecifier AS,
uint64_t offsetInBits, uint64_t offsetInBits,
llvm::DIFile tunit) { llvm::DIFile tunit,
llvm::DIDescriptor scope) {
llvm::DIType debugType = getOrCreateType(type, tunit); llvm::DIType debugType = getOrCreateType(type, tunit);
// Get the location for the field. // Get the location for the field.
@ -614,15 +616,16 @@ llvm::DIType CGDebugInfo::createFieldType(llvm::StringRef name,
else if (AS == clang::AS_protected) else if (AS == clang::AS_protected)
flags |= llvm::DIDescriptor::FlagProtected; flags |= llvm::DIDescriptor::FlagProtected;
return DBuilder.createMemberType(name, file, line, sizeInBits, alignInBits, return DBuilder.createMemberType(scope, name, file, line, sizeInBits,
offsetInBits, flags, debugType); alignInBits, offsetInBits, flags, debugType);
} }
/// CollectRecordFields - A helper function to collect debug info for /// CollectRecordFields - A helper function to collect debug info for
/// record fields. This is used while creating debug info entry for a Record. /// record fields. This is used while creating debug info entry for a Record.
void CGDebugInfo:: void CGDebugInfo::
CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit, CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit,
llvm::SmallVectorImpl<llvm::Value *> &elements) { llvm::SmallVectorImpl<llvm::Value *> &elements,
llvm::DIType RecordTy) {
unsigned fieldNo = 0; unsigned fieldNo = 0;
const FieldDecl *LastFD = 0; const FieldDecl *LastFD = 0;
bool IsMsStruct = record->hasAttr<MsStructAttr>(); bool IsMsStruct = record->hasAttr<MsStructAttr>();
@ -653,7 +656,7 @@ CollectRecordFields(const RecordDecl *record, llvm::DIFile tunit,
llvm::DIType fieldType llvm::DIType fieldType
= createFieldType(name, type, field->getBitWidth(), = createFieldType(name, type, field->getBitWidth(),
field->getLocation(), field->getAccess(), field->getLocation(), field->getAccess(),
layout.getFieldOffset(fieldNo), tunit); layout.getFieldOffset(fieldNo), tunit, RecordTy);
elements.push_back(fieldType); elements.push_back(fieldType);
} }
@ -961,7 +964,7 @@ CollectVTableInfo(const CXXRecordDecl *RD, llvm::DIFile Unit,
unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy); unsigned Size = CGM.getContext().getTypeSize(CGM.getContext().VoidPtrTy);
llvm::DIType VPTR llvm::DIType VPTR
= DBuilder.createMemberType(getVTableName(RD), Unit, = DBuilder.createMemberType(Unit, getVTableName(RD), Unit,
0, Size, 0, 0, 0, 0, Size, 0, 0, 0,
getOrCreateVTablePtrType(Unit)); getOrCreateVTablePtrType(Unit));
EltTys.push_back(VPTR); 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; llvm::DIArray TParamsArray;
if (CXXDecl) { if (CXXDecl) {
CollectCXXMemberFunctions(CXXDecl, Unit, EltTys, FwdDecl); 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. // FIXME: This should probably be a function type instead.
ElementTypes[0] = ElementTypes[0] =
DBuilder.createMemberType("ptr", U, 0, DBuilder.createMemberType(U, "ptr", U, 0,
Info.first, Info.second, FieldOffset, 0, Info.first, Info.second, FieldOffset, 0,
PointerDiffDITy); PointerDiffDITy);
FieldOffset += Info.first; FieldOffset += Info.first;
ElementTypes[1] = ElementTypes[1] =
DBuilder.createMemberType("ptr", U, 0, DBuilder.createMemberType(U, "ptr", U, 0,
Info.first, Info.second, FieldOffset, 0, Info.first, Info.second, FieldOffset, 0,
PointerDiffDITy); PointerDiffDITy);
@ -1587,7 +1590,7 @@ llvm::DIType CGDebugInfo::CreateMemberType(llvm::DIFile Unit, QualType FType,
llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit); llvm::DIType FieldTy = CGDebugInfo::getOrCreateType(FType, Unit);
uint64_t FieldSize = CGM.getContext().getTypeSize(FType); uint64_t FieldSize = CGM.getContext().getTypeSize(FType);
unsigned FieldAlign = CGM.getContext().getTypeAlign(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, FieldSize, FieldAlign,
*Offset, 0, FieldTy); *Offset, 0, FieldTy);
*Offset += FieldSize; *Offset += FieldSize;
@ -1898,7 +1901,7 @@ llvm::DIType CGDebugInfo::EmitTypeForVarWithBlocksAttr(const ValueDecl *VD,
FieldAlign = CGM.getContext().toBits(Align); FieldAlign = CGM.getContext().toBits(Align);
*XOffset = FieldOffset; *XOffset = FieldOffset;
FieldTy = DBuilder.createMemberType(VD->getName(), Unit, FieldTy = DBuilder.createMemberType(Unit, VD->getName(), Unit,
0, FieldSize, FieldAlign, 0, FieldSize, FieldAlign,
FieldOffset, 0, FieldTy); FieldOffset, 0, FieldTy);
EltTys.push_back(FieldTy); EltTys.push_back(FieldTy);
@ -2134,23 +2137,23 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
llvm::SmallVector<llvm::Value*, 16> fields; llvm::SmallVector<llvm::Value*, 16> fields;
fields.push_back(createFieldType("__isa", C.VoidPtrTy, 0, loc, AS_public, fields.push_back(createFieldType("__isa", C.VoidPtrTy, 0, loc, AS_public,
blockLayout->getElementOffsetInBits(0), blockLayout->getElementOffsetInBits(0),
tunit)); tunit, tunit));
fields.push_back(createFieldType("__flags", C.IntTy, 0, loc, AS_public, fields.push_back(createFieldType("__flags", C.IntTy, 0, loc, AS_public,
blockLayout->getElementOffsetInBits(1), blockLayout->getElementOffsetInBits(1),
tunit)); tunit, tunit));
fields.push_back(createFieldType("__reserved", C.IntTy, 0, loc, AS_public, fields.push_back(createFieldType("__reserved", C.IntTy, 0, loc, AS_public,
blockLayout->getElementOffsetInBits(2), blockLayout->getElementOffsetInBits(2),
tunit)); tunit, tunit));
fields.push_back(createFieldType("__FuncPtr", C.VoidPtrTy, 0, loc, AS_public, fields.push_back(createFieldType("__FuncPtr", C.VoidPtrTy, 0, loc, AS_public,
blockLayout->getElementOffsetInBits(3), blockLayout->getElementOffsetInBits(3),
tunit)); tunit, tunit));
fields.push_back(createFieldType("__descriptor", fields.push_back(createFieldType("__descriptor",
C.getPointerType(block.NeedsCopyDispose ? C.getPointerType(block.NeedsCopyDispose ?
C.getBlockDescriptorExtendedType() : C.getBlockDescriptorExtendedType() :
C.getBlockDescriptorType()), C.getBlockDescriptorType()),
0, loc, AS_public, 0, loc, AS_public,
blockLayout->getElementOffsetInBits(4), blockLayout->getElementOffsetInBits(4),
tunit)); tunit, tunit));
// We want to sort the captures by offset, not because DWARF // We want to sort the captures by offset, not because DWARF
// requires this, but because we're paranoid about debuggers. // requires this, but because we're paranoid about debuggers.
@ -2199,7 +2202,7 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
QualType type = method->getThisType(C); QualType type = method->getThisType(C);
fields.push_back(createFieldType("this", type, 0, loc, AS_public, fields.push_back(createFieldType("this", type, 0, loc, AS_public,
offsetInBits, tunit)); offsetInBits, tunit, tunit));
continue; continue;
} }
@ -2214,12 +2217,12 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
uint64_t xoffset; uint64_t xoffset;
fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset); fieldType = EmitTypeForVarWithBlocksAttr(variable, &xoffset);
fieldType = DBuilder.createPointerType(fieldType, ptrInfo.first); fieldType = DBuilder.createPointerType(fieldType, ptrInfo.first);
fieldType = DBuilder.createMemberType(name, tunit, line, fieldType = DBuilder.createMemberType(tunit, name, tunit, line,
ptrInfo.first, ptrInfo.second, ptrInfo.first, ptrInfo.second,
offsetInBits, 0, fieldType); offsetInBits, 0, fieldType);
} else { } else {
fieldType = createFieldType(name, variable->getType(), 0, fieldType = createFieldType(name, variable->getType(), 0,
loc, AS_public, offsetInBits, tunit); loc, AS_public, offsetInBits, tunit, tunit);
} }
fields.push_back(fieldType); fields.push_back(fieldType);
} }

View File

@ -139,9 +139,11 @@ class CGDebugInfo {
llvm::DIType createFieldType(llvm::StringRef name, QualType type, llvm::DIType createFieldType(llvm::StringRef name, QualType type,
Expr *bitWidth, SourceLocation loc, Expr *bitWidth, SourceLocation loc,
AccessSpecifier AS, uint64_t offsetInBits, AccessSpecifier AS, uint64_t offsetInBits,
llvm::DIFile tunit); llvm::DIFile tunit,
llvm::DIDescriptor scope);
void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F, void CollectRecordFields(const RecordDecl *Decl, llvm::DIFile F,
llvm::SmallVectorImpl<llvm::Value *> &E); llvm::SmallVectorImpl<llvm::Value *> &E,
llvm::DIType RecordTy);
void CollectVTableInfo(const CXXRecordDecl *Decl, void CollectVTableInfo(const CXXRecordDecl *Decl,
llvm::DIFile F, llvm::DIFile F,

View File

@ -0,0 +1,3 @@
// RUN: %clang_cc1 -emit-llvm -g < %s | grep DW_TAG_member | grep \!3
struct A { int x; } a;