<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW " title="NEW --- - [META] Fix as many instructions with missing DebugLoc as possible." href="https://urldefense.proofpoint.com/v2/url?u=https-3A__llvm.org_bugs_show-5Fbug.cgi-3Fid-3D23837&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=UsnwvgY6Uq5G3EjTfvwWr0L9xtttecCydL1FfvC6oVg&e=">23837</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[META] Fix as many instructions with missing DebugLoc as possible.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Miscellaneous Instrumentation passes
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>vonosmas@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dblaikie@gmail.com, echristo@gmail.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Generally, LLVM does very bad job in ensuring that, when debug info is enabled
(-gline-tables-only or above), all necessary([1]) instructions indeed have
DebugLoc attached to them, or that DebugLoc are preserved as we transform the
code. For example:

* DebugLoc can be easily missed as we split/rearrange basic blocks.
* Synthesized instructions in GVN, SCEV etc. often have no debug info.

Once we have an instruction I with no DebugLoc, this "missing" DebugLoc would
propagate through the program - e.g. every time we construct IRBuilder<> with I
as insertion point, it will fail to set correct DebugLoc for instructions it
creates.

This is painful - with optimizations enabled, we may often fail to provide
reasonable line info for instructions, or (worse case, which often happens)
incorrectly return line info for *some* preceding instruction which happened
to have DebugLoc, but may be completely irrelevant (e.g. come from a
different inlined subroutine).

I've did several improvements recently:
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239438-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=Poy3dvG6dIVLNGi1tgVG0Q0pRaj9w_iNbUJCneJWXZ0&e=">http://llvm.org/viewvc/llvm-project?rev=239438&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239479-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=FBsoQ0AP5AyCVhKNJ73j81VimfOi5nWN7ELrqGuTvlc&e=">http://llvm.org/viewvc/llvm-project?rev=239479&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239550-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=OYCiZxxIoU9Ooom5wNBMUioP9DoUHsqLm5Xw13G6R-c&e=">http://llvm.org/viewvc/llvm-project?rev=239550&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239551-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=OafHbtlBOPpashtSiAfVGvAxfYDtrEPu9sDkBtAjOTw&e=">http://llvm.org/viewvc/llvm-project?rev=239551&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239584-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=Qi2i2D6uNpxUt8QomAC-RbAPG9B84j2hb1yQLLqiByw&e=">http://llvm.org/viewvc/llvm-project?rev=239584&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239585-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=P4mxt4Q-a-gehR7YfQZNl_1GELGQDjyQBBi-9kv5vIU&e=">http://llvm.org/viewvc/llvm-project?rev=239585&view=rev</a>
<a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D239643-26view-3Drev&d=AwMBaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=pF93YEPyB-J_PERP4DUZOJDzFVX5ZQ57vQk33wu0vio&m=8OD-fY4e6Mtk0OHUEi_4PrY7fbr4QJjOE4Ih2yly11s&s=57oyzhHkVLMKaFFT49N5oO1Ttx5xORhHGm0jV7y1WzE&e=">http://llvm.org/viewvc/llvm-project?rev=239643&view=rev</a>

But there are many more cases to fix, and even if we fix them all,
we should be able to somehow prevent further breakages.
* We can improve API for creating new instructions that would force callers
  to set DebugLoc (or explicitly pass empty one, promising to set it up later).
* Add module verifier check that would enforce that if function has *some*
  attached DebugLocs, then all ([1]) instruction should have them.
* Add asserts to places where we believe DebugLoc should always be present if
  line tables are enabled (e.g. we need it in SanitizerCoverage pass where
  we know that PCs of certain instructions would be collected, and possibly
  symbolized later).
* Some combination of above.


Notes:
[1] - Function prologue instructions (alloca's etc.) intentionally have no
DebugLoc. PHI nodes *sometimes* do have them, but it's not clear whether
there's a contract of some sort. Many users actually call
BB->getFirstNonPHI()->getDebugLoc() to get the "entry" debug location, probably
because they believe it will be the first insertion point / non-transient
instruction.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>