Index: include/llvm/Linker/IRMover.h =================================================================== --- include/llvm/Linker/IRMover.h +++ include/llvm/Linker/IRMover.h @@ -61,6 +61,7 @@ }; IRMover(Module &M); + IRMover(Module &M, bool OnlyNamedTypes); typedef std::function ValueAdder; Index: include/llvm/Linker/Linker.h =================================================================== --- include/llvm/Linker/Linker.h +++ include/llvm/Linker/Linker.h @@ -30,9 +30,11 @@ None = 0, OverrideFromSrc = (1 << 0), LinkOnlyNeeded = (1 << 1), + DontLinkUnnamedTypes = (1 << 2), }; Linker(Module &M); + Linker(Module &M, unsigned Flags); /// \brief Link \p Src into the composite. /// Index: lib/Linker/IRMover.cpp =================================================================== --- lib/Linker/IRMover.cpp +++ lib/Linker/IRMover.cpp @@ -1411,9 +1411,10 @@ return I == NonOpaqueStructTypes.end() ? false : *I == Ty; } -IRMover::IRMover(Module &M) : Composite(M) { +IRMover::IRMover(Module &M) : IRMover::IRMover(M, false) {} +IRMover::IRMover(Module &M, bool OnlyNamedTypes) : Composite(M) { TypeFinder StructTypes; - StructTypes.run(M, /* OnlyNamed */ false); + StructTypes.run(M, OnlyNamedTypes); for (StructType *Ty : StructTypes) { if (Ty->isOpaque()) IdentifiedStructTypes.addOpaque(Ty); Index: lib/Linker/LinkModules.cpp =================================================================== --- lib/Linker/LinkModules.cpp +++ lib/Linker/LinkModules.cpp @@ -561,6 +561,9 @@ Linker::Linker(Module &M) : Mover(M) {} +Linker::Linker(Module &M, unsigned Flags) : + Mover(M, (Flags & DontLinkUnnamedTypes) != 0) {} + bool Linker::linkInModule( std::unique_ptr Src, unsigned Flags, std::function &)> InternalizeCallback) { @@ -581,7 +584,7 @@ bool Linker::linkModules( Module &Dest, std::unique_ptr Src, unsigned Flags, std::function &)> InternalizeCallback) { - Linker L(Dest); + Linker L(Dest, Flags); return L.linkInModule(std::move(Src), Flags, std::move(InternalizeCallback)); }