[codeview] Emit incomplete member pointer types with the unknown model

An incomplete member pointer type will always have a size of zero, so we
don't need an extra flag. Credit to David Majnemer for the idea.

llvm-svn: 273057
This commit is contained in:
Reid Kleckner 2016-06-17 22:14:39 +00:00
parent aecc0267e2
commit 6fa1546ad9
2 changed files with 93 additions and 35 deletions

View File

@ -979,12 +979,16 @@ TypeIndex CodeViewDebug::lowerTypePointer(const DIDerivedType *Ty) {
return TypeTable.writePointer(PR);
}
static PointerToMemberRepresentation translatePtrToMemberRep(bool IsPMF,
unsigned Flags) {
static PointerToMemberRepresentation
translatePtrToMemberRep(unsigned SizeInBytes, bool IsPMF, unsigned Flags) {
// SizeInBytes being zero generally implies that the member pointer type was
// incomplete, which can happen if it is part of a function prototype. In this
// case, use the unknown model instead of the general model.
if (IsPMF) {
switch (Flags & DINode::FlagPtrToMemberRep) {
case 0:
return PointerToMemberRepresentation::GeneralFunction;
return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
: PointerToMemberRepresentation::GeneralFunction;
case DINode::FlagSingleInheritance:
return PointerToMemberRepresentation::SingleInheritanceFunction;
case DINode::FlagMultipleInheritance:
@ -995,7 +999,8 @@ static PointerToMemberRepresentation translatePtrToMemberRep(bool IsPMF,
} else {
switch (Flags & DINode::FlagPtrToMemberRep) {
case 0:
return PointerToMemberRepresentation::GeneralData;
return SizeInBytes == 0 ? PointerToMemberRepresentation::Unknown
: PointerToMemberRepresentation::GeneralData;
case DINode::FlagSingleInheritance:
return PointerToMemberRepresentation::SingleInheritanceData;
case DINode::FlagMultipleInheritance:
@ -1017,9 +1022,10 @@ TypeIndex CodeViewDebug::lowerTypeMemberPointer(const DIDerivedType *Ty) {
PointerMode PM = IsPMF ? PointerMode::PointerToMemberFunction
: PointerMode::PointerToDataMember;
PointerOptions PO = PointerOptions::None; // FIXME
MemberPointerInfo MPI(ClassTI,
translatePtrToMemberRep(IsPMF, Ty->getFlags()));
uint64_t SizeInBytes = Ty->getSizeInBits() / 8;
assert(Ty->getSizeInBits() / 8 <= 0xff && "pointer size too big");
uint8_t SizeInBytes = Ty->getSizeInBits() / 8;
MemberPointerInfo MPI(
ClassTI, translatePtrToMemberRep(SizeInBytes, IsPMF, Ty->getFlags()));
PointerRecord PR(PointeeTI, PK, PM, PO, SizeInBytes, MPI);
return TypeTable.writePointer(PR);
}

View File

@ -15,6 +15,9 @@
; void (C::*pmf_b)();
; void (D::*pmf_c)();
; void (E::*pmf_d)();
; struct Incomplete;
; int Incomplete::**ppmd;
; void (Incomplete::**ppmf)();
; $ clang t.cpp -S -emit-llvm -g -gcodeview -o t.ll
; CHECK: CodeViewTypes [
@ -82,7 +85,7 @@
; CHECK: Pointer ({{.*}}) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: void (const A*)
; CHECK: PointeeType: void (A*)
; CHECK: PointerAttributes: 0x1006C
; CHECK: PtrType: Near64 (0xC)
; CHECK: PtrMode: PointerToMemberFunction (0x3)
@ -136,6 +139,41 @@
; CHECK: ClassType: E
; CHECK: Representation: GeneralFunction (0x8)
; CHECK: }
; Unknown inheritance model MPT
; CHECK: Pointer ({{.*}}) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: int
; CHECK: PointerAttributes: 0x4C
; CHECK: PtrType: Near64 (0xC)
; CHECK: PtrMode: PointerToDataMember (0x2)
; CHECK: IsFlat: 0
; CHECK: IsConst: 0
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
; CHECK: SizeOf: 0
; CHECK: ClassType: Incomplete
; CHECK: Representation: Unknown (0x0)
; CHECK: }
; CHECK: Pointer ({{.*}}) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: Pointer ({{.*}}) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: PointeeType: void (Incomplete*)
; CHECK: PointerAttributes: 0x6C
; CHECK: PtrType: Near64 (0xC)
; CHECK: PtrMode: PointerToMemberFunction (0x3)
; CHECK: IsFlat: 0
; CHECK: IsConst: 0
; CHECK: IsVolatile: 0
; CHECK: IsUnaligned: 0
; CHECK: SizeOf: 0
; CHECK: ClassType: Incomplete
; CHECK: Representation: Unknown (0x0)
; CHECK: }
; CHECK: Pointer ({{.*}}) {
; CHECK: TypeLeafKind: LF_POINTER (0x1002)
; CHECK: ]
; ModuleID = 't.cpp'
@ -143,23 +181,28 @@ source_filename = "t.cpp"
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-pc-windows-msvc19.0.23918"
%0 = type opaque
%1 = type opaque
@"\01?pmd_a@@3PEQA@@HEQ1@" = global i32 -1, align 8
@"\01?pmd_b@@3PEQC@@HEQ1@" = global i32 -1, align 8
@"\01?pmd_c@@3PEQD@@HEQ1@" = global { i32, i32 } { i32 0, i32 -1 }, align 8
@"\01?pmd_d@@3PEQE@@HEQ1@" = global { i32, i32, i32 } { i32 0, i32 0, i32 -1 }, align 8
@"\01?pmf_a@@3P8A@@EBAXXZEQ1@" = global i8* null, align 8
@"\01?pmf_a@@3P8A@@EAAXXZEQ1@" = global i8* null, align 8
@"\01?pmf_b@@3P8C@@EAAXXZEQ1@" = global { i8*, i32 } zeroinitializer, align 8
@"\01?pmf_c@@3P8D@@EAAXXZEQ1@" = global { i8*, i32, i32 } zeroinitializer, align 8
@"\01?pmf_d@@3P8E@@EAAXXZEQ1@" = global { i8*, i32, i32, i32 } zeroinitializer, align 8
@"\01?ppmd@@3PEAPEQIncomplete@@HEA" = global %0* null, align 8
@"\01?ppmf@@3PEAP8Incomplete@@EAAXXZEA" = global %1* null, align 8
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!47, !48, !49}
!llvm.ident = !{!50}
!llvm.module.flags = !{!56, !57, !58}
!llvm.ident = !{!59}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 273036) (llvm/trunk 273053)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3)
!1 = !DIFile(filename: "t.cpp", directory: "D:\5Csrc\5Cllvm\5Cbuild")
!2 = !{}
!3 = !{!4, !10, !20, !23, !26, !32, !37, !42}
!3 = !{!4, !10, !20, !23, !26, !31, !36, !41, !46, !50}
!4 = distinct !DIGlobalVariable(name: "pmd_a", linkageName: "\01?pmd_a@@3PEQA@@HEQ1@", scope: !0, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, variable: i32* @"\01?pmd_a@@3PEQA@@HEQ1@")
!5 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !6, size: 32, flags: DIFlagSingleInheritance, extraData: !7)
!6 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
@ -182,28 +225,37 @@ target triple = "x86_64-pc-windows-msvc19.0.23918"
!23 = distinct !DIGlobalVariable(name: "pmd_d", linkageName: "\01?pmd_d@@3PEQE@@HEQ1@", scope: !0, file: !1, line: 9, type: !24, isLocal: false, isDefinition: true, variable: { i32, i32, i32 }* @"\01?pmd_d@@3PEQE@@HEQ1@")
!24 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !6, size: 96, extraData: !25)
!25 = !DICompositeType(tag: DW_TAG_structure_type, name: "E", file: !1, line: 5, flags: DIFlagFwdDecl, identifier: ".?AUE@@")
!26 = distinct !DIGlobalVariable(name: "pmf_a", linkageName: "\01?pmf_a@@3P8A@@EBAXXZEQ1@", scope: !0, file: !1, line: 10, type: !27, isLocal: false, isDefinition: true, variable: i8** @"\01?pmf_a@@3P8A@@EBAXXZEQ1@")
!26 = distinct !DIGlobalVariable(name: "pmf_a", linkageName: "\01?pmf_a@@3P8A@@EAAXXZEQ1@", scope: !0, file: !1, line: 10, type: !27, isLocal: false, isDefinition: true, variable: i8** @"\01?pmf_a@@3P8A@@EAAXXZEQ1@")
!27 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !28, size: 64, flags: DIFlagSingleInheritance, extraData: !7)
!28 = !DISubroutineType(types: !29)
!29 = !{null, !30}
!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !31, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!31 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !7)
!32 = distinct !DIGlobalVariable(name: "pmf_b", linkageName: "\01?pmf_b@@3P8C@@EAAXXZEQ1@", scope: !0, file: !1, line: 11, type: !33, isLocal: false, isDefinition: true, variable: { i8*, i32 }* @"\01?pmf_b@@3P8C@@EAAXXZEQ1@")
!33 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !34, size: 128, flags: DIFlagMultipleInheritance, extraData: !12)
!34 = !DISubroutineType(types: !35)
!35 = !{null, !36}
!36 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!37 = distinct !DIGlobalVariable(name: "pmf_c", linkageName: "\01?pmf_c@@3P8D@@EAAXXZEQ1@", scope: !0, file: !1, line: 12, type: !38, isLocal: false, isDefinition: true, variable: { i8*, i32, i32 }* @"\01?pmf_c@@3P8D@@EAAXXZEQ1@")
!38 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !39, size: 128, flags: DIFlagVirtualInheritance, extraData: !22)
!39 = !DISubroutineType(types: !40)
!40 = !{null, !41}
!41 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!42 = distinct !DIGlobalVariable(name: "pmf_d", linkageName: "\01?pmf_d@@3P8E@@EAAXXZEQ1@", scope: !0, file: !1, line: 13, type: !43, isLocal: false, isDefinition: true, variable: { i8*, i32, i32, i32 }* @"\01?pmf_d@@3P8E@@EAAXXZEQ1@")
!43 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !44, size: 192, extraData: !25)
!44 = !DISubroutineType(types: !45)
!45 = !{null, !46}
!46 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !25, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!47 = !{i32 2, !"CodeView", i32 1}
!48 = !{i32 2, !"Debug Info Version", i32 3}
!49 = !{i32 1, !"PIC Level", i32 2}
!50 = !{!"clang version 3.9.0 "}
!30 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !7, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!31 = distinct !DIGlobalVariable(name: "pmf_b", linkageName: "\01?pmf_b@@3P8C@@EAAXXZEQ1@", scope: !0, file: !1, line: 11, type: !32, isLocal: false, isDefinition: true, variable: { i8*, i32 }* @"\01?pmf_b@@3P8C@@EAAXXZEQ1@")
!32 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !33, size: 128, flags: DIFlagMultipleInheritance, extraData: !12)
!33 = !DISubroutineType(types: !34)
!34 = !{null, !35}
!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!36 = distinct !DIGlobalVariable(name: "pmf_c", linkageName: "\01?pmf_c@@3P8D@@EAAXXZEQ1@", scope: !0, file: !1, line: 12, type: !37, isLocal: false, isDefinition: true, variable: { i8*, i32, i32 }* @"\01?pmf_c@@3P8D@@EAAXXZEQ1@")
!37 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !38, size: 128, flags: DIFlagVirtualInheritance, extraData: !22)
!38 = !DISubroutineType(types: !39)
!39 = !{null, !40}
!40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !22, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!41 = distinct !DIGlobalVariable(name: "pmf_d", linkageName: "\01?pmf_d@@3P8E@@EAAXXZEQ1@", scope: !0, file: !1, line: 13, type: !42, isLocal: false, isDefinition: true, variable: { i8*, i32, i32, i32 }* @"\01?pmf_d@@3P8E@@EAAXXZEQ1@")
!42 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !43, size: 192, extraData: !25)
!43 = !DISubroutineType(types: !44)
!44 = !{null, !45}
!45 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !25, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!46 = distinct !DIGlobalVariable(name: "ppmd", linkageName: "\01?ppmd@@3PEAPEQIncomplete@@HEA", scope: !0, file: !1, line: 15, type: !47, isLocal: false, isDefinition: true, variable: %0** @"\01?ppmd@@3PEAPEQIncomplete@@HEA")
!47 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !48, size: 64, align: 64)
!48 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !6, extraData: !49)
!49 = !DICompositeType(tag: DW_TAG_structure_type, name: "Incomplete", file: !1, line: 14, flags: DIFlagFwdDecl, identifier: ".?AUIncomplete@@")
!50 = distinct !DIGlobalVariable(name: "ppmf", linkageName: "\01?ppmf@@3PEAP8Incomplete@@EAAXXZEA", scope: !0, file: !1, line: 16, type: !51, isLocal: false, isDefinition: true, variable: %1** @"\01?ppmf@@3PEAP8Incomplete@@EAAXXZEA")
!51 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !52, size: 64, align: 64)
!52 = !DIDerivedType(tag: DW_TAG_ptr_to_member_type, baseType: !53, extraData: !49)
!53 = !DISubroutineType(types: !54)
!54 = !{null, !55}
!55 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !49, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer)
!56 = !{i32 2, !"CodeView", i32 1}
!57 = !{i32 2, !"Debug Info Version", i32 3}
!58 = !{i32 1, !"PIC Level", i32 2}
!59 = !{!"clang version 3.9.0 (trunk 273036) (llvm/trunk 273053)"}