Skip to content

Commit 5c8bec4

Browse files
committed
Two more test cases where DW_AT_const cannot be used.
These test cases check loclist merging in buildLocationList with basic block sections. 8.ll does not create any basic block sections and the merging must quit early because there is no constant value. 9.11 creates sections but cannot be merged as i is not a constant value.
1 parent 11a5026 commit 5c8bec4

File tree

2 files changed

+249
-0
lines changed

2 files changed

+249
-0
lines changed
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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 %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 %s
5+
6+
; CHECK: DW_TAG_variable
7+
; CHECK: DW_TAG_variable
8+
; CHECK-NEXT: DW_AT_location
9+
; CHECK-NEXT: DW_OP_consts +0, DW_OP_stack_value
10+
; CHECK-NEXT: DW_OP_consts +7, DW_OP_stack_value
11+
; CHECK-NEXT: DW_OP_consts +8, DW_OP_stack_value
12+
; CHECK: DW_AT_name ("i")
13+
14+
; void f1(int *);
15+
; void f2(int);
16+
; extern bool b;
17+
; int test() {
18+
; // i is not a const throughout the whole scope and
19+
; // should *not* use DW_AT_const_value.
20+
; int i = 0;
21+
; int j = 10;
22+
; {
23+
; i = 7;
24+
; f1(&j);
25+
; }
26+
; i = 8;
27+
; f2(i);
28+
; return j;
29+
; }
30+
; clang++ -S scoped_section.cc -g -O2 -emit-llvm
31+
32+
; Function Attrs: mustprogress uwtable
33+
define dso_local noundef i32 @_Z4testv() local_unnamed_addr #0 !dbg !10 {
34+
entry:
35+
%j = alloca i32, align 4, !DIAssignID !17
36+
#dbg_assign(i1 undef, !16, !DIExpression(), !17, ptr %j, !DIExpression(), !18)
37+
#dbg_value(i32 0, !15, !DIExpression(), !18)
38+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %j) #3, !dbg !19
39+
store i32 10, ptr %j, align 4, !dbg !20, !tbaa !21, !DIAssignID !25
40+
#dbg_assign(i32 10, !16, !DIExpression(), !25, ptr %j, !DIExpression(), !18)
41+
#dbg_value(i32 7, !15, !DIExpression(), !18)
42+
call void @_Z2f1Pi(ptr noundef nonnull %j), !dbg !26
43+
#dbg_value(i32 8, !15, !DIExpression(), !18)
44+
call void @_Z2f2i(i32 noundef 8), !dbg !28
45+
%0 = load i32, ptr %j, align 4, !dbg !29, !tbaa !21
46+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j) #3, !dbg !30
47+
ret i32 %0, !dbg !31
48+
}
49+
50+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
51+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
52+
53+
declare !dbg !32 void @_Z2f1Pi(ptr noundef) local_unnamed_addr #2
54+
55+
declare !dbg !36 void @_Z2f2i(i32 noundef) local_unnamed_addr #2
56+
57+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
58+
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
59+
60+
attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
61+
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
62+
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
63+
attributes #3 = { nounwind }
64+
65+
!llvm.dbg.cu = !{!0}
66+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
67+
!llvm.ident = !{!9}
68+
69+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git ([email protected]:tmsri/llvm-project.git 11a50269e82b6dce49249c5cbe3a989b06f0848f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
70+
!1 = !DIFile(filename: "scoped_section.cc", directory: "", checksumkind: CSK_MD5, checksum: "2d5675e292541e4f04eb60edf76b14d6")
71+
!2 = !{i32 7, !"Dwarf Version", i32 5}
72+
!3 = !{i32 2, !"Debug Info Version", i32 3}
73+
!4 = !{i32 1, !"wchar_size", i32 4}
74+
!5 = !{i32 8, !"PIC Level", i32 2}
75+
!6 = !{i32 7, !"PIE Level", i32 2}
76+
!7 = !{i32 7, !"uwtable", i32 2}
77+
!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
78+
!9 = !{!"clang version 20.0.0git ([email protected]:tmsri/llvm-project.git 11a50269e82b6dce49249c5cbe3a989b06f0848f)"}
79+
!10 = distinct !DISubprogram(name: "test", linkageName: "_Z4testv", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
80+
!11 = !DISubroutineType(types: !12)
81+
!12 = !{!13}
82+
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
83+
!14 = !{!15, !16}
84+
!15 = !DILocalVariable(name: "i", scope: !10, file: !1, line: 7, type: !13)
85+
!16 = !DILocalVariable(name: "j", scope: !10, file: !1, line: 8, type: !13)
86+
!17 = distinct !DIAssignID()
87+
!18 = !DILocation(line: 0, scope: !10)
88+
!19 = !DILocation(line: 8, column: 5, scope: !10)
89+
!20 = !DILocation(line: 8, column: 9, scope: !10)
90+
!21 = !{!22, !22, i64 0}
91+
!22 = !{!"int", !23, i64 0}
92+
!23 = !{!"omnipotent char", !24, i64 0}
93+
!24 = !{!"Simple C++ TBAA"}
94+
!25 = distinct !DIAssignID()
95+
!26 = !DILocation(line: 11, column: 7, scope: !27)
96+
!27 = distinct !DILexicalBlock(scope: !10, file: !1, line: 9, column: 5)
97+
!28 = !DILocation(line: 14, column: 5, scope: !10)
98+
!29 = !DILocation(line: 15, column: 12, scope: !10)
99+
!30 = !DILocation(line: 16, column: 1, scope: !10)
100+
!31 = !DILocation(line: 15, column: 5, scope: !10)
101+
!32 = !DISubprogram(name: "f1", linkageName: "_Z2f1Pi", scope: !1, file: !1, line: 1, type: !33, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
102+
!33 = !DISubroutineType(types: !34)
103+
!34 = !{null, !35}
104+
!35 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
105+
!36 = !DISubprogram(name: "f2", linkageName: "_Z2f2i", scope: !1, file: !1, line: 2, type: !37, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
106+
!37 = !DISubroutineType(types: !38)
107+
!38 = !{null, !13}
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
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
5+
6+
; CHECK: DW_TAG_subprogram
7+
; CHECK-NEXT: DW_AT_low_pc
8+
; CHECK-NEXT: DW_AT_high_pc
9+
; CHECK: DW_TAG_variable
10+
; CHECK: DW_TAG_variable
11+
; CHECK-NEXT: DW_AT_location
12+
; CHECK-NEXT: DW_OP_consts +0, DW_OP_stack_value
13+
; CHECK-NEXT: DW_OP_consts +7, DW_OP_stack_value
14+
; CHECK-NEXT: DW_OP_consts +8, DW_OP_stack_value
15+
; CHECK-NEXT: DW_AT_name ("i")
16+
17+
; SECTIONS: DW_TAG_subprogram
18+
; SECTIONS-NEXT: DW_AT_ranges
19+
; SECTIONS: DW_TAG_variable
20+
; SECTIONS: DW_TAG_variable
21+
; SECTIONS-NEXT: DW_AT_location
22+
; SECTIONS-NEXT: DW_OP_consts +0, DW_OP_stack_value
23+
; SECTIONS-NEXT: DW_OP_consts +7, DW_OP_stack_value
24+
; SECTIONS-NEXT: DW_OP_consts +7, DW_OP_stack_value
25+
; SECTIONS-NEXT: DW_OP_consts +8, DW_OP_stack_value
26+
; SECTIONS-NEXT: DW_AT_name ("i")
27+
28+
; void f1(int *);
29+
; void f2(int);
30+
; extern bool b;
31+
; int test() {
32+
; // i is not a const throughout the whole scope and
33+
; // should *not* use DW_AT_const_value. The scope
34+
; // creates basic block sections and should use
35+
; // DW_AT_ranges.
36+
; int i = 0;
37+
; int j = 10;
38+
; {
39+
; i = 7;
40+
; if (b)
41+
; f1(&j);
42+
; }
43+
; i = 8;
44+
; f2(i);
45+
; return j;
46+
; }
47+
; clang++ -S scoped_section.cc -g -O2 -emit-llvm
48+
49+
50+
@b = external local_unnamed_addr global i8, align 1
51+
52+
; Function Attrs: mustprogress uwtable
53+
define dso_local noundef i32 @_Z4testv() local_unnamed_addr #0 !dbg !10 {
54+
entry:
55+
%j = alloca i32, align 4, !DIAssignID !17
56+
#dbg_assign(i1 undef, !16, !DIExpression(), !17, ptr %j, !DIExpression(), !18)
57+
#dbg_value(i32 0, !15, !DIExpression(), !18)
58+
call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %j) #3, !dbg !19
59+
store i32 10, ptr %j, align 4, !dbg !20, !tbaa !21, !DIAssignID !25
60+
#dbg_assign(i32 10, !16, !DIExpression(), !25, ptr %j, !DIExpression(), !18)
61+
#dbg_value(i32 7, !15, !DIExpression(), !18)
62+
%0 = load i8, ptr @b, align 1, !dbg !26, !tbaa !29, !range !31, !noundef !32
63+
%loadedv = trunc nuw i8 %0 to i1, !dbg !26
64+
br i1 %loadedv, label %if.then, label %if.end, !dbg !33
65+
66+
if.then: ; preds = %entry
67+
call void @_Z2f1Pi(ptr noundef nonnull %j), !dbg !34
68+
br label %if.end, !dbg !34
69+
70+
if.end: ; preds = %if.then, %entry
71+
#dbg_value(i32 8, !15, !DIExpression(), !18)
72+
call void @_Z2f2i(i32 noundef 8), !dbg !35
73+
%1 = load i32, ptr %j, align 4, !dbg !36, !tbaa !21
74+
call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %j) #3, !dbg !37
75+
ret i32 %1, !dbg !38
76+
}
77+
78+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
79+
declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #1
80+
81+
declare !dbg !39 void @_Z2f1Pi(ptr noundef) local_unnamed_addr #2
82+
83+
declare !dbg !43 void @_Z2f2i(i32 noundef) local_unnamed_addr #2
84+
85+
; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
86+
declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #1
87+
88+
attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
89+
attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
90+
attributes #2 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
91+
attributes #3 = { nounwind }
92+
93+
!llvm.dbg.cu = !{!0}
94+
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
95+
!llvm.ident = !{!9}
96+
97+
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 20.0.0git ([email protected]:tmsri/llvm-project.git 11a50269e82b6dce49249c5cbe3a989b06f0848f)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
98+
!1 = !DIFile(filename: "scoped_section.cc", directory: "", checksumkind: CSK_MD5, checksum: "9dda8d16c16edf7724c901692e07587c")
99+
!2 = !{i32 7, !"Dwarf Version", i32 5}
100+
!3 = !{i32 2, !"Debug Info Version", i32 3}
101+
!4 = !{i32 1, !"wchar_size", i32 4}
102+
!5 = !{i32 8, !"PIC Level", i32 2}
103+
!6 = !{i32 7, !"PIE Level", i32 2}
104+
!7 = !{i32 7, !"uwtable", i32 2}
105+
!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
106+
!9 = !{!"clang version 20.0.0git ([email protected]:tmsri/llvm-project.git 11a50269e82b6dce49249c5cbe3a989b06f0848f)"}
107+
!10 = distinct !DISubprogram(name: "test", linkageName: "_Z4testv", scope: !1, file: !1, line: 4, type: !11, scopeLine: 4, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
108+
!11 = !DISubroutineType(types: !12)
109+
!12 = !{!13}
110+
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
111+
!14 = !{!15, !16}
112+
!15 = !DILocalVariable(name: "i", scope: !10, file: !1, line: 7, type: !13)
113+
!16 = !DILocalVariable(name: "j", scope: !10, file: !1, line: 8, type: !13)
114+
!17 = distinct !DIAssignID()
115+
!18 = !DILocation(line: 0, scope: !10)
116+
!19 = !DILocation(line: 8, column: 5, scope: !10)
117+
!20 = !DILocation(line: 8, column: 9, scope: !10)
118+
!21 = !{!22, !22, i64 0}
119+
!22 = !{!"int", !23, i64 0}
120+
!23 = !{!"omnipotent char", !24, i64 0}
121+
!24 = !{!"Simple C++ TBAA"}
122+
!25 = distinct !DIAssignID()
123+
!26 = !DILocation(line: 11, column: 11, scope: !27)
124+
!27 = distinct !DILexicalBlock(scope: !28, file: !1, line: 11, column: 11)
125+
!28 = distinct !DILexicalBlock(scope: !10, file: !1, line: 9, column: 5)
126+
!29 = !{!30, !30, i64 0}
127+
!30 = !{!"bool", !23, i64 0}
128+
!31 = !{i8 0, i8 2}
129+
!32 = !{}
130+
!33 = !DILocation(line: 11, column: 11, scope: !28)
131+
!34 = !DILocation(line: 12, column: 9, scope: !27)
132+
!35 = !DILocation(line: 15, column: 5, scope: !10)
133+
!36 = !DILocation(line: 16, column: 12, scope: !10)
134+
!37 = !DILocation(line: 17, column: 1, scope: !10)
135+
!38 = !DILocation(line: 16, column: 5, scope: !10)
136+
!39 = !DISubprogram(name: "f1", linkageName: "_Z2f1Pi", scope: !1, file: !1, line: 1, type: !40, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
137+
!40 = !DISubroutineType(types: !41)
138+
!41 = !{null, !42}
139+
!42 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
140+
!43 = !DISubprogram(name: "f2", linkageName: "_Z2f2i", scope: !1, file: !1, line: 2, type: !44, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
141+
!44 = !DISubroutineType(types: !45)
142+
!45 = !{null, !13}

0 commit comments

Comments
 (0)