Skip to content

Commit 6fe5316

Browse files
committed
accept codegen tests
1 parent 618a3d1 commit 6fe5316

File tree

2 files changed

+186
-32
lines changed

2 files changed

+186
-32
lines changed

src/codegen/tests/debug_tests.rs

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -353,26 +353,35 @@ fn dbg_declare_has_valid_metadata_references_for_methods() {
353353
; ModuleID = '<internal>'
354354
source_filename = "<internal>"
355355
356+
%__vtable_fb = type { i32* }
356357
%fb = type {}
357358
358-
@__fb__init = constant %fb zeroinitializer, !dbg !0
359+
@____vtable_fb__init = constant %__vtable_fb zeroinitializer, !dbg !0
360+
@__fb__init = constant %fb zeroinitializer, !dbg !8
359361
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
360362
361-
define void @fb(%fb* %0) !dbg !9 {
363+
define void @fb(%fb* %0) !dbg !16 {
362364
entry:
363-
call void @llvm.dbg.declare(metadata %fb* %0, metadata !12, metadata !DIExpression()), !dbg !13
364-
ret void, !dbg !13
365+
call void @llvm.dbg.declare(metadata %fb* %0, metadata !19, metadata !DIExpression()), !dbg !20
366+
ret void, !dbg !20
365367
}
366368
367-
define void @fb_foo(%fb* %0) !dbg !14 {
369+
define void @fb_foo(%fb* %0) !dbg !21 {
368370
entry:
369-
call void @llvm.dbg.declare(metadata %fb* %0, metadata !15, metadata !DIExpression()), !dbg !16
370-
ret void, !dbg !16
371+
call void @llvm.dbg.declare(metadata %fb* %0, metadata !22, metadata !DIExpression()), !dbg !23
372+
ret void, !dbg !23
371373
}
372374
373375
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
374376
declare void @llvm.dbg.declare(metadata, metadata, metadata) #0
375377
378+
define void @__init___vtable_fb(%__vtable_fb* %0) {
379+
entry:
380+
%self = alloca %__vtable_fb*, align 8
381+
store %__vtable_fb* %0, %__vtable_fb** %self, align 8
382+
ret void
383+
}
384+
376385
define void @__init_fb(%fb* %0) {
377386
entry:
378387
%self = alloca %fb*, align 8
@@ -387,26 +396,33 @@ fn dbg_declare_has_valid_metadata_references_for_methods() {
387396
388397
attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
389398
390-
!llvm.module.flags = !{!5, !6}
391-
!llvm.dbg.cu = !{!7}
399+
!llvm.module.flags = !{!12, !13}
400+
!llvm.dbg.cu = !{!14}
392401
393402
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
394-
!1 = distinct !DIGlobalVariable(name: "__fb__init", scope: !2, file: !2, line: 2, type: !3, isLocal: false, isDefinition: true)
403+
!1 = distinct !DIGlobalVariable(name: "____vtable_fb__init", scope: !2, file: !2, type: !3, isLocal: false, isDefinition: true)
395404
!2 = !DIFile(filename: "<internal>", directory: "")
396-
!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "fb", scope: !2, file: !2, line: 2, align: 64, flags: DIFlagPublic, elements: !4, identifier: "fb")
397-
!4 = !{}
398-
!5 = !{i32 2, !"Dwarf Version", i32 5}
399-
!6 = !{i32 2, !"Debug Info Version", i32 3}
400-
!7 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !8, splitDebugInlining: false)
401-
!8 = !{!0}
402-
!9 = distinct !DISubprogram(name: "fb", linkageName: "fb", scope: !2, file: !2, line: 2, type: !10, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
403-
!10 = !DISubroutineType(flags: DIFlagPublic, types: !11)
404-
!11 = !{null, !3}
405-
!12 = !DILocalVariable(name: "fb", scope: !9, file: !2, line: 5, type: !3)
406-
!13 = !DILocation(line: 5, column: 8, scope: !9)
407-
!14 = distinct !DISubprogram(name: "fb.foo", linkageName: "fb.foo", scope: !9, file: !2, line: 3, type: !10, scopeLine: 4, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !7, retainedNodes: !4)
408-
!15 = !DILocalVariable(name: "fb", scope: !14, file: !2, line: 4, type: !3)
409-
!16 = !DILocation(line: 4, column: 8, scope: !14)
405+
!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "__vtable_fb", scope: !2, file: !2, size: 64, align: 64, flags: DIFlagPublic, elements: !4, identifier: "__vtable_fb")
406+
!4 = !{!5}
407+
!5 = !DIDerivedType(tag: DW_TAG_member, name: "fb.foo", scope: !2, file: !2, baseType: !6, size: 64, align: 64, flags: DIFlagPublic)
408+
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "VOID_POINTER", baseType: !7, size: 64, align: 64, dwarfAddressSpace: 1)
409+
!7 = !DIBasicType(name: "__VOID", encoding: DW_ATE_unsigned, flags: DIFlagPublic)
410+
!8 = !DIGlobalVariableExpression(var: !9, expr: !DIExpression())
411+
!9 = distinct !DIGlobalVariable(name: "__fb__init", scope: !2, file: !2, line: 2, type: !10, isLocal: false, isDefinition: true)
412+
!10 = !DICompositeType(tag: DW_TAG_structure_type, name: "fb", scope: !2, file: !2, line: 2, align: 64, flags: DIFlagPublic, elements: !11, identifier: "fb")
413+
!11 = !{}
414+
!12 = !{i32 2, !"Dwarf Version", i32 5}
415+
!13 = !{i32 2, !"Debug Info Version", i32 3}
416+
!14 = distinct !DICompileUnit(language: DW_LANG_C, file: !2, producer: "RuSTy Structured text Compiler", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !15, splitDebugInlining: false)
417+
!15 = !{!8, !0}
418+
!16 = distinct !DISubprogram(name: "fb", linkageName: "fb", scope: !2, file: !2, line: 2, type: !17, scopeLine: 5, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !14, retainedNodes: !11)
419+
!17 = !DISubroutineType(flags: DIFlagPublic, types: !18)
420+
!18 = !{null, !10}
421+
!19 = !DILocalVariable(name: "fb", scope: !16, file: !2, line: 5, type: !10)
422+
!20 = !DILocation(line: 5, column: 8, scope: !16)
423+
!21 = distinct !DISubprogram(name: "fb.foo", linkageName: "fb.foo", scope: !16, file: !2, line: 3, type: !17, scopeLine: 4, flags: DIFlagPublic, spFlags: DISPFlagDefinition, unit: !14, retainedNodes: !11)
424+
!22 = !DILocalVariable(name: "fb", scope: !21, file: !2, line: 4, type: !10)
425+
!23 = !DILocation(line: 4, column: 8, scope: !21)
410426
"#);
411427
}
412428

src/codegen/tests/oop_tests.rs

Lines changed: 146 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ fn members_from_base_class_are_available_in_subclasses() {
1919
END_FUNCTION_BLOCK
2020
"#,
2121
);
22-
insta::assert_snapshot!(result, @r###"
22+
insta::assert_snapshot!(result, @r#"
2323
; ModuleID = '<internal>'
2424
source_filename = "<internal>"
2525
26+
%__vtable_foo = type {}
27+
%__vtable_bar = type { %__vtable_foo }
2628
%foo = type { i16, [81 x i8], [11 x [81 x i8]] }
2729
%bar = type { %foo }
2830
31+
@____vtable_foo__init = constant %__vtable_foo zeroinitializer
32+
@____vtable_bar__init = constant %__vtable_bar zeroinitializer
2933
@__foo__init = constant %foo zeroinitializer
3034
@__bar__init = constant %bar zeroinitializer
3135
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
@@ -44,6 +48,23 @@ fn members_from_base_class_are_available_in_subclasses() {
4448
ret void
4549
}
4650
51+
define void @__init___vtable_foo(%__vtable_foo* %0) {
52+
entry:
53+
%self = alloca %__vtable_foo*, align 8
54+
store %__vtable_foo* %0, %__vtable_foo** %self, align 8
55+
ret void
56+
}
57+
58+
define void @__init___vtable_bar(%__vtable_bar* %0) {
59+
entry:
60+
%self = alloca %__vtable_bar*, align 8
61+
store %__vtable_bar* %0, %__vtable_bar** %self, align 8
62+
%deref = load %__vtable_bar*, %__vtable_bar** %self, align 8
63+
%__vtable_foo = getelementptr inbounds %__vtable_bar, %__vtable_bar* %deref, i32 0, i32 0
64+
call void @__init___vtable_foo(%__vtable_foo* %__vtable_foo)
65+
ret void
66+
}
67+
4768
define void @__init_foo(%foo* %0) {
4869
entry:
4970
%self = alloca %foo*, align 8
@@ -65,7 +86,7 @@ fn members_from_base_class_are_available_in_subclasses() {
6586
entry:
6687
ret void
6788
}
68-
"###);
89+
"#);
6990
}
7091

7192
#[test]
@@ -91,14 +112,20 @@ fn write_to_parent_variable_qualified_access() {
91112
",
92113
);
93114

94-
insta::assert_snapshot!(res, @r###"
115+
insta::assert_snapshot!(res, @r#"
95116
; ModuleID = '<internal>'
96117
source_filename = "<internal>"
97118
119+
%__vtable_fb = type {}
120+
%__vtable_fb2 = type { %__vtable_fb }
121+
%__vtable_foo = type {}
98122
%fb2 = type { %fb }
99123
%fb = type { i16, i16 }
100124
%foo = type { %fb2 }
101125
126+
@____vtable_fb__init = constant %__vtable_fb zeroinitializer
127+
@____vtable_fb2__init = constant %__vtable_fb2 zeroinitializer
128+
@____vtable_foo__init = constant %__vtable_foo zeroinitializer
102129
@__fb2__init = constant %fb2 zeroinitializer
103130
@__fb__init = constant %fb zeroinitializer
104131
@__foo__init = constant %foo zeroinitializer
@@ -126,6 +153,30 @@ fn write_to_parent_variable_qualified_access() {
126153
ret void
127154
}
128155
156+
define void @__init___vtable_fb(%__vtable_fb* %0) {
157+
entry:
158+
%self = alloca %__vtable_fb*, align 8
159+
store %__vtable_fb* %0, %__vtable_fb** %self, align 8
160+
ret void
161+
}
162+
163+
define void @__init___vtable_fb2(%__vtable_fb2* %0) {
164+
entry:
165+
%self = alloca %__vtable_fb2*, align 8
166+
store %__vtable_fb2* %0, %__vtable_fb2** %self, align 8
167+
%deref = load %__vtable_fb2*, %__vtable_fb2** %self, align 8
168+
%__vtable_fb = getelementptr inbounds %__vtable_fb2, %__vtable_fb2* %deref, i32 0, i32 0
169+
call void @__init___vtable_fb(%__vtable_fb* %__vtable_fb)
170+
ret void
171+
}
172+
173+
define void @__init___vtable_foo(%__vtable_foo* %0) {
174+
entry:
175+
%self = alloca %__vtable_foo*, align 8
176+
store %__vtable_foo* %0, %__vtable_foo** %self, align 8
177+
ret void
178+
}
179+
129180
define void @__init_fb2(%fb2* %0) {
130181
entry:
131182
%self = alloca %fb2*, align 8
@@ -157,7 +208,7 @@ fn write_to_parent_variable_qualified_access() {
157208
entry:
158209
ret void
159210
}
160-
"###);
211+
"#);
161212
}
162213

163214
#[test]
@@ -191,11 +242,15 @@ fn write_to_parent_variable_in_instance() {
191242
; ModuleID = '<internal>'
192243
source_filename = "<internal>"
193244
245+
%__vtable_foo = type { i32* }
246+
%__vtable_bar = type { %__vtable_foo }
194247
%bar = type { %foo }
195248
%foo = type { [81 x i8] }
196249
197250
@utf08_literal_0 = private unnamed_addr constant [6 x i8] c"hello\00"
198251
@utf08_literal_1 = private unnamed_addr constant [6 x i8] c"world\00"
252+
@____vtable_foo__init = constant %__vtable_foo zeroinitializer
253+
@____vtable_bar__init = constant %__vtable_bar zeroinitializer
199254
@__bar__init = constant %bar zeroinitializer
200255
@__foo__init = constant %foo zeroinitializer
201256
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 0, void ()* @__init___Test, i8* null }]
@@ -247,6 +302,23 @@ fn write_to_parent_variable_in_instance() {
247302
; Function Attrs: argmemonly nofree nounwind willreturn
248303
declare void @llvm.memcpy.p0i8.p0i8.i64(i8* noalias nocapture writeonly, i8* noalias nocapture readonly, i64, i1 immarg) #0
249304
305+
define void @__init___vtable_foo(%__vtable_foo* %0) {
306+
entry:
307+
%self = alloca %__vtable_foo*, align 8
308+
store %__vtable_foo* %0, %__vtable_foo** %self, align 8
309+
ret void
310+
}
311+
312+
define void @__init___vtable_bar(%__vtable_bar* %0) {
313+
entry:
314+
%self = alloca %__vtable_bar*, align 8
315+
store %__vtable_bar* %0, %__vtable_bar** %self, align 8
316+
%deref = load %__vtable_bar*, %__vtable_bar** %self, align 8
317+
%__vtable_foo = getelementptr inbounds %__vtable_bar, %__vtable_bar* %deref, i32 0, i32 0
318+
call void @__init___vtable_foo(%__vtable_foo* %__vtable_foo)
319+
ret void
320+
}
321+
250322
define void @__init_bar(%bar* %0) {
251323
entry:
252324
%self = alloca %bar*, align 8
@@ -310,14 +382,20 @@ fn array_in_parent_generated() {
310382
END_FUNCTION
311383
"#,
312384
);
313-
insta::assert_snapshot!(result, @r###"
385+
insta::assert_snapshot!(result, @r#"
314386
; ModuleID = '<internal>'
315387
source_filename = "<internal>"
316388
389+
%__vtable_grandparent = type {}
390+
%__vtable_parent = type { %__vtable_grandparent }
391+
%__vtable_child = type { %__vtable_parent }
317392
%child = type { %parent, [11 x i16] }
318393
%parent = type { %grandparent, [11 x i16], i16 }
319394
%grandparent = type { [6 x i16], i16 }
320395
396+
@____vtable_grandparent__init = constant %__vtable_grandparent zeroinitializer
397+
@____vtable_parent__init = constant %__vtable_parent zeroinitializer
398+
@____vtable_child__init = constant %__vtable_child zeroinitializer
321399
@__child__init = constant %child zeroinitializer
322400
@__parent__init = constant %parent zeroinitializer
323401
@__grandparent__init = constant %grandparent zeroinitializer
@@ -380,6 +458,33 @@ fn array_in_parent_generated() {
380458
; Function Attrs: argmemonly nofree nounwind willreturn writeonly
381459
declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #0
382460
461+
define void @__init___vtable_grandparent(%__vtable_grandparent* %0) {
462+
entry:
463+
%self = alloca %__vtable_grandparent*, align 8
464+
store %__vtable_grandparent* %0, %__vtable_grandparent** %self, align 8
465+
ret void
466+
}
467+
468+
define void @__init___vtable_parent(%__vtable_parent* %0) {
469+
entry:
470+
%self = alloca %__vtable_parent*, align 8
471+
store %__vtable_parent* %0, %__vtable_parent** %self, align 8
472+
%deref = load %__vtable_parent*, %__vtable_parent** %self, align 8
473+
%__vtable_grandparent = getelementptr inbounds %__vtable_parent, %__vtable_parent* %deref, i32 0, i32 0
474+
call void @__init___vtable_grandparent(%__vtable_grandparent* %__vtable_grandparent)
475+
ret void
476+
}
477+
478+
define void @__init___vtable_child(%__vtable_child* %0) {
479+
entry:
480+
%self = alloca %__vtable_child*, align 8
481+
store %__vtable_child* %0, %__vtable_child** %self, align 8
482+
%deref = load %__vtable_child*, %__vtable_child** %self, align 8
483+
%__vtable_parent = getelementptr inbounds %__vtable_child, %__vtable_child* %deref, i32 0, i32 0
484+
call void @__init___vtable_parent(%__vtable_parent* %__vtable_parent)
485+
ret void
486+
}
487+
383488
define void @__init_child(%child* %0) {
384489
entry:
385490
%self = alloca %child*, align 8
@@ -413,7 +518,7 @@ fn array_in_parent_generated() {
413518
}
414519
415520
attributes #0 = { argmemonly nofree nounwind willreturn writeonly }
416-
"###);
521+
"#);
417522
}
418523

419524
#[test]
@@ -443,14 +548,20 @@ fn complex_array_access_generated() {
443548
"#,
444549
);
445550

446-
insta::assert_snapshot!(result, @r###"
551+
insta::assert_snapshot!(result, @r#"
447552
; ModuleID = '<internal>'
448553
source_filename = "<internal>"
449554
555+
%__vtable_grandparent = type {}
556+
%__vtable_parent = type { %__vtable_grandparent }
557+
%__vtable_child = type { %__vtable_parent }
450558
%parent = type { %grandparent, [11 x i16], i16 }
451559
%grandparent = type { [6 x i16], i16 }
452560
%child = type { %parent, [11 x i16] }
453561
562+
@____vtable_grandparent__init = constant %__vtable_grandparent zeroinitializer
563+
@____vtable_parent__init = constant %__vtable_parent zeroinitializer
564+
@____vtable_child__init = constant %__vtable_child zeroinitializer
454565
@__parent__init = constant %parent zeroinitializer
455566
@__grandparent__init = constant %grandparent zeroinitializer
456567
@__child__init = constant %child zeroinitializer
@@ -502,6 +613,33 @@ fn complex_array_access_generated() {
502613
ret void
503614
}
504615
616+
define void @__init___vtable_grandparent(%__vtable_grandparent* %0) {
617+
entry:
618+
%self = alloca %__vtable_grandparent*, align 8
619+
store %__vtable_grandparent* %0, %__vtable_grandparent** %self, align 8
620+
ret void
621+
}
622+
623+
define void @__init___vtable_parent(%__vtable_parent* %0) {
624+
entry:
625+
%self = alloca %__vtable_parent*, align 8
626+
store %__vtable_parent* %0, %__vtable_parent** %self, align 8
627+
%deref = load %__vtable_parent*, %__vtable_parent** %self, align 8
628+
%__vtable_grandparent = getelementptr inbounds %__vtable_parent, %__vtable_parent* %deref, i32 0, i32 0
629+
call void @__init___vtable_grandparent(%__vtable_grandparent* %__vtable_grandparent)
630+
ret void
631+
}
632+
633+
define void @__init___vtable_child(%__vtable_child* %0) {
634+
entry:
635+
%self = alloca %__vtable_child*, align 8
636+
store %__vtable_child* %0, %__vtable_child** %self, align 8
637+
%deref = load %__vtable_child*, %__vtable_child** %self, align 8
638+
%__vtable_parent = getelementptr inbounds %__vtable_child, %__vtable_child* %deref, i32 0, i32 0
639+
call void @__init___vtable_parent(%__vtable_parent* %__vtable_parent)
640+
ret void
641+
}
642+
505643
define void @__init_parent(%parent* %0) {
506644
entry:
507645
%self = alloca %parent*, align 8
@@ -533,7 +671,7 @@ fn complex_array_access_generated() {
533671
entry:
534672
ret void
535673
}
536-
"###);
674+
"#);
537675
}
538676

539677
#[test]

0 commit comments

Comments
 (0)