xref: /llvm-project/llvm/test/DebugInfo/COFF/retained-types.ll (revision 5a288fa32e0c91b211e39f3e370255916902f898)
1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
2; RUN: llc < %s | llvm-mc -filetype=obj --triple=x86_64-windows | llvm-readobj - --codeview | FileCheck %s
3
4; This test checks that types which are used in expressions, but for which
5; there are no variables, known as retained types, get emitted.
6
7; C++ source to regenerate:
8; $ cat /tmp/a.cc
9; struct S { int x; };
10; int f(ptr p) {
11;   return static_cast<S*>(p)->x;
12; }
13; $ clang /tmp/a.cc -S -emit-llvm -g -gcodeview -target x86_64-windows-msvc -o t.ll
14
15; CHECK:       Struct (0x{{[0-9A-F]+}}) {
16; CHECK-NEXT:     TypeLeafKind: LF_STRUCTURE (0x1505)
17; CHECK-NEXT:     MemberCount: 0
18; CHECK-NEXT:     Properties [ (0x280)
19; CHECK-NEXT:       ForwardReference (0x80)
20; CHECK-NEXT:       HasUniqueName (0x200)
21; CHECK-NEXT:     ]
22; CHECK-NEXT:     FieldList: 0x0
23; CHECK-NEXT:     DerivedFrom: 0x0
24; CHECK-NEXT:     VShape: 0x0
25; CHECK-NEXT:     SizeOf: 0
26; CHECK-NEXT:     Name: S
27; CHECK-NEXT:     LinkageName: .?AUS@@
28; CHECK-NEXT:   }
29
30; CHECK:        Struct (0x{{[0-9A-F]+}}) {
31; CHECK-NEXT:     TypeLeafKind: LF_STRUCTURE (0x1505)
32; CHECK-NEXT:     MemberCount: 1
33; CHECK-NEXT:     Properties [ (0x200)
34; CHECK-NEXT:       HasUniqueName (0x200)
35; CHECK-NEXT:     ]
36; CHECK-NEXT:     FieldList: <field list> (0x{{[0-9A-F]+}})
37; CHECK-NEXT:     DerivedFrom: 0x0
38; CHECK-NEXT:     VShape: 0x0
39; CHECK-NEXT:     SizeOf: 4
40; CHECK-NEXT:     Name: S
41; CHECK-NEXT:     LinkageName: .?AUS@@
42; CHECK-NEXT:   }
43
44; ModuleID = '/tmp/a.cc'
45source_filename = "/tmp/a.cc"
46target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
47target triple = "x86_64--windows-msvc18.0.0"
48
49%struct.S = type { i32 }
50
51; Function Attrs: nounwind uwtable
52define i32 @"\01?f@@YAHPEAX@Z"(ptr %p) #0 !dbg !13 {
53entry:
54  %p.addr = alloca ptr, align 8
55  store ptr %p, ptr %p.addr, align 8
56  call void @llvm.dbg.declare(metadata ptr %p.addr, metadata !17, metadata !18), !dbg !19
57  %0 = load ptr, ptr %p.addr, align 8, !dbg !20
58  %1 = load i32, ptr %0, align 4, !dbg !22
59  ret i32 %1, !dbg !23
60}
61
62; Function Attrs: nounwind readnone
63declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
64
65attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
66attributes #1 = { nounwind readnone }
67
68!llvm.dbg.cu = !{!0}
69!llvm.module.flags = !{!9, !10, !11}
70!llvm.ident = !{!12}
71
72!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.9.0 (trunk 273441) (llvm/trunk 273449)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, retainedTypes: !3)
73!1 = !DIFile(filename: "/tmp/a.cc", directory: "/usr/local/google/work/llvm/build.release")
74!2 = !{}
75!3 = !{!4}
76!4 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64, align: 64)
77!5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 1, size: 32, align: 32, elements: !6, identifier: ".?AUS@@")
78!6 = !{!7}
79!7 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !5, file: !1, line: 1, baseType: !8, size: 32, align: 32)
80!8 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
81!9 = !{i32 2, !"CodeView", i32 1}
82!10 = !{i32 2, !"Debug Info Version", i32 3}
83!11 = !{i32 1, !"PIC Level", i32 2}
84!12 = !{!"clang version 3.9.0 (trunk 273441) (llvm/trunk 273449)"}
85!13 = distinct !DISubprogram(name: "f", linkageName: "\01?f@@YAHPEAX@Z", scope: !1, file: !1, line: 2, type: !14, isLocal: false, isDefinition: true, scopeLine: 2, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
86!14 = !DISubroutineType(types: !15)
87!15 = !{!8, !16}
88!16 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64, align: 64)
89!17 = !DILocalVariable(name: "p", arg: 1, scope: !13, file: !1, line: 2, type: !16)
90!18 = !DIExpression()
91!19 = !DILocation(line: 2, column: 13, scope: !13)
92!20 = !DILocation(line: 3, column: 26, scope: !13)
93!21 = !DILocation(line: 3, column: 10, scope: !13)
94!22 = !DILocation(line: 3, column: 30, scope: !13)
95!23 = !DILocation(line: 3, column: 3, scope: !13)
96