Just wanted to revisit this quickly. It looks like the issue with Sean's implementation is that it doesn't work correctly in the presence of invalidated iterators that result from replacing intermediate values with 0, due to the fact that it uses a ranged based for loop.<br><br><div class="gmail_quote">On Fri Jan 09 2015 at 12:40:37 PM <<a href="mailto:jingham@apple.com">jingham@apple.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't see a problem with that. If we start seeing other issues we can always back it out.<br>
<br>
Jim<br>
<br>
<br>
> On Jan 9, 2015, at 11:10 AM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
><br>
> FWIW I ran the test suite on Linux with this patch applied and nothing regressed. Since Windows is the only platform with a different compiler ABI, I think it should be ok to check in since it passes on Linux. Thoughts?<br>
><br>
> On Thu Jan 08 2015 at 11:42:32 AM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> +David Majnemer +Chandler Carruth<br>
><br>
> David works on the LLVM side and he is the one that actually worked with me at my desk to figure this out, and it was his suggestion that led me to try out replaceAllUsesWith to begin with. Also adding Chandler as another LLVM person for general commentary since many other people hare are also still out on various types of holiday leave.<br>
><br>
> From what I can tell, Windows just generates different LLVM IR for guard variables, and the particular arrangement of the guard users wasn't being correctly handled by Sean's original implementation of the function.<br>
><br>
> The most obvious difference I can see from looking at the two implementations is that the LLVM version handles constants, whereas the implementation I've "fixed" here didn't, but had a comment indicating that they should be handled in the future. I guess without Sean's thoughts on why this function wasn't used originally, it's hard to know for sure the history there.<br>
><br>
> I'll let David and/or Chandler offer more commentary, although David did mention that he thinks a better, but more involved fix is to simply allow LLDB's IR Interpreter to correctly handle loads and stores to global variables, and then none of this would have ever happened.<br>
><br>
><br>
> On Thu Jan 08 2015 at 11:29:44 AM <<a href="mailto:jingham@apple.com" target="_blank">jingham@apple.com</a>> wrote:<br>
> Sean is on paternity leave, so he'll probably be slow to answer this sort of ping for a while.<br>
><br>
> Value::replaceAllUsesWith does things very differently from this little function Sean wrote. From what I can tell, it looks like it is the right thing to use, but that function has been in llvm for a while so I don't know why Sean didn't originally use it here. Do you know what about Windows in particular caused Sean's version to fail, since it doesn't look like it causes any trouble on other platforms?<br>
><br>
> If one of the llvm folks reading this list knows more about the IR Value class and has an opinion about the use of replaceAllUsesWith as opposed to the simpler operation Sean did, I'd love to hear that too...<br>
><br>
> Jim<br>
><br>
><br>
> > On Jan 6, 2015, at 3:45 PM, Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> ><br>
> > +Sean Callanan<br>
> ><br>
> > I couldn't include you on the Phabricator issue Sean, so I'm CC'ing you directly. PTAL<br>
> ><br>
> > On Tue Jan 06 2015 at 3:45:04 PM Zachary Turner <<a href="mailto:zturner@google.com" target="_blank">zturner@google.com</a>> wrote:<br>
> > MS ABI guard variables end with @4IA, so this patch teaches the interpreter about that. Additionally, there was an issue with TurnGuardLoadIntoZero which was causing some guard uses of a variable to be missed. This fixes that by calling Instruction::<u></u>replaceAllUsesWith() instead of trying to replicate that function.<br>
> ><br>
> > This fixes between 8 and 10 tests on Windows, and in particular fixes evaluation of C / C++ local variables.<br>
> ><br>
> > <a href="http://reviews.llvm.org/D6859" target="_blank">http://reviews.llvm.org/D6859</a><br>
> ><br>
> > Files:<br>
> > source/Expression/IRForTarget.<u></u>cpp<br>
> ><br>
> > Index: source/Expression/IRForTarget.<u></u>cpp<br>
> > ==============================<u></u>==============================<u></u>=======<br>
> > --- source/Expression/IRForTarget.<u></u>cpp<br>
> > +++ source/Expression/IRForTarget.<u></u>cpp<br>
> > @@ -2043,8 +2043,12 @@<br>
> ><br>
> > GlobalVariable *GV = dyn_cast<GlobalVariable>(Old);<br>
> ><br>
> > - if (!GV || !GV->hasName() || !GV->getName().startswith("_<u></u>ZGV"))<br>
> > + if (!GV || !GV->hasName() ||<br>
> > + (!GV->getName().startswith("_<u></u>ZGV") && // Itanium ABI guard variable<br>
> > + !GV->getName().endswith("@4IA"<u></u>))) // Microsoft ABI guard variable<br>
> > + {<br>
> > return false;<br>
> > + }<br>
> ><br>
> > return true;<br>
> > }<br>
> > @@ -2052,20 +2056,8 @@<br>
> > void<br>
> > IRForTarget::<u></u>TurnGuardLoadIntoZero(llvm::<u></u>Instruction* guard_load)<br>
> > {<br>
> > - Constant* zero(ConstantInt::get(Type::<u></u>getInt8Ty(m_module-><u></u>getContext()), 0, true));<br>
> > -<br>
> > - for (llvm::User *u : guard_load->users())<br>
> > - {<br>
> > - if (isa<Constant>(u))<br>
> > - {<br>
> > - // do nothing for the moment<br>
> > - }<br>
> > - else<br>
> > - {<br>
> > - u->replaceUsesOfWith(guard_<u></u>load, zero);<br>
> > - }<br>
> > - }<br>
> > -<br>
> > + Constant *zero(Constant::getNullValue(<u></u>guard_load->getType()));<br>
> > + guard_load-><u></u>replaceAllUsesWith(zero);<br>
> > guard_load->eraseFromParent();<br>
> > }<br>
> ><br>
> > EMAIL PREFERENCES<br>
> > <a href="http://reviews.llvm.org/settings/panel/emailpreferences/" target="_blank">http://reviews.llvm.org/<u></u>settings/panel/<u></u>emailpreferences/</a><br>
> > ______________________________<u></u>_________________<br>
> > lldb-commits mailing list<br>
> > <a href="mailto:lldb-commits@cs.uiuc.edu" target="_blank">lldb-commits@cs.uiuc.edu</a><br>
> > <a href="http://lists.cs.uiuc.edu/mailman/listinfo/lldb-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/lldb-commits</a><br>
><br>
<br>
</blockquote></div>