<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 9, 2014, at 10:11 AM, David Blaikie <<a href="mailto:dblaikie@gmail.com" class="">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><br class="Apple-interchange-newline"><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Dec 9, 2014 at 9:55 AM, Frederic Riss<span class="Apple-converted-space"> </span><span dir="ltr" class=""><<a href="mailto:friss@apple.com" target="_blank" class="">friss@apple.com</a>></span><span class="Apple-converted-space"> </span>wrote:<br class=""><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">Author: friss<br class="">Date: Tue Dec  9 11:55:48 2014<br class="">New Revision: 223799<br class=""><br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project?rev=223799&view=rev" target="_blank" class="">http://llvm.org/viewvc/llvm-project?rev=223799&view=rev</a><br class="">Log:<br class="">Correctly handle complex locations expressions in replaceDbgDeclareForAlloca()<br class=""><br class="">replaceDbgDeclareForAlloca() replaces an alloca by a value storing the<br class="">address of what was the alloca. If there is a dbg.declare corresponding<br class="">to that alloca, we need to lower it to a dbg.value describing the additional<br class="">dereference operation to be performed to get to the underlying variable.<br class=""> This is done by adding a DW_OP_deref to the complex location part of the<br class="">location description. This deref was added to the end of the operation list,<br class="">which is wrong. The expression applies to what is described by the<br class="">dbg.{declare,value}, and as we are changing this, we need to apply the<br class="">DW_OP_deref as the first operation in the list.<br class=""><br class="">Part of the fix for <a href="rdar://19162268" class="">rdar://19162268</a>.<br class=""><br class="">Added:<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/test/DebugInfo/block-asan.ll<br class="">Modified:<br class="">   <span class="Apple-converted-space"> </span>llvm/trunk/lib/Transforms/Utils/Local.cpp<br class=""><br class="">Modified: llvm/trunk/lib/Transforms/Utils/Local.cpp<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=223799&r1=223798&r2=223799&view=diff" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/Local.cpp?rev=223799&r1=223798&r2=223799&view=diff</a><br class="">==============================================================================<br class="">--- llvm/trunk/lib/Transforms/Utils/Local.cpp (original)<br class="">+++ llvm/trunk/lib/Transforms/Utils/Local.cpp Tue Dec  9 11:55:48 2014<br class="">@@ -1111,7 +1111,7 @@ bool llvm::replaceDbgDeclareForAlloca(Al<br class="">   if (!DIVar)<br class="">     return false;<br class=""><br class="">-  // Create a copy of the original DIDescriptor for user variable, appending<br class="">+  // Create a copy of the original DIDescriptor for user variable, prepending<br class="">   // "deref" operation to a list of address elements, as new llvm.dbg.declare<br class="">   // will take a value storing address of the memory for variable, not<br class="">   // alloca itself.<br class="">@@ -1121,7 +1121,7 @@ bool llvm::replaceDbgDeclareForAlloca(Al<br class="">       NewDIExpr.push_back(DIExpr.getElement(i));<br class="">     }<br class="">   }<br class="">-  NewDIExpr.push_back(dwarf::DW_OP_deref);<br class="">+  NewDIExpr.insert(NewDIExpr.begin(), dwarf::DW_OP_deref);<br class=""></blockquote><div class=""><br class="">Could we move this to before the loop, so we don't have to shift everything up in the vector to make space for this new first element?<br class=""></div></div></div></blockquote><div><br class=""></div><div>Sure, I didn’t even notice that we copied the expression, I thought we were just reusing the one we replace! Thanks for the catch.</div><div>I’ll retest before committing, but this will go in shortly.</div><div><br class=""></div><div>Fred</div><br class=""><blockquote type="cite" class=""><div class=""><div class="gmail_quote" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><br class="">   // Insert llvm.dbg.declare in the same basic block as the original alloca,<br class="">   // and remove old llvm.dbg.declare.<br class=""><br class="">Added: llvm/trunk/test/DebugInfo/block-asan.ll<br class="">URL:<span class="Apple-converted-space"> </span><a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/block-asan.ll?rev=223799&view=auto" target="_blank" class="">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/DebugInfo/block-asan.ll?rev=223799&view=auto</a><br class="">==============================================================================<br class="">--- llvm/trunk/test/DebugInfo/block-asan.ll (added)<br class="">+++ llvm/trunk/test/DebugInfo/block-asan.ll Tue Dec  9 11:55:48 2014<br class="">@@ -0,0 +1,87 @@<br class="">+; RUN: opt -S -asan %s | FileCheck %s<br class="">+<br class="">+; The IR of this testcase is generated from the following C code:<br class="">+; void bar (int);<br class="">+;<br class="">+; void foo() {<br class="">+;   __block int x;<br class="">+;   bar(x);<br class="">+; }<br class="">+; by compiling it with 'clang -emit-llvm -g -S' and then by manually<br class="">+; adding the sanitize_address attribute to the @foo() function (so<br class="">+; that ASAN accepts to instrument the function in the above opt run).<br class="">+<br class="">+; Check that the location of the ASAN instrumented __block variable is<br class="">+; correct.<br class="">+; CHECK: [ DW_TAG_expression ] [DW_OP_deref] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]<br class="">+<br class="">+target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"<br class="">+<br class="">+%struct.__block_byref_x = type { i8*, %struct.__block_byref_x*, i32, i32, i32 }<br class="">+<br class="">+; Function Attrs: nounwind ssp uwtable<br class="">+define void @foo() #0 {<br class="">+entry:<br class="">+  %x = alloca %struct.__block_byref_x, align 8<br class="">+  call void @llvm.dbg.declare(metadata !{%struct.__block_byref_x* %x}, metadata !12, metadata !22), !dbg !23<br class="">+  %byref.isa = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 0, !dbg !24<br class="">+  store i8* null, i8** %byref.isa, !dbg !24<br class="">+  %byref.forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !24<br class="">+  store %struct.__block_byref_x* %x, %struct.__block_byref_x** %byref.forwarding, !dbg !24<br class="">+  %byref.flags = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 2, !dbg !24<br class="">+  store i32 0, i32* %byref.flags, !dbg !24<br class="">+  %byref.size = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 3, !dbg !24<br class="">+  store i32 32, i32* %byref.size, !dbg !24<br class="">+  %forwarding = getelementptr inbounds %struct.__block_byref_x* %x, i32 0, i32 1, !dbg !25<br class="">+  %0 = load %struct.__block_byref_x** %forwarding, !dbg !25<br class="">+  %x1 = getelementptr inbounds %struct.__block_byref_x* %0, i32 0, i32 4, !dbg !25<br class="">+  %1 = load i32* %x1, align 4, !dbg !25<br class="">+  call void @bar(i32 %1), !dbg !25<br class="">+  %2 = bitcast %struct.__block_byref_x* %x to i8*, !dbg !26<br class="">+  call void @_Block_object_dispose(i8* %2, i32 8) #3, !dbg !26<br class="">+  ret void, !dbg !26<br class="">+}<br class="">+<br class="">+; Function Attrs: nounwind readnone<br class="">+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1<br class="">+<br class="">+declare void @bar(i32) #2<br class="">+<br class="">+declare void @_Block_object_dispose(i8*, i32)<br class="">+<br class="">+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" }<br class="">+attributes #1 = { nounwind readnone }<br class="">+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" }<br class="">+attributes #3 = { nounwind }<br class="">+<br class="">+!<a href="http://llvm.dbg.cu/" target="_blank" class="">llvm.dbg.cu</a><span class="Apple-converted-space"> </span>= !{!0}<br class="">+!llvm.module.flags = !{!8, !9, !10}<br class="">+!llvm.ident = !{!11}<br class="">+<br class="">+!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]<br class="">+!1 = metadata !{metadata !"block.c", metadata !"/tmp"}<br class="">+!2 = metadata !{}<br class="">+!3 = metadata !{metadata !4}<br class="">+!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]<br class="">+!5 = metadata !{metadata !"0x29", metadata !1}    ; [ DW_TAG_file_type ] [/tmp/block.c]<br class="">+!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 ]<br class="">+!7 = metadata !{null}<br class="">+!8 = metadata !{i32 2, metadata !"Dwarf Version", i32 2}<br class="">+!9 = metadata !{i32 2, metadata !"Debug Info Version", i32 2}<br class="">+!10 = metadata !{i32 1, metadata !"PIC Level", i32 2}<br class="">+!11 = metadata !{metadata !"clang version 3.6.0 (trunk 223120) (llvm/trunk 223119)"}<br class="">+!12 = metadata !{metadata !"0x100\00x\004\000", metadata !4, metadata !5, metadata !13} ; [ DW_TAG_auto_variable ] [x] [line 4]<br class="">+!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 ]<br class="">+!14 = metadata !{metadata !15, metadata !17, metadata !18, metadata !20, metadata !21}<br class="">+!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 ]<br class="">+!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 ]<br class="">+!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 ]<br class="">+!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]<br class="">+!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]<br class="">+!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]<br class="">+!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]<br class="">+!22 = metadata !{metadata !"0x102\0034\008\006\0034\0024"} ; [ DW_TAG_expression ] [DW_OP_plus 8] [DW_OP_deref] [DW_OP_plus 24]<br class="">+!23 = metadata !{i32 4, i32 15, metadata !4, null}<br class="">+!24 = metadata !{i32 4, i32 3, metadata !4, null}<br class="">+!25 = metadata !{i32 5, i32 3, metadata !4, null}<br class="">+!26 = metadata !{i32 6, i32 1, metadata !4, null}<br class=""><br class=""><br class="">_______________________________________________<br class="">llvm-commits mailing list<br class=""><a href="mailto:llvm-commits@cs.uiuc.edu" class="">llvm-commits@cs.uiuc.edu</a><br class=""><a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank" class="">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a></blockquote></div></div></blockquote></div><br class=""></body></html>