llvm.org GIT mirror llvm / fa3c6de
Correctly handle complex locations expressions in replaceDbgDeclareForAlloca() replaceDbgDeclareForAlloca() replaces an alloca by a value storing the address of what was the alloca. If there is a dbg.declare corresponding to that alloca, we need to lower it to a dbg.value describing the additional dereference operation to be performed to get to the underlying variable. This is done by adding a DW_OP_deref to the complex location part of the location description. This deref was added to the end of the operation list, which is wrong. The expression applies to what is described by the dbg.{declare,value}, and as we are changing this, we need to apply the DW_OP_deref as the first operation in the list. Part of the fix for rdar://19162268. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@223799 91177308-0d34-0410-b5e6-96231b3b80d8 Frederic Riss 5 years ago
2 changed file(s) with 89 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
11101110 if (!DIVar)
11111111 return false;
11121112
1113 // Create a copy of the original DIDescriptor for user variable, appending
1113 // Create a copy of the original DIDescriptor for user variable, prepending
11141114 // "deref" operation to a list of address elements, as new llvm.dbg.declare
11151115 // will take a value storing address of the memory for variable, not
11161116 // alloca itself.
11201120 NewDIExpr.push_back(DIExpr.getElement(i));
11211121 }
11221122 }
1123 NewDIExpr.push_back(dwarf::DW_OP_deref);
1123 NewDIExpr.insert(NewDIExpr.begin(), dwarf::DW_OP_deref);
11241124
11251125 // Insert llvm.dbg.declare in the same basic block as the original alloca,
11261126 // and remove old llvm.dbg.declare.
0 ; RUN: opt -S -asan %s | FileCheck %s
1
2 ; The IR of this testcase is generated from the following C code:
3 ; void bar (int);
4 ;
5 ; void foo() {
6 ; __block int x;
7 ; bar(x);
8 ; }
9 ; by compiling it with 'clang -emit-llvm -g -S' and then by manually
10 ; adding the sanitize_address attribute to the @foo() function (so
11 ; that ASAN accepts to instrument the function in the above opt run).
12
13 ; Check that the location of the ASAN instrumented __block variable is
14 ; correct.
15 ; CHECK: [ DW_TAG_expression ] [DW_OP_deref] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]
16
17 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
18
19 %struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 }
20
21 ; Function Attrs: nounwind ssp uwtable
22 define void @foo() #0 {
23 entry:
24 %x = alloca %struct.__block_byref_x, align 8
25 call void @llvm.dbg.declare(metadata !{%struct.__block_byref_x* %x}, metadata !12, metadata !22), !dbg !23
26 %byref.isa = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 0, !dbg !24
27 store i8* null, i8** %byref.isa, !dbg !24
28 %byref.forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !24
29 store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, !dbg !24
30 %byref.flags = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 2, !dbg !24
31 store i32 0, i32* %byref.flags, !dbg !24
32 %byref.size = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 3, !dbg !24
33 store i32 32, i32* %byref.size, !dbg !24
34 %forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !25
35 %0 = load %struct.__block_byref_x** %forwarding, !dbg !25
36 %x1 = getelementptr inbounds %struct.__block_byref_x* %0, i32 0, i32 4, !dbg !25
37 %1 = load i32* %x1, align 4, !dbg !25
38 call void @bar(i32 %1), !dbg !25
39 %2 = bitcast %struct.__block_byref_x* %x to i8*, !dbg !26
40 call void @_Block_object_dispose(i8* %2, i32 8) #3, !dbg !26
41 ret void, !dbg !26
42 }
43
44 ; Function Attrs: nounwind readnone
45 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46
47 declare void @bar(i32) #2
48
49 declare void @_Block_object_dispose(i8*, i32)
50
51 attributes #0 = { nounwind ssp uwtable sanitize_address "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
52 attributes #1 = { nounwind readnone }
53 attributes #2 = { "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }
54 attributes #3 = { nounwind }
55
56 !llvm.dbg.cu = !{!0}
57 !llvm.module.flags = !{!8, !9, !10}
58 !llvm.ident = !{!11}
59
60 !0 = metadata !{metadata !"0x11\0012\00clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)\000\00\000\00\001", metadata !1, metadata !2, metadata !2, metadata !3, metadata !2, metadata !2} ; [ DW_TAG_compile_unit ] [/tmp/block.c] [DW_LANG_C99]
61 !1 = metadata !{metadata !"block.c", metadata !"/tmp"}
62 !2 = metadata !{}
63 !3 = metadata !{metadata !4}
64 !4 = metadata !{metadata !"0x2e\00foo\00foo\00\003\000\001\000\000\000\000\003", metadata !1, metadata !5, metadata !6, null, void ()* @foo, null, null, metadata !2} ; [ DW_TAG_subprogram ] [line 3] [def] [foo]
65 !5 = metadata !{metadata !"0x29", metadata !1} ; [ DW_TAG_file_type ] [/tmp/block.c]
66 !6 = metadata !{metadata !"0x15\00\000\000\000\000\000\000", null, null, null, metadata !7, null, null, null} ; [ DW_TAG_subroutine_type ] [line 0, size 0, align 0, offset 0] [from ]
67 !7 = metadata !{null}
68 !8 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}
69 !9 = metadata !{i32 2, metadata !"Debug Info Version", i32 2}
70 !10 = metadata !{i32 1, metadata !"PIC Level", i32 2}
71 !11 = metadata !{metadata !"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"}
72 !12 = metadata !{metadata !"0x100\00x\004\000", metadata !4, metadata !5, metadata !13} ; [ DW_TAG_auto_variable ] [x] [line 4]
73 !13 = metadata !{metadata !"0x13\00\000\00224\000\000\0016\000", metadata !1, metadata !5, null, metadata !14, null, null, null} ; [ DW_TAG_structure_type ] [line 0, size 224, align 0, offset 0] [def] [from ]
74 !14 = metadata !{metadata !15, metadata !17, metadata !18, metadata !20, metadata !21}
75 !15 = metadata !{metadata !"0xd\00__isa\000\0064\0064\000\000", metadata !1, metadata !5, metadata !16} ; [ DW_TAG_member ] [__isa] [line 0, size 64, align 64, offset 0] [from ]
76 !16 = metadata !{metadata !"0xf\00\000\0064\0064\000\000", null, null, null} ; [ DW_TAG_pointer_type ] [line 0, size 64, align 64, offset 0] [from ]
77 !17 = metadata !{metadata !"0xd\00__forwarding\000\0064\0064\0064\000", metadata !1, metadata !5, metadata !16} ; [ DW_TAG_member ] [__forwarding] [line 0, size 64, align 64, offset 64] [from ]
78 !18 = metadata !{metadata !"0xd\00__flags\000\0032\0032\00128\000", metadata !1, metadata !5, metadata !19} ; [ DW_TAG_member ] [__flags] [line 0, size 32, align 32, offset 128] [from int]
79 !19 = metadata !{metadata !"0x24\00int\000\0032\0032\000\000\005", null, null} ; [ DW_TAG_base_type ] [int] [line 0, size 32, align 32, offset 0, enc DW_ATE_signed]
80 !20 = metadata !{metadata !"0xd\00__size\000\0032\0032\00160\000", metadata !1, metadata !5, metadata !19} ; [ DW_TAG_member ] [__size] [line 0, size 32, align 32, offset 160] [from int]
81 !21 = metadata !{metadata !"0xd\00x\000\0032\0032\00192\000", metadata !1, metadata !5, metadata !19} ; [ DW_TAG_member ] [x] [line 0, size 32, align 32, offset 192] [from int]
82 !22 = metadata !{metadata !"0x102\0034\008\006\0034\0024"} ; [ DW_TAG_expression ] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]
83 !23 = metadata !{i32 4, i32 15, metadata !4, null}
84 !24 = metadata !{i32 4, i32 3, metadata !4, null}
85 !25 = metadata !{i32 5, i32 3, metadata !4, null}
86 !26 = metadata !{i32 6, i32 1, metadata !4, null}