Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -11,6 +11,7 @@ #include "LinkDiagnosticInfo.h" #include "llvm/ADT/SetVector.h" #include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringSet.h" #include "llvm/ADT/Triple.h" #include "llvm/IR/Constants.h" #include "llvm/IR/DebugInfo.h" @@ -992,6 +993,27 @@ if (&NMD == SrcModFlags) continue; NamedMDNode *DestNMD = DstM.getOrInsertNamedMetadata(NMD.getName()); + + if (NMD.getName() == "llvm.ident") { + StringSet<> UniqueIdents; + + // Unique the compiler IDs linked together. + for (const MDNode *DestID : DestNMD->operands()) { + if (const MDString *VerStr + = cast_or_null(DestID->getOperand(0))) + UniqueIdents.insert(VerStr->getString()); + } + + for (const MDNode *Op : NMD.operands()) { + if (const MDString *VerStr = cast_or_null(Op->getOperand(0))) { + if (UniqueIdents.insert(VerStr->getString()).second) + DestNMD->addOperand(Mapper.mapMDNode(*Op)); + } + } + + continue; + } + // Add Src elements into Dest node. for (const MDNode *Op : NMD.operands()) DestNMD->addOperand(Mapper.mapMDNode(*Op)); Index: test/Linker/ident.ll =================================================================== --- test/Linker/ident.ll +++ test/Linker/ident.ll @@ -1,6 +1,6 @@ -; RUN: llvm-link %S/Inputs/ident.a.ll %S/Inputs/ident.b.ll -S | FileCheck %s +; RUN: llvm-link %S/Inputs/ident.a.ll %S/Inputs/ident.b.ll %S/Inputs/ident.c.ll -S | FileCheck %s -; Verify that multiple input llvm.ident metadata are linked together. +; Verify that multiple input llvm.ident metadata are linked together, but uniqued. ; CHECK-DAG: !llvm.ident = !{!0, !1, !2} ; CHECK-DAG: "Compiler V1"