xref: /llvm-project/llvm/test/DebugInfo/Generic/enum.ll (revision 10b03e66629aedad79a804e22d23b575077303b3)
1; RUN: %llc_dwarf -O0 -filetype=obj < %s > %t
2; RUN: llvm-dwarfdump -v %t | FileCheck %s
3
4; RUN: %llc_dwarf --try-experimental-debuginfo-iterators -O0 -filetype=obj < %s > %t
5; RUN: llvm-dwarfdump -v %t | FileCheck %s
6
7; IR generated from the following code compiled with clang -g:
8; enum e1 { I, J = 0xffffffffU, K = 0xf000000000000000ULL } a;
9; enum e2 { X };
10; void func() {
11;   int b = X;
12; }
13
14; These values were previously being truncated to -1 and 0 respectively.
15
16; CHECK: debug_info contents
17; CHECK: DW_TAG_enumeration_type
18; CHECK-NEXT: DW_AT_name {{.*}}"e1"
19; CHECK-NOT: NULL
20; CHECK: DW_TAG_enumerator
21; CHECK-NOT: NULL
22; CHECK: DW_TAG_enumerator
23; CHECK-NEXT: DW_AT_name {{.*}}"J"
24; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]     (4294967295)
25; CHECK-NOT: NULL
26; CHECK: DW_TAG_enumerator
27; CHECK-NEXT: DW_AT_name {{.*}}"K"
28; CHECK-NEXT: DW_AT_const_value [DW_FORM_sdata]     (-1152921504606846976)
29
30; Check that we retain enums that aren't referenced by any variables, etc
31; CHECK: DW_TAG_enumeration_type
32; CHECK-NEXT: DW_AT_name {{.*}}"e2"
33; CHECK-NOT: NULL
34; CHECK: DW_TAG_enumerator
35; CHECK-NEXT: DW_AT_name {{.*}}"X"
36
37source_filename = "test/DebugInfo/Generic/enum.ll"
38
39@a = global i64 0, align 8, !dbg !0
40
41; Function Attrs: nounwind uwtable
42define void @_Z4funcv() #0 !dbg !17 {
43entry:
44  %b = alloca i32, align 4
45  call void @llvm.dbg.declare(metadata ptr %b, metadata !20, metadata !22), !dbg !23
46  store i32 0, ptr %b, align 4, !dbg !23
47  ret void, !dbg !24
48}
49
50; Function Attrs: nounwind readnone
51declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
52
53attributes #0 = { nounwind uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "unsafe-fp-math"="false" "use-soft-float"="false" }
54attributes #1 = { nounwind readnone }
55
56!llvm.dbg.cu = !{!8}
57!llvm.module.flags = !{!15, !16}
58
59!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
60!1 = !DIGlobalVariable(name: "a", scope: null, file: !2, line: 1, type: !3, isLocal: false, isDefinition: true)
61!2 = !DIFile(filename: "enum.cpp", directory: "/tmp")
62!3 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "e1", file: !2, line: 1, size: 64, align: 64, elements: !4)
63!4 = !{!5, !6, !7}
64!5 = !DIEnumerator(name: "I", value: 0)
65!6 = !DIEnumerator(name: "J", value: 4294967295) ; [ DW_TAG_enumerator ] [I :: 0]
66!7 = !DIEnumerator(name: "K", value: -1152921504606846976) ; [ DW_TAG_enumerator ] [J :: 4294967295]
67!8 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 3.4 ", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !9, retainedTypes: !13, globals: !14, imports: !13) ; [ DW_TAG_enumerator ] [K :: 17293822569102704640]
68!9 = !{!3, !10}
69!10 = !DICompositeType(tag: DW_TAG_enumeration_type, name: "e2", file: !2, line: 2, size: 32, align: 32, elements: !11)
70!11 = !{!12}
71!12 = !DIEnumerator(name: "X", value: 0) ; [ DW_TAG_enumerator ] [X :: 0]
72!13 = !{}
73!14 = !{!0}
74!15 = !{i32 2, !"Dwarf Version", i32 3}
75!16 = !{i32 1, !"Debug Info Version", i32 3}
76!17 = distinct !DISubprogram(name: "func", linkageName: "_Z4funcv", scope: !2, file: !2, line: 3, type: !18, isLocal: false, isDefinition: true, scopeLine: 3, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !8, retainedNodes: !13)
77!18 = !DISubroutineType(types: !19)
78!19 = !{null}
79!20 = !DILocalVariable(name: "b", scope: !17, file: !2, line: 4, type: !21)
80!21 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
81!22 = !DIExpression()
82!23 = !DILocation(line: 4, scope: !17)
83!24 = !DILocation(line: 5, scope: !17)
84
85