Recommit LiveDebugValues pass after fixing a couple of minor issues.
[oota-llvm.git] / test / DebugInfo / live-debug-values.ll
1 ; RUN: llc -filetype=asm %s -o - | FileCheck %s
2
3 ; Test the extension of debug ranges from predecessors.
4 ; Generated from the source file LiveDebugValues.c:
5 ; #include <stdio.h>
6 ; int m;
7 ; extern int inc(int n); 
8 ; extern int change(int n); 
9 ; extern int modify(int n); 
10 ; int main(int argc, char **argv) {
11 ;   int n;
12 ;   if (argc != 2)
13 ;     n = 2;
14 ;   else
15 ;     n = atoi(argv[1]);
16 ;   n = change(n);
17 ;   if (n > 10) {
18 ;     m = modify(n);
19 ;     m = m + n;  // var `m' doesn't has a dbg.value
20 ;   }
21 ;   else
22 ;     m = inc(n); // var `m' doesn't has a dbg.value
23 ;   printf("m(main): %d\n", m); 
24 ;   return 0;
25 ; }
26 ; with clang -g -O3 -emit-llvm -c LiveDebugValues.c -S -o live-debug-values.ll
27 ; This case will also produce multiple locations but only the debug range
28 ; extension is tested here.
29
30 ; DBG_VALUE for variable "n" is extended into BB#5 from its predecessors BB#3
31 ; and BB#4.
32 ; CHECK:       .LBB0_5:
33 ; CHECK-NEXT:  #DEBUG_VALUE: main:argv <- %RSI
34 ; CHECK-NEXT:  #DEBUG_VALUE: main:n <- %EBX
35
36
37 ; ModuleID = 'LiveDebugValues.c'
38 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
39 target triple = "x86_64-unknown-linux-gnu"
40
41 @m = common global i32 0, align 4
42 @.str = private unnamed_addr constant [13 x i8] c"m(main): %d\0A\00", align 1
43
44 ; Function Attrs: nounwind uwtable
45 define i32 @main(i32 %argc, i8** nocapture readonly %argv) #0 !dbg !4 {
46 entry:
47   tail call void @llvm.dbg.value(metadata i32 %argc, i64 0, metadata !12, metadata !20), !dbg !21
48   tail call void @llvm.dbg.value(metadata i8** %argv, i64 0, metadata !13, metadata !20), !dbg !22
49   %cmp = icmp eq i32 %argc, 2, !dbg !24
50   br i1 %cmp, label %if.else, label %if.end, !dbg !26
51
52 if.else:                                          ; preds = %entry
53   %arrayidx = getelementptr inbounds i8*, i8** %argv, i64 1, !dbg !27
54   %0 = load i8*, i8** %arrayidx, align 8, !dbg !27, !tbaa !28
55   %call = tail call i32 (i8*, ...) bitcast (i32 (...)* @atoi to i32 (i8*, ...)*)(i8* %0) #4, !dbg !32
56   tail call void @llvm.dbg.value(metadata i32 %call, i64 0, metadata !14, metadata !20), !dbg !33
57   br label %if.end
58
59 if.end:                                           ; preds = %entry, %if.else
60   %n.0 = phi i32 [ %call, %if.else ], [ 2, %entry ]
61   %call1 = tail call i32 @change(i32 %n.0) #4, !dbg !34
62   tail call void @llvm.dbg.value(metadata i32 %call1, i64 0, metadata !14, metadata !20), !dbg !33
63   %cmp2 = icmp sgt i32 %call1, 10, !dbg !35
64   br i1 %cmp2, label %if.then.3, label %if.else.5, !dbg !37
65
66 if.then.3:                                        ; preds = %if.end
67   %call4 = tail call i32 @modify(i32 %call1) #4, !dbg !38
68   %add = add nsw i32 %call4, %call1, !dbg !40
69   br label %if.end.7, !dbg !41
70
71 if.else.5:                                        ; preds = %if.end
72   %call6 = tail call i32 @inc(i32 %call1) #4, !dbg !42
73   br label %if.end.7
74
75 if.end.7:                                         ; preds = %if.else.5, %if.then.3
76   %storemerge = phi i32 [ %call6, %if.else.5 ], [ %add, %if.then.3 ]
77   store i32 %storemerge, i32* @m, align 4, !dbg !43, !tbaa !44
78   %call8 = tail call i32 (i8*, ...) @printf(i8* nonnull getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 %storemerge) #4, !dbg !46
79   ret i32 0, !dbg !47
80 }
81
82 declare i32 @atoi(...) #1
83
84 declare i32 @change(i32) #1
85
86 declare i32 @modify(i32) #1
87
88 declare i32 @inc(i32) #1
89
90 ; Function Attrs: nounwind
91 declare i32 @printf(i8* nocapture readonly, ...) #2
92
93 ; Function Attrs: nounwind readnone
94 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
95
96 attributes #0 = { nounwind uwtable }
97 attributes #1 = { nounwind }
98 attributes #2 = { nounwind }
99 attributes #3 = { nounwind readnone }
100 attributes #4 = { nounwind }
101
102 !llvm.dbg.cu = !{!0}
103 !llvm.module.flags = !{!17, !18}
104 !llvm.ident = !{!19}
105
106 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.8.0 (trunk 253049) ", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3, globals: !15)
107 !1 = !DIFile(filename: "LiveDebugValues.c", directory: "/home/vt/julia/test/tvvikram")
108 !2 = !{}
109 !3 = !{!4}
110 !4 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 6, type: !5, isLocal: false, isDefinition: true, scopeLine: 6, flags: DIFlagPrototyped, isOptimized: true, variables: !11)
111 !5 = !DISubroutineType(types: !6)
112 !6 = !{!7, !7, !8}
113 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
114 !8 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !9, size: 64, align: 64)
115 !9 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !10, size: 64, align: 64)
116 !10 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
117 !11 = !{!12, !13, !14}
118 !12 = !DILocalVariable(name: "argc", arg: 1, scope: !4, file: !1, line: 6, type: !7)
119 !13 = !DILocalVariable(name: "argv", arg: 2, scope: !4, file: !1, line: 6, type: !8)
120 !14 = !DILocalVariable(name: "n", scope: !4, file: !1, line: 7, type: !7)
121 !15 = !{!16}
122 !16 = !DIGlobalVariable(name: "m", scope: !0, file: !1, line: 2, type: !7, isLocal: false, isDefinition: true, variable: i32* @m)
123 !17 = !{i32 2, !"Dwarf Version", i32 4}
124 !18 = !{i32 2, !"Debug Info Version", i32 3}
125 !19 = !{!"clang version 3.8.0 (trunk 253049) "}
126 !20 = !DIExpression()
127 !21 = !DILocation(line: 6, column: 14, scope: !4)
128 !22 = !DILocation(line: 6, column: 27, scope: !23)
129 !23 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 1)
130 !24 = !DILocation(line: 8, column: 12, scope: !25)
131 !25 = distinct !DILexicalBlock(scope: !4, file: !1, line: 8, column: 7)
132 !26 = !DILocation(line: 8, column: 7, scope: !4)
133 !27 = !DILocation(line: 11, column: 14, scope: !25)
134 !28 = !{!29, !29, i64 0}
135 !29 = !{!"any pointer", !30, i64 0}
136 !30 = !{!"omnipotent char", !31, i64 0}
137 !31 = !{!"Simple C/C++ TBAA"}
138 !32 = !DILocation(line: 11, column: 9, scope: !25)
139 !33 = !DILocation(line: 7, column: 7, scope: !23)
140 !34 = !DILocation(line: 12, column: 7, scope: !4)
141 !35 = !DILocation(line: 13, column: 9, scope: !36)
142 !36 = distinct !DILexicalBlock(scope: !4, file: !1, line: 13, column: 7)
143 !37 = !DILocation(line: 13, column: 7, scope: !4)
144 !38 = !DILocation(line: 14, column: 9, scope: !39)
145 !39 = distinct !DILexicalBlock(scope: !36, file: !1, line: 13, column: 15)
146 !40 = !DILocation(line: 15, column: 11, scope: !39)
147 !41 = !DILocation(line: 16, column: 3, scope: !39)
148 !42 = !DILocation(line: 18, column: 9, scope: !36)
149 !43 = !DILocation(line: 15, column: 7, scope: !39)
150 !44 = !{!45, !45, i64 0}
151 !45 = !{!"int", !30, i64 0}
152 !46 = !DILocation(line: 19, column: 3, scope: !4)
153 !47 = !DILocation(line: 20, column: 3, scope: !4)