blob: 5e2f46686bd6c018636791e497a24d84810df2be [file] [log] [blame]
Eric Christopheraf7eca22014-03-13 23:26:25 +00001; RUN: llc %s -o %t -filetype=obj -O0 -mtriple=x86_64-unknown-linux-gnu -dwarf-version=4
Adrian Prantl16aa4cf2017-09-11 23:05:20 +00002; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s -check-prefix=PRESENT
3; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s -check-prefix=ABSENT
Eric Christopheraf7eca22014-03-13 23:26:25 +00004; RUN: llc %s -o %t -filetype=obj -O0 -mtriple=x86_64-apple-darwin -dwarf-version=4
Adrian Prantl16aa4cf2017-09-11 23:05:20 +00005; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s -check-prefix=DARWINP
6; RUN: llvm-dwarfdump -v -debug-info %t | FileCheck %s -check-prefix=DARWINA
Eric Christopherce26df82013-01-16 19:53:47 +00007; Verify that attributes we do want are PRESENT;
8; verify that attributes we don't want are ABSENT.
9; It's a lot easier to do this in two passes than in one.
10; PR14471
11
David Blaikie9f4b70d2013-01-26 21:55:23 +000012; LLVM IR generated using: clang -emit-llvm -S -g
Eric Christopherce26df82013-01-16 19:53:47 +000013; (with the Clang part of this patch applied).
14;
15; class C
16; {
17; static int a;
David Blaikieb0859312013-01-19 23:00:25 +000018; const static bool const_a = true;
Eric Christopherce26df82013-01-16 19:53:47 +000019; protected:
20; static int b;
David Blaikiea39a76e2013-01-20 01:18:01 +000021; const static float const_b = 3.14;
Eric Christopherce26df82013-01-16 19:53:47 +000022; public:
23; static int c;
24; const static int const_c = 18;
25; int d;
26; };
27;
28; int C::a = 4;
29; int C::b = 2;
30; int C::c = 1;
31;
32; int main()
33; {
34; C instance_C;
35; instance_C.d = 8;
36; return C::c;
37; }
38
Adrian Prantl1eadba12016-12-22 00:45:21 +000039source_filename = "test/DebugInfo/X86/debug-info-static-member.ll"
40
Eric Christopherce26df82013-01-16 19:53:47 +000041%class.C = type { i32 }
42
Adrian Prantl1eadba12016-12-22 00:45:21 +000043@_ZN1C1aE = global i32 4, align 4, !dbg !0
44@_ZN1C1bE = global i32 2, align 4, !dbg !18
45@_ZN1C1cE = global i32 1, align 4, !dbg !20
Eric Christopherce26df82013-01-16 19:53:47 +000046
Adrian Prantl1eadba12016-12-22 00:45:21 +000047; Function Attrs: nounwind uwtable
48define i32 @main() #0 !dbg !26 {
Eric Christopherce26df82013-01-16 19:53:47 +000049entry:
50 %retval = alloca i32, align 4
51 %instance_C = alloca %class.C, align 4
52 store i32 0, i32* %retval
Adrian Prantl1eadba12016-12-22 00:45:21 +000053 call void @llvm.dbg.declare(metadata %class.C* %instance_C, metadata !29, metadata !30), !dbg !31
54 %d = getelementptr inbounds %class.C, %class.C* %instance_C, i32 0, i32 0, !dbg !32
55 store i32 8, i32* %d, align 4, !dbg !32
56 %0 = load i32, i32* @_ZN1C1cE, align 4, !dbg !33
57 ret i32 %0, !dbg !33
Eric Christopherce26df82013-01-16 19:53:47 +000058}
59
Adrian Prantl1eadba12016-12-22 00:45:21 +000060; Function Attrs: nounwind readnone
61declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
Eric Christopherce26df82013-01-16 19:53:47 +000062
Adrian Prantl1eadba12016-12-22 00:45:21 +000063attributes #0 = { nounwind uwtable }
64attributes #1 = { nounwind readnone }
Eric Christopherce26df82013-01-16 19:53:47 +000065
Adrian Prantl1eadba12016-12-22 00:45:21 +000066!llvm.dbg.cu = !{!22}
67!llvm.module.flags = !{!25}
68
Adrian Prantl05782212017-08-30 18:06:51 +000069!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
Adrian Prantl1eadba12016-12-22 00:45:21 +000070!1 = !DIGlobalVariable(name: "a", linkageName: "_ZN1C1aE", scope: null, file: !2, line: 14, type: !3, isLocal: false, isDefinition: true, declaration: !4)
71!2 = !DIFile(filename: "/usr/local/google/home/blaikie/Development/llvm/src/tools/clang/test/CodeGenCXX/debug-info-static-member.cpp", directory: "/home/blaikie/local/Development/llvm/build/clang/x86-64/Debug/llvm")
72!3 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
73!4 = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: !5, file: !2, line: 3, baseType: !3, flags: DIFlagPrivate | DIFlagStaticMember)
74!5 = !DICompositeType(tag: DW_TAG_class_type, name: "C", file: !2, line: 1, size: 32, align: 32, elements: !6)
75!6 = !{!4, !7, !10, !11, !14, !15, !17}
76!7 = !DIDerivedType(tag: DW_TAG_member, name: "const_a", scope: !5, file: !2, line: 4, baseType: !8, flags: DIFlagPrivate | DIFlagStaticMember, extraData: i1 true)
77!8 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !9)
78!9 = !DIBasicType(name: "bool", size: 8, align: 8, encoding: DW_ATE_boolean)
79!10 = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: !5, file: !2, line: 6, baseType: !3, flags: DIFlagProtected | DIFlagStaticMember)
80!11 = !DIDerivedType(tag: DW_TAG_member, name: "const_b", scope: !5, file: !2, line: 7, baseType: !12, flags: DIFlagProtected | DIFlagStaticMember, extraData: float 0x40091EB860000000)
81!12 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !13)
82!13 = !DIBasicType(name: "float", size: 32, align: 32, encoding: DW_ATE_float)
83!14 = !DIDerivedType(tag: DW_TAG_member, name: "c", scope: !5, file: !2, line: 9, baseType: !3, flags: DIFlagPublic | DIFlagStaticMember)
84!15 = !DIDerivedType(tag: DW_TAG_member, name: "const_c", scope: !5, file: !2, line: 10, baseType: !16, flags: DIFlagPublic | DIFlagStaticMember, extraData: i32 18)
85!16 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !3)
86!17 = !DIDerivedType(tag: DW_TAG_member, name: "d", scope: !5, file: !2, line: 11, baseType: !3, size: 32, align: 32, flags: DIFlagPublic)
Adrian Prantl05782212017-08-30 18:06:51 +000087!18 = !DIGlobalVariableExpression(var: !19, expr: !DIExpression())
Adrian Prantl1eadba12016-12-22 00:45:21 +000088!19 = !DIGlobalVariable(name: "b", linkageName: "_ZN1C1bE", scope: null, file: !2, line: 15, type: !3, isLocal: false, isDefinition: true, declaration: !10)
Adrian Prantl05782212017-08-30 18:06:51 +000089!20 = !DIGlobalVariableExpression(var: !21, expr: !DIExpression())
Adrian Prantl1eadba12016-12-22 00:45:21 +000090!21 = !DIGlobalVariable(name: "c", linkageName: "_ZN1C1cE", scope: null, file: !2, line: 16, type: !3, isLocal: false, isDefinition: true, declaration: !14)
91!22 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.3 (trunk 171914)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !23, retainedTypes: !23, globals: !24, imports: !23)
92!23 = !{}
93!24 = !{!0, !18, !20}
94!25 = !{i32 1, !"Debug Info Version", i32 3}
Shiva Chen2c864552018-05-09 02:40:45 +000095!26 = distinct !DISubprogram(name: "main", scope: !2, file: !2, line: 18, type: !27, isLocal: false, isDefinition: true, scopeLine: 23, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !22, retainedNodes: !23)
Adrian Prantl1eadba12016-12-22 00:45:21 +000096!27 = !DISubroutineType(types: !28)
97!28 = !{!3}
98!29 = !DILocalVariable(name: "instance_C", scope: !26, file: !2, line: 20, type: !5)
99!30 = !DIExpression()
100!31 = !DILocation(line: 20, scope: !26)
101!32 = !DILocation(line: 21, scope: !26)
102!33 = !DILocation(line: 22, scope: !26)
103
Eric Christopherce26df82013-01-16 19:53:47 +0000104; PRESENT verifies that static member declarations have these attributes:
Paul Robinson857b4432015-03-10 22:44:45 +0000105; external, declaration, accessibility, and either DW_AT_linkage_name
Eric Christopherce26df82013-01-16 19:53:47 +0000106; (for variables) or DW_AT_const_value (for constants).
107;
108; PRESENT: .debug_info contents:
David Blaikie49cfc8c2014-10-23 19:12:43 +0000109; PRESENT: DW_TAG_variable
110; PRESENT-NEXT: DW_AT_specification {{.*}} "a"
111; PRESENT-NEXT: DW_AT_location
112; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1aE"
Eric Christopherce26df82013-01-16 19:53:47 +0000113; PRESENT: DW_TAG_class_type
114; PRESENT-NEXT: DW_AT_name {{.*}} "C"
Frederic Rissd4de1802014-10-10 15:51:02 +0000115; PRESENT: DW_TAG_member
Eric Christopherce26df82013-01-16 19:53:47 +0000116; PRESENT-NEXT: DW_AT_name {{.*}} "a"
117; PRESENT: DW_AT_external
118; PRESENT: DW_AT_declaration
Frederic Riss878065b2014-09-04 19:39:20 +0000119; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
Eric Christopherce26df82013-01-16 19:53:47 +0000120; PRESENT: DW_TAG_member
121; PRESENT-NEXT: DW_AT_name {{.*}} "const_a"
122; PRESENT: DW_AT_external
123; PRESENT: DW_AT_declaration
Frederic Riss878065b2014-09-04 19:39:20 +0000124; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
David Blaikieb0859312013-01-19 23:00:25 +0000125; PRESENT: DW_AT_const_value {{.*}} (1)
Frederic Rissd4de1802014-10-10 15:51:02 +0000126; PRESENT: DW_TAG_member
Eric Christopherce26df82013-01-16 19:53:47 +0000127; PRESENT-NEXT: DW_AT_name {{.*}} "b"
Frederic Riss878065b2014-09-04 19:39:20 +0000128; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
Eric Christopherce26df82013-01-16 19:53:47 +0000129; PRESENT: DW_TAG_member
130; PRESENT-NEXT: DW_AT_name {{.*}} "const_b"
Frederic Riss878065b2014-09-04 19:39:20 +0000131; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
David Blaikiec05c8f42014-05-11 15:47:39 +0000132; PRESENT: DW_AT_const_value [DW_FORM_udata] (1078523331)
Frederic Rissd4de1802014-10-10 15:51:02 +0000133; PRESENT: DW_TAG_member
Eric Christopherce26df82013-01-16 19:53:47 +0000134; PRESENT-NEXT: DW_AT_name {{.*}} "c"
Frederic Riss878065b2014-09-04 19:39:20 +0000135; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Eric Christopherce26df82013-01-16 19:53:47 +0000136; PRESENT: DW_TAG_member
137; PRESENT-NEXT: DW_AT_name {{.*}} "const_c"
Frederic Riss878065b2014-09-04 19:39:20 +0000138; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Eric Christopher9d1daa82013-08-27 23:49:04 +0000139; PRESENT: DW_AT_const_value {{.*}} (18)
Eric Christopherce26df82013-01-16 19:53:47 +0000140; While we're here, a normal member has data_member_location and
141; accessibility attributes.
142; PRESENT: DW_TAG_member
143; PRESENT-NEXT: DW_AT_name {{.*}} "d"
144; PRESENT: DW_AT_data_member_location
Frederic Riss878065b2014-09-04 19:39:20 +0000145; PRESENT: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Eric Christopherce26df82013-01-16 19:53:47 +0000146; PRESENT: NULL
147; Definitions point back to their declarations, and have a location.
148; PRESENT: DW_TAG_variable
Frederic Rissd4de1802014-10-10 15:51:02 +0000149; PRESENT-NEXT: DW_AT_specification {{.*}} "b"
Eric Christopherce26df82013-01-16 19:53:47 +0000150; PRESENT-NEXT: DW_AT_location
Eric Christopheraf7eca22014-03-13 23:26:25 +0000151; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1bE"
Eric Christopherce26df82013-01-16 19:53:47 +0000152; PRESENT: DW_TAG_variable
Frederic Rissd4de1802014-10-10 15:51:02 +0000153; PRESENT-NEXT: DW_AT_specification {{.*}} "c"
Eric Christopherce26df82013-01-16 19:53:47 +0000154; PRESENT-NEXT: DW_AT_location
Eric Christopheraf7eca22014-03-13 23:26:25 +0000155; PRESENT-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1cE"
Eric Christopherce26df82013-01-16 19:53:47 +0000156
Manman Ren584e4c02013-02-27 23:21:02 +0000157; For Darwin gdb:
158; DARWINP: .debug_info contents:
David Blaikie49cfc8c2014-10-23 19:12:43 +0000159; DARWINP: DW_TAG_variable
160; DARWINP-NEXT: DW_AT_specification {{.*}} "a"
161; DARWINP-NEXT: DW_AT_location
162; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1aE"
Manman Ren584e4c02013-02-27 23:21:02 +0000163; DARWINP: DW_TAG_class_type
164; DARWINP-NEXT: DW_AT_name {{.*}} "C"
Frederic Rissd4de1802014-10-10 15:51:02 +0000165; DARWINP: DW_TAG_member
Manman Ren584e4c02013-02-27 23:21:02 +0000166; DARWINP-NEXT: DW_AT_name {{.*}} "a"
167; DARWINP: DW_AT_external
168; DARWINP: DW_AT_declaration
Frederic Riss878065b2014-09-04 19:39:20 +0000169; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
Manman Ren584e4c02013-02-27 23:21:02 +0000170; DARWINP: DW_TAG_member
171; DARWINP-NEXT: DW_AT_name {{.*}} "const_a"
172; DARWINP: DW_AT_external
173; DARWINP: DW_AT_declaration
Frederic Riss878065b2014-09-04 19:39:20 +0000174; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_private)
Manman Ren584e4c02013-02-27 23:21:02 +0000175; DARWINP: DW_AT_const_value {{.*}} (1)
Frederic Rissd4de1802014-10-10 15:51:02 +0000176; DARWINP: DW_TAG_member
Manman Ren584e4c02013-02-27 23:21:02 +0000177; DARWINP-NEXT: DW_AT_name {{.*}} "b"
Frederic Riss878065b2014-09-04 19:39:20 +0000178; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
Manman Ren584e4c02013-02-27 23:21:02 +0000179; DARWINP: DW_TAG_member
180; DARWINP-NEXT: DW_AT_name {{.*}} "const_b"
Frederic Riss878065b2014-09-04 19:39:20 +0000181; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_protected)
David Blaikiec05c8f42014-05-11 15:47:39 +0000182; DARWINP: DW_AT_const_value [DW_FORM_udata] (1078523331)
Frederic Rissd4de1802014-10-10 15:51:02 +0000183; DARWINP: DW_TAG_member
Manman Ren584e4c02013-02-27 23:21:02 +0000184; DARWINP-NEXT: DW_AT_name {{.*}} "c"
Frederic Riss878065b2014-09-04 19:39:20 +0000185; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Manman Ren584e4c02013-02-27 23:21:02 +0000186; DARWINP: DW_TAG_member
187; DARWINP-NEXT: DW_AT_name {{.*}} "const_c"
Frederic Riss878065b2014-09-04 19:39:20 +0000188; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Eric Christopher9d1daa82013-08-27 23:49:04 +0000189; DARWINP: DW_AT_const_value {{.*}} (18)
Manman Ren584e4c02013-02-27 23:21:02 +0000190; While we're here, a normal member has data_member_location and
191; accessibility attributes.
192; DARWINP: DW_TAG_member
193; DARWINP-NEXT: DW_AT_name {{.*}} "d"
194; DARWINP: DW_AT_data_member_location
Frederic Riss878065b2014-09-04 19:39:20 +0000195; DARWINP: DW_AT_accessibility [DW_FORM_data1] (DW_ACCESS_public)
Manman Ren584e4c02013-02-27 23:21:02 +0000196; DARWINP: NULL
197; Definitions point back to their declarations, and have a location.
198; DARWINP: DW_TAG_variable
Frederic Rissd4de1802014-10-10 15:51:02 +0000199; DARWINP-NEXT: DW_AT_specification {{.*}} "b"
Manman Ren584e4c02013-02-27 23:21:02 +0000200; DARWINP-NEXT: DW_AT_location
Eric Christopheraf7eca22014-03-13 23:26:25 +0000201; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1bE"
Manman Ren584e4c02013-02-27 23:21:02 +0000202; DARWINP: DW_TAG_variable
Frederic Rissd4de1802014-10-10 15:51:02 +0000203; DARWINP-NEXT: DW_AT_specification {{.*}} "c"
Manman Ren584e4c02013-02-27 23:21:02 +0000204; DARWINP-NEXT: DW_AT_location
Eric Christopheraf7eca22014-03-13 23:26:25 +0000205; DARWINP-NEXT: DW_AT_linkage_name {{.*}} "_ZN1C1cE"
Manman Ren584e4c02013-02-27 23:21:02 +0000206
Eric Christopherce26df82013-01-16 19:53:47 +0000207; ABSENT verifies that static member declarations do not have either
208; DW_AT_location or DW_AT_data_member_location; also, variables do not
Eric Christopheraf7eca22014-03-13 23:26:25 +0000209; have DW_AT_const_value and constants do not have DW_AT_linkage_name.
Eric Christopherce26df82013-01-16 19:53:47 +0000210;
211; ABSENT: .debug_info contents:
212; ABSENT: DW_TAG_member
213; ABSENT: DW_AT_name {{.*}} "a"
214; ABSENT-NOT: DW_AT_const_value
215; ABSENT-NOT: location
216; ABSENT: DW_AT_name {{.*}} "const_a"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000217; ABSENT-NOT: DW_AT_linkage_name
Eric Christopherce26df82013-01-16 19:53:47 +0000218; ABSENT-NOT: location
219; ABSENT: DW_AT_name {{.*}} "b"
220; ABSENT-NOT: DW_AT_const_value
221; ABSENT-NOT: location
222; ABSENT: DW_AT_name {{.*}} "const_b"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000223; ABSENT-NOT: DW_AT_linkage_name
Eric Christopherce26df82013-01-16 19:53:47 +0000224; ABSENT-NOT: location
225; ABSENT: DW_AT_name {{.*}} "c"
226; ABSENT-NOT: DW_AT_const_value
227; ABSENT-NOT: location
228; ABSENT: DW_AT_name {{.*}} "const_c"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000229; ABSENT-NOT: DW_AT_linkage_name
Eric Christopherce26df82013-01-16 19:53:47 +0000230; ABSENT-NOT: location
231; While we're here, a normal member does not have a linkage name, constant
232; value, or DW_AT_location.
233; ABSENT: DW_AT_name {{.*}} "d"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000234; ABSENT-NOT: DW_AT_linkage_name
Eric Christopherce26df82013-01-16 19:53:47 +0000235; ABSENT-NOT: DW_AT_const_value
236; ABSENT-NOT: DW_AT_location
237; ABSENT: NULL
Manman Ren584e4c02013-02-27 23:21:02 +0000238
239; For Darwin gdb:
240; DARWINA: .debug_info contents:
241; DARWINA: DW_TAG_member
242; DARWINA: DW_AT_name {{.*}} "a"
243; DARWINA-NOT: DW_AT_const_value
244; DARWINA-NOT: location
245; DARWINA: DW_AT_name {{.*}} "const_a"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000246; DARWINA-NOT: DW_AT_linkage_name
Manman Ren584e4c02013-02-27 23:21:02 +0000247; DARWINA-NOT: location
248; DARWINA: DW_AT_name {{.*}} "b"
249; DARWINA-NOT: DW_AT_const_value
250; DARWINA-NOT: location
251; DARWINA: DW_AT_name {{.*}} "const_b"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000252; DARWINA-NOT: DW_AT_linkage_name
Manman Ren584e4c02013-02-27 23:21:02 +0000253; DARWINA-NOT: location
254; DARWINA: DW_AT_name {{.*}} "c"
255; DARWINA-NOT: DW_AT_const_value
256; DARWINA-NOT: location
257; DARWINA: DW_AT_name {{.*}} "const_c"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000258; DARWINA-NOT: DW_AT_linkage_name
Manman Ren584e4c02013-02-27 23:21:02 +0000259; DARWINA-NOT: location
260; While we're here, a normal member does not have a linkage name, constant
261; value, or DW_AT_location.
262; DARWINA: DW_AT_name {{.*}} "d"
Eric Christopheraf7eca22014-03-13 23:26:25 +0000263; DARWINA-NOT: DW_AT_linkage_name
Manman Ren584e4c02013-02-27 23:21:02 +0000264; DARWINA-NOT: DW_AT_const_value
265; DARWINA-NOT: DW_AT_location
266; DARWINA: NULL