<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">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.git/llvm-carte/llvm-4.0.0/llvm/lib/IR/Verifier.cpp:4500: virtual bool {anonymous}::VerifierLegacyPass::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/Cloning.h"<br>#include <vector><br>using namespace llvm;<br><br>struct FunctionDuplication;<br><br>namespace llvm {<br>void initializeFunctionDuplicationPass(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::getAnalysisUsage(AnalysisUsage &AU) const {<br>  ModulePass::getAnalysisUsage(AU);<br>}<br><br>Function *FunctionDuplication::duplicate(Module &M, Function &Old,<br>                                         FunctionType *NewTy) const {<br>  Function *New = Function::Create(NewTy, Old.getLinkage(), "", &M);<br>  New->setAttributes(Old.getAttributes());<br>  New->setCallingConv(Old.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::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(FunctionDuplication, "dupl", "Duplicate every function", false,<br>                false)<br>ModulePass *createFunctionDuplicationPass(void) {<br>  return new FunctionDuplication();<br>}<br></font><br></div></div>