<div dir="ltr">Hi,<div><br></div><div>I am learning to write LLVM modules. I am using IRBuilder to insert calls to an existing function. The call is to be inserted at a random location in every function in the code. The call does get inserted, however, the module crashes later (after doFinalization()). The crash happens only sometimes, not always. </div><div><br></div><div>These are the kind of instructions that I see in the generated code.</div><div>  %callins = call void @myfunc(), !dbg !285</div><div>  %callins = call void @myfunc()<br></div><div><br></div><div>The stack trace shows the crash has something to do with debug information. Do I need to add metadata or debug info to the newly added call instruction? Any pointers on how I can do that?<br></div><div><br></div><div>Here is the code snippet and the stack trace:</div><div><br></div><div><div>IRBuilder<> Builder(ins); // to be inserted before ins</div><div>CallInst *call = Builder.CreateCall(func, "callins"); // call to func</div></div><div><br></div><div><br></div><div><div>0  clang           0x0000000001492ec2 llvm::sys::PrintStackTrace(_IO_FILE*) + 34</div><div>1  clang           0x0000000001490f61</div><div>2  libpthread.so.0 0x00002b33bd0ee340</div><div>3  clang           0x00000000016a43a6 llvm::DwarfUnit::addString(llvm::DIE&, llvm::dwarf::Attribute, llvm::StringRef) + 22</div><div>4  clang           0x00000000016c2003 llvm::DwarfCompileUnit::applyVariableAttributes(llvm::DbgVariable const&, llvm::DIE&) + 915</div><div>5  clang           0x000000000168bdfe llvm::DwarfDebug::finishVariableDefinitions() + 270</div><div>6  clang           0x0000000001690424 llvm::DwarfDebug::finalizeModuleInfo() + 52</div><div>7  clang           0x000000000169c4a8 llvm::DwarfDebug::endModule() + 40</div><div>8  clang           0x00000000016850f7 llvm::AsmPrinter::doFinalization(llvm::Module&) + 551</div><div>9  clang           0x00000000011befe5 llvm::FPPassManager::doFinalization(llvm::Module&) + 69</div><div>10 clang           0x00000000011ca40d llvm::legacy::PassManagerImpl::run(llvm::Module&) + 813</div><div>11 clang           0x0000000001837fad clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::raw_ostream*) + 1629</div><div>12 clang           0x000000000182a47f</div><div>13 clang           0x0000000001bdf043 clang::ParseAST(clang::Sema&, bool, bool) + 483</div><div>14 clang           0x0000000001603ba6 clang::FrontendAction::Execute() + 118</div><div>15 clang           0x00000000015e47b8 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) + 280</div><div>16 clang           0x0000000001673b41 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) + 1921</div><div>17 clang           0x0000000000820358 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) + 1320</div><div>18 clang           0x00000000007fceaa main + 8298</div><div>19 libc.so.6       0x00002b33bdd56ec5 __libc_start_main + 245</div><div>20 clang           0x000000000081e5d9</div></div><div><br></div><div>Any help is appreciated.</div><div><br></div><div>Thanks,</div><div>Pankaj</div><div><br></div><div><br></div></div>