<div dir="ltr">Might be a lot of functions to change - maybe a wrapper would be easier:<br><br>template<typename T><br>T *applyDebugLoc(T *t, DebugLoc L) { t->setDebugLoc(L); return t; }<br><br>Or change/improve/modify/add setDebugLoc to return the Instruction* so it could be chained? (NewInst = Foo::Create(...).applyDebugLoc(L); )</div><br><div class="gmail_quote"><div dir="ltr">On Tue, Aug 7, 2018 at 4:59 AM Anast Gramm via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Many DI-related bugs are caused by missing Debug Location<br>
in an instruction created in a transformation. Most of the<br>
time the fix is trivial once you found where the culprit<br>
instruction is created (<a href="https://reviews.llvm.org/D50263" rel="noreferrer" target="_blank">https://reviews.llvm.org/D50263</a>).<br>
Currently, when you create a new Instruction, in order to<br>
give it DL you have to either use an IRBuilder that is<br>
previously set to the correct DL or “manually” create<br>
the instruction via one of it’s Create() routines and then<br>
call `setDebugLoc()` to it.<br>
<br>
I propose the addition of a DebugLoc parameter<br>
in the *::Create() instruction constructors.<br>
This could be in the form of a pure DebugLoc<br>
variable or possibly an `Instruction *InheritLocationFromInst` one<br>
<br>
Some pros of this idea are:<br>
 - Easier to create instructions with debug location.<br>
 - It will make the code more readable by eliminating<br>
 the many `NewInst->setDebugLoc(OldInst->getDebugLoc)` calls.<br>
 - It will incentivize people to think about the DebugLoc of<br>
 their newly created instruction and where it should come from.<br>
<br>
As the Create() functions are widely used, and sometimes<br>
location data could be out of scope when the Instruction<br>
is created, I think the best approach to this is to<br>
introduce the new field as optional that defaults to<br>
empty DL (as it is now) to avoid huge refactoring,<br>
and to allow more time for testing individual changes.<br>
Refactoring could then be done in steps and the<br>
parameter could become mandatory in some ::Create()<br>
constructors as we judge fit.<br>
<br>
With that in mind here are some cons:<br>
 - Incomplete transition of APIs.<br>
 - Lack of infrastructure to check that the locations<br>
 supplied to *::Create are correct.<br>
<br>
What do you think?<br>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>