Index: include/llvm/DebugInfo/CodeView/ListRecordBuilder.h =================================================================== --- include/llvm/DebugInfo/CodeView/ListRecordBuilder.h +++ include/llvm/DebugInfo/CodeView/ListRecordBuilder.h @@ -28,7 +28,13 @@ public: llvm::StringRef str() { return Builder.str(); } - void reset(TypeRecordKind K) { Builder.reset(K); } + void reset(TypeRecordKind K) { + Builder.reset(K); + ContinuationOffsets.clear(); + SubrecordCount = 0; + } + + unsigned getSubrecordCount() { return SubrecordCount; } protected: void finishSubRecord(); @@ -38,6 +44,7 @@ private: TypeRecordBuilder Builder; SmallVector ContinuationOffsets; + unsigned SubrecordCount = 0; }; } } Index: lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -191,6 +191,7 @@ codeview::TypeIndex lowerTypeMemberPointer(const DIDerivedType *Ty); codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty); codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty); + codeview::TypeIndex lowerTypeClass(const DICompositeType *Ty); public: CodeViewDebug(AsmPrinter *Asm); Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -13,6 +13,7 @@ #include "CodeViewDebug.h" #include "llvm/DebugInfo/CodeView/CodeView.h" +#include "llvm/DebugInfo/CodeView/FieldListRecordBuilder.h" #include "llvm/DebugInfo/CodeView/Line.h" #include "llvm/DebugInfo/CodeView/SymbolRecord.h" #include "llvm/DebugInfo/CodeView/TypeDumper.h" @@ -746,6 +747,10 @@ return lowerTypeModifier(cast(Ty)); case dwarf::DW_TAG_subroutine_type: return lowerTypeFunction(cast(Ty)); + case dwarf::DW_TAG_class_type: + case dwarf::DW_TAG_structure_type: + case dwarf::DW_TAG_union_type: + return lowerTypeClass(cast(Ty)); default: // Use the null type index. return TypeIndex(); @@ -962,6 +967,107 @@ return TypeTable.writeProcedure(Procedure); } +static MemberAccess translateAccessFlags(unsigned RecordTag, + const DIType *Member) { + switch (Member->getFlags() & DINode::FlagAccessibility) { + case DINode::FlagPrivate: return MemberAccess::Private; + case DINode::FlagPublic: return MemberAccess::Public; + case DINode::FlagProtected: return MemberAccess::Protected; + case 0: + // If there was no explicit access control, provide the default for the tag. + return RecordTag == dwarf::DW_TAG_class_type ? MemberAccess::Private + : MemberAccess::Public; + } + llvm_unreachable("access flags are exclusive"); +} + +TypeIndex CodeViewDebug::lowerTypeClass(const DICompositeType *Ty) { + // First, construct the forward decl. Don't look into Ty to compute the + // forward decl options, since it might not be available in all TUs. + TypeRecordKind Kind; + switch (Ty->getTag()) { + default: llvm_unreachable("unexpected tag"); + case dwarf::DW_TAG_class_type: Kind = TypeRecordKind::Class; break; + case dwarf::DW_TAG_structure_type: Kind = TypeRecordKind::Struct; break; + case dwarf::DW_TAG_union_type: Kind = TypeRecordKind::Union; break; + } + ClassOptions CO = ClassOptions::ForwardReference; + // Clang doesn't generate a unique mangling for things like function-local + // types, but MSVC does. + // FIXME: Investigate the consequences of not following them here. + if (!Ty->getIdentifier().empty()) + CO |= ClassOptions::HasUniqueName; + TypeIndex FwdDeclTI; + if (Kind == TypeRecordKind::Union) { + FwdDeclTI = + TypeTable.writeUnion(UnionRecord(0, CO, HfaKind::None, TypeIndex(), 0, + Ty->getName(), Ty->getIdentifier())); + } else { + FwdDeclTI = TypeTable.writeClass(ClassRecord( + Kind, 0, CO, HfaKind::None, WindowsRTClassKind::None, TypeIndex(), + TypeIndex(), TypeIndex(), 0, Ty->getName(), Ty->getIdentifier())); + } + + // Construct the field list and complete type record if this is not a forward + // decl. + if (!Ty->isForwardDecl()) { + FieldListRecordBuilder Fields; + for (const DINode *Element : Ty->getElements()) { + // We assume that the frontend provides all members in source declaration + // order, which is what MSVC does. + if (!Element) + continue; + if (auto *SP = dyn_cast(Element)) { + // C++ method. + // FIXME: Overloaded methods are grouped together, so we'll need two + // passes to group them. + (void)SP; + } else if (auto *Member = dyn_cast(Element)) { + if (Member->getTag() == dwarf::DW_TAG_member) { + if (Member->isStaticMember()) { + // Static data member. + Fields.writeStaticDataMember(StaticDataMemberRecord( + translateAccessFlags(Ty->getTag(), Member), + getTypeIndex(Member->getBaseType()), Member->getName())); + } else { + // Data member. + Fields.writeDataMember(DataMemberRecord( + translateAccessFlags(Ty->getTag(), Member), + getTypeIndex(Member->getBaseType()), + Member->getOffsetInBits() / 8, Member->getName())); + } + } else if (Member->getTag() == dwarf::DW_TAG_friend) { + // Ignore friend members. It appears that MSVC emitted info about + // friends in the past, but modern versions do not. + } + // FIXME: Get clang to emit nested types here and do something with + // them. + } + // Skip other unrecognized kinds of elements. + } + TypeIndex FTI = TypeTable.writeFieldList(Fields); + + // FIXME: Other ClassOptions, like ContainsNestedClass and NestedClass. + CO &= ClassOptions::ForwardReference; + uint64_t SizeInBytes = Ty->getSizeInBits() / 8; + if (Kind == TypeRecordKind::Union) { + TypeTable.writeUnion(UnionRecord(Fields.getSubrecordCount(), CO, + HfaKind::None, FTI, SizeInBytes, + Ty->getName(), Ty->getIdentifier())); + } else { + TypeTable.writeClass( + ClassRecord(Kind, Fields.getSubrecordCount(), CO, HfaKind::None, + WindowsRTClassKind::None, FTI, TypeIndex(), TypeIndex(), + SizeInBytes, Ty->getName(), Ty->getIdentifier())); + } + // The type index of the complete record is unused. It just exists in the + // type stream, and is looked up by name. + } + + // Always return the index of the forward decl. + return FwdDeclTI; +} + TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef) { const DIType *Ty = TypeRef.resolve(); Index: lib/DebugInfo/CodeView/ListRecordBuilder.cpp =================================================================== --- lib/DebugInfo/CodeView/ListRecordBuilder.cpp +++ lib/DebugInfo/CodeView/ListRecordBuilder.cpp @@ -15,6 +15,8 @@ ListRecordBuilder::ListRecordBuilder(TypeRecordKind Kind) : Builder(Kind) {} void ListRecordBuilder::finishSubRecord() { + SubrecordCount++; + // The builder starts at offset 2 in the actual CodeView buffer, so add an // additional offset of 2 before computing the alignment. uint32_t Remainder = (Builder.size() + 2) % 4; Index: test/DebugInfo/COFF/types-basic.ll =================================================================== --- test/DebugInfo/COFF/types-basic.ll +++ test/DebugInfo/COFF/types-basic.ll @@ -32,6 +32,8 @@ ; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll ; CHECK: CodeViewTypes [ +; CHECK: Section: .debug$T (6) +; CHECK: Magic: 0x4 ; CHECK: ArgList (0x1000) { ; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) ; CHECK: NumArgs: 3 @@ -74,7 +76,40 @@ ; CHECK: IsVolatile: 0 ; CHECK: IsUnaligned: 0 ; CHECK: } -; CHECK: Pointer (0x1005) { +; CHECK: Struct (0x1005) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: A +; CHECK: } +; CHECK: UnknownLeaf (0x1006) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: a +; CHECK: } +; CHECK: } +; CHECK: Struct (0x1007) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 1 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: a (0x1006) +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 4 +; CHECK: Name: A +; CHECK: } +; CHECK: Pointer (0x1008) { ; CHECK: TypeLeafKind: LF_POINTER (0x1002) ; CHECK: PointeeType: int (0x74) ; CHECK: PointerAttributes: 0x804C @@ -84,28 +119,39 @@ ; CHECK: IsConst: 0 ; CHECK: IsVolatile: 0 ; CHECK: IsUnaligned: 0 -; CHECK: ClassType: 0x0 +; CHECK: ClassType: A (0x1005) ; CHECK: Representation: Unknown (0x0) ; CHECK: } -; CHECK: ArgList (0x1006) { +; CHECK: Pointer (0x1009) { +; CHECK: TypeLeafKind: LF_POINTER (0x1002) +; CHECK: PointeeType: A (0x1005) +; CHECK: PointerAttributes: 0x1000C +; CHECK: PtrType: Near64 (0xC) +; CHECK: PtrMode: Pointer (0x0) +; CHECK: IsFlat: 0 +; CHECK: IsConst: 0 +; CHECK: IsVolatile: 0 +; CHECK: IsUnaligned: 0 +; CHECK: } +; CHECK: ArgList (0x100A) { ; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) ; CHECK: NumArgs: 1 ; CHECK: Arguments [ -; CHECK: ArgType: (0x600) +; CHECK: ArgType: A* (0x1009) ; CHECK: ] ; CHECK: } -; CHECK: Procedure (0x1007) { +; CHECK: Procedure (0x100B) { ; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) ; CHECK: ReturnType: void (0x3) ; CHECK: CallingConvention: NearC (0x0) ; CHECK: FunctionOptions [ (0x0) ; CHECK: ] ; CHECK: NumParameters: 1 -; CHECK: ArgListType: () (0x1006) +; CHECK: ArgListType: (A*) (0x100A) ; CHECK: } -; CHECK: Pointer (0x1008) { +; CHECK: Pointer (0x100C) { ; CHECK: TypeLeafKind: LF_POINTER (0x1002) -; CHECK: PointeeType: void () (0x1007) +; CHECK: PointeeType: void (A*) (0x100B) ; CHECK: PointerAttributes: 0x1006C ; CHECK: PtrType: Near64 (0xC) ; CHECK: PtrMode: PointerToMemberFunction (0x3) @@ -113,10 +159,32 @@ ; CHECK: IsConst: 0 ; CHECK: IsVolatile: 0 ; CHECK: IsUnaligned: 0 -; CHECK: ClassType: 0x0 +; CHECK: ClassType: A (0x1005) ; CHECK: Representation: Unknown (0x0) ; CHECK: } +; CHECK: ArgList (0x100D) { +; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) +; CHECK: NumArgs: 0 +; CHECK: Arguments [ +; CHECK: ] +; CHECK: } +; CHECK: Procedure (0x100E) { +; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) +; CHECK: ReturnType: void (0x3) +; CHECK: CallingConvention: NearC (0x0) +; CHECK: FunctionOptions [ (0x0) +; CHECK: ] +; CHECK: NumParameters: 0 +; CHECK: ArgListType: () (0x100D) +; CHECK: } +; CHECK: FuncId (0x100F) { +; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601) +; CHECK: ParentScope: 0x0 +; CHECK: FunctionType: void () (0x100E) +; CHECK: Name: CharTypes +; CHECK: } ; CHECK: ] + ; CHECK: CodeViewDebugInfo [ ; CHECK: Subsection [ ; CHECK: SubSectionType: Symbols (0xF1) @@ -169,11 +237,11 @@ ; CHECK: VarName: v3 ; CHECK: } ; CHECK: Local { -; CHECK: Type: int ::* (0x1005) +; CHECK: Type: int A::* (0x1008) ; CHECK: VarName: v4 ; CHECK: } ; CHECK: Local { -; CHECK: Type: void () ::* (0x1008) +; CHECK: Type: void (A*) A::* (0x100C) ; CHECK: VarName: v5 ; CHECK: } ; CHECK: Local { Index: test/DebugInfo/COFF/types-data-members.ll =================================================================== --- /dev/null +++ test/DebugInfo/COFF/types-data-members.ll @@ -0,0 +1,478 @@ +; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s + +; C++ source to regenerate: +; $ cat t.cpp +; struct Struct { +; int s1; +; int s2; +; int s3; +; static const int sdm = 3; +; }; +; union Union { +; int a; +; float b; +; }; +; class Class { +; public: +; int pub; +; struct Nested; +; private: +; int priv; +; protected: +; int prot; +; }; +; struct DerivedClass : Struct, virtual Class { +; int d; +; }; +; struct Class::Nested { +; int n; +; }; +; void UseTypes() { +; Struct s; +; Union u; +; Class c; +; DerivedClass dc; +; Class::Nested n; +; } +; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll + +; CHECK: CodeViewTypes [ +; CHECK: Section: .debug$T (10) +; CHECK: Magic: 0x4 +; CHECK: ArgList (0x1000) { +; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) +; CHECK: NumArgs: 0 +; CHECK: Arguments [ +; CHECK: ] +; CHECK: } +; CHECK: Procedure (0x1001) { +; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) +; CHECK: ReturnType: void (0x3) +; CHECK: CallingConvention: NearC (0x0) +; CHECK: FunctionOptions [ (0x0) +; CHECK: ] +; CHECK: NumParameters: 0 +; CHECK: ArgListType: () (0x1000) +; CHECK: } +; CHECK: FuncId (0x1002) { +; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601) +; CHECK: ParentScope: 0x0 +; CHECK: FunctionType: void () (0x1001) +; CHECK: Name: UseTypes +; CHECK: } +; CHECK: Struct (0x1003) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: Struct +; CHECK: } +; CHECK: Modifier (0x1004) { +; CHECK: TypeLeafKind: LF_MODIFIER (0x1001) +; CHECK: ModifiedType: int (0x74) +; CHECK: Modifiers [ (0x1) +; CHECK: Const (0x1) +; CHECK: ] +; CHECK: } +; CHECK: UnknownLeaf (0x1005) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: s1 +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x4 +; CHECK: Name: s2 +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x8 +; CHECK: Name: s3 +; CHECK: } +; CHECK: StaticDataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: const int (0x1004) +; CHECK: Name: sdm +; CHECK: } +; CHECK: } +; CHECK: Struct (0x1006) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 4 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: sdm (0x1005) +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 12 +; CHECK: Name: Struct +; CHECK: } +; CHECK: Union (0x1007) { +; CHECK: TypeLeafKind: LF_UNION (0x1506) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: Union +; CHECK: } +; CHECK: UnknownLeaf (0x1008) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: a +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: float (0x40) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: b +; CHECK: } +; CHECK: } +; CHECK: Union (0x1009) { +; CHECK: TypeLeafKind: LF_UNION (0x1506) +; CHECK: MemberCount: 2 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: b (0x1008) +; CHECK: SizeOf: 4 +; CHECK: Name: Union +; CHECK: } +; CHECK: Class (0x100A) { +; CHECK: TypeLeafKind: LF_CLASS (0x1504) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: Class +; CHECK: } +; CHECK: UnknownLeaf (0x100B) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: pub +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Private (0x1) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x4 +; CHECK: Name: priv +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Protected (0x2) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x8 +; CHECK: Name: prot +; CHECK: } +; CHECK: } +; CHECK: Class (0x100C) { +; CHECK: TypeLeafKind: LF_CLASS (0x1504) +; CHECK: MemberCount: 3 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: prot (0x100B) +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 12 +; CHECK: Name: Class +; CHECK: } +; CHECK: Struct (0x100D) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: DerivedClass +; CHECK: } +; CHECK: Procedure (0x100E) { +; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) +; CHECK: ReturnType: int (0x74) +; CHECK: CallingConvention: NearC (0x0) +; CHECK: FunctionOptions [ (0x0) +; CHECK: ] +; CHECK: NumParameters: 0 +; CHECK: ArgListType: () (0x1000) +; CHECK: } +; CHECK: Pointer (0x100F) { +; CHECK: TypeLeafKind: LF_POINTER (0x1002) +; CHECK: PointeeType: int () (0x100E) +; CHECK: PointerAttributes: 0x1000C +; CHECK: PtrType: Near64 (0xC) +; CHECK: PtrMode: Pointer (0x0) +; CHECK: IsFlat: 0 +; CHECK: IsConst: 0 +; CHECK: IsVolatile: 0 +; CHECK: IsUnaligned: 0 +; CHECK: } +; CHECK: Pointer (0x1010) { +; CHECK: TypeLeafKind: LF_POINTER (0x1002) +; CHECK: PointeeType: int ()* (0x100F) +; CHECK: PointerAttributes: 0x1000C +; CHECK: PtrType: Near64 (0xC) +; CHECK: PtrMode: Pointer (0x0) +; CHECK: IsFlat: 0 +; CHECK: IsConst: 0 +; CHECK: IsVolatile: 0 +; CHECK: IsUnaligned: 0 +; CHECK: } +; CHECK: UnknownLeaf (0x1011) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int ()** (0x1010) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: _vptr$DerivedClass +; CHECK: } +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x18 +; CHECK: Name: d +; CHECK: } +; CHECK: } +; CHECK: Struct (0x1012) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 2 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: d (0x1011) +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 48 +; CHECK: Name: DerivedClass +; CHECK: } +; CHECK: Struct (0x1013) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 0 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: 0x0 +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 0 +; CHECK: Name: Nested +; CHECK: } +; CHECK: UnknownLeaf (0x1014) { +; CHECK: TypeLeafKind: LF_FIELDLIST (0x1203) +; CHECK: DataMember { +; CHECK: AccessSpecifier: Public (0x3) +; CHECK: Type: int (0x74) +; CHECK: FieldOffset: 0x0 +; CHECK: Name: n +; CHECK: } +; CHECK: } +; CHECK: Struct (0x1015) { +; CHECK: TypeLeafKind: LF_STRUCTURE (0x1505) +; CHECK: MemberCount: 1 +; CHECK: Properties [ (0x80) +; CHECK: ForwardReference (0x80) +; CHECK: ] +; CHECK: FieldList: n (0x1014) +; CHECK: DerivedFrom: 0x0 +; CHECK: VShape: 0x0 +; CHECK: SizeOf: 4 +; CHECK: Name: Nested +; CHECK: } +; CHECK: Pointer (0x1016) { +; CHECK: TypeLeafKind: LF_POINTER (0x1002) +; CHECK: PointeeType: DerivedClass (0x100D) +; CHECK: PointerAttributes: 0x1000C +; CHECK: PtrType: Near64 (0xC) +; CHECK: PtrMode: Pointer (0x0) +; CHECK: IsFlat: 0 +; CHECK: IsConst: 0 +; CHECK: IsVolatile: 0 +; CHECK: IsUnaligned: 0 +; CHECK: } +; CHECK: ArgList (0x1017) { +; CHECK: TypeLeafKind: LF_ARGLIST (0x1201) +; CHECK: NumArgs: 1 +; CHECK: Arguments [ +; CHECK: ArgType: DerivedClass* (0x1016) +; CHECK: ] +; CHECK: } +; CHECK: Procedure (0x1018) { +; CHECK: TypeLeafKind: LF_PROCEDURE (0x1008) +; CHECK: ReturnType: void (0x3) +; CHECK: CallingConvention: NearC (0x0) +; CHECK: FunctionOptions [ (0x0) +; CHECK: ] +; CHECK: NumParameters: 1 +; CHECK: ArgListType: (DerivedClass*) (0x1017) +; CHECK: } +; CHECK: FuncId (0x1019) { +; CHECK: TypeLeafKind: LF_FUNC_ID (0x1601) +; CHECK: ParentScope: 0x0 +; CHECK: FunctionType: void (DerivedClass*) (0x1018) +; CHECK: Name: DerivedClass::DerivedClass +; CHECK: } +; CHECK: ] + +; ModuleID = 'record-types.cpp' +source_filename = "record-types.cpp" +target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-windows-msvc19.0.23918" + +%struct.Struct = type { i32, i32, i32 } +%union.Union = type { i32 } +%class.Class = type { i32, i32, i32 } +%struct.DerivedClass = type { %struct.Struct, i32*, i32, [4 x i8], %class.Class } +%"struct.Class::Nested" = type { i32 } + +$"\01??0DerivedClass@@QEAA@XZ" = comdat any + +$"\01??_8DerivedClass@@7B@" = comdat any + +@"\01??_8DerivedClass@@7B@" = linkonce_odr unnamed_addr constant [2 x i32] [i32 -16, i32 16], comdat + +; Function Attrs: nounwind uwtable +define void @"\01?UseTypes@@YAXXZ"() #0 !dbg !7 { +entry: + %s = alloca %struct.Struct, align 4 + %u = alloca %union.Union, align 4 + %c = alloca %class.Class, align 4 + %dc = alloca %struct.DerivedClass, align 8 + %n = alloca %"struct.Class::Nested", align 4 + call void @llvm.dbg.declare(metadata %struct.Struct* %s, metadata !10, metadata !19), !dbg !20 + call void @llvm.dbg.declare(metadata %union.Union* %u, metadata !21, metadata !19), !dbg !27 + call void @llvm.dbg.declare(metadata %class.Class* %c, metadata !28, metadata !19), !dbg !34 + call void @llvm.dbg.declare(metadata %struct.DerivedClass* %dc, metadata !35, metadata !19), !dbg !46 + %call = call %struct.DerivedClass* @"\01??0DerivedClass@@QEAA@XZ"(%struct.DerivedClass* %dc, i32 1) #3, !dbg !46 + call void @llvm.dbg.declare(metadata %"struct.Class::Nested"* %n, metadata !47, metadata !19), !dbg !51 + ret void, !dbg !52 +} + +; Function Attrs: nounwind readnone +declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 + +; Function Attrs: inlinehint nounwind uwtable +define linkonce_odr %struct.DerivedClass* @"\01??0DerivedClass@@QEAA@XZ"(%struct.DerivedClass* returned %this, i32 %is_most_derived) unnamed_addr #2 comdat align 2 !dbg !53 { +entry: + %retval = alloca %struct.DerivedClass*, align 8 + %is_most_derived.addr = alloca i32, align 4 + %this.addr = alloca %struct.DerivedClass*, align 8 + store i32 %is_most_derived, i32* %is_most_derived.addr, align 4 + call void @llvm.dbg.declare(metadata i32* %is_most_derived.addr, metadata !58, metadata !19), !dbg !59 + store %struct.DerivedClass* %this, %struct.DerivedClass** %this.addr, align 8 + call void @llvm.dbg.declare(metadata %struct.DerivedClass** %this.addr, metadata !60, metadata !19), !dbg !59 + %this1 = load %struct.DerivedClass*, %struct.DerivedClass** %this.addr, align 8 + store %struct.DerivedClass* %this1, %struct.DerivedClass** %retval, align 8 + %is_most_derived2 = load i32, i32* %is_most_derived.addr, align 4 + %is_complete_object = icmp ne i32 %is_most_derived2, 0, !dbg !62 + br i1 %is_complete_object, label %ctor.init_vbases, label %ctor.skip_vbases, !dbg !62 + +ctor.init_vbases: ; preds = %entry + %this.int8 = bitcast %struct.DerivedClass* %this1 to i8*, !dbg !62 + %0 = getelementptr inbounds i8, i8* %this.int8, i64 16, !dbg !62 + %vbptr.DerivedClass = bitcast i8* %0 to i32**, !dbg !62 + store i32* getelementptr inbounds ([2 x i32], [2 x i32]* @"\01??_8DerivedClass@@7B@", i32 0, i32 0), i32** %vbptr.DerivedClass, align 8, !dbg !62 + %1 = bitcast %struct.DerivedClass* %this1 to i8*, !dbg !62 + %2 = getelementptr inbounds i8, i8* %1, i64 32, !dbg !62 + %3 = bitcast i8* %2 to %class.Class*, !dbg !62 + br label %ctor.skip_vbases, !dbg !62 + +ctor.skip_vbases: ; preds = %ctor.init_vbases, %entry + %4 = bitcast %struct.DerivedClass* %this1 to %struct.Struct*, !dbg !62 + %5 = load %struct.DerivedClass*, %struct.DerivedClass** %retval, align 8, !dbg !62 + ret %struct.DerivedClass* %5, !dbg !62 +} + +attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #1 = { nounwind readnone } +attributes #2 = { inlinehint nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" } +attributes #3 = { nounwind } + +!llvm.dbg.cu = !{!0} +!llvm.module.flags = !{!3, !4, !5} +!llvm.ident = !{!6} + +!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 271336) (llvm/trunk 271339)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2) +!1 = !DIFile(filename: "record-types.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild") +!2 = !{} +!3 = !{i32 2, !"CodeView", i32 1} +!4 = !{i32 2, !"Debug Info Version", i32 3} +!5 = !{i32 1, !"PIC Level", i32 2} +!6 = !{!"clang version 3.9.0 (trunk 271336) (llvm/trunk 271339)"} +!7 = distinct !DISubprogram(name: "UseTypes", linkageName: "\01?UseTypes@@YAXXZ", scope: !1, file: !1, line: 31, type: !8, isLocal: false, isDefinition: true, scopeLine: 31, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2) +!8 = !DISubroutineType(types: !9) +!9 = !{null} +!10 = !DILocalVariable(name: "s", scope: !7, file: !1, line: 32, type: !11) +!11 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Struct", file: !1, line: 1, size: 96, align: 32, elements: !12) +!12 = !{!13, !15, !16, !17} +!13 = !DIDerivedType(tag: DW_TAG_member, name: "s1", scope: !11, file: !1, line: 2, baseType: !14, size: 32, align: 32) +!14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) +!15 = !DIDerivedType(tag: DW_TAG_member, name: "s2", scope: !11, file: !1, line: 3, baseType: !14, size: 32, align: 32, offset: 32) +!16 = !DIDerivedType(tag: DW_TAG_member, name: "s3", scope: !11, file: !1, line: 4, baseType: !14, size: 32, align: 32, offset: 64) +!17 = !DIDerivedType(tag: DW_TAG_member, name: "sdm", scope: !11, file: !1, line: 5, baseType: !18, flags: DIFlagStaticMember, extraData: i32 3) +!18 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !14) +!19 = !DIExpression() +!20 = !DILocation(line: 32, column: 10, scope: !7) +!21 = !DILocalVariable(name: "u", scope: !7, file: !1, line: 33, type: !22) +!22 = distinct !DICompositeType(tag: DW_TAG_union_type, name: "Union", file: !1, line: 8, size: 32, align: 32, elements: !23) +!23 = !{!24, !25} +!24 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !22, file: !1, line: 9, baseType: !14, size: 32, align: 32) +!25 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !22, file: !1, line: 10, baseType: !26, size: 32, align: 32) +!26 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float) +!27 = !DILocation(line: 33, column: 9, scope: !7) +!28 = !DILocalVariable(name: "c", scope: !7, file: !1, line: 34, type: !29) +!29 = distinct !DICompositeType(tag: DW_TAG_class_type, name: "Class", file: !1, line: 13, size: 96, align: 32, elements: !30) +!30 = !{!31, !32, !33} +!31 = !DIDerivedType(tag: DW_TAG_member, name: "pub", scope: !29, file: !1, line: 15, baseType: !14, size: 32, align: 32, flags: DIFlagPublic) +!32 = !DIDerivedType(tag: DW_TAG_member, name: "priv", scope: !29, file: !1, line: 18, baseType: !14, size: 32, align: 32, offset: 32) +!33 = !DIDerivedType(tag: DW_TAG_member, name: "prot", scope: !29, file: !1, line: 20, baseType: !14, size: 32, align: 32, offset: 64, flags: DIFlagProtected) +!34 = !DILocation(line: 34, column: 9, scope: !7) +!35 = !DILocalVariable(name: "dc", scope: !7, file: !1, line: 35, type: !36) +!36 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "DerivedClass", file: !1, line: 23, size: 384, align: 64, elements: !37, vtableHolder: !36) +!37 = !{!38, !39, !40, !45} +!38 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !36, baseType: !11) +!39 = !DIDerivedType(tag: DW_TAG_inheritance, scope: !36, baseType: !29, offset: 4, flags: DIFlagVirtual) +!40 = !DIDerivedType(tag: DW_TAG_member, name: "_vptr$DerivedClass", scope: !1, file: !1, baseType: !41, size: 64, flags: DIFlagArtificial) +!41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !42, size: 64) +!42 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "__vtbl_ptr_type", baseType: !43, size: 64) +!43 = !DISubroutineType(types: !44) +!44 = !{!14} +!45 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !36, file: !1, line: 24, baseType: !14, size: 32, align: 32, offset: 192) +!46 = !DILocation(line: 35, column: 16, scope: !7) +!47 = !DILocalVariable(name: "n", scope: !7, file: !1, line: 36, type: !48) +!48 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "Nested", scope: !29, file: !1, line: 27, size: 32, align: 32, elements: !49) +!49 = !{!50} +!50 = !DIDerivedType(tag: DW_TAG_member, name: "n", scope: !48, file: !1, line: 28, baseType: !14, size: 32, align: 32) +!51 = !DILocation(line: 36, column: 17, scope: !7) +!52 = !DILocation(line: 37, column: 1, scope: !7) +!53 = distinct !DISubprogram(name: "DerivedClass::DerivedClass", linkageName: "\01??0DerivedClass@@QEAA@XZ", scope: !36, file: !1, line: 23, type: !54, isLocal: false, isDefinition: true, scopeLine: 23, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false, unit: !0, declaration: !57, variables: !2) +!54 = !DISubroutineType(types: !55) +!55 = !{null, !56} +!56 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer) +!57 = !DISubprogram(name: "DerivedClass::DerivedClass", scope: !36, type: !54, isLocal: false, isDefinition: false, flags: DIFlagArtificial | DIFlagPrototyped, isOptimized: false) +!58 = !DILocalVariable(name: "is_most_derived", arg: 2, scope: !53, type: !14, flags: DIFlagArtificial) +!59 = !DILocation(line: 0, scope: !53) +!60 = !DILocalVariable(name: "this", arg: 1, scope: !53, type: !61, flags: DIFlagArtificial | DIFlagObjectPointer) +!61 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !36, size: 64, align: 64) +!62 = !DILocation(line: 23, column: 8, scope: !53)