<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Could you file a bug report about this (<a href="http://bugs.llvm.org" class="">bugs.llvm.org</a>)? If you don't have an account on bugzilla, I'd be happy to file one for you. Please provide exact instructions to reproduce the issue including any compilation flags.<br class=""><div class=""><br class=""></div><div class="">thanks,</div><div class="">vedant</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 7, 2018, at 9:16 AM, Son Tuan VU <<a href="mailto:sontuan.vu119@gmail.com" class="">sontuan.vu119@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class=""><div class="">Hello,<br class=""><br class=""></div>Has anyone taken a look at this bug? I really want to fix this, but as Paul pointed out, this requires a lot of care...<br class=""><br class=""></div>Thank you for your help<br class=""></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr" class="">Son Tuan Vu</div></div></div>
<br class=""><div class="gmail_quote">On Fri, Apr 27, 2018 at 7:29 PM, Son Tuan VU <span dir="ltr" class=""><<a href="mailto:sontuan.vu119@gmail.com" target="_blank" class="">sontuan.vu119@gmail.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class="">Thank you all for taking a look at this.  I pasted the C source then deleted it because I was afraid that it was too long to read...<br class=""><br class=""></div>Here's the code of <b class="">foo</b>. Its real name is <b class="">verifyPIN</b>. The variable <b class="">bar</b> is <b class="">userPin</b>.<br class=""><br class="">int <b class="">verifyPIN</b>(char *<b class="">userPin</b>, char *cardPin, int *cpt)<br class="">{<br class="">  int i;<br class="">  int status;<br class="">  int diff;<br class=""><br class="">  if (*cpt > 0) {<br class="">    status = 0x55;<br class="">    diff = 0x55;<br class=""><br class="">    for (i = 0; i < 4; i++) {<br class="">      if (<b class="">userPin</b>[i] != cardPin[i]) {<br class="">        diff = 0xAA;<br class="">      }<br class="">    }<br class=""><br class="">    if (diff == 0x55) {<br class="">      status = 0xAA;<br class="">    }<br class="">    else {<br class="">      status = 0x55;<br class="">    }<br class=""><br class="">    if (status == 0xAA) {<br class="">      *cpt = 3;<br class="">      return 0xAA;<br class="">    } else {<br class="">      *cpt--;<br class="">      return 0x55;<br class="">    }<br class="">  }<br class=""><br class="">  return 0x55;<br class="">}<br class=""><br class=""></div>@paul: Yes you are right, I have investigated the backend and it all starts at <b class="">IfConversionPass</b>. <b class="">r4</b> is clobbered by <b class="">poplt</b>, and there's no logic to handle conditional instruction in <b class="">DbgValueHistoryCalculator</b>, thus the issue at the binary level.<span class="HOEnZb"><font color="#888888" class=""><br class=""></font></span><div class=""><div class=""><div class="gmail_extra"><span class="HOEnZb"><font color="#888888" class=""><br clear="all" class=""><div class=""><div class="m_-8398178226514364903gmail_signature"><div dir="ltr" class="">Son Tuan Vu</div></div></div></font></span><div class=""><div class="h5">
<br class=""><div class="gmail_quote">On Fri, Apr 27, 2018 at 5:53 PM,  <span dir="ltr" class=""><<a href="mailto:paul.robinson@sony.com" target="_blank" class="">paul.robinson@sony.com</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">





<div lang="EN-US" class="">
<div class="m_-8398178226514364903gmail-m_-7351827624220065084WordSection1"><p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)" class="">As Adrian said, we'd need to see the source of foo() to assess what the location-list for bar ought to be.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)" class="">Without actually going to look, I would guess that 'poplt' is considered a conditional move, therefore r4's contents are not guaranteed after it executes (i.e.
 it is a clobber).  If one operand of 'poplt' is 'pc' then of course it is also a conditional indirect branch (which is probably but not necessarily a return).  This combination might be worth handling differently for location-list purposes.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)" class="">But this is a tricky area, and we'd need to consider the consequences carefully.<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)" class="">--paulr<u class=""></u><u class=""></u></span></p><p class="MsoNormal"><a name="m_-8398178226514364903_m_-7351827624220065084__MailEndCompose" class=""><span style="font-size:11pt;font-family:"Calibri","sans-serif";color:rgb(31,73,125)" class=""><u class=""></u> <u class=""></u></span></a></p>
<div style="border-width:medium medium medium 1.5pt;border-style:none none none solid;border-color:currentcolor currentcolor currentcolor blue;padding:0in 0in 0in 4pt" class="">
<div class="">
<div style="border-width:1pt medium medium;border-style:solid none none;border-color:rgb(181,196,223) currentcolor currentcolor;padding:3pt 0in 0in" class=""><p class="MsoNormal"><b class=""><span style="font-size:10pt;font-family:"Tahoma","sans-serif"" class="">From:</span></b><span style="font-size:10pt;font-family:"Tahoma","sans-serif"" class=""> <a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a> [mailto:<a href="mailto:aprantl@apple.com" target="_blank" class="">aprantl@apple.com</a>]
<br class="">
<b class="">Sent:</b> Friday, April 27, 2018 11:22 AM<br class="">
<b class="">To:</b> Son Tuan VU<br class="">
<b class="">Cc:</b> Robinson, Paul; Vedant Kumar; <a href="mailto:dblaikie@gmail.com" target="_blank" class="">dblaikie@gmail.com</a>; llvm-dev<br class="">
<b class="">Subject:</b> Re: [DbgInfo] Potential bug in location list address ranges<u class=""></u><u class=""></u></span></p>
</div>
</div><div class=""><div class="m_-8398178226514364903gmail-h5"><p class="MsoNormal"><u class=""></u> <u class=""></u></p><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class=""><p class="MsoNormal"><br class="">
<br class="">
<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal">On Apr 27, 2018, at 7:48 AM, Son Tuan VU <<a href="mailto:sontuan.vu119@gmail.com" target="_blank" class="">sontuan.vu119@gmail.com</a>> wrote:<u class=""></u><u class=""></u></p>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
<div class="">
<div class=""><p class="MsoNormal">Hi all,<u class=""></u><u class=""></u></p>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class="">
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">Consider this ARM assembly code of a C function:<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class=""><u class=""></u> <u class=""></u></span></p>
</div>
<div class="">
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">00008124 <foo>:<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8124:                   push    {r4, r6, r7, lr}<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8126:                   add     r7, sp, #8<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8128:                   mov     r4, r0<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    812a:                   ldrsb.w r0, [r2]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    812e:                   cmp     r0, #1<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8130:                   itt     lt<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8132:                   movlt   r0, #85 ; 0x55<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8134:                   poplt   {r4, r6, r7, pc}            // a function return<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class=""><u class=""></u> <u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8136:                   ldrb.w  ip, [r1, #3]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    813a:                   ldrb.w  lr, [r4, #3]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    813e:                   movs    r0, #85 ; 0x55<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8140:                   cmp     lr, ip<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8142:                   bne.n   8168 <foo+0x44><u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class=""><u class=""></u> <u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8144:                   ldrb.w  ip, [r1, #2]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8148:                   ldrb    r3, [r4, #2]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    814a:                   cmp     r3, ip<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    814c:                   it      ne<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    814e:                   popne   {r4, r6, r7, pc} <span style="background:white none repeat scroll 0% 0%" class="">         // a function return</span><u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class=""><u class=""></u> <u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8150:                   ldrb.w  ip, [r1, #1]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8154:                   ldrb    r3, [r4, #1]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8156:                   cmp     r3, ip<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8158:                   bne.n   8168 <foo+0x44><u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class=""><u class=""></u> <u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    815a:                   ldrb    r1, [r1, #0]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    815c:                   ldrb    r3, [r4, #0]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    815e:                   cmp     r3, r1<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8160:                   ittt    eq<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8162:                   moveq   r0, #3<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8164:                   strbeq  r0, [r2, #0]<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8166:                   moveq   r0, #170        ; 0xaa<u class=""></u><u class=""></u></span></p>
</div>
<div class=""><p class="MsoNormal" style="background:white none repeat scroll 0% 0%"><span style="font-family:"Arial","sans-serif";color:rgb(34,34,34)" class="">    8168:                   pop     {r4, r6, r7, pc}<span style="background:white none repeat scroll 0% 0%" class="">          // a function return</span><u class=""></u><u class=""></u></span></p>
</div>
</div>
</div>
<div class="">
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">I have a variable <b class="">bar</b> and here's its corresponding DWARF DIE:<u class=""></u><u class=""></u></p>
</div>
<div class="">
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class="">
<div class=""><p class="MsoNormal"> <2><3b>: Abbrev Number: 3 (DW_TAG_formal_parameter)<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    <3c>   DW_AT_location    : 0x0 (location list)<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    <40>   DW_AT_name        : (indirect string, offset: 0x9e):
<b class="">bar</b><u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    <44>   DW_AT_decl_file   : 1<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    <45>   DW_AT_decl_line   : 34<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    <46>   DW_AT_type        : <0x153><u class=""></u><u class=""></u></p>
</div>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"> // <b class="">Its location list</b><u class=""></u><u class=""></u></p>
</div>
<div class="">
<div class=""><p class="MsoNormal">    00000000 00008124 0000812a (DW_OP_reg0 (r0))<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    0000000b 0000812a 00008136 (DW_OP_reg4 (r4))<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">    00000016 <End of list><u class=""></u><u class=""></u></p>
</div>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">As you can see, it says that we can find <b class="">bar </b>in <b class="">r4</b> from
<b class="">0x812a </b>to <b class="">0x8134 (poplt)</b>.  However, this is only true when the <b class="">cmp
</b>instruction at <b class="">0x812e</b> yields <b class="">less than (lt)</b>.  So if the value in
<b class="">r0 </b>is greater than 1 (which is the case of my input), we should still be able to read the value of
<b class="">bar</b> from <b class="">r4</b> in the remaining of the function.<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">I don't know if we can consider this a bug, because I don't even know what should be the correct location information for
<b class="">bar</b>. However, in this case, since the conditional instruction that clobbers
<b class="">r4</b> is a function return, I'd expect to read the value of <b class="">bar</b> from <b class="">
r4</b> in the remaining of the function. <u class=""></u><u class=""></u></p>
</div>
</div>
</div>
</div>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">I can't tell for sure whether the debug info is correct without also seeing the source code, but as a general point: Debug information is
<i class="">must</i>-information that holds over all paths through the program. Debug information that is only accurate for some paths is a bug. A serious bug, because if the user can't rely on the debug info to be correct in
<b class="">some</b> cases, they can't rely on <b class="">any</b> of the debug info to be correct.<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">-- adrian<u class=""></u><u class=""></u></p>
</div><p class="MsoNormal"><br class="">
<br class="">
<u class=""></u><u class=""></u></p>
<div class="">
<div class="">
<div class="">
<div class="">
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">If the conditional instruction <b class="">poplt </b>was <b class="">addlt r4, r0, 3</b> for example, what should be the correct location list of
<b class="">bar</b>?<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
</div>
<div class=""><p class="MsoNormal">For now, my only idea is to check if the clobbering MI is a <b class="">
conditional return</b> in <b class="">DbgValueHistoryCalculator</b> whic<wbr class="">h computes the end address of a location llist entry. But I do not feel like this is the correct fix though.<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">Looking forward to hearing your thoughts on this,<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class=""><p class="MsoNormal">Thank you for reading this,<u class=""></u><u class=""></u></p>
</div>
<div class=""><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div>
<div class="">
<div class="">
<div class=""><p class="MsoNormal">Son Tuan Vu<u class=""></u><u class=""></u></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div><p class="MsoNormal"><u class=""></u> <u class=""></u></p>
</div></div></div>
</div>
</div>

</blockquote></div><br class=""></div></div></div></div></div></div>
</blockquote></div><br class=""></div>
</div></blockquote></div><br class=""></div></div></body></html>