diff options
author | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-24 17:42:21 +0000 |
---|---|---|
committer | Peter Collingbourne <peter@pcc.me.uk> | 2016-06-24 17:42:21 +0000 |
commit | 43c5139fd2b97f6a76839c6fb9e8c4acddceb78a (patch) | |
tree | c0209ab79c37ded2b7bdfa21fc1bb35cedab1dee /lib/Linker/IRMover.cpp | |
parent | b892430f0968ae7f80f0d6fe2883f1ad6c452a22 (diff) |
Linker: Copy metadata when linking declarations.
Differential Revision: http://reviews.llvm.org/D21624
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@273692 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Linker/IRMover.cpp')
-rw-r--r-- | lib/Linker/IRMover.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/Linker/IRMover.cpp b/lib/Linker/IRMover.cpp index c82fc8b3dff..2f3813f6184 100644 --- a/lib/Linker/IRMover.cpp +++ b/lib/Linker/IRMover.cpp @@ -638,6 +638,12 @@ GlobalValue *IRLinker::copyGlobalValueProto(const GlobalValue *SGV, NewGV->copyAttributesFrom(SGV); + if (auto *NewGO = dyn_cast<GlobalObject>(NewGV)) { + // Metadata for global variables and function declarations is copied eagerly. + if (isa<GlobalVariable>(SGV) || SGV->isDeclaration()) + NewGO->copyMetadata(cast<GlobalObject>(SGV)); + } + // Remove these copied constants in case this stays a declaration, since // they point to the source module. If the def is linked the values will // be mapped in during linkFunctionBody. @@ -961,10 +967,7 @@ Error IRLinker::linkFunctionBody(Function &Dst, Function &Src) { Dst.setPersonalityFn(Src.getPersonalityFn()); // Copy over the metadata attachments without remapping. - SmallVector<std::pair<unsigned, MDNode *>, 8> MDs; - Src.getAllMetadata(MDs); - for (const auto &I : MDs) - Dst.setMetadata(I.first, I.second); + Dst.copyMetadata(&Src); // Steal arguments and splice the body of Src into Dst. Dst.stealArgumentListFrom(Src); |