<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 4, 2015 at 5:23 PM, Duncan P. N. Exon Smith <span dir="ltr"><<a href="mailto:dexonsmith@apple.com" target="_blank">dexonsmith@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><br>
> On 2015 Jun 4, at 16:50, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
><br>
><br>
><br>
> On Thu, Jun 4, 2015 at 4:46 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
><br>
> > On 2015 Jun 4, at 16:36, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> ><br>
> ><br>
> ><br>
> > On Thu, Jun 4, 2015 at 4:28 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
> ><br>
> > > On 2015 Jun 4, at 16:09, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:<br>
> > ><br>
> > > Judging by the code, does this cause us not to create a variable if it has no locations? That's probably not quite right - even if we have no locations, it's probably a good idea/correct to describe the variable so shadowing, etc, works correctly (if someone tries to print the variable the compiler still finds the right variable but just reports that it doesn't know the location)<br>
> ><br>
> > So the code here already has an early return if there are no ranges:<br>
> ><br>
> >     for (const auto &I : DbgValues) {<br>
> >       InlinedVariable IV = I.first;<br>
> >       if (Processed.count(IV))<br>
> >         continue;<br>
> ><br>
> >       // Instruction ranges, specifying where IV is accessible.<br>
> >       const auto &Ranges = I.second;<br>
> >       if (Ranges.empty())<br>
> >         continue;<br>
> ><br>
> > My patch effectively hits this `continue` more often.  The difference<br>
> > is cases where we *thought* we knew how to emit ranges, but in fact<br>
> > didn't know how.<br>
> ><br>
> > I suppose I assumed the intended behaviour was "don't emit the<br>
> > variable if we don't have any ranges for it" since that's what was<br>
> > going on, but are you saying this `continue` is a bug?  (Or am I<br>
> > totally missing your point?)<br>
> ><br>
> > How do we end up with an empty range list here? That seems strange - I assume we're just lazily creating the rang lists in calculateDbgValueHistory... (I could sort of understand empty entries in a range list - when it turns out the dbg_value intrinsic describes no instructions due to things being optimized away, hoisted here or there, etc).<br>
><br>
> No idea, I just assume it happens because there's code.<br>
><br>
> Not sure what you mean.<br>
><br>
> What I'm trying to understand is whether or not we should be fixing this bug closer to the source (in calculateDbgValueHistory) that's producing empty ranges or empty entries.<br>
<br>
</div></div>One thing that Adrian walked me through is that even if we have<br>
ranges, and we have entries after the call to `buildLocationList()`,<br>
we can still fail to emit any bytes during `DebugLocEntry::finalize()`<br>
since we don't know how to emit every DWARF expression.<br></blockquote><div><br>How are we building DWARF expressions we can't emit? Shouldn't we just not build those? (I guess this is more of a question for Adrian)<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Because of that, I changed my approach from "trying to get `Ranges` to<br>
match up with `Entries`" to "popping empty/useless entries and ranges<br>
off the stack", and figured Ranges/Entries inconsistencies were a<br>
compile-time optimization that weren't as urgent.<br></blockquote><div><br>My perspective is just to understand why they're there in the first place - I dislike solutions/fixes/patches that are predicated on "I don't know why this state occurs, but I can handle it here" - they feel unsatisfying & can end up layering workarounds on workarounds when there was some underlying issues that could've been addressed & lead to simpler code with stronger invariants.<br><br>But if there's a reason for them (Empty range lists or empty ranges in the range lists) that's cool - I just don't know it & wanted to understand it before I'd be comfortable with the patch.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Maybe we should also be adding the commented out code I had in:<br>
 <a href="http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150525/278797.html" target="_blank">http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20150525/278797.html</a><br>
<br>
It also seems like the `continue` in the current code might be the wrong<br>
thing (and we should create the variable with no DW_AT_location?).<br></blockquote><div><br>As you mentioned, the loop that catches optimized-out variables is probably fine for all these cases (because there are cases where all the dbg_values could be optimized away & we'd find no evidence of the variable at all, I should imagine - so that logic has to be up to the task of coping with these cases).<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(All of this stuff is a tangent for me.  I wandered in here to remove<br>
the empty .debug_loc entries/lists in the output.)<br></blockquote><div><br>Right - just trying to make sure I understand why this is the right place to fix that issue & not working around some other issue/missing invariant.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">> What's the right thing to do?<br>
><br>
> I don't have all the context here to know that off-hand. Trying to discuss it to try to wrap my head around enough of it to offer a useful opinion - sorry it takes a while.<br>
<br>
</span>Not trying to rush you, sorry if it seems that way.  This isn't really<br>
blocking me (I have other things to work on (although obviously I'd<br>
like to resolve this some time)).<br>
<span class=""><br>
> Should we create a variable the same<br>
> was as the for loop below for function arguments (that doesn't<br>
> attach ranges)?  Should we not create a variable?<br>
><br>
> If we get the same output between creating it here or in the later loop, it doesn't matter in the broad sense.<br>
><br>
> Is it actually<br>
> *useful* that we create a .debug_loc list with no entries and point<br>
> to it?<br>
><br>
> No, there's no benefit to pointing to an empty loc list compared to just having no DW_AT_location at all.<br>
<br>
</span>Thanks for confirming.<br>
<br>
I'd be happy to adjust my patch to just address the empty .debug_loc<br>
list/entries and continue to create the same variables that were being<br>
created before (just missing whatever magic makes them create a<br>
`DW_AT_location` -- I'm guessing I just use the constructor logic<br>
that's used for optimized-out function parameters in the loop that<br>
follows?).<br></blockquote><div><br>No, I think that's fine as is - as you pointed out, we have that other loop for emitting optimized-out variables and we have other logic that's skipping variables here already.<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">(It sounds like it was a poor assumption on my part that we were trying<br>
to avoid emitting variables if they have no ranges.)</blockquote></div><br></div></div>