<div dir="ltr"><br><br><div class="gmail_quote"><div dir="ltr">On Tue, Feb 14, 2017 at 9:41 AM Teresa Johnson via Phabricator <<a href="mailto:reviews@reviews.llvm.org">reviews@reviews.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">tejohnson added inline comments.<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
================<br class="gmail_msg">
Comment at: lib/CodeGen/LexicalScopes.cpp:82<br class="gmail_msg">
+      // Ignore locations linked from a NoDebug compile unit.<br class="gmail_msg">
+      auto *SP = dyn_cast<DISubprogram>(MIDL->getScope());<br class="gmail_msg">
+      if (SP && SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) {<br class="gmail_msg">
----------------<br class="gmail_msg">
dblaikie wrote:<br class="gmail_msg">
> This probably won't catch all cases - if the location was in a subscope within the function (eg: try adding a {} to the function which should add an extra scope). Walking the scope chain until a DISubprogram is probably needed here - I forget if we have a nice wrapped up utility for that. Don't see one at a glance.<br class="gmail_msg">
><br class="gmail_msg">
> It should be an invariant/guaranteed that a DISubprogram is reached (& is the end of the scope chain), so something like:<br class="gmail_msg">
><br class="gmail_msg">
> oh, wait, no, here it is: <a href="http://llvm.org/docs/doxygen/html/classllvm_1_1DILocalScope.html#a747dd1690fc477a8d9638fa37a30ced8" rel="noreferrer" class="gmail_msg" target="_blank">http://llvm.org/docs/doxygen/html/classllvm_1_1DILocalScope.html#a747dd1690fc477a8d9638fa37a30ced8</a><br class="gmail_msg">
><br class="gmail_msg">
> so, I think, maybe:<br class="gmail_msg">
><br class="gmail_msg">
>   if (cast<DILocalScope>(MIDL->getScope())->getSubprogram()->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) {<br class="gmail_msg">
>     ...<br class="gmail_msg">
I had just found the DILocalScope::getSubprogram() helper, since I was still getting the original seg fault when I tried the original failing internal code with this change. So now I have:<br class="gmail_msg">
<br class="gmail_msg">
      // Ignore locations linked from a NoDebug compile unit.<br class="gmail_msg">
      auto *SP = MIDL->getScope()->getSubprogram();<br class="gmail_msg">
      if (SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug) {<br class="gmail_msg">
        PrevMI = &MInsn;<br class="gmail_msg">
        continue;<br class="gmail_msg">
      }<br class="gmail_msg">
<br class="gmail_msg">
(Don't need to cast MIDL->getScope() since it returns a DILocalScope).</blockquote><div><br></div><div>Ah, handy!</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"> But I am *still* getting the original seg fault. Any idea what else I could be missing?<br class="gmail_msg"></blockquote><div><br></div><div>Not sure, no, sorry :/ I know reducing LTO test cases is difficult, but if this works for the simple test case and doesn't in the original failing situation it'll be good to understand why.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
<br class="gmail_msg">
================<br class="gmail_msg">
Comment at: test/DebugInfo/Generic/debug_and_nodebug_CUs.ll:4<br class="gmail_msg">
+<br class="gmail_msg">
+; RUN: llc %s -o - | FileCheck %s<br class="gmail_msg">
+; CHECK-DAG: # debug.c:<br class="gmail_msg">
----------------<br class="gmail_msg">
dblaikie wrote:<br class="gmail_msg">
> Include the steps for reproducing this test case (basically the RUN lines, and the original C source/steps for producing the IR, from the first version of the test) - helps to visualize/document/reproduce the situation.<br class="gmail_msg">
Will do<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<a href="https://reviews.llvm.org/D29765" rel="noreferrer" class="gmail_msg" target="_blank">https://reviews.llvm.org/D29765</a><br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
<br class="gmail_msg">
</blockquote></div></div>