1; Tests that debug information is sane after coro-split
2; RUN: opt < %s -coro-split -S | FileCheck %s
3; RUN: opt < %s -passes=coro-split -S | FileCheck %s
4
5source_filename = "simple-repro.c"
6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7target triple = "x86_64-unknown-linux-gnu"
8
9; Function Attrs: noinline nounwind
10define i8* @f(i32 %x) #0 !dbg !6 {
11entry:
12  %x.addr = alloca i32, align 4
13  %coro_hdl = alloca i8*, align 8
14  store i32 %x, i32* %x.addr, align 4
15  %0 = call token @llvm.coro.id(i32 0, i8* null, i8* bitcast (i8* (i32)* @f to i8*), i8* null), !dbg !16
16  %undef = bitcast i8* undef to [16 x i8]*
17  %1 = call i64 @llvm.coro.size.i64(), !dbg !16
18  %call = call i8* @malloc(i64 %1), !dbg !16
19  %2 = call i8* @llvm.coro.begin(token %0, i8* %call) #7, !dbg !16
20  store i8* %2, i8** %coro_hdl, align 8, !dbg !16
21  %3 = call i8 @llvm.coro.suspend(token none, i1 false), !dbg !17
22  %conv = sext i8 %3 to i32, !dbg !17
23  call void @coro.devirt.trigger(i8* null)
24  switch i32 %conv, label %sw.default [
25    i32 0, label %sw.bb
26    i32 1, label %sw.bb1
27  ], !dbg !17
28
29sw.bb:                                            ; preds = %entry
30  %direct = load i32, i32* %x.addr, align 4, !dbg !14
31  %gep = getelementptr inbounds [16 x i8], [16 x i8]* %undef, i32 %direct, !dbg !14
32  call void @llvm.dbg.declare(metadata [16 x i8] *%gep, metadata !27, metadata !13), !dbg !14
33  call void @llvm.dbg.declare(metadata i32 %conv, metadata !26, metadata !13), !dbg !14
34  call void @llvm.dbg.declare(metadata i32 %direct, metadata !25, metadata !13), !dbg !14
35  call void @llvm.dbg.declare(metadata i32* %x.addr, metadata !12, metadata !13), !dbg !14
36  call void @llvm.dbg.declare(metadata i8** %coro_hdl, metadata !15, metadata !13), !dbg !16
37  br label %sw.epilog, !dbg !18
38
39sw.bb1:                                           ; preds = %entry
40  br label %coro_Cleanup, !dbg !18
41
42sw.default:                                       ; preds = %entry
43  br label %coro_Suspend, !dbg !18
44
45sw.epilog:                                        ; preds = %sw.bb
46  %4 = load i32, i32* %x.addr, align 4, !dbg !20
47  %add = add nsw i32 %4, 1, !dbg !21
48  store i32 %add, i32* %x.addr, align 4, !dbg !22
49  br label %coro_Cleanup, !dbg !23
50
51coro_Cleanup:                                     ; preds = %sw.epilog, %sw.bb1
52  %5 = load i8*, i8** %coro_hdl, align 8, !dbg !24
53  %6 = call i8* @llvm.coro.free(token %0, i8* %5), !dbg !24
54  call void @free(i8* %6), !dbg !24
55  br label %coro_Suspend, !dbg !24
56
57coro_Suspend:                                     ; preds = %coro_Cleanup, %sw.default
58  %7 = call i1 @llvm.coro.end(i8* null, i1 false) #7, !dbg !24
59  %8 = load i8*, i8** %coro_hdl, align 8, !dbg !24
60  ret i8* %8, !dbg !24
61}
62
63; Function Attrs: nounwind readnone speculatable
64declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
65
66; Function Attrs: argmemonly nounwind readonly
67declare token @llvm.coro.id(i32, i8* readnone, i8* nocapture readonly, i8*) #2
68
69declare i8* @malloc(i64) #3
70
71; Function Attrs: nounwind readnone
72declare i64 @llvm.coro.size.i64() #4
73
74; Function Attrs: nounwind
75declare i8* @llvm.coro.begin(token, i8* writeonly) #5
76
77; Function Attrs: nounwind
78declare i8 @llvm.coro.suspend(token, i1) #5
79
80declare void @free(i8*) #3
81
82; Function Attrs: argmemonly nounwind readonly
83declare i8* @llvm.coro.free(token, i8* nocapture readonly) #2
84
85; Function Attrs: nounwind
86declare i1 @llvm.coro.end(i8*, i1) #5
87
88; Function Attrs: alwaysinline
89define private void @coro.devirt.trigger(i8*) #6 {
90entry:
91  ret void
92}
93
94; Function Attrs: argmemonly nounwind readonly
95declare i8* @llvm.coro.subfn.addr(i8* nocapture readonly, i8) #2
96
97attributes #0 = { noinline nounwind "coroutine.presplit"="1" "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"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
98attributes #1 = { nounwind readnone speculatable }
99attributes #2 = { argmemonly nounwind readonly }
100attributes #3 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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-features"="+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
101attributes #4 = { nounwind readnone }
102attributes #5 = { nounwind }
103attributes #6 = { alwaysinline }
104attributes #7 = { noduplicate }
105
106!llvm.dbg.cu = !{!0}
107!llvm.module.flags = !{!3, !4}
108!llvm.ident = !{!5}
109
110!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 5.0.0", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
111!1 = !DIFile(filename: "<stdin>", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
112!2 = !{}
113!3 = !{i32 2, !"Dwarf Version", i32 4}
114!4 = !{i32 2, !"Debug Info Version", i32 3}
115!5 = !{!"clang version 5.0.0"}
116!6 = distinct !DISubprogram(name: "f", linkageName: "flink", scope: !7, file: !7, line: 55, type: !8, isLocal: false, isDefinition: true, scopeLine: 55, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
117!7 = !DIFile(filename: "simple-repro.c", directory: "C:\5CGitHub\5Cllvm\5Cbuild\5CDebug\5Cbin")
118!8 = !DISubroutineType(types: !9)
119!9 = !{!10, !11}
120!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: null, size: 64)
121!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
122!12 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !7, line: 55, type: !11)
123!13 = !DIExpression()
124!14 = !DILocation(line: 55, column: 13, scope: !6)
125!15 = !DILocalVariable(name: "coro_hdl", scope: !6, file: !7, line: 56, type: !10)
126!16 = !DILocation(line: 56, column: 3, scope: !6)
127!17 = !DILocation(line: 58, column: 5, scope: !6)
128!18 = !DILocation(line: 58, column: 5, scope: !19)
129!19 = distinct !DILexicalBlock(scope: !6, file: !7, line: 58, column: 5)
130!20 = !DILocation(line: 59, column: 9, scope: !6)
131!21 = !DILocation(line: 59, column: 10, scope: !6)
132!22 = !DILocation(line: 59, column: 7, scope: !6)
133!23 = !DILocation(line: 59, column: 5, scope: !6)
134!24 = !DILocation(line: 62, column: 3, scope: !6)
135; These variables were added manually.
136!25 = !DILocalVariable(name: "direct_mem", scope: !6, file: !7, line: 55, type: !11)
137!26 = !DILocalVariable(name: "direct_const", scope: !6, file: !7, line: 55, type: !11)
138!27 = !DILocalVariable(name: "undefined", scope: !6, file: !7, line: 55, type: !11)
139
140; CHECK: define i8* @f(i32 %x) #0 !dbg ![[ORIG:[0-9]+]]
141; CHECK: define internal fastcc void @f.resume(%f.Frame* noalias nonnull align 8 dereferenceable(32) %FramePtr) #0 !dbg ![[RESUME:[0-9]+]]
142; CHECK: entry.resume:
143; CHECK: %[[DBG_PTR:.*]] = alloca %f.Frame*
144; CHECK: call void @llvm.dbg.declare(metadata %f.Frame** %[[DBG_PTR]], metadata ![[RESUME_COROHDL:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst,
145; CHECK: call void @llvm.dbg.declare(metadata %f.Frame** %[[DBG_PTR]], metadata ![[RESUME_X:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL:.*]])
146; CHECK: call void @llvm.dbg.declare(metadata %f.Frame** %[[DBG_PTR]], metadata ![[RESUME_DIRECT:[0-9]+]], metadata !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[EXPR_TAIL]])
147; CHECK: store %f.Frame* {{.*}}, %f.Frame** %[[DBG_PTR]]
148; CHECK-NOT: alloca %struct.test*
149; CHECK: call void @llvm.dbg.declare(metadata i32 0, metadata ![[RESUME_CONST:[0-9]+]], metadata !DIExpression())
150; CHECK: call void @coro.devirt.trigger(i8* null)
151; CHECK: define internal fastcc void @f.destroy(%f.Frame* noalias nonnull align 8 dereferenceable(32) %FramePtr) #0 !dbg ![[DESTROY:[0-9]+]]
152; CHECK: define internal fastcc void @f.cleanup(%f.Frame* noalias nonnull align 8 dereferenceable(32) %FramePtr) #0 !dbg ![[CLEANUP:[0-9]+]]
153
154; CHECK: ![[ORIG]] = distinct !DISubprogram(name: "f", linkageName: "flink"
155
156; CHECK: ![[RESUME]] = distinct !DISubprogram(name: "f", linkageName: "flink"
157; CHECK: ![[RESUME_COROHDL]] = !DILocalVariable(name: "coro_hdl", scope: ![[RESUME]]
158; CHECK: ![[RESUME_X]] = !DILocalVariable(name: "x", arg: 1, scope: ![[RESUME]]
159; CHECK: ![[RESUME_DIRECT]] = !DILocalVariable(name: "direct_mem", scope: ![[RESUME]]
160; CHECK: ![[RESUME_CONST]] = !DILocalVariable(name: "direct_const", scope: ![[RESUME]]
161
162; CHECK: ![[DESTROY]] = distinct !DISubprogram(name: "f", linkageName: "flink"
163
164; CHECK: ![[CLEANUP]] = distinct !DISubprogram(name: "f", linkageName: "flink"
165