Skip to content

Commit bf94cf8

Browse files
authored
Merge pull request #3 from cuviper/rustc-D57070
[CodeView] Allow empty types in member functions
2 parents 25bfc9f + 38f17b6 commit bf94cf8

File tree

2 files changed

+76
-1
lines changed

2 files changed

+76
-1
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,10 @@ TypeIndex CodeViewDebug::lowerTypeMemberFunction(const DISubroutineType *Ty,
18361836

18371837
unsigned Index = 0;
18381838
SmallVector<TypeIndex, 8> ArgTypeIndices;
1839-
TypeIndex ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]);
1839+
TypeIndex ReturnTypeIndex = TypeIndex::Void();
1840+
if (ReturnAndArgs.size() > Index) {
1841+
ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]);
1842+
}
18401843

18411844
// If the first argument is a pointer type and this isn't a static method,
18421845
// treat it as the special 'this' parameter, which is encoded separately from
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
; RUN: llc < %s -filetype=obj | llvm-readobj - -codeview | FileCheck %s
2+
3+
; ModuleID = 'foo.3a1fbbbh-cgu.0'
4+
source_filename = "foo.3a1fbbbh-cgu.0"
5+
target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
6+
target triple = "x86_64-pc-windows-msvc"
7+
8+
; Rust source to regenerate:
9+
; $ cat foo.rs
10+
; pub struct Foo;
11+
; impl Foo {
12+
; pub fn foo() {}
13+
; }
14+
; $ rustc foo.rs --crate-type lib -Cdebuginfo=1 --emit=llvm-ir
15+
16+
; CHECK: CodeViewTypes [
17+
; CHECK: MemberFunction (0x1006) {
18+
; CHECK-NEXT: TypeLeafKind: LF_MFUNCTION (0x1009)
19+
; CHECK-NEXT: ReturnType: void (0x3)
20+
; CHECK-NEXT: ClassType: foo::Foo (0x1000)
21+
; CHECK-NEXT: ThisType: 0x0
22+
; CHECK-NEXT: CallingConvention: NearC (0x0)
23+
; CHECK-NEXT: FunctionOptions [ (0x0)
24+
; CHECK-NEXT: ]
25+
; CHECK-NEXT: NumParameters: 0
26+
; CHECK-NEXT: ArgListType: () (0x1005)
27+
; CHECK-NEXT: ThisAdjustment: 0
28+
; CHECK-NEXT: }
29+
; CHECK-NEXT: MemberFuncId (0x1007) {
30+
; CHECK-NEXT: TypeLeafKind: LF_MFUNC_ID (0x1602)
31+
; CHECK-NEXT: ClassType: foo::Foo (0x1000)
32+
; CHECK-NEXT: FunctionType: void foo::Foo::() (0x1006)
33+
; CHECK-NEXT: Name: foo
34+
; CHECK-NEXT: }
35+
; CHECK: CodeViewDebugInfo [
36+
; CHECK: FunctionLineTable [
37+
; CHECK-NEXT: LinkageName: _ZN3foo3Foo3foo17hc557c2121772885bE
38+
; CHECK-NEXT: Flags: 0x0
39+
; CHECK-NEXT: CodeSize: 0x1
40+
; CHECK-NEXT: FilenameSegment [
41+
; CHECK-NEXT: Filename: D:\rust\foo.rs (0x0)
42+
; CHECK-NEXT: +0x0 [
43+
; CHECK-NEXT: LineNumberStart: 3
44+
; CHECK-NEXT: LineNumberEndDelta: 0
45+
; CHECK-NEXT: IsStatement: No
46+
; CHECK-NEXT: ]
47+
; CHECK-NEXT: ]
48+
; CHECK-NEXT: ]
49+
50+
; foo::Foo::foo
51+
; Function Attrs: uwtable
52+
define void @_ZN3foo3Foo3foo17hc557c2121772885bE() unnamed_addr #0 !dbg !5 {
53+
start:
54+
ret void, !dbg !10
55+
}
56+
57+
attributes #0 = { uwtable "target-cpu"="x86-64" }
58+
59+
!llvm.dbg.cu = !{!0}
60+
!llvm.module.flags = !{!3, !4}
61+
62+
!0 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !1, producer: "clang LLVM (rustc version 1.33.0-nightly (8b0f0156e 2019-01-22))", isOptimized: false, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
63+
!1 = !DIFile(filename: "foo.rs", directory: "D:\5Crust")
64+
!2 = !{}
65+
!3 = !{i32 2, !"CodeView", i32 1}
66+
!4 = !{i32 2, !"Debug Info Version", i32 3}
67+
!5 = distinct !DISubprogram(name: "foo", linkageName: "_ZN3foo3Foo3foo17hc557c2121772885bE", scope: !6, file: !1, line: 3, type: !9, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !0, templateParams: !2, retainedNodes: !2)
68+
!6 = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo", scope: !8, file: !7, align: 8, elements: !2, templateParams: !2, identifier: "5105d9fe1a2a3c68518268151b672274")
69+
!7 = !DIFile(filename: "<unknown>", directory: "")
70+
!8 = !DINamespace(name: "foo", scope: null)
71+
!9 = !DISubroutineType(types: !2)
72+
!10 = !DILocation(line: 3, scope: !5)

0 commit comments

Comments
 (0)