[PATCH] D36082: [Cloning] Move distinct GlobalVariable debug info metadata in CloneModule

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 10 12:45:06 PST 2021


dexonsmith added inline comments.


================
Comment at: llvm/trunk/lib/Transforms/Utils/CloneModule.cpp:189
     for (unsigned i = 0, e = NMD.getNumOperands(); i != e; ++i)
       NewNMD->addOperand(MapMetadata(NMD.getOperand(i), VMap));
   }
----------------
rtereshin wrote:
> I'm hitting a case with an older version of LLVM I can't unfortunately expose as a test: this part of `CloneModule` while iterating over operands of `!llvm.dbg.cu`, which are `DICompileUnit`s, sometimes duplicates a `DICompileUnit`. Not always, strangely enough. The duplicate itself is completely redundant, but it also explicitly breaks the debug info as that CU doesn't get included into `llvm.dbg.cu` list. Adding `RF_MoveDistinctMDs` flag to this `MapMetadata` call solves the problem.
> 
> Do you think you could take a look and see if we need `RF_MoveDistinctMDs` here as well as above?
> Adding RF_MoveDistinctMDs flag to this MapMetadata call solves the problem.

Doing so will only paper over the problem, and invalidate the source module being cloned.

Whatever is happening here may be the key to understanding both bugs. `MapMetadata` should clone metadata, and `NewNMD` should reference the clone instead of the original. It sounds like some caller is not going through `VMap` and is getting a different copy.




Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D36082/new/

https://reviews.llvm.org/D36082



More information about the llvm-commits mailing list