aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/CloneModule.cpp
diff options
context:
space:
mode:
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-02-10 15:23:53 -0800
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>2021-02-10 16:53:21 -0800
commitfa35c1f80f0ea080a7cbc581416929b0a654f25c (patch)
tree8d867ee62c0769a96ec8858ffbf1432bfe85714d /llvm/lib/Transforms/Utils/CloneModule.cpp
parentedd365c7098d212172b6e94a793910a8e1a0f521 (diff)
downloadllvm-fa35c1f80f0ea080a7cbc581416929b0a654f25c.zip
llvm-fa35c1f80f0ea080a7cbc581416929b0a654f25c.tar.gz
llvm-fa35c1f80f0ea080a7cbc581416929b0a654f25c.tar.bz2
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.
Diffstat (limited to 'llvm/lib/Transforms/Utils/CloneModule.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/CloneModule.cpp8
1 files changed, 6 insertions, 2 deletions
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<Module> llvm::CloneModule(
SmallVector<std::pair<unsigned, MDNode *>, 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;