1; RUN: llc -mtriple=x86_64-windows-msvc < %s | FileCheck %s --check-prefix=ASM
2; RUN: llc -mtriple=x86_64-windows-msvc < %s -filetype=obj | llvm-readobj --codeview - | FileCheck %s --check-prefix=OBJ
3
4; This test attempts to exercise gaps in local variables. The local variable 'p'
5; will end up in some CSR (esi), which will be used in both the BB scheduled
6; discontiguously out of line and the normal return BB. The best way to encode
7; this is to use a LocalVariableAddrGap. If the gap is too large, multiple
8; ranges should be emitted.
9
10; Source to regenerate:
11; int barrier();
12; int vardef();
13; void use(int);
14; void __declspec(noreturn) call_noreturn(int);
15; int f() {
16;   if (barrier()) {
17;     int p = vardef();
18;     if (barrier()) // Unlikely, will be placed after return
19;       call_noreturn(p);
20;     use(p);
21;   } else {
22;     barrier();
23;   }
24;   return 0;
25; }
26
27; ASM: f:                                      # @f
28; ASM:         pushq   %rsi
29; ASM:         subq    $32, %rsp
30; ASM:         callq   barrier
31; ASM:         testl   %eax, %eax
32; ASM:         je      .LBB0_3
33; ASM:         callq   vardef
34; ASM:         movl    %eax, %esi
35; ASM: [[p_b1:\.Ltmp[0-9]+]]:
36; ASM:         #DEBUG_VALUE: p <- $esi
37; ASM:         callq   barrier
38; ASM:         movl    %esi, %ecx
39; ASM:         testl   %eax, %eax
40; ASM:         jne     .LBB0_5
41; ASM: # %bb.2:                                 # %if.end
42; ASM:         #DEBUG_VALUE: p <- $esi
43; ASM:         callq   use
44; ASM:         jmp     .LBB0_4
45; ASM: [[p_e1:\.Ltmp[0-9]+]]:
46; ASM: .LBB0_3:                                # %if.else
47; ASM:         callq   barrier
48; ASM: .LBB0_4:                                # %if.end6
49; ASM:         xorl    %eax, %eax
50; ASM:         addq    $32, %rsp
51; ASM:         popq    %rsi
52; ASM:         retq
53; ASM: .LBB0_5:                                # %if.then4
54; ASM: [[p_b2:\.Ltmp[0-9]+]]:
55; ASM:         #DEBUG_VALUE: p <- $esi
56; ASM:         callq   call_noreturn
57; ASM:         ud2
58; ASM: .Lfunc_end0:
59
60; ASM:         .short  {{.*}}         # Record length
61; ASM:         .short  4414                    # Record kind: S_LOCAL
62; ASM:         .long   116                     # TypeIndex
63; ASM:         .short  0                       # Flags
64; ASM:         .asciz  "p"
65; ASM:         .cv_def_range    [[p_b1]] [[p_e1]] [[p_b2]] .Lfunc_end0, "A\021\027\000\000\000"
66; ASM:         .short  2                       # Record length
67; ASM:         .short  4431                    # Record kind: S_PROC_ID_END
68
69; OBJ:         LocalSym {
70; OBJ:           Type: int (0x74)
71; OBJ:           VarName: p
72; OBJ:         }
73; OBJ-NOT:     LocalSym {
74; OBJ:         DefRangeRegisterSym {
75; OBJ-NEXT:      Kind:
76; OBJ-NEXT:      Register: ESI (0x17)
77; OBJ-NEXT:      MayHaveNoName: 0
78; OBJ-NEXT:      LocalVariableAddrRange {
79; OBJ-NEXT:        OffsetStart: .text+0x{{.*}}
80; OBJ-NEXT:        ISectStart: 0x0
81; OBJ-NEXT:        Range: 0x{{.*}}
82; OBJ-NEXT:      }
83; OBJ-NEXT:      LocalVariableAddrGap [
84; OBJ-NEXT:        GapStartOffset: 0x{{.*}}
85; OBJ-NEXT:        Range: 0x{{.*}}
86; OBJ-NEXT:      ]
87; OBJ-NEXT:    }
88
89; ModuleID = 't.cpp'
90source_filename = "t.cpp"
91target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
92target triple = "x86_64-pc-windows-msvc19.0.24210"
93
94; Function Attrs: nounwind uwtable
95define i32 @f() local_unnamed_addr #0 !dbg !7 {
96entry:
97  %call = tail call i32 bitcast (i32 (...)* @barrier to i32 ()*)() #4, !dbg !15
98  %tobool = icmp eq i32 %call, 0, !dbg !15
99  br i1 %tobool, label %if.else, label %if.then, !dbg !16
100
101if.then:                                          ; preds = %entry
102  %call1 = tail call i32 bitcast (i32 (...)* @vardef to i32 ()*)() #4, !dbg !17
103  tail call void @llvm.dbg.value(metadata i32 %call1, metadata !12, metadata !18), !dbg !19
104  %call2 = tail call i32 bitcast (i32 (...)* @barrier to i32 ()*)() #4, !dbg !20
105  %tobool3 = icmp eq i32 %call2, 0, !dbg !20
106  br i1 %tobool3, label %if.end, label %if.then4, !dbg !22
107
108if.then4:                                         ; preds = %if.then
109  tail call void @call_noreturn(i32 %call1) #5, !dbg !23
110  unreachable, !dbg !23
111
112if.end:                                           ; preds = %if.then
113  tail call void @use(i32 %call1) #4, !dbg !24
114  br label %if.end6, !dbg !25
115
116if.else:                                          ; preds = %entry
117  %call5 = tail call i32 bitcast (i32 (...)* @barrier to i32 ()*)() #4, !dbg !26
118  br label %if.end6
119
120if.end6:                                          ; preds = %if.else, %if.end
121  ret i32 0, !dbg !28
122}
123
124declare i32 @barrier(...) local_unnamed_addr #1
125
126declare i32 @vardef(...) local_unnamed_addr #1
127
128; Function Attrs: noreturn
129declare void @call_noreturn(i32) local_unnamed_addr #2
130
131declare void @use(i32) local_unnamed_addr #1
132
133; Function Attrs: nounwind readnone
134declare void @llvm.dbg.value(metadata, metadata, metadata) #3
135
136attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "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-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
137attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
138attributes #2 = { noreturn "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
139attributes #3 = { nounwind readnone }
140attributes #4 = { nounwind }
141attributes #5 = { noreturn nounwind }
142
143!llvm.dbg.cu = !{!0}
144!llvm.module.flags = !{!3, !4, !5}
145!llvm.ident = !{!6}
146
147!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 4.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
148!1 = !DIFile(filename: "t.cpp", directory: "C:\5Csrc\5Cllvm\5Cbuild")
149!2 = !{}
150!3 = !{i32 2, !"CodeView", i32 1}
151!4 = !{i32 2, !"Debug Info Version", i32 3}
152!5 = !{i32 1, !"PIC Level", i32 2}
153!6 = !{!"clang version 4.0.0 "}
154!7 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 19, type: !8, isLocal: false, isDefinition: true, scopeLine: 19, isOptimized: true, unit: !0, retainedNodes: !11)
155!8 = !DISubroutineType(types: !9)
156!9 = !{!10}
157!10 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
158!11 = !{!12}
159!12 = !DILocalVariable(name: "p", scope: !13, file: !1, line: 21, type: !10)
160!13 = distinct !DILexicalBlock(scope: !14, file: !1, line: 20, column: 18)
161!14 = distinct !DILexicalBlock(scope: !7, file: !1, line: 20, column: 7)
162!15 = !DILocation(line: 20, column: 7, scope: !14)
163!16 = !DILocation(line: 20, column: 7, scope: !7)
164!17 = !DILocation(line: 21, column: 13, scope: !13)
165!18 = !DIExpression()
166!19 = !DILocation(line: 21, column: 9, scope: !13)
167!20 = !DILocation(line: 22, column: 9, scope: !21)
168!21 = distinct !DILexicalBlock(scope: !13, file: !1, line: 22, column: 9)
169!22 = !DILocation(line: 22, column: 9, scope: !13)
170!23 = !DILocation(line: 23, column: 7, scope: !21)
171!24 = !DILocation(line: 24, column: 5, scope: !13)
172!25 = !DILocation(line: 25, column: 3, scope: !13)
173!26 = !DILocation(line: 26, column: 5, scope: !27)
174!27 = distinct !DILexicalBlock(scope: !14, file: !1, line: 25, column: 10)
175!28 = !DILocation(line: 28, column: 3, scope: !7)
176