xref: /llvm-project/llvm/test/DebugInfo/X86/asan_debug_info.ll (revision 10b03e66629aedad79a804e22d23b575077303b3)
1; RUN: opt < %s -passes=asan -asan-use-after-return=never -S | \
2; RUN:   llc -O0 -filetype=obj - -o - | \
3; RUN:   llvm-dwarfdump - | FileCheck %s
4
5; RUN: opt --try-experimental-debuginfo-iterators < %s -passes=asan -asan-use-after-return=never -S | \
6; RUN:   llc --try-experimental-debuginfo-iterators -O0 -filetype=obj - -o - | \
7; RUN:   llvm-dwarfdump - | FileCheck %s
8
9; For this test case, ASan used to produce IR which resulted in the following
10; DWARF (at -O0):
11;
12;   DW_TAG_subprogram
13;     DW_AT_low_pc    (0x0000000000000000)
14;     DW_AT_high_pc   (0x00000000000000f1)
15;
16;     DW_TAG_variable
17;       DW_AT_location        (0x00000000
18;         [0x0000000000000014,  0x000000000000006d): DW_OP_breg0 RAX+32
19;         [0x000000000000006d,  0x00000000000000a4): DW_OP_breg7 RSP+16, DW_OP_deref, DW_OP_plus_uconst 0x20
20;         [0x00000000000000a6,  0x00000000000000ef): DW_OP_breg7 RSP+16, DW_OP_deref, DW_OP_plus_uconst 0x20)
21;
22; The DWARF produced for the original ObjC code that motivated this test case
23; was actually not as nice! In that example, the location list ranges didn't
24; intersect with the ranges of the parent lexical scope. But recreating that
25; exactly requires playing tricks to get LiveDebugValue's lexical dominance
26; check to kill a variable range early, and it isn't strictly necessary to show
27; the problem here.
28;
29; The problem is that we shouldn't get a location list at all. The instruction
30; selector should recognize that we have an "alloca" in the entry block, and
31; just make the fixed location available in the whole function. We now produce
32; the correct DWARF, namely:
33
34; CHECK: DW_TAG_variable
35; CHECK-NEXT:  DW_AT_location (DW_OP_breg7 RSP+32, DW_OP_plus_uconst 0x20)
36
37target triple = "x86_64-apple-macosx10.10.0"
38
39declare void @escape(ptr)
40
41; Function Attrs: sanitize_address
42define ptr @foo(i1 %cond) #0 !dbg !6 {
43entry:
44  %a1 = alloca ptr, !dbg !12
45  call void @escape(ptr %a1), !dbg !13
46  br i1 %cond, label %l1, label %l2, !dbg !14
47
48l1:                                               ; preds = %entry
49  ret ptr null, !dbg !15
50
51l2:                                               ; preds = %entry
52  call void @llvm.dbg.declare(metadata ptr %a1, metadata !11, metadata !DIExpression()), !dbg !16
53  %p = load ptr, ptr %a1, !dbg !16
54  ret ptr %p, !dbg !17
55}
56
57declare void @llvm.dbg.declare(metadata, metadata, metadata)
58
59attributes #0 = { sanitize_address }
60
61!llvm.dbg.cu = !{!0}
62!llvm.debugify = !{!3, !4}
63!llvm.module.flags = !{!5}
64
65!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
66!1 = !DIFile(filename: "redu.ll", directory: "/")
67!2 = !{}
68!3 = !{i32 6}
69!4 = !{i32 2}
70!5 = !{i32 2, !"Debug Info Version", i32 3}
71!6 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: null, file: !1, line: 1, type: !7, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
72!7 = !DISubroutineType(types: !2)
73!8 = !{!11}
74!10 = !DIBasicType(name: "ty64", size: 64, encoding: DW_ATE_unsigned)
75!11 = !DILocalVariable(name: "2", scope: !6, file: !1, line: 5, type: !10)
76!12 = !DILocation(line: 1, column: 1, scope: !6)
77!13 = !DILocation(line: 2, column: 1, scope: !6)
78!14 = !DILocation(line: 3, column: 1, scope: !6)
79!15 = !DILocation(line: 4, column: 1, scope: !6)
80!16 = !DILocation(line: 5, column: 1, scope: !6)
81!17 = !DILocation(line: 6, column: 1, scope: !6)
82