From fa35c1f80f0ea080a7cbc581416929b0a654f25c Mon Sep 17 00:00:00 2001 From: "Duncan P. N. Exon Smith" Date: Wed, 10 Feb 2021 15:23:53 -0800 Subject: ValueMapper: Rename RF_MoveDistinctMDs => RF_ReuseAndMutateDistinctMDs, NFC Rename the `RF_MoveDistinctMDs` flag passed into `MapValue` and `MapMetadata` to `RF_ReuseAndMutateDistinctMDs` in order to more precisely describe its effect and clarify the header documentation. Found this while helping to investigate PR48841, which pointed out an unsound use of the flag in `CloneModule()`. For now I've just added a FIXME there, but I'm hopeful that the new (more precise) name will prevent other similar errors. --- llvm/lib/Transforms/Utils/CloneModule.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Transforms/Utils/CloneModule.cpp') diff --git a/llvm/lib/Transforms/Utils/CloneModule.cpp b/llvm/lib/Transforms/Utils/CloneModule.cpp index 6de679b..487cd4e 100644 --- a/llvm/lib/Transforms/Utils/CloneModule.cpp +++ b/llvm/lib/Transforms/Utils/CloneModule.cpp @@ -120,9 +120,13 @@ std::unique_ptr llvm::CloneModule( SmallVector, 1> MDs; G.getAllMetadata(MDs); + + // FIXME: Stop using RF_ReuseAndMutateDistinctMDs here, since it's unsound + // to mutate metadata that is still referenced by the source module unless + // the source is about to be discarded (see IRMover for a valid use). for (auto MD : MDs) - GV->addMetadata(MD.first, - *MapMetadata(MD.second, VMap, RF_MoveDistinctMDs)); + GV->addMetadata(MD.first, *MapMetadata(MD.second, VMap, + RF_ReuseAndMutateDistinctMDs)); if (G.isDeclaration()) continue; -- cgit v1.1