168 lines · plain
1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s2;3; This test verifies global variables with no scope, as rust generates them for vtables, are handled correctly.4;5; -- global_rust.rs ----------------------------------------------------6; #![crate_type = "lib"]7; pub trait Foo {8; fn foo(&self) {}9; }10;11; impl Foo for u32 {}12;13; pub fn foo(_: &dyn Foo) {}14;15; pub fn bar() {16; foo(&42);17; }18; -----------------------------------------------------------------------------19;20; $ rustc -emit=llvm-ir --target=x86_64-pc-windows-msvc -C debuginfo=2 global_rust.rs21;22 23; CHECK: CodeViewDebugInfo [24; CHECK: Section: .debug$S (6)25 26; CHECK: Subsection [27; CHECK: SubSectionType: Symbols (0xF1)28; CHECK: SubSectionSize: 0x3429; CHECK: DataSym {30; CHECK: Kind: S_LDATA32 (0x110C)31; CHECK: DataOffset: .rdata+0x832; CHECK: Type: impl$<u32, global_rust::Foo>::vtable_type$ (0x101D)33; CHECK: DisplayName: impl$<u32, global_rust::Foo>::vtable$34; CHECK: LinkageName: .rdata35; CHECK: }36; CHECK: ]37 38; ModuleID = 'global_rust.5984dd87-cgu.0'39source_filename = "global_rust.5984dd87-cgu.0"40target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"41target triple = "x86_64-pc-windows-msvc"42 43@alloc7 = private unnamed_addr constant <{ [4 x i8] }> <{ [4 x i8] c"*\00\00\00" }>, align 444@vtable.0 = private unnamed_addr constant <{ ptr, [16 x i8], ptr }> <{ ptr @"_ZN4core3ptr24drop_in_place$LT$u32$GT$17h5aa897c8344c34eaE", [16 x i8] c"\04\00\00\00\00\00\00\00\04\00\00\00\00\00\00\00", ptr @_ZN11global_rust3Foo3foo17h17696ada84e467feE }>, align 8, !dbg !045 46; core::ptr::drop_in_place<u32>47; Function Attrs: inlinehint uwtable48define internal void @"_ZN4core3ptr24drop_in_place$LT$u32$GT$17h5aa897c8344c34eaE"(ptr %_1) unnamed_addr #0 !dbg !22 {49start:50 %_1.dbg.spill = alloca ptr, align 851 store ptr %_1, ptr %_1.dbg.spill, align 852 call void @llvm.dbg.declare(metadata ptr %_1.dbg.spill, metadata !30, metadata !DIExpression()), !dbg !3353 ret void, !dbg !3354}55 56; global_rust::Foo::foo57; Function Attrs: uwtable58define void @_ZN11global_rust3Foo3foo17h17696ada84e467feE(ptr align 4 %self) unnamed_addr #1 !dbg !34 {59start:60 %self.dbg.spill = alloca ptr, align 861 store ptr %self, ptr %self.dbg.spill, align 862 call void @llvm.dbg.declare(metadata ptr %self.dbg.spill, metadata !42, metadata !DIExpression()), !dbg !4563 ret void, !dbg !4564}65 66; global_rust::foo67; Function Attrs: uwtable68define void @_ZN11global_rust3foo17hbb4da99a7bb855e3E(ptr align 1 %_1.0, ptr align 8 %_1.1) unnamed_addr #1 !dbg !46 {69start:70 %_1.dbg.spill = alloca { ptr, ptr }, align 871 %0 = getelementptr inbounds { ptr, ptr }, ptr %_1.dbg.spill, i32 0, i32 072 store ptr %_1.0, ptr %0, align 873 %1 = getelementptr inbounds { ptr, ptr }, ptr %_1.dbg.spill, i32 0, i32 174 store ptr %_1.1, ptr %1, align 875 call void @llvm.dbg.declare(metadata ptr %_1.dbg.spill, metadata !60, metadata !DIExpression()), !dbg !6176 ret void, !dbg !6177}78 79; global_rust::bar80; Function Attrs: uwtable81define void @_ZN11global_rust3bar17h9ea8de32fc3f1360E() unnamed_addr #1 !dbg !62 {82start:83; call global_rust::foo84 call void @_ZN11global_rust3foo17hbb4da99a7bb855e3E(ptr align 1 @alloc7, ptr align 8 @vtable.0), !dbg !6585 br label %bb1, !dbg !6586 87bb1: ; preds = %start88 ret void, !dbg !6689}90 91; Function Attrs: nofree nosync nounwind readnone speculatable willreturn92declare void @llvm.dbg.declare(metadata, metadata, metadata) #293 94attributes #0 = { inlinehint uwtable "target-cpu"="x86-64" }95attributes #1 = { uwtable "target-cpu"="x86-64" }96attributes #2 = { nofree nosync nounwind readnone speculatable willreturn }97 98!llvm.module.flags = !{!16, !17, !18}99!llvm.dbg.cu = !{!19}100 101!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())102!1 = distinct !DIGlobalVariable(name: "impl$<u32, global_rust::Foo>::vtable$", scope: null, file: !2, type: !3, isLocal: true, isDefinition: true)103!2 = !DIFile(filename: "<unknown>", directory: "")104!3 = !DICompositeType(tag: DW_TAG_structure_type, name: "impl$<u32, global_rust::Foo>::vtable_type$", file: !2, size: 256, align: 64, flags: DIFlagArtificial, elements: !4, vtableHolder: !14, templateParams: !8, identifier: "4a384a40e448d9d82ef8cb395527d231")105!4 = !{!5, !9, !12, !13}106!5 = !DIDerivedType(tag: DW_TAG_member, name: "drop_in_place", scope: !3, file: !2, baseType: !6, size: 64, align: 64)107!6 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_const$<tuple$<> >", baseType: !7, size: 64, align: 64, dwarfAddressSpace: 0)108!7 = !DICompositeType(tag: DW_TAG_structure_type, name: "tuple$<>", file: !2, align: 8, elements: !8, identifier: "65e33f3994015bcf158992dbe0323c0")109!8 = !{}110!9 = !DIDerivedType(tag: DW_TAG_member, name: "size", scope: !3, file: !2, baseType: !10, size: 64, align: 64, offset: 64)111!10 = !DIDerivedType(tag: DW_TAG_typedef, name: "usize", file: !2, baseType: !11)112!11 = !DIBasicType(name: "size_t", size: 64, encoding: DW_ATE_unsigned)113!12 = !DIDerivedType(tag: DW_TAG_member, name: "align", scope: !3, file: !2, baseType: !10, size: 64, align: 64, offset: 128)114!13 = !DIDerivedType(tag: DW_TAG_member, name: "__method3", scope: !3, file: !2, baseType: !6, size: 64, align: 64, offset: 192)115!14 = !DIDerivedType(tag: DW_TAG_typedef, name: "u32", file: !2, baseType: !15)116!15 = !DIBasicType(name: "unsigned __int32", size: 32, encoding: DW_ATE_unsigned)117!16 = !{i32 7, !"PIC Level", i32 2}118!17 = !{i32 2, !"CodeView", i32 1}119!18 = !{i32 2, !"Debug Info Version", i32 3}120!19 = distinct !DICompileUnit(language: DW_LANG_Rust, file: !20, producer: "clang LLVM (rustc version 1.64.0 (a55dd71d5 2022-09-19))", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, globals: !21)121!20 = !DIFile(filename: "global_rust.rs/@/global_rust.5984dd87-cgu.0", directory: "/tmp/llvm2")122!21 = !{!0}123!22 = distinct !DISubprogram(name: "drop_in_place<u32>", linkageName: "_ZN4core3ptr24drop_in_place$LT$u32$GT$17h5aa897c8344c34eaE", scope: !24, file: !23, line: 487, type: !26, scopeLine: 487, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !19, templateParams: !31, retainedNodes: !29)124!23 = !DIFile(filename: "/rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52\\library\\core\\src\\ptr\\mod.rs", directory: "", checksumkind: CSK_SHA1, checksum: "09826e1d72e15b98151545882632f685c97dc29f")125!24 = !DINamespace(name: "ptr", scope: !25)126!25 = !DINamespace(name: "core", scope: null)127!26 = !DISubroutineType(types: !27)128!27 = !{null, !28}129!28 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "ptr_mut$<u32>", baseType: !14, size: 64, align: 64, dwarfAddressSpace: 0)130!29 = !{!30}131!30 = !DILocalVariable(arg: 1, scope: !22, file: !23, line: 487, type: !28)132!31 = !{!32}133!32 = !DITemplateTypeParameter(name: "T", type: !14)134!33 = !DILocation(line: 487, scope: !22)135!34 = distinct !DISubprogram(name: "foo<u32>", linkageName: "_ZN11global_rust3Foo3foo17h17696ada84e467feE", scope: !36, file: !35, line: 3, type: !38, scopeLine: 3, flags: DIFlagPrototyped, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !19, templateParams: !43, retainedNodes: !41)136!35 = !DIFile(filename: "global_rust.rs", directory: "/tmp/llvm2", checksumkind: CSK_SHA1, checksum: "d28353083c5fcd457fffa5827b0372c4a843c302")137!36 = !DINamespace(name: "Foo", scope: !37)138!37 = !DINamespace(name: "global_rust", scope: null)139!38 = !DISubroutineType(types: !39)140!39 = !{null, !40}141!40 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "ref$<u32>", baseType: !14, size: 64, align: 64, dwarfAddressSpace: 0)142!41 = !{!42}143!42 = !DILocalVariable(name: "self", arg: 1, scope: !34, file: !35, line: 3, type: !40)144!43 = !{!44}145!44 = !DITemplateTypeParameter(name: "Self", type: !14)146!45 = !DILocation(line: 3, scope: !34)147!46 = distinct !DISubprogram(name: "foo", linkageName: "_ZN11global_rust3foo17hbb4da99a7bb855e3E", scope: !37, file: !35, line: 8, type: !47, scopeLine: 8, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !19, templateParams: !8, retainedNodes: !59)148!47 = !DISubroutineType(types: !48)149!48 = !{null, !49}150!49 = !DICompositeType(tag: DW_TAG_structure_type, name: "ref$<dyn$<global_rust::Foo> >", file: !2, size: 128, align: 64, elements: !50, templateParams: !8, identifier: "2c39c7f196ba93e4e4fbfefe6e460dfb")151!50 = !{!51, !54}152!51 = !DIDerivedType(tag: DW_TAG_member, name: "pointer", scope: !49, file: !2, baseType: !52, size: 64, align: 64)153!52 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !53, size: 64, align: 64, dwarfAddressSpace: 0)154!53 = !DICompositeType(tag: DW_TAG_structure_type, name: "dyn$<global_rust::Foo>", file: !2, align: 8, elements: !8, identifier: "dc5af67081d01f4b3cf3420f9b3ec7fa")155!54 = !DIDerivedType(tag: DW_TAG_member, name: "vtable", scope: !49, file: !2, baseType: !55, size: 64, align: 64, offset: 64)156!55 = !DIDerivedType(tag: DW_TAG_pointer_type, name: "ref$<array$<usize,3> >", baseType: !56, size: 64, align: 64, dwarfAddressSpace: 0)157!56 = !DICompositeType(tag: DW_TAG_array_type, baseType: !10, size: 192, align: 64, elements: !57)158!57 = !{!58}159!58 = !DISubrange(count: 3, lowerBound: 0)160!59 = !{!60}161!60 = !DILocalVariable(arg: 1, scope: !46, file: !35, line: 8, type: !49)162!61 = !DILocation(line: 8, scope: !46)163!62 = distinct !DISubprogram(name: "bar", linkageName: "_ZN11global_rust3bar17h9ea8de32fc3f1360E", scope: !37, file: !35, line: 10, type: !63, scopeLine: 10, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !19, templateParams: !8, retainedNodes: !8)164!63 = !DISubroutineType(types: !64)165!64 = !{null}166!65 = !DILocation(line: 11, scope: !62)167!66 = !DILocation(line: 12, scope: !62)168