Re-Revert r257105 (Verifier debug info changes)
[oota-llvm.git] / test / DebugInfo / Generic / incorrect-variable-debugloc.ll
1 ; REQUIRES: object-emission
2
3 ; RUN: %llc_dwarf -O2 -filetype=obj < %s | llvm-dwarfdump -debug-dump=info - | FileCheck %s
4
5 ; This is a test case that's as reduced as I can get it, though I haven't fully
6 ; understood the mechanisms by which this bug occurs, so perhaps there's further
7 ; simplification to be had (it's certainly a bit non-obvious what's going on). I
8 ; hesitate to hand-craft or otherwise simplify the IR compared to what Clang
9 ; generates as this is a particular tickling of optimizations and debug location
10 ; propagation I want a realistic example of.
11
12 ; Generated with clang-tot -cc1 -g -O2 -w -std=c++11  -fsanitize=address,use-after-return -fcxx-exceptions -fexceptions -x c++ incorrect-variable-debug-loc.cpp -emit-llvm
13
14 ; struct A {
15 ;   int m_fn1();
16 ; };
17 ;
18 ; struct B {
19 ;   void __attribute__((always_inline)) m_fn2() { i = 0; }
20 ;   int i;
21 ; };
22 ;
23 ; struct C {
24 ;   void m_fn3();
25 ;   int j;
26 ;   B b;
27 ; };
28 ;
29 ; int fn1() {
30 ;   C A;
31 ;   A.b.m_fn2();
32 ;   A.m_fn3();
33 ; }
34 ; void C::m_fn3() {
35 ;   A().m_fn1();
36 ;   b.m_fn2();
37 ; }
38
39 ; CHECK: DW_TAG_structure_type
40 ; CHECK-NEXT: DW_AT_name {{.*}} "C"
41 ; CHECK: [[M_FN3_DECL:.*]]:  DW_TAG_subprogram
42 ; CHECK-NOT: {{DW_TAG|NULL}}
43 ; CHECK: DW_AT_name {{.*}} "m_fn3"
44
45 ; CHECK: DW_AT_specification {{.*}} {[[M_FN3_DECL]]}
46 ; CHECK-NOT: DW_TAG
47 ; CHECK:   DW_TAG_formal_parameter
48 ; CHECK-NOT: DW_TAG
49 ; CHECK:     DW_AT_name {{.*}} "this"
50
51 %struct.C = type { i32, %struct.B }
52 %struct.B = type { i32 }
53 %struct.A = type { i8 }
54
55 @llvm.global_ctors = appending global [1 x { i32, void ()* }] [{ i32, void ()* } { i32 1, void ()* @asan.module_ctor }]
56 @__asan_option_detect_stack_use_after_return = external global i32
57 @__asan_gen_ = private unnamed_addr constant [11 x i8] c"1 32 8 1 A\00", align 1
58 @__asan_gen_1 = private unnamed_addr constant [13 x i8] c"1 32 1 3 tmp\00", align 1
59
60 ; Function Attrs: noreturn sanitize_address
61 define i32 @_Z3fn1v() #0 !dbg !22 {
62 entry:
63   %MyAlloca = alloca [64 x i8], align 32, !dbg !39
64   %0 = ptrtoint [64 x i8]* %MyAlloca to i64, !dbg !39
65   %1 = load i32, i32* @__asan_option_detect_stack_use_after_return, !dbg !39
66   %2 = icmp ne i32 %1, 0, !dbg !39
67   br i1 %2, label %3, label %5
68
69 ; <label>:3                                       ; preds = %entry
70   %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0), !dbg !39
71   br label %5
72
73 ; <label>:5                                       ; preds = %entry, %3
74   %6 = phi i64 [ %0, %entry ], [ %4, %3 ], !dbg !39
75   %7 = add i64 %6, 32, !dbg !39
76   %8 = inttoptr i64 %7 to %struct.C*, !dbg !39
77   %9 = inttoptr i64 %6 to i64*, !dbg !39
78   store i64 1102416563, i64* %9, !dbg !39
79   %10 = add i64 %6, 8, !dbg !39
80   %11 = inttoptr i64 %10 to i64*, !dbg !39
81   store i64 ptrtoint ([11 x i8]* @__asan_gen_ to i64), i64* %11, !dbg !39
82   %12 = add i64 %6, 16, !dbg !39
83   %13 = inttoptr i64 %12 to i64*, !dbg !39
84   store i64 ptrtoint (i32 ()* @_Z3fn1v to i64), i64* %13, !dbg !39
85   %14 = lshr i64 %6, 3, !dbg !39
86   %15 = add i64 %14, 2147450880, !dbg !39
87   %16 = add i64 %15, 0, !dbg !39
88   %17 = inttoptr i64 %16 to i64*, !dbg !39
89   store i64 -868083117767659023, i64* %17, !dbg !39
90   %i.i = getelementptr inbounds %struct.C, %struct.C* %8, i64 0, i32 1, i32 0, !dbg !39
91   %18 = ptrtoint i32* %i.i to i64, !dbg !39
92   %19 = lshr i64 %18, 3, !dbg !39
93   %20 = add i64 %19, 2147450880, !dbg !39
94   %21 = inttoptr i64 %20 to i8*, !dbg !39
95   %22 = load i8, i8* %21, !dbg !39
96   %23 = icmp ne i8 %22, 0, !dbg !39
97   br i1 %23, label %24, label %30, !dbg !39
98
99 ; <label>:24                                      ; preds = %5
100   %25 = and i64 %18, 7, !dbg !39
101   %26 = add i64 %25, 3, !dbg !39
102   %27 = trunc i64 %26 to i8, !dbg !39
103   %28 = icmp sge i8 %27, %22, !dbg !39
104   br i1 %28, label %29, label %30
105
106 ; <label>:29                                      ; preds = %24
107   call void @__asan_report_store4(i64 %18), !dbg !39
108   call void asm sideeffect "", ""()
109   unreachable
110
111 ; <label>:30                                      ; preds = %24, %5
112   store i32 0, i32* %i.i, align 4, !dbg !39, !tbaa !41
113   tail call void @llvm.dbg.value(metadata %struct.C* %8, i64 0, metadata !27, metadata !DIExpression()), !dbg !46
114   call void @_ZN1C5m_fn3Ev(%struct.C* %8), !dbg !47
115   unreachable, !dbg !47
116 }
117
118 ; Function Attrs: sanitize_address
119 define void @_ZN1C5m_fn3Ev(%struct.C* nocapture %this) #1 align 2 !dbg !28 {
120 entry:
121   %MyAlloca = alloca [64 x i8], align 32, !dbg !48
122   %0 = ptrtoint [64 x i8]* %MyAlloca to i64, !dbg !48
123   %1 = load i32, i32* @__asan_option_detect_stack_use_after_return, !dbg !48
124   %2 = icmp ne i32 %1, 0, !dbg !48
125   br i1 %2, label %3, label %5
126
127 ; <label>:3                                       ; preds = %entry
128   %4 = call i64 @__asan_stack_malloc_0(i64 64, i64 %0), !dbg !48
129   br label %5
130
131 ; <label>:5                                       ; preds = %entry, %3
132   %6 = phi i64 [ %0, %entry ], [ %4, %3 ], !dbg !48
133   %7 = add i64 %6, 32, !dbg !48
134   %8 = inttoptr i64 %7 to %struct.A*, !dbg !48
135   %9 = inttoptr i64 %6 to i64*, !dbg !48
136   store i64 1102416563, i64* %9, !dbg !48
137   %10 = add i64 %6, 8, !dbg !48
138   %11 = inttoptr i64 %10 to i64*, !dbg !48
139   store i64 ptrtoint ([13 x i8]* @__asan_gen_1 to i64), i64* %11, !dbg !48
140   %12 = add i64 %6, 16, !dbg !48
141   %13 = inttoptr i64 %12 to i64*, !dbg !48
142   store i64 ptrtoint (void (%struct.C*)* @_ZN1C5m_fn3Ev to i64), i64* %13, !dbg !48
143   %14 = lshr i64 %6, 3, !dbg !48
144   %15 = add i64 %14, 2147450880, !dbg !48
145   %16 = add i64 %15, 0, !dbg !48
146   %17 = inttoptr i64 %16 to i64*, !dbg !48
147   store i64 -868083113472691727, i64* %17, !dbg !48
148   tail call void @llvm.dbg.value(metadata %struct.C* %this, i64 0, metadata !30, metadata !DIExpression()), !dbg !48
149   %call = call i32 @_ZN1A5m_fn1Ev(%struct.A* %8), !dbg !49
150   %i.i = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 1, i32 0, !dbg !50
151   %18 = ptrtoint i32* %i.i to i64, !dbg !50
152   %19 = lshr i64 %18, 3, !dbg !50
153   %20 = add i64 %19, 2147450880, !dbg !50
154   %21 = inttoptr i64 %20 to i8*, !dbg !50
155   %22 = load i8, i8* %21, !dbg !50
156   %23 = icmp ne i8 %22, 0, !dbg !50
157   br i1 %23, label %24, label %30, !dbg !50
158
159 ; <label>:24                                      ; preds = %5
160   %25 = and i64 %18, 7, !dbg !50
161   %26 = add i64 %25, 3, !dbg !50
162   %27 = trunc i64 %26 to i8, !dbg !50
163   %28 = icmp sge i8 %27, %22, !dbg !50
164   br i1 %28, label %29, label %30
165
166 ; <label>:29                                      ; preds = %24
167   call void @__asan_report_store4(i64 %18), !dbg !50
168   call void asm sideeffect "", ""()
169   unreachable
170
171 ; <label>:30                                      ; preds = %24, %5
172   store i32 0, i32* %i.i, align 4, !dbg !50, !tbaa !41
173   store i64 1172321806, i64* %9, !dbg !52
174   %31 = icmp ne i64 %6, %0, !dbg !52
175   br i1 %31, label %32, label %39, !dbg !52
176
177 ; <label>:32                                      ; preds = %30
178   %33 = add i64 %15, 0, !dbg !52
179   %34 = inttoptr i64 %33 to i64*, !dbg !52
180   store i64 -723401728380766731, i64* %34, !dbg !52
181   %35 = add i64 %6, 56, !dbg !52
182   %36 = inttoptr i64 %35 to i64*, !dbg !52
183   %37 = load i64, i64* %36, !dbg !52
184   %38 = inttoptr i64 %37 to i8*, !dbg !52
185   store i8 0, i8* %38, !dbg !52
186   br label %42, !dbg !52
187
188 ; <label>:39                                      ; preds = %30
189   %40 = add i64 %15, 0, !dbg !52
190   %41 = inttoptr i64 %40 to i64*, !dbg !52
191   store i64 0, i64* %41, !dbg !52
192   br label %42, !dbg !52
193
194 ; <label>:42                                      ; preds = %39, %32
195   ret void, !dbg !52
196 }
197
198 declare i32 @_ZN1A5m_fn1Ev(%struct.A*) #2
199
200 ; Function Attrs: nounwind readnone
201 declare void @llvm.dbg.value(metadata, i64, metadata, metadata) #3
202
203 define internal void @asan.module_ctor() {
204   tail call void @__asan_init_v3()
205   ret void
206 }
207
208 declare void @__asan_init_v3()
209
210 declare void @__asan_report_load1(i64)
211
212 declare void @__asan_load1(i64)
213
214 declare void @__asan_report_load2(i64)
215
216 declare void @__asan_load2(i64)
217
218 declare void @__asan_report_load4(i64)
219
220 declare void @__asan_load4(i64)
221
222 declare void @__asan_report_load8(i64)
223
224 declare void @__asan_load8(i64)
225
226 declare void @__asan_report_load16(i64)
227
228 declare void @__asan_load16(i64)
229
230 declare void @__asan_report_store1(i64)
231
232 declare void @__asan_store1(i64)
233
234 declare void @__asan_report_store2(i64)
235
236 declare void @__asan_store2(i64)
237
238 declare void @__asan_report_store4(i64)
239
240 declare void @__asan_store4(i64)
241
242 declare void @__asan_report_store8(i64)
243
244 declare void @__asan_store8(i64)
245
246 declare void @__asan_report_store16(i64)
247
248 declare void @__asan_store16(i64)
249
250 declare void @__asan_report_load_n(i64, i64)
251
252 declare void @__asan_report_store_n(i64, i64)
253
254 declare void @__asan_loadN(i64, i64)
255
256 declare void @__asan_storeN(i64, i64)
257
258 declare i8* @__asan_memmove(i8*, i8*, i64)
259
260 declare i8* @__asan_memcpy(i8*, i8*, i64)
261
262 declare i8* @__asan_memset(i8*, i32, i64)
263
264 declare void @__asan_handle_no_return()
265
266 declare void @__sanitizer_cov()
267
268 declare void @__sanitizer_ptr_cmp(i64, i64)
269
270 declare void @__sanitizer_ptr_sub(i64, i64)
271
272 declare i64 @__asan_stack_malloc_0(i64, i64)
273
274 declare void @__asan_stack_free_0(i64, i64, i64)
275
276 declare i64 @__asan_stack_malloc_1(i64, i64)
277
278 declare void @__asan_stack_free_1(i64, i64, i64)
279
280 declare i64 @__asan_stack_malloc_2(i64, i64)
281
282 declare void @__asan_stack_free_2(i64, i64, i64)
283
284 declare i64 @__asan_stack_malloc_3(i64, i64)
285
286 declare void @__asan_stack_free_3(i64, i64, i64)
287
288 declare i64 @__asan_stack_malloc_4(i64, i64)
289
290 declare void @__asan_stack_free_4(i64, i64, i64)
291
292 declare i64 @__asan_stack_malloc_5(i64, i64)
293
294 declare void @__asan_stack_free_5(i64, i64, i64)
295
296 declare i64 @__asan_stack_malloc_6(i64, i64)
297
298 declare void @__asan_stack_free_6(i64, i64, i64)
299
300 declare i64 @__asan_stack_malloc_7(i64, i64)
301
302 declare void @__asan_stack_free_7(i64, i64, i64)
303
304 declare i64 @__asan_stack_malloc_8(i64, i64)
305
306 declare void @__asan_stack_free_8(i64, i64, i64)
307
308 declare i64 @__asan_stack_malloc_9(i64, i64)
309
310 declare void @__asan_stack_free_9(i64, i64, i64)
311
312 declare i64 @__asan_stack_malloc_10(i64, i64)
313
314 declare void @__asan_stack_free_10(i64, i64, i64)
315
316 declare void @__asan_poison_stack_memory(i64, i64)
317
318 declare void @__asan_unpoison_stack_memory(i64, i64)
319
320 declare void @__asan_before_dynamic_init(i64)
321
322 declare void @__asan_after_dynamic_init()
323
324 declare void @__asan_register_globals(i64, i64)
325
326 declare void @__asan_unregister_globals(i64, i64)
327
328 declare void @__sanitizer_cov_module_init(i64)
329
330 attributes #0 = { noreturn sanitize_address "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
331 attributes #1 = { sanitize_address "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
332 attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-realign-stack" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
333 attributes #3 = { nounwind readnone }
334
335 !llvm.dbg.cu = !{!0}
336 !llvm.module.flags = !{!36, !37}
337 !llvm.ident = !{!38}
338
339 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5.0 ", isOptimized: true, emissionKind: 1, file: !1, enums: !2, retainedTypes: !3, subprograms: !21, globals: !2, imports: !2)
340 !1 = !DIFile(filename: "<stdin>", directory: "/tmp/dbginfo")
341 !2 = !{}
342 !3 = !{!4, !14}
343 !4 = !DICompositeType(tag: DW_TAG_structure_type, name: "C", line: 10, size: 64, align: 32, file: !5, elements: !6, identifier: "_ZTS1C")
344 !5 = !DIFile(filename: "incorrect-variable-debug-loc.cpp", directory: "/tmp/dbginfo")
345 !6 = !{!7, !9, !10}
346 !7 = !DIDerivedType(tag: DW_TAG_member, name: "j", line: 12, size: 32, align: 32, file: !5, scope: !"_ZTS1C", baseType: !8)
347 !8 = !DIBasicType(tag: DW_TAG_base_type, name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
348 !9 = !DIDerivedType(tag: DW_TAG_member, name: "b", line: 13, size: 32, align: 32, offset: 32, file: !5, scope: !"_ZTS1C", baseType: !"_ZTS1B")
349 !10 = !DISubprogram(name: "m_fn3", linkageName: "_ZN1C5m_fn3Ev", line: 11, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 11, file: !5, scope: !"_ZTS1C", type: !11)
350 !11 = !DISubroutineType(types: !12)
351 !12 = !{null, !13}
352 !13 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !"_ZTS1C")
353 !14 = !DICompositeType(tag: DW_TAG_structure_type, name: "B", line: 5, size: 32, align: 32, file: !5, elements: !15, identifier: "_ZTS1B")
354 !15 = !{!16, !17}
355 !16 = !DIDerivedType(tag: DW_TAG_member, name: "i", line: 7, size: 32, align: 32, file: !5, scope: !"_ZTS1B", baseType: !8)
356 !17 = !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2Ev", line: 6, isLocal: false, isDefinition: false, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !5, scope: !"_ZTS1B", type: !18)
357 !18 = !DISubroutineType(types: !19)
358 !19 = !{null, !20}
359 !20 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, flags: DIFlagArtificial | DIFlagObjectPointer, baseType: !"_ZTS1B")
360 !21 = !{!22, !28, !32}
361 !22 = distinct !DISubprogram(name: "fn1", linkageName: "_Z3fn1v", line: 16, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 16, file: !5, scope: !23, type: !24, variables: !26)
362 !23 = !DIFile(filename: "incorrect-variable-debug-loc.cpp", directory: "/tmp/dbginfo")
363 !24 = !DISubroutineType(types: !25)
364 !25 = !{!8}
365 !26 = !{!27}
366 !27 = !DILocalVariable(name: "A", line: 17, scope: !22, file: !23, type: !"_ZTS1C")
367 !28 = distinct !DISubprogram(name: "m_fn3", linkageName: "_ZN1C5m_fn3Ev", line: 21, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 21, file: !5, scope: !"_ZTS1C", type: !11, declaration: !10, variables: !29)
368 !29 = !{!30}
369 !30 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !28, type: !31)
370 !31 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !"_ZTS1C")
371 !32 = distinct !DISubprogram(name: "m_fn2", linkageName: "_ZN1B5m_fn2Ev", line: 6, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 6, file: !5, scope: !"_ZTS1B", type: !18, declaration: !17, variables: !33)
372 !33 = !{!34}
373 !34 = !DILocalVariable(name: "this", arg: 1, flags: DIFlagArtificial | DIFlagObjectPointer, scope: !32, type: !35)
374 !35 = !DIDerivedType(tag: DW_TAG_pointer_type, size: 64, align: 64, baseType: !"_ZTS1B")
375 !36 = !{i32 2, !"Dwarf Version", i32 4}
376 !37 = !{i32 2, !"Debug Info Version", i32 3}
377 !38 = !{!"clang version 3.5.0 "}
378 !39 = !DILocation(line: 6, scope: !32, inlinedAt: !40)
379 !40 = !DILocation(line: 18, scope: !22)
380 !41 = !{!42, !43, i64 0}
381 !42 = !{!"_ZTS1B", !43, i64 0}
382 !43 = !{!"int", !44, i64 0}
383 !44 = !{!"omnipotent char", !45, i64 0}
384 !45 = !{!"Simple C/C++ TBAA"}
385 !46 = !DILocation(line: 17, scope: !22)
386 !47 = !DILocation(line: 19, scope: !22)
387 !48 = !DILocation(line: 0, scope: !28)
388 !49 = !DILocation(line: 22, scope: !28)
389 !50 = !DILocation(line: 6, scope: !32, inlinedAt: !51)
390 !51 = !DILocation(line: 23, scope: !28)
391 !52 = !DILocation(line: 24, scope: !28)