<div dir="ltr">There have in the past been bugs in the cloner involving duplicate DICompileUnits (see e.g. <a href="https://reviews.llvm.org/D29240">https://reviews.llvm.org/D29240</a>), this one may need a similar fix.<div><br></div><div>Peter</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 8, 2017 at 3:07 PM, Matthew O'Connor via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>All,<br><br></div>I'm seeing duplication of DICompileUnits in a pass that worked in 3.8. I assume I'm doing something wrong. Would someone be willing to point me in the right direction?<br><br></div>The below minimized pass reproduces my issue in 4.0 with the following error:<br><br><span style="font-family:monospace,monospace">DICompileUnit not listed in <a href="http://llvm.dbg.cu" target="_blank">llvm.dbg.cu</a><br>!1707 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (tags/RELEASE_400/final)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, imports: !1708)<br>dsc-opt: /home/moconnor/Source/carte.<wbr>git/llvm-carte/llvm-4.0.0/<wbr>llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::<wbr>VerifierLegacyPass::<wbr>doFinalization(llvm::Module&): Assertion `!V->hasBrokenDebugInfo() && "Module contains invalid debug info"' failed.</span><br><br></div>Pass implementation:<br><div><br><font face="monospace,monospace">#define DEBUG_TYPE "dupl"<br>#include "llvm/Pass.h"<br>#include "llvm/Support/Debug.h"<br>#include "llvm/Support/raw_ostream.h"<br>#include "llvm/Transforms/Utils/<wbr>Cloning.h"<br>#include <vector><br>using namespace llvm;<br><br>struct FunctionDuplication;<br><br>namespace llvm {<br>void initializeFunctionDuplicationP<wbr>ass(PassRegistry &);<br>}<br><br>struct FunctionDuplication : public ModulePass {<br> static char ID;<br> FunctionDuplication() : ModulePass(ID) {}<br><br> virtual StringRef getPassName() const override {<br> return "Duplicate every function";<br> }<br><br> virtual void getAnalysisUsage(AnalysisUsage &) const override;<br><br> virtual bool runOnModule(Module &) override;<br><br> Function *duplicate(Module &, Function &Old, FunctionType *NewTy) const;<br>};<br><br>void FunctionDuplication::<wbr>getAnalysisUsage(AnalysisUsage &AU) const {<br> ModulePass::getAnalysisUsage(<wbr>AU);<br>}<br><br>Function *FunctionDuplication::<wbr>duplicate(Module &M, Function &Old,<br> <wbr> FunctionType *NewTy) const {<br> Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);<br> New->setAttributes(Old.<wbr>getAttributes());<br> New->setCallingConv(Old.<wbr>getCallingConv());<br><br> // Map old arguments to the new arguments.<br> ValueToValueMapTy VMap;<br> for (auto OldFI = Old.arg_begin(), OldFE = Old.arg_end(),<br> NewFI = New->arg_begin();<br> OldFI != OldFE; ++OldFI, ++NewFI) {<br> Argument &OldA = *OldFI;<br> Argument &NewA = *NewFI;<br> NewA.setName(OldA.getName());<br> VMap[&OldA] = &NewA;<br> }<br><br> SmallVector<ReturnInst *, 16> Returns;<br> CloneAndPruneFunctionInto(New, &Old, VMap, true, Returns);<br><br> return New;<br>}<br><br>bool FunctionDuplication::<wbr>runOnModule(Module &M) {<br> DataLayout const &DL = M.getDataLayout();<br> bool Modified = false;<br><br> std::vector<Function *> Functions;<br> for (auto &Fn : M.functions()) {<br> Functions.push_back(&Fn);<br> }<br><br> for (auto *F : Functions) {<br> if (F->size() > 0) {<br> dbgs() << "duplicating " << F->getName() << "\n";<br><br> duplicate(M, *F, F->getFunctionType());<br> Modified = true;<br> }<br> }<br><br> return Modified;<br>}<br><br>char FunctionDuplication::ID = 0;<br>INITIALIZE_PASS(<wbr>FunctionDuplication, "dupl", "Duplicate every function", false,<br> false)<br>ModulePass *<wbr>createFunctionDuplicationPass(<wbr>void) {<br> return new FunctionDuplication();<br>}<br></font><br></div></div>
<br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">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/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr">-- <div>Peter</div></div></div>
</div>