xref: /llvm-project/llvm/test/DebugInfo/COFF/lexicalblock.ll (revision 9a578a9f602547bb7b0cdf54d4759eab20d150b3)
1; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s
2;
3; -- lexicablock.cxx begin ----------------------------------------------------
4; int main(int argc, char *argv[]) {
5;   int localA = 1;
6;
7;   { // S_BLOCK32 not emitted because it has multiple address ranges.
8;     int localB = 2;
9;
10;     if (__builtin_expect(argc != 1, 0)) { // S_BLOCK32 containing 'localC'
11;       int localC = 3;
12;     }
13;   }
14;
15;   { // S_BLOCK32 containing 'localD'
16;     int localD = 4;
17;     localA = localD;
18;   }
19;
20;   { // S_BLOCK32 not emitted
21;     { // S_BLOCK32 containing 'localE'
22;       int localE = 5;
23;       localA = localE;
24;     }
25;   }
26;
27;   { // S_BLOCK32 containing 'localF'
28;     int localF = 6;
29;     localA = localF;
30;
31;     { // S_BLOCK32 containing 'localG'
32;       int localG = 7;
33;       localA = localG;
34;     }
35;   }
36;
37;   if (localA == 7) { // S_BLOCK32 containing 'localH'
38;     int localH = 8;
39;     localA = localH;
40;   }
41;
42;   return localA != 8 ? -1 : 0;
43; }
44; -- lexicalblock.cxx end -----------------------------------------------------
45;
46; To regenerate the IR below:
47;   $ clang -cc1 -triple i686-pc-windows -emit-llvm -o lexicalblock.tmp -debug-info-kind=limited -gcodeview lexicablock.cxx -O1 -disable-llvm-passes
48;   $ opt -lower-expect -S -o lexicalblock.ll < lexicalblock.tmp
49;
50; The commands above split the lexical block containing localB and localC into
51; two parts, thus creating multiple ranges for the containing lexical block
52; without optimizing out the whole thing.
53;
54; CHECK: {{.*}}Proc{{.*}}Sym {
55; CHECK:   DisplayName: main
56; CHECK: }
57; CHECK: LocalSym {
58; CHECK:   VarName: argc
59; CHECK: }
60; CHECK: LocalSym {
61; CHECK:   VarName: argv
62; CHECK: }
63; CHECK: LocalSym {
64; CHECK:   VarName: localA
65; CHECK: }
66; CHECK: LocalSym {
67; CHECK:   VarName: localB
68; CHECK: }
69; CHECK: BlockSym {
70; CHECK:   Kind: S_BLOCK32 {{.*}}
71; CHECK:   BlockName:
72; CHECK: }
73; CHECK: ScopeEndSym {
74; CHECK:   Kind: S_END {{.*}}
75; CHECK: }
76; CHECK: BlockSym {
77; CHECK:   Kind: S_BLOCK32 {{.*}}
78; CHECK:   BlockName:
79; CHECK: }
80; CHECK: ScopeEndSym {
81; CHECK:   Kind: S_END {{.*}}
82; CHECK: }
83; CHECK: BlockSym {
84; CHECK:   Kind: S_BLOCK32 {{.*}}
85; CHECK:   BlockName:
86; CHECK: }
87; CHECK: ScopeEndSym {
88; CHECK: }
89; CHECK: BlockSym {
90; CHECK:   Kind: S_BLOCK32 {{.*}}
91; CHECK:   BlockName:
92; CHECK: }
93; CHECK: ScopeEndSym {
94; CHECK:   Kind: S_END {{.*}}
95; CHECK: }
96; CHECK: ProcEnd {
97; CHECK: }
98;
99; ModuleID = 'lexicalblock.cxx'
100source_filename = "lexicalblock.cxx"
101target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
102target triple = "i686-pc-windows-msvc"
103
104; Function Attrs: norecurse nounwind
105define i32 @main(i32 %argc, ptr %argv) #0 !dbg !8 {
106entry:
107  %retval = alloca i32, align 4
108  %argv.addr = alloca ptr, align 4
109  %argc.addr = alloca i32, align 4
110  %localA = alloca i32, align 4
111  %localB = alloca i32, align 4
112  %localC = alloca i32, align 4
113  %localD = alloca i32, align 4
114  %localE = alloca i32, align 4
115  %localF = alloca i32, align 4
116  %localG = alloca i32, align 4
117  %localH = alloca i32, align 4
118  store i32 0, ptr %retval, align 4
119  store ptr %argv, ptr %argv.addr, align 4, !tbaa !37
120  call void @llvm.dbg.declare(metadata ptr %argv.addr, metadata !17, metadata !DIExpression()), !dbg !41
121  store i32 %argc, ptr %argc.addr, align 4, !tbaa !42
122  call void @llvm.dbg.declare(metadata ptr %argc.addr, metadata !18, metadata !DIExpression()), !dbg !41
123  call void @llvm.lifetime.start.p0(i64 4, ptr %localA) #4, !dbg !44
124  call void @llvm.dbg.declare(metadata ptr %localA, metadata !19, metadata !DIExpression()), !dbg !44
125  store i32 1, ptr %localA, align 4, !dbg !44, !tbaa !42
126  call void @llvm.lifetime.start.p0(i64 4, ptr %localB) #4, !dbg !45
127  call void @llvm.dbg.declare(metadata ptr %localB, metadata !20, metadata !DIExpression()), !dbg !45
128  store i32 2, ptr %localB, align 4, !dbg !45, !tbaa !42
129  %0 = load i32, ptr %argc.addr, align 4, !dbg !46, !tbaa !42
130  %cmp = icmp ne i32 %0, 1, !dbg !46
131  %conv = zext i1 %cmp to i32, !dbg !46
132  %tobool = icmp ne i32 %conv, 0, !dbg !46
133  br i1 %tobool, label %if.then, label %if.end, !dbg !46, !prof !47
134
135if.then:                                          ; preds = %entry
136  call void @llvm.lifetime.start.p0(i64 4, ptr %localC) #4, !dbg !48
137  call void @llvm.dbg.declare(metadata ptr %localC, metadata !22, metadata !DIExpression()), !dbg !48
138  store i32 3, ptr %localC, align 4, !dbg !48, !tbaa !42
139  call void @llvm.lifetime.end.p0(i64 4, ptr %localC) #4, !dbg !49
140  br label %if.end, !dbg !49
141
142if.end:                                           ; preds = %if.then, %entry
143  call void @llvm.lifetime.end.p0(i64 4, ptr %localB) #4, !dbg !50
144  call void @llvm.lifetime.start.p0(i64 4, ptr %localD) #4, !dbg !51
145  call void @llvm.dbg.declare(metadata ptr %localD, metadata !25, metadata !DIExpression()), !dbg !51
146  store i32 4, ptr %localD, align 4, !dbg !51, !tbaa !42
147  %1 = load i32, ptr %localD, align 4, !dbg !52, !tbaa !42
148  store i32 %1, ptr %localA, align 4, !dbg !52, !tbaa !42
149  call void @llvm.lifetime.end.p0(i64 4, ptr %localD) #4, !dbg !53
150  call void @llvm.lifetime.start.p0(i64 4, ptr %localE) #4, !dbg !54
151  call void @llvm.dbg.declare(metadata ptr %localE, metadata !27, metadata !DIExpression()), !dbg !54
152  store i32 5, ptr %localE, align 4, !dbg !54, !tbaa !42
153  %2 = load i32, ptr %localE, align 4, !dbg !55, !tbaa !42
154  store i32 %2, ptr %localA, align 4, !dbg !55, !tbaa !42
155  call void @llvm.lifetime.end.p0(i64 4, ptr %localE) #4, !dbg !56
156  call void @llvm.lifetime.start.p0(i64 4, ptr %localF) #4, !dbg !57
157  call void @llvm.dbg.declare(metadata ptr %localF, metadata !30, metadata !DIExpression()), !dbg !57
158  store i32 6, ptr %localF, align 4, !dbg !57, !tbaa !42
159  %3 = load i32, ptr %localF, align 4, !dbg !58, !tbaa !42
160  store i32 %3, ptr %localA, align 4, !dbg !58, !tbaa !42
161  call void @llvm.lifetime.start.p0(i64 4, ptr %localG) #4, !dbg !59
162  call void @llvm.dbg.declare(metadata ptr %localG, metadata !32, metadata !DIExpression()), !dbg !59
163  store i32 7, ptr %localG, align 4, !dbg !59, !tbaa !42
164  %4 = load i32, ptr %localG, align 4, !dbg !60, !tbaa !42
165  store i32 %4, ptr %localA, align 4, !dbg !60, !tbaa !42
166  call void @llvm.lifetime.end.p0(i64 4, ptr %localG) #4, !dbg !61
167  call void @llvm.lifetime.end.p0(i64 4, ptr %localF) #4, !dbg !62
168  %5 = load i32, ptr %localA, align 4, !dbg !63, !tbaa !42
169  %cmp1 = icmp eq i32 %5, 7, !dbg !63
170  br i1 %cmp1, label %if.then2, label %if.end3, !dbg !63
171
172if.then2:                                         ; preds = %if.end
173  call void @llvm.lifetime.start.p0(i64 4, ptr %localH) #4, !dbg !64
174  call void @llvm.dbg.declare(metadata ptr %localH, metadata !34, metadata !DIExpression()), !dbg !64
175  store i32 8, ptr %localH, align 4, !dbg !64, !tbaa !42
176  %6 = load i32, ptr %localH, align 4, !dbg !65, !tbaa !42
177  store i32 %6, ptr %localA, align 4, !dbg !65, !tbaa !42
178  call void @llvm.lifetime.end.p0(i64 4, ptr %localH) #4, !dbg !66
179  br label %if.end3, !dbg !66
180
181if.end3:                                          ; preds = %if.then2, %if.end
182  %7 = load i32, ptr %localA, align 4, !dbg !67, !tbaa !42
183  %cmp4 = icmp ne i32 %7, 8, !dbg !67
184  %8 = zext i1 %cmp4 to i64, !dbg !67
185  %cond = select i1 %cmp4, i32 -1, i32 0, !dbg !67
186  call void @llvm.lifetime.end.p0(i64 4, ptr %localA) #4, !dbg !68
187  ret i32 %cond, !dbg !67
188}
189
190; Function Attrs: nounwind readnone speculatable
191declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
192
193; Function Attrs: argmemonly nounwind
194declare void @llvm.lifetime.start.p0(i64, ptr nocapture) #2
195
196; Function Attrs: nounwind readnone
197declare i32 @llvm.expect.i32(i32, i32) #3
198
199; Function Attrs: argmemonly nounwind
200declare void @llvm.lifetime.end.p0(i64, ptr nocapture) #2
201
202attributes #0 = { norecurse nounwind "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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-features"="+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
203attributes #1 = { nounwind readnone speculatable }
204attributes #2 = { argmemonly nounwind }
205attributes #3 = { nounwind readnone }
206attributes #4 = { nounwind }
207
208!llvm.dbg.cu = !{!0}
209!llvm.module.flags = !{!3, !4, !5, !6}
210!llvm.ident = !{!7}
211
212!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 7.0.0 (trunk)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
213!1 = !DIFile(filename: "<stdin>", directory: "C:/path/to/directory", checksumkind: CSK_MD5, checksum: "169b810b4f895de9a9e19d8d0634af5d")
214!2 = !{}
215!3 = !{i32 1, !"NumRegisterParameters", i32 0}
216!4 = !{i32 2, !"CodeView", i32 1}
217!5 = !{i32 2, !"Debug Info Version", i32 3}
218!6 = !{i32 1, !"wchar_size", i32 2}
219!7 = !{!"clang version 7.0.0 (trunk)"}
220!8 = distinct !DISubprogram(name: "main", scope: !9, file: !9, line: 1, type: !10, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !16)
221!9 = !DIFile(filename: "lexicalblock.cxx", directory: "C:/path/to/directory", checksumkind: CSK_MD5, checksum: "169b810b4f895de9a9e19d8d0634af5d")
222!10 = !DISubroutineType(types: !11)
223!11 = !{!12, !12, !13}
224!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
225!13 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !14, size: 32)
226!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !15, size: 32)
227!15 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
228!16 = !{!17, !18, !19, !20, !22, !25, !27, !30, !32, !34}
229!17 = !DILocalVariable(name: "argv", arg: 2, scope: !8, file: !9, line: 1, type: !13)
230!18 = !DILocalVariable(name: "argc", arg: 1, scope: !8, file: !9, line: 1, type: !12)
231!19 = !DILocalVariable(name: "localA", scope: !8, file: !9, line: 2, type: !12)
232!20 = !DILocalVariable(name: "localB", scope: !21, file: !9, line: 5, type: !12)
233!21 = distinct !DILexicalBlock(scope: !8, file: !9, line: 4)
234!22 = !DILocalVariable(name: "localC", scope: !23, file: !9, line: 8, type: !12)
235!23 = distinct !DILexicalBlock(scope: !24, file: !9, line: 7)
236!24 = distinct !DILexicalBlock(scope: !21, file: !9, line: 7)
237!25 = !DILocalVariable(name: "localD", scope: !26, file: !9, line: 13, type: !12)
238!26 = distinct !DILexicalBlock(scope: !8, file: !9, line: 12)
239!27 = !DILocalVariable(name: "localE", scope: !28, file: !9, line: 19, type: !12)
240!28 = distinct !DILexicalBlock(scope: !29, file: !9, line: 18)
241!29 = distinct !DILexicalBlock(scope: !8, file: !9, line: 17)
242!30 = !DILocalVariable(name: "localF", scope: !31, file: !9, line: 25, type: !12)
243!31 = distinct !DILexicalBlock(scope: !8, file: !9, line: 24)
244!32 = !DILocalVariable(name: "localG", scope: !33, file: !9, line: 29, type: !12)
245!33 = distinct !DILexicalBlock(scope: !31, file: !9, line: 28)
246!34 = !DILocalVariable(name: "localH", scope: !35, file: !9, line: 35, type: !12)
247!35 = distinct !DILexicalBlock(scope: !36, file: !9, line: 34)
248!36 = distinct !DILexicalBlock(scope: !8, file: !9, line: 34)
249!37 = !{!38, !38, i64 0}
250!38 = !{!"any pointer", !39, i64 0}
251!39 = !{!"omnipotent char", !40, i64 0}
252!40 = !{!"Simple C++ TBAA"}
253!41 = !DILocation(line: 1, scope: !8)
254!42 = !{!43, !43, i64 0}
255!43 = !{!"int", !39, i64 0}
256!44 = !DILocation(line: 2, scope: !8)
257!45 = !DILocation(line: 5, scope: !21)
258!46 = !DILocation(line: 7, scope: !21)
259!47 = !{!"branch_weights", i32 1, i32 2000}
260!48 = !DILocation(line: 8, scope: !23)
261!49 = !DILocation(line: 9, scope: !23)
262!50 = !DILocation(line: 10, scope: !21)
263!51 = !DILocation(line: 13, scope: !26)
264!52 = !DILocation(line: 14, scope: !26)
265!53 = !DILocation(line: 15, scope: !26)
266!54 = !DILocation(line: 19, scope: !28)
267!55 = !DILocation(line: 20, scope: !28)
268!56 = !DILocation(line: 21, scope: !28)
269!57 = !DILocation(line: 25, scope: !31)
270!58 = !DILocation(line: 26, scope: !31)
271!59 = !DILocation(line: 29, scope: !33)
272!60 = !DILocation(line: 30, scope: !33)
273!61 = !DILocation(line: 31, scope: !33)
274!62 = !DILocation(line: 32, scope: !31)
275!63 = !DILocation(line: 34, scope: !8)
276!64 = !DILocation(line: 35, scope: !35)
277!65 = !DILocation(line: 36, scope: !35)
278!66 = !DILocation(line: 37, scope: !35)
279!67 = !DILocation(line: 39, scope: !8)
280!68 = !DILocation(line: 40, scope: !8)
281