1 ; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu --dwarf-version=4 --basic-block-sections=none -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
2 ; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu --dwarf-version=4 --basic-block-sections=all -filetype=obj -o - | llvm-dwarfdump - | FileCheck --check-prefix=SECTIONS %s
3 ; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu --dwarf-version=5 --basic-block-sections=none -filetype=obj -o - | llvm-dwarfdump - | FileCheck %s
4 ; RUN: llc %s -mtriple=x86_64-unknown-linux-gnu --dwarf-version=5 --basic-block-sections=all -filetype=obj -o - | llvm-dwarfdump - | FileCheck --check-prefix=SECTIONS %s
6 ; CHECK: DW_TAG_lexical_block
7 ; CHECK-NEXT: DW_AT_low_pc
8 ; CHECK-NEXT: DW_AT_high_pc
9 ; CHECK: DW_TAG_variable
10 ; CHECK-NEXT: DW_AT_const_value (7)
11 ; CHECK-NEXT: DW_AT_name ("i")
13 ; SECTIONS: DW_TAG_lexical_block
14 ; SECTIONS-NEXT: DW_AT_ranges
15 ; SECTIONS: DW_TAG_variable
16 ; SECTIONS-NEXT: DW_AT_const_value (7)
17 ; SECTIONS-NEXT: DW_AT_name ("i")
19 ; Test to check that a variable declared within a scope that has basic block
20 ; sections still produces DW_AT_const_value.
21 ; Source to generate the IR below:
26 ; // i is const throughout the whole scope and should
27 ; // use DW_AT_const_value. The scope creates basic
28 ; // block sections and should use DW_AT_ranges.
39 ; clang++ -S scoped_section_const.cc -g -O2 -emit-llvm
41 @b = external local_unnamed_addr global i8, align 1
43 ; Function Attrs: mustprogress uwtable
44 define dso_local noundef i32 @_Z4testv() local_unnamed_addr #0 !dbg !9 {
45 %1 = alloca i32, align 4
46 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %1) #4, !dbg !17
47 call void @llvm.dbg.value(metadata i32 10, metadata !14, metadata !DIExpression()), !dbg !18
48 store i32 10, ptr %1, align 4, !dbg !19, !tbaa !20
49 call void @llvm.dbg.value(metadata i32 7, metadata !15, metadata !DIExpression()), !dbg !24
50 call void @llvm.dbg.value(metadata ptr %1, metadata !14, metadata !DIExpression(DW_OP_deref)), !dbg !18
51 call void @_Z2f1Pi(ptr noundef nonnull %1), !dbg !25
52 %2 = load i8, ptr @b, align 1, !dbg !26, !tbaa !28, !range !30, !noundef !31
53 %3 = icmp eq i8 %2, 0, !dbg !26
54 br i1 %3, label %5, label %4, !dbg !32
57 call void @llvm.dbg.value(metadata ptr %1, metadata !14, metadata !DIExpression(DW_OP_deref)), !dbg !18
58 call void @_Z2f1Pi(ptr noundef nonnull %1), !dbg !33
62 %6 = load i32, ptr %1, align 4, !dbg !34, !tbaa !20
63 call void @llvm.dbg.value(metadata i32 %6, metadata !14, metadata !DIExpression()), !dbg !18
64 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %1) #4, !dbg !35
68 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
69 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
71 declare !dbg !37 void @_Z2f1Pi(ptr noundef) local_unnamed_addr #2
73 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
74 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
76 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
77 declare void @llvm.dbg.value(metadata, metadata, metadata) #3
79 attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
80 attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
81 attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
82 attributes #3 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
83 attributes #4 = { nounwind }
86 !llvm.module.flags = !{!2, !3, !4, !5, !6, !7}
89 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "Debian clang version 16.0.6 (26)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
90 !1 = !DIFile(filename: "scoped_section_const.cc", directory: "", checksumkind: CSK_MD5, checksum: "0406492d2e2e38af35d9ea210ba1f24b")
91 !2 = !{i32 7, !"Dwarf Version", i32 5}
92 !3 = !{i32 2, !"Debug Info Version", i32 3}
93 !4 = !{i32 1, !"wchar_size", i32 4}
94 !5 = !{i32 8, !"PIC Level", i32 2}
95 !6 = !{i32 7, !"PIE Level", i32 2}
96 !7 = !{i32 7, !"uwtable", i32 2}
97 !8 = !{!"Debian clang version 16.0.6 (26)"}
98 !9 = distinct !DISubprogram(name: "test", linkageName: "_Z4testv", scope: !1, file: !1, line: 3, type: !10, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !13)
99 !10 = !DISubroutineType(types: !11)
101 !12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
103 !14 = !DILocalVariable(name: "j", scope: !9, file: !1, line: 6, type: !12)
104 !15 = !DILocalVariable(name: "i", scope: !16, file: !1, line: 8, type: !12)
105 !16 = distinct !DILexicalBlock(scope: !9, file: !1, line: 7, column: 5)
106 !17 = !DILocation(line: 6, column: 5, scope: !9)
107 !18 = !DILocation(line: 0, scope: !9)
108 !19 = !DILocation(line: 6, column: 9, scope: !9)
109 !20 = !{!21, !21, i64 0}
110 !21 = !{!"int", !22, i64 0}
111 !22 = !{!"omnipotent char", !23, i64 0}
112 !23 = !{!"Simple C++ TBAA"}
113 !24 = !DILocation(line: 0, scope: !16)
114 !25 = !DILocation(line: 9, column: 7, scope: !16)
115 !26 = !DILocation(line: 10, column: 11, scope: !27)
116 !27 = distinct !DILexicalBlock(scope: !16, file: !1, line: 10, column: 11)
117 !28 = !{!29, !29, i64 0}
118 !29 = !{!"bool", !22, i64 0}
121 !32 = !DILocation(line: 10, column: 11, scope: !16)
122 !33 = !DILocation(line: 11, column: 9, scope: !27)
123 !34 = !DILocation(line: 13, column: 12, scope: !9)
124 !35 = !DILocation(line: 14, column: 1, scope: !9)
125 !36 = !DILocation(line: 13, column: 5, scope: !9)
126 !37 = !DISubprogram(name: "f1", linkageName: "_Z2f1Pi", scope: !1, file: !1, line: 1, type: !38, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !31)
127 !38 = !DISubroutineType(types: !39)
129 !40 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)