<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>Thanks for the quick response.</div><div><br></div><div>I wrote some code to search “llvm.dbg.cu” for the function (right before the failed assertion):</div><div><br></div><div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">  <span style="color: #9a64b9">if</span> (TheCU == <span style="color: #9a64b9">nullptr</span>) {</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #576ebb">errs</span>() << <span style="color: #5d975f">"compile unit: "</span> << TheCU << <span style="color: #5d975f">"\n  scopeNode("</span> << FnScope-><span style="color: #576ebb">getScopeNode</span>() << <span style="color: #5d975f">") => "</span> << *FnScope-><span style="color: #576ebb">getScopeNode</span>() << <span style="color: #5d975f">"\n"</span>;</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #9a64b9">auto</span> fn = MF-><span style="color: #576ebb">getFunction</span>();</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #576ebb">errs</span>() << <span style="color: #5d975f">"  fn => "</span> << fn-><span style="color: #576ebb">getName</span>() << <span style="color: #5d975f">"\n"</span>;</div><p style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC'; min-height: 14px;">    <br class="webkit-block-placeholder"></p><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #f3ba00">MDNode</span> *node = <span style="color: #9a64b9">nullptr</span>;</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #9a64b9">auto</span> mod = fn-><span style="color: #576ebb">getParent</span>();</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #9a64b9">auto</span> dbg = mod-><span style="color: #576ebb">getNamedMetadata</span>(<span style="color: #5d975f">"llvm.dbg.cu"</span>);</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #9a64b9">for</span> (<span style="color: #9a64b9">unsigned</span> ni = <span style="color: #f43c00">0</span>; ni < dbg-><span style="color: #576ebb">getNumOperands</span>(); ni++) {</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">      <span style="color: #f3ba00">DICompileUnit</span> <span style="color: #576ebb">cu</span>(dbg-><span style="color: #576ebb">getOperand</span>(ni));</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">      <span style="color: #9a64b9">auto</span> subs = cu.<span style="color: #576ebb">getSubprograms</span>();</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">      <span style="color: #9a64b9">for</span> (<span style="color: #9a64b9">unsigned</span> si = <span style="color: #f43c00">0</span>; si < subs.<span style="color: #576ebb">getNumElements</span>(); si++) {</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">        <span style="color: #f3ba00">DISubprogram</span> <span style="color: #576ebb">sp</span>(subs.<span style="color: #576ebb">getElement</span>(si));</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">        <span style="color: #9a64b9">if</span> (sp.<span style="color: #576ebb">getFunction</span>() == fn) {</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">          node = sp;</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">          <span style="color: #9a64b9">break</span>;</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">        }</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">      }</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    }</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">    <span style="color: #576ebb">errs</span>() << <span style="color: #5d975f">"  ("</span> << node << <span style="color: #5d975f">" ) node => "</span> << *node << <span style="color: #5d975f">"\n"</span>;</div><div style="margin: 0px; font-size: 10px; font-family: 'Inconsolata LGC';">  }</div></div><div><br></div><div>Strangely, the node my code finds *prints* the same, but the pointer is different:</div><div><br></div><div><div></div></div><blockquote type="cite"><div><div style="font-size: 10px;"><font face="Inconsolata LGC">  scopeNode(0x7fe53dc6c2c0) => !{i32 786478, metadata <badref>, metadata <badref>, metadata !"grappa_wide_get_pointer", metadata !"grappa_wide_get_pointer", metadata !"", i32 53, metadata <badref>, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i8* (i8*)* @grappa_wide_get_pointer, null, null, metadata <badref>, i32 53} ; [ DW_TAG_subprogram ] [line 53] [def] [grappa_wide_get_pointer]</font></div><div style="font-size: 10px;"><font face="Inconsolata LGC"><br></font></div><div style="font-size: 10px;"><font face="Inconsolata LGC">  fn => grappa_wide_get_pointer</font></div><div style="font-size: 10px;"><font face="Inconsolata LGC">  (0x7fe53bc241b0 ) node => !{i32 786478, metadata <badref>, metadata <badref>, metadata !"grappa_wide_get_pointer", metadata !"grappa_wide_get_pointer", metadata !"", i32 53, metadata <badref>, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i8* (i8*)* @grappa_wide_get_pointer, null, null, metadata <badref>, i32 53} ; [ DW_TAG_subprogram ] [line 53] [def] [grappa_wide_get_pointer]</font></div></div></blockquote><div><br></div><div>Any idea what that could mean?</div><br><div><div>On Dec 3, 2013, at 9:38 PM, David Blaikie <<a href="mailto:dblaikie@gmail.com">dblaikie@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div style="font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">On Tue, Dec 3, 2013 at 9:04 PM, Brandon Holt <<a href="mailto:bholt@cs.washington.edu">bholt@cs.washington.edu</a>> wrote:<br><blockquote type="cite">In a pass I’m working on, I’ve done some manipulation of several functions, replacing them with new copies with different types, etc.<br><br>The LLVM IR passes the verifier, but when I have debug symbols enabled (“-g”), I get the following error when Clang generates the Dwarf info (using a very recent build of LLVM/Clang from Git mirror):<br><br><blockquote type="cite">Assertion failed: (TheCU && "Unable to find compile unit!"), function beginFunction, file ../lib/CodeGen/AsmPrinter/DwarfDebug.cpp, line 1617.<br>0  clang-3.4                0x0000000103ff3808 llvm::sys::PrintStackTrace(__sFILE*) + 40<br>1  clang-3.4                0x0000000103ff3c64 SignalHandler(int) + 388<br>2  libsystem_platform.dylib 0x00007fff8dd185aa _sigtramp + 26<br>3  libsystem_platform.dylib 000000000000000000 _sigtramp + 1915648624<br>4  clang-3.4                0x0000000103ff3ac6 abort + 22<br>5  clang-3.4                0x0000000103ff3aa1 __assert_rtn + 81<br>6  clang-3.4                0x00000001038bcb70 llvm::DwarfDebug::endFunction(llvm::MachineFunction const*) + 0<br>7  clang-3.4                0x0000000103892677 llvm::AsmPrinter::EmitFunctionHeader() + 727<br>8  clang-3.4                0x00000001036229ea llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) + 170<br>9  clang-3.4                0x0000000103b0fbec llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 60<br>10 clang-3.4                0x0000000103f1244b llvm::FPPassManager::runOnFunction(llvm::Function&) + 347<br>11 clang-3.4                0x0000000103f126db llvm::FPPassManager::runOnModule(llvm::Module&) + 43<br>12 clang-3.4                0x0000000103f12b49 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 713<br>13 clang-3.4                0x0000000103f12f5d llvm::legacy::PassManager::run(llvm::Module&) + 13<br>14 clang-3.4                0x0000000104230b3e clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 5790<br>15 clang-3.4                0x000000010431b9a7 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) + 455<br>16 clang-3.4                0x00000001044a7644 clang::ParseAST(clang::Sema&, bool, bool) + 516<br>17 clang-3.4                0x000000010431aab8 clang::CodeGenAction::ExecuteAction() + 584<br>18 clang-3.4                0x000000010441c0b6 clang::FrontendAction::Execute() + 134<br>19 clang-3.4                0x00000001043f802d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 973<br>20 clang-3.4                0x0000000103ff6ab4 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 4276<br>21 clang-3.4                0x000000010330306d cc1_main(char const**, char const**, char const*, void*) + 925<br>22 clang-3.4                0x00000001033015c3 main + 7283<br>23 libdyld.dylib            0x00007fff8e68d5fd start + 1<br></blockquote><br>(note the line number of the assertion is probably different because I’ve added some prints to help me debug this)<br><br>When I print the MDNode returned by “FnScope->getScopeNode()”, I get lots of <badref>’s:<br></blockquote><br>The badrefs are a red herring, so far as I know - they're printed that<br>way even when they're valid references, in my experience.<br><br>That being said, given your assertion it does look like /something/ is up.<br><br>It appears as if the function being emitted is somehow not visited<br>when emitting functions in the list of functions on the compilation<br>units. Somehow it got separated, perhaps.<br><br><blockquote type="cite"><blockquote type="cite">!{i32 786478, metadata <badref>, metadata <badref>, metadata !"grappa_wide_get_pointer", metadata !"grappa_wide_get_pointer", metadata !"", i32 53, metadata <badref>, i1 false, i1 true, i32 0, i32 0, null, i32 256, i1 true, i8* (i8*)* @grappa_wide_get_pointer, null, null, metadata <badref>, i32 53} ; [ DW_TAG_subprogram ] [line 53] [def] [grappa_wide_get_pointer]<br></blockquote><br><br>It looks to me like I must be corrupting the lexical scope information somehow, but I don’t think I’m explicitly touching metadata at all. Any idea what may have caused this? Is there something I must be sure to update within the debug metadata?<br></blockquote><br>I'd look at the cu metadata and the associated subprogram lists to see<br>what's in there and why your subprogram isn't in that list (if I'm<br>reading it right, that's the case - but I could be wrong).</div></blockquote></div><br></body></html>