[llvm] r222172 - Factor common code it Linker::init.
Rafael Espindola
rafael.espindola at gmail.com
Mon Nov 17 12:51:02 PST 2014
Author: rafael
Date: Mon Nov 17 14:51:01 2014
New Revision: 222172
URL: http://llvm.org/viewvc/llvm-project?rev=222172&view=rev
Log:
Factor common code it Linker::init.
The TypeFinder was not being used in one of the constructors.
Modified:
llvm/trunk/include/llvm/Linker/Linker.h
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/unittests/Linker/CMakeLists.txt
llvm/trunk/unittests/Linker/LinkModulesTest.cpp
Modified: llvm/trunk/include/llvm/Linker/Linker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker/Linker.h?rev=222172&r1=222171&r2=222172&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Linker/Linker.h (original)
+++ llvm/trunk/include/llvm/Linker/Linker.h Mon Nov 17 14:51:01 2014
@@ -45,6 +45,7 @@ class Linker {
static bool LinkModules(Module *Dest, Module *Src);
private:
+ void init(Module *M, DiagnosticHandlerFunction DiagnosticHandler);
Module *Composite;
SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
DiagnosticHandlerFunction DiagnosticHandler;
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=222172&r1=222171&r2=222172&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Nov 17 14:51:01 2014
@@ -1594,18 +1594,25 @@ bool ModuleLinker::run() {
return false;
}
-Linker::Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler)
- : Composite(M), DiagnosticHandler(DiagnosticHandler) {}
+void Linker::init(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
+ this->Composite = M;
+ this->DiagnosticHandler = DiagnosticHandler;
-Linker::Linker(Module *M)
- : Composite(M), DiagnosticHandler([this](const DiagnosticInfo &DI) {
- Composite->getContext().diagnose(DI);
- }) {
TypeFinder StructTypes;
StructTypes.run(*M, true);
IdentifiedStructTypes.insert(StructTypes.begin(), StructTypes.end());
}
+Linker::Linker(Module *M, DiagnosticHandlerFunction DiagnosticHandler) {
+ init(M, DiagnosticHandler);
+}
+
+Linker::Linker(Module *M) {
+ init(M, [this](const DiagnosticInfo &DI) {
+ Composite->getContext().diagnose(DI);
+ });
+}
+
Linker::~Linker() {
}
Modified: llvm/trunk/unittests/Linker/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Linker/CMakeLists.txt?rev=222172&r1=222171&r2=222172&view=diff
==============================================================================
--- llvm/trunk/unittests/Linker/CMakeLists.txt (original)
+++ llvm/trunk/unittests/Linker/CMakeLists.txt Mon Nov 17 14:51:01 2014
@@ -1,4 +1,5 @@
set(LLVM_LINK_COMPONENTS
+ AsmParser
core
linker
)
Modified: llvm/trunk/unittests/Linker/LinkModulesTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Linker/LinkModulesTest.cpp?rev=222172&r1=222171&r2=222172&view=diff
==============================================================================
--- llvm/trunk/unittests/Linker/LinkModulesTest.cpp (original)
+++ llvm/trunk/unittests/Linker/LinkModulesTest.cpp Mon Nov 17 14:51:01 2014
@@ -7,12 +7,14 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/AsmParser/Parser.h"
#include "llvm/Linker/Linker.h"
#include "llvm/IR/BasicBlock.h"
#include "llvm/IR/DataLayout.h"
#include "llvm/IR/Function.h"
#include "llvm/IR/IRBuilder.h"
#include "llvm/IR/Module.h"
+#include "llvm/Support/SourceMgr.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -157,4 +159,22 @@ TEST_F(LinkModuleTest, EmptyModule2) {
Linker::LinkModules(InternalM.get(), EmptyM.get());
}
+TEST_F(LinkModuleTest, TypeMerge) {
+ LLVMContext C;
+ SMDiagnostic Err;
+
+ const char *M1Str = "%t = type {i32}\n"
+ "@t1 = weak global %t zeroinitializer\n";
+ std::unique_ptr<Module> M1 = parseAssemblyString(M1Str, Err, C);
+
+ const char *M2Str = "%t = type {i32}\n"
+ "@t2 = weak global %t zeroinitializer\n";
+ std::unique_ptr<Module> M2 = parseAssemblyString(M2Str, Err, C);
+
+ Linker::LinkModules(M1.get(), M2.get(), [](const llvm::DiagnosticInfo &){});
+
+ EXPECT_EQ(M1->getNamedGlobal("t1")->getType(),
+ M1->getNamedGlobal("t2")->getType());
+}
+
} // end anonymous namespace
More information about the llvm-commits
mailing list