1 ; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
3 ; This test verifies global variables are emitted within the correct scope.
5 ; -- global_visibility.cpp ----------------------------------------------------
7 ; 2 int global_int = 0;
9 ; 4 template <typename T> struct A {
10 ; 5 static T comdat_int;
11 ; 6 static T set(T value) { T r = comdat_int; comdat_int = value; return r; };
14 ; 9 template <typename T> T A<T>::comdat_int = 42;
17 ; 12 static int local_int = 1;
19 ; 14 static int nested_int = 2;
20 ; 15 local_int = nested_int;
22 ; 17 local_int = A<int>::set(42);
26 ; 21 static int local_int = 3;
28 ; 23 static int nested_int = 4;
29 ; 24 local_int = nested_int;
31 ; 26 local_int = A<unsigned>::set(42);
34 ; -----------------------------------------------------------------------------
36 ; $ clang -S -emit-llvm -g -gcodeview global_visibility.cpp
38 ; NOTE: The scope for both DIGlobalVariable's named "nested_int" should refer
39 ; to the appropriate DILexicalBlock, not a DISubprogram.
42 ; CHECK: CodeViewDebugInfo [
43 ; CHECK: Section: .debug$S (9)
46 ; CHECK: SubSectionType: Symbols (0xF1)
47 ; CHECK: GlobalProcIdSym {
48 ; CHECK: Kind: S_GPROC32_ID (0x1147)
49 ; CHECK: DisplayName: foo
50 ; CHECK: LinkageName: ?foo@@YAXXZ
53 ; CHECK: Kind: S_LDATA32 (0x110C)
54 ; CHECK: DisplayName: local_int
55 ; CHECK: LinkageName: ?local_int@?1??foo@@YAXXZ@4HA
58 ; CHECK: Kind: S_BLOCK32 (0x1103)
61 ; CHECK: Kind: S_LDATA32 (0x110C)
62 ; CHECK: DisplayName: nested_int
63 ; CHECK: LinkageName: ?nested_int@?1??foo@@YAXXZ@4HA
65 ; CHECK: ScopeEndSym {
66 ; CHECK: Kind: S_END (0x6)
69 ; CHECK: Kind: S_PROC_ID_END (0x114F)
73 ; CHECK: SubSectionType: Symbols (0xF1)
74 ; CHECK: GlobalProcIdSym {
75 ; CHECK: Kind: S_GPROC32_ID (0x1147)
76 ; CHECK: DisplayName: bar
77 ; CHECK: LinkageName: ?bar@@YAXXZ
80 ; CHECK: Kind: S_LDATA32 (0x110C)
81 ; CHECK: DisplayName: local_int
82 ; CHECK: LinkageName: ?local_int@?1??bar@@YAXXZ@4HA
85 ; CHECK: Kind: S_BLOCK32 (0x1103)
88 ; CHECK: Kind: S_LDATA32 (0x110C)
89 ; CHECK: DisplayName: nested_int
90 ; CHECK: LinkageName: ?nested_int@?1??bar@@YAXXZ@4HA
92 ; CHECK: ScopeEndSym {
93 ; CHECK: Kind: S_END (0x6)
96 ; CHECK: Kind: S_PROC_ID_END (0x114F)
100 ; CHECK: SubSectionType: Symbols (0xF1)
101 ; CHECK: GlobalData {
102 ; CHECK: Kind: S_GDATA32 (0x110D)
103 ; CHECK: DisplayName: global_int
104 ; CHECK: LinkageName: ?global_int@@3HA
108 ; CHECK: CodeViewDebugInfo [
109 ; CHECK: Section: .debug$S (16)
110 ; CHECK: Subsection [
111 ; CHECK: SubSectionType: Symbols (0xF1)
112 ; CHECK: GlobalData {
113 ; CHECK: Kind: S_GDATA32 (0x110D)
114 ; CHECK: DisplayName: comdat_int
115 ; CHECK: LinkageName: ?comdat_int@?$A@H@@2HA
119 ; CHECK: CodeViewDebugInfo [
120 ; CHECK: Section: .debug$S (17)
121 ; CHECK: Subsection [
122 ; CHECK: SubSectionType: Symbols (0xF1)
123 ; CHECK: GlobalData {
124 ; CHECK: Kind: S_GDATA32 (0x110D)
125 ; CHECK: DisplayName: comdat_int
126 ; CHECK: LinkageName: ?comdat_int@?$A@I@@2IA
132 ; ModuleID = 'global_visibility.cpp'
133 source_filename = "global_visibility.cpp"
134 target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
135 target triple = "x86_64-pc-windows-msvc19.15.26730"
137 $"?set@?$A@H@@SAHH@Z" = comdat any
139 $"?set@?$A@I@@SAII@Z" = comdat any
141 $"?comdat_int@?$A@H@@2HA" = comdat any
143 $"?comdat_int@?$A@I@@2IA" = comdat any
145 @"?global_int@@3HA" = dso_local global i32 0, align 4, !dbg !0
146 @"?local_int@?1??foo@@YAXXZ@4HA" = internal global i32 1, align 4, !dbg !6
147 @"?nested_int@?1??foo@@YAXXZ@4HA" = internal global i32 2, align 4, !dbg !12
148 @"?local_int@?1??bar@@YAXXZ@4HA" = internal global i32 3, align 4, !dbg !14
149 @"?nested_int@?1??bar@@YAXXZ@4HA" = internal global i32 4, align 4, !dbg !17
150 @"?comdat_int@?$A@H@@2HA" = linkonce_odr dso_local global i32 42, comdat, align 4, !dbg !19
151 @"?comdat_int@?$A@I@@2IA" = linkonce_odr dso_local global i32 42, comdat, align 4, !dbg !29
153 ; Function Attrs: noinline optnone uwtable
154 define dso_local void @"?foo@@YAXXZ"() #0 !dbg !8 {
156 %0 = load i32, i32* @"?nested_int@?1??foo@@YAXXZ@4HA", align 4, !dbg !45
157 store i32 %0, i32* @"?local_int@?1??foo@@YAXXZ@4HA", align 4, !dbg !45
158 %call = call i32 @"?set@?$A@H@@SAHH@Z"(i32 42), !dbg !47
159 store i32 %call, i32* @"?local_int@?1??foo@@YAXXZ@4HA", align 4, !dbg !47
163 ; Function Attrs: noinline nounwind optnone uwtable
164 define linkonce_odr dso_local i32 @"?set@?$A@H@@SAHH@Z"(i32 %value) #1 comdat align 2 !dbg !49 {
166 %value.addr = alloca i32, align 4
167 %r = alloca i32, align 4
168 store i32 %value, i32* %value.addr, align 4
169 call void @llvm.dbg.declare(metadata i32* %value.addr, metadata !50, metadata !DIExpression()), !dbg !51
170 call void @llvm.dbg.declare(metadata i32* %r, metadata !52, metadata !DIExpression()), !dbg !51
171 %0 = load i32, i32* @"?comdat_int@?$A@H@@2HA", align 4, !dbg !51
172 store i32 %0, i32* %r, align 4, !dbg !51
173 %1 = load i32, i32* %value.addr, align 4, !dbg !51
174 store i32 %1, i32* @"?comdat_int@?$A@H@@2HA", align 4, !dbg !51
175 %2 = load i32, i32* %r, align 4, !dbg !51
179 ; Function Attrs: noinline optnone uwtable
180 define dso_local void @"?bar@@YAXXZ"() #0 !dbg !16 {
182 %0 = load i32, i32* @"?nested_int@?1??bar@@YAXXZ@4HA", align 4, !dbg !53
183 store i32 %0, i32* @"?local_int@?1??bar@@YAXXZ@4HA", align 4, !dbg !53
184 %call = call i32 @"?set@?$A@I@@SAII@Z"(i32 42), !dbg !55
185 store i32 %call, i32* @"?local_int@?1??bar@@YAXXZ@4HA", align 4, !dbg !55
189 ; Function Attrs: noinline nounwind optnone uwtable
190 define linkonce_odr dso_local i32 @"?set@?$A@I@@SAII@Z"(i32 %value) #1 comdat align 2 !dbg !57 {
192 %value.addr = alloca i32, align 4
193 %r = alloca i32, align 4
194 store i32 %value, i32* %value.addr, align 4
195 call void @llvm.dbg.declare(metadata i32* %value.addr, metadata !58, metadata !DIExpression()), !dbg !59
196 call void @llvm.dbg.declare(metadata i32* %r, metadata !60, metadata !DIExpression()), !dbg !59
197 %0 = load i32, i32* @"?comdat_int@?$A@I@@2IA", align 4, !dbg !59
198 store i32 %0, i32* %r, align 4, !dbg !59
199 %1 = load i32, i32* %value.addr, align 4, !dbg !59
200 store i32 %1, i32* @"?comdat_int@?$A@I@@2IA", align 4, !dbg !59
201 %2 = load i32, i32* %r, align 4, !dbg !59
205 ; Function Attrs: nounwind readnone speculatable
206 declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
208 attributes #0 = { noinline optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-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" }
209 attributes #1 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-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" }
210 attributes #2 = { nounwind readnone speculatable }
213 !llvm.module.flags = !{!40, !41, !42, !43}
216 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
217 !1 = distinct !DIGlobalVariable(name: "global_int", linkageName: "?global_int@@3HA", scope: !2, file: !3, line: 2, type: !11, isLocal: false, isDefinition: true)
218 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 8.0.0 (trunk)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, nameTableKind: None)
219 !3 = !DIFile(filename: "global_visibility.cpp", directory: "C:\5Cpath\5Cto\5Cdirectory", checksumkind: CSK_MD5, checksum: "f59b9e5de12391471b1a61888cb68a3e")
221 !5 = !{!0, !6, !12, !14, !17, !19, !29}
222 !6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression())
223 !7 = distinct !DIGlobalVariable(name: "local_int", scope: !8, file: !3, line: 12, type: !11, isLocal: true, isDefinition: true)
224 !8 = distinct !DISubprogram(name: "foo", linkageName: "?foo@@YAXXZ", scope: !3, file: !3, line: 11, type: !9, scopeLine: 11, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
225 !9 = !DISubroutineType(types: !10)
227 !11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
228 !12 = !DIGlobalVariableExpression(var: !13, expr: !DIExpression())
229 !13 = distinct !DIGlobalVariable(name: "nested_int", scope: !46, file: !3, line: 14, type: !11, isLocal: true, isDefinition: true)
230 !14 = !DIGlobalVariableExpression(var: !15, expr: !DIExpression())
231 !15 = distinct !DIGlobalVariable(name: "local_int", scope: !16, file: !3, line: 21, type: !11, isLocal: true, isDefinition: true)
232 !16 = distinct !DISubprogram(name: "bar", linkageName: "?bar@@YAXXZ", scope: !3, file: !3, line: 20, type: !9, scopeLine: 20, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !4)
233 !17 = !DIGlobalVariableExpression(var: !18, expr: !DIExpression())
234 !18 = distinct !DIGlobalVariable(name: "nested_int", scope: !54, file: !3, line: 23, type: !11, isLocal: true, isDefinition: true)
235 !19 = !DIGlobalVariableExpression(var: !20, expr: !DIExpression())
236 !20 = distinct !DIGlobalVariable(name: "comdat_int", linkageName: "?comdat_int@?$A@H@@2HA", scope: !2, file: !3, line: 9, type: !11, isLocal: false, isDefinition: true, declaration: !21)
237 !21 = !DIDerivedType(tag: DW_TAG_member, name: "comdat_int", scope: !22, file: !3, line: 5, baseType: !11, flags: DIFlagStaticMember)
238 !22 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A<int>", file: !3, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !23, templateParams: !27, identifier: ".?AU?$A@H@@")
240 !24 = !DISubprogram(name: "set", linkageName: "?set@?$A@H@@SAHH@Z", scope: !22, file: !3, line: 6, type: !25, scopeLine: 6, flags: DIFlagPrototyped | DIFlagStaticMember, spFlags: 0)
241 !25 = !DISubroutineType(types: !26)
244 !28 = !DITemplateTypeParameter(name: "T", type: !11)
245 !29 = !DIGlobalVariableExpression(var: !30, expr: !DIExpression())
246 !30 = distinct !DIGlobalVariable(name: "comdat_int", linkageName: "?comdat_int@?$A@I@@2IA", scope: !2, file: !3, line: 9, type: !31, isLocal: false, isDefinition: true, declaration: !32)
247 !31 = !DIBasicType(name: "unsigned int", size: 32, encoding: DW_ATE_unsigned)
248 !32 = !DIDerivedType(tag: DW_TAG_member, name: "comdat_int", scope: !33, file: !3, line: 5, baseType: !31, flags: DIFlagStaticMember)
249 !33 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "A<unsigned int>", file: !3, line: 4, size: 8, flags: DIFlagTypePassByValue, elements: !34, templateParams: !38, identifier: ".?AU?$A@I@@")
251 !35 = !DISubprogram(name: "set", linkageName: "?set@?$A@I@@SAII@Z", scope: !33, file: !3, line: 6, type: !36, scopeLine: 6, flags: DIFlagPrototyped | DIFlagStaticMember, spFlags: 0)
252 !36 = !DISubroutineType(types: !37)
255 !39 = !DITemplateTypeParameter(name: "T", type: !31)
256 !40 = !{i32 2, !"CodeView", i32 1}
257 !41 = !{i32 2, !"Debug Info Version", i32 3}
258 !42 = !{i32 1, !"wchar_size", i32 2}
259 !43 = !{i32 7, !"PIC Level", i32 2}
260 !44 = !{!"clang version 8.0.0 (trunk)"}
261 !45 = !DILocation(line: 15, scope: !46)
262 !46 = distinct !DILexicalBlock(scope: !8, file: !3, line: 13)
263 !47 = !DILocation(line: 17, scope: !8)
264 !48 = !DILocation(line: 18, scope: !8)
265 !49 = distinct !DISubprogram(name: "set", linkageName: "?set@?$A@H@@SAHH@Z", scope: !22, file: !3, line: 6, type: !25, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, declaration: !24, retainedNodes: !4)
266 !50 = !DILocalVariable(name: "value", arg: 1, scope: !49, file: !3, line: 6, type: !11)
267 !51 = !DILocation(line: 6, scope: !49)
268 !52 = !DILocalVariable(name: "r", scope: !49, file: !3, line: 6, type: !11)
269 !53 = !DILocation(line: 24, scope: !54)
270 !54 = distinct !DILexicalBlock(scope: !16, file: !3, line: 22)
271 !55 = !DILocation(line: 26, scope: !16)
272 !56 = !DILocation(line: 27, scope: !16)
273 !57 = distinct !DISubprogram(name: "set", linkageName: "?set@?$A@I@@SAII@Z", scope: !33, file: !3, line: 6, type: !36, scopeLine: 6, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition, unit: !2, declaration: !35, retainedNodes: !4)
274 !58 = !DILocalVariable(name: "value", arg: 1, scope: !57, file: !3, line: 6, type: !31)
275 !59 = !DILocation(line: 6, scope: !57)
276 !60 = !DILocalVariable(name: "r", scope: !57, file: !3, line: 6, type: !31)