2014-01-16 14:29:36 +08:00
|
|
|
//===- llvm/unittest/Linker/LinkModulesTest.cpp - IRBuilder tests ---------===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2017-06-06 19:06:56 +08:00
|
|
|
#include "llvm-c/Core.h"
|
|
|
|
#include "llvm-c/Linker.h"
|
2015-08-04 01:09:38 +08:00
|
|
|
#include "llvm/ADT/STLExtras.h"
|
2014-11-18 04:51:01 +08:00
|
|
|
#include "llvm/AsmParser/Parser.h"
|
2014-01-16 14:29:36 +08:00
|
|
|
#include "llvm/IR/BasicBlock.h"
|
|
|
|
#include "llvm/IR/DataLayout.h"
|
|
|
|
#include "llvm/IR/Function.h"
|
2014-03-04 18:07:28 +08:00
|
|
|
#include "llvm/IR/IRBuilder.h"
|
2014-01-16 14:29:36 +08:00
|
|
|
#include "llvm/IR/Module.h"
|
2015-01-14 19:23:27 +08:00
|
|
|
#include "llvm/Linker/Linker.h"
|
2014-11-18 04:51:01 +08:00
|
|
|
#include "llvm/Support/SourceMgr.h"
|
2014-01-16 14:29:36 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
class LinkModuleTest : public testing::Test {
|
|
|
|
protected:
|
2015-04-11 10:11:45 +08:00
|
|
|
void SetUp() override {
|
2014-01-16 14:29:36 +08:00
|
|
|
M.reset(new Module("MyModule", Ctx));
|
2014-04-29 23:52:46 +08:00
|
|
|
FunctionType *FTy = FunctionType::get(
|
|
|
|
Type::getInt8PtrTy(Ctx), Type::getInt32Ty(Ctx), false /*=isVarArg*/);
|
2014-01-16 14:29:36 +08:00
|
|
|
F = Function::Create(FTy, Function::ExternalLinkage, "ba_func", M.get());
|
|
|
|
F->setCallingConv(CallingConv::C);
|
|
|
|
|
|
|
|
EntryBB = BasicBlock::Create(Ctx, "entry", F);
|
|
|
|
SwitchCase1BB = BasicBlock::Create(Ctx, "switch.case.1", F);
|
|
|
|
SwitchCase2BB = BasicBlock::Create(Ctx, "switch.case.2", F);
|
|
|
|
ExitBB = BasicBlock::Create(Ctx, "exit", F);
|
|
|
|
|
2015-03-25 07:34:31 +08:00
|
|
|
AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3);
|
2014-01-16 14:29:36 +08:00
|
|
|
|
|
|
|
GV = new GlobalVariable(*M.get(), AT, false /*=isConstant*/,
|
2014-06-09 06:29:17 +08:00
|
|
|
GlobalValue::InternalLinkage, nullptr,"switch.bas");
|
2014-01-16 14:29:36 +08:00
|
|
|
|
|
|
|
// Global Initializer
|
2014-04-29 23:52:46 +08:00
|
|
|
std::vector<Constant *> Init;
|
2014-01-16 14:29:36 +08:00
|
|
|
Constant *SwitchCase1BA = BlockAddress::get(SwitchCase1BB);
|
|
|
|
Init.push_back(SwitchCase1BA);
|
|
|
|
|
|
|
|
Constant *SwitchCase2BA = BlockAddress::get(SwitchCase2BB);
|
|
|
|
Init.push_back(SwitchCase2BA);
|
|
|
|
|
|
|
|
ConstantInt *One = ConstantInt::get(Type::getInt32Ty(Ctx), 1);
|
2014-04-29 23:52:46 +08:00
|
|
|
Constant *OnePtr = ConstantExpr::getCast(Instruction::IntToPtr, One,
|
|
|
|
Type::getInt8PtrTy(Ctx));
|
2014-01-16 14:29:36 +08:00
|
|
|
Init.push_back(OnePtr);
|
|
|
|
|
|
|
|
GV->setInitializer(ConstantArray::get(AT, Init));
|
|
|
|
}
|
|
|
|
|
2015-04-11 10:11:45 +08:00
|
|
|
void TearDown() override { M.reset(); }
|
2014-01-16 14:29:36 +08:00
|
|
|
|
2014-04-29 23:52:27 +08:00
|
|
|
LLVMContext Ctx;
|
2014-03-06 13:51:42 +08:00
|
|
|
std::unique_ptr<Module> M;
|
2014-01-16 14:29:36 +08:00
|
|
|
Function *F;
|
2015-03-25 07:34:31 +08:00
|
|
|
ArrayType *AT;
|
2014-01-16 14:29:36 +08:00
|
|
|
GlobalVariable *GV;
|
|
|
|
BasicBlock *EntryBB;
|
|
|
|
BasicBlock *SwitchCase1BB;
|
|
|
|
BasicBlock *SwitchCase2BB;
|
|
|
|
BasicBlock *ExitBB;
|
|
|
|
};
|
|
|
|
|
2015-12-15 07:17:03 +08:00
|
|
|
static void expectNoDiags(const DiagnosticInfo &DI, void *C) {
|
|
|
|
EXPECT_TRUE(false);
|
|
|
|
}
|
2015-12-05 06:08:53 +08:00
|
|
|
|
2014-01-16 14:29:36 +08:00
|
|
|
TEST_F(LinkModuleTest, BlockAddress) {
|
|
|
|
IRBuilder<> Builder(EntryBB);
|
|
|
|
|
2014-04-29 23:52:46 +08:00
|
|
|
std::vector<Value *> GEPIndices;
|
2014-01-16 14:29:36 +08:00
|
|
|
GEPIndices.push_back(ConstantInt::get(Type::getInt32Ty(Ctx), 0));
|
2015-10-21 02:30:20 +08:00
|
|
|
GEPIndices.push_back(&*F->arg_begin());
|
2014-01-16 14:29:36 +08:00
|
|
|
|
2015-03-25 07:34:31 +08:00
|
|
|
Value *GEP = Builder.CreateGEP(AT, GV, GEPIndices, "switch.gep");
|
2014-01-16 14:29:36 +08:00
|
|
|
Value *Load = Builder.CreateLoad(GEP, "switch.load");
|
|
|
|
|
|
|
|
Builder.CreateRet(Load);
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(SwitchCase1BB);
|
|
|
|
Builder.CreateBr(ExitBB);
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(SwitchCase2BB);
|
|
|
|
Builder.CreateBr(ExitBB);
|
|
|
|
|
|
|
|
Builder.SetInsertPoint(ExitBB);
|
|
|
|
Builder.CreateRet(ConstantPointerNull::get(Type::getInt8PtrTy(Ctx)));
|
|
|
|
|
2014-04-29 23:52:27 +08:00
|
|
|
Module *LinkedModule = new Module("MyModuleLinked", Ctx);
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2015-12-17 07:16:33 +08:00
|
|
|
Linker::linkModules(*LinkedModule, std::move(M));
|
2014-01-16 14:29:36 +08:00
|
|
|
|
|
|
|
// Check that the global "@switch.bas" is well-formed.
|
|
|
|
const GlobalVariable *LinkedGV = LinkedModule->getNamedGlobal("switch.bas");
|
|
|
|
const Constant *Init = LinkedGV->getInitializer();
|
|
|
|
|
|
|
|
// @switch.bas = internal global [3 x i8*]
|
|
|
|
// [i8* blockaddress(@ba_func, %switch.case.1),
|
|
|
|
// i8* blockaddress(@ba_func, %switch.case.2),
|
|
|
|
// i8* inttoptr (i32 1 to i8*)]
|
|
|
|
|
|
|
|
ArrayType *AT = ArrayType::get(Type::getInt8PtrTy(Ctx), 3);
|
|
|
|
EXPECT_EQ(AT, Init->getType());
|
|
|
|
|
|
|
|
Value *Elem = Init->getOperand(0);
|
|
|
|
ASSERT_TRUE(isa<BlockAddress>(Elem));
|
|
|
|
EXPECT_EQ(cast<BlockAddress>(Elem)->getFunction(),
|
|
|
|
LinkedModule->getFunction("ba_func"));
|
|
|
|
EXPECT_EQ(cast<BlockAddress>(Elem)->getBasicBlock()->getParent(),
|
|
|
|
LinkedModule->getFunction("ba_func"));
|
2014-04-29 23:52:46 +08:00
|
|
|
|
2014-01-16 14:29:36 +08:00
|
|
|
Elem = Init->getOperand(1);
|
|
|
|
ASSERT_TRUE(isa<BlockAddress>(Elem));
|
|
|
|
EXPECT_EQ(cast<BlockAddress>(Elem)->getFunction(),
|
|
|
|
LinkedModule->getFunction("ba_func"));
|
|
|
|
EXPECT_EQ(cast<BlockAddress>(Elem)->getBasicBlock()->getParent(),
|
|
|
|
LinkedModule->getFunction("ba_func"));
|
|
|
|
|
|
|
|
delete LinkedModule;
|
|
|
|
}
|
|
|
|
|
2015-06-13 07:26:42 +08:00
|
|
|
static Module *getExternal(LLVMContext &Ctx, StringRef FuncName) {
|
|
|
|
// Create a module with an empty externally-linked function
|
|
|
|
Module *M = new Module("ExternalModule", Ctx);
|
|
|
|
FunctionType *FTy = FunctionType::get(
|
|
|
|
Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false /*=isVarArgs*/);
|
|
|
|
|
|
|
|
Function *F =
|
|
|
|
Function::Create(FTy, Function::ExternalLinkage, FuncName, M);
|
|
|
|
F->setCallingConv(CallingConv::C);
|
|
|
|
|
|
|
|
BasicBlock *BB = BasicBlock::Create(Ctx, "", F);
|
|
|
|
IRBuilder<> Builder(BB);
|
|
|
|
Builder.CreateRetVoid();
|
|
|
|
return M;
|
|
|
|
}
|
|
|
|
|
2014-10-28 08:24:16 +08:00
|
|
|
static Module *getInternal(LLVMContext &Ctx) {
|
2014-01-16 14:29:36 +08:00
|
|
|
Module *InternalM = new Module("InternalModule", Ctx);
|
2014-04-29 23:52:46 +08:00
|
|
|
FunctionType *FTy = FunctionType::get(
|
|
|
|
Type::getVoidTy(Ctx), Type::getInt8PtrTy(Ctx), false /*=isVarArgs*/);
|
2014-01-16 14:29:36 +08:00
|
|
|
|
2014-10-28 08:24:16 +08:00
|
|
|
Function *F =
|
|
|
|
Function::Create(FTy, Function::InternalLinkage, "bar", InternalM);
|
2014-01-16 14:29:36 +08:00
|
|
|
F->setCallingConv(CallingConv::C);
|
|
|
|
|
|
|
|
BasicBlock *BB = BasicBlock::Create(Ctx, "", F);
|
|
|
|
IRBuilder<> Builder(BB);
|
|
|
|
Builder.CreateRetVoid();
|
|
|
|
|
|
|
|
StructType *STy = StructType::create(Ctx, PointerType::get(FTy, 0));
|
|
|
|
|
|
|
|
GlobalVariable *GV =
|
2014-04-29 23:52:46 +08:00
|
|
|
new GlobalVariable(*InternalM, STy, false /*=isConstant*/,
|
2014-06-09 06:29:17 +08:00
|
|
|
GlobalValue::InternalLinkage, nullptr, "g");
|
2014-01-16 14:29:36 +08:00
|
|
|
|
|
|
|
GV->setInitializer(ConstantStruct::get(STy, F));
|
2014-10-28 08:24:16 +08:00
|
|
|
return InternalM;
|
|
|
|
}
|
2014-01-16 14:29:36 +08:00
|
|
|
|
2014-10-28 08:24:16 +08:00
|
|
|
TEST_F(LinkModuleTest, EmptyModule) {
|
|
|
|
std::unique_ptr<Module> InternalM(getInternal(Ctx));
|
|
|
|
std::unique_ptr<Module> EmptyM(new Module("EmptyModule1", Ctx));
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2015-12-17 07:16:33 +08:00
|
|
|
Linker::linkModules(*EmptyM, std::move(InternalM));
|
2014-10-28 08:24:16 +08:00
|
|
|
}
|
2014-01-16 14:29:36 +08:00
|
|
|
|
2014-10-28 08:24:16 +08:00
|
|
|
TEST_F(LinkModuleTest, EmptyModule2) {
|
|
|
|
std::unique_ptr<Module> InternalM(getInternal(Ctx));
|
|
|
|
std::unique_ptr<Module> EmptyM(new Module("EmptyModule1", Ctx));
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2015-12-17 07:16:33 +08:00
|
|
|
Linker::linkModules(*InternalM, std::move(EmptyM));
|
2014-01-16 14:29:36 +08:00
|
|
|
}
|
|
|
|
|
2014-11-18 04:51:01 +08:00
|
|
|
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);
|
|
|
|
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2015-12-17 07:16:33 +08:00
|
|
|
Linker::linkModules(*M1, std::move(M2));
|
2014-11-18 04:51:01 +08:00
|
|
|
|
|
|
|
EXPECT_EQ(M1->getNamedGlobal("t1")->getType(),
|
|
|
|
M1->getNamedGlobal("t2")->getType());
|
|
|
|
}
|
|
|
|
|
2015-12-17 07:16:33 +08:00
|
|
|
TEST_F(LinkModuleTest, NewCAPISuccess) {
|
|
|
|
std::unique_ptr<Module> DestM(getExternal(Ctx, "foo"));
|
|
|
|
std::unique_ptr<Module> SourceM(getExternal(Ctx, "bar"));
|
|
|
|
LLVMBool Result =
|
|
|
|
LLVMLinkModules2(wrap(DestM.get()), wrap(SourceM.release()));
|
|
|
|
EXPECT_EQ(0, Result);
|
|
|
|
// "bar" is present in destination module
|
|
|
|
EXPECT_NE(nullptr, DestM->getFunction("bar"));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void diagnosticHandler(LLVMDiagnosticInfoRef DI, void *C) {
|
|
|
|
auto *Err = reinterpret_cast<std::string *>(C);
|
|
|
|
char *CErr = LLVMGetDiagInfoDescription(DI);
|
|
|
|
*Err = CErr;
|
|
|
|
LLVMDisposeMessage(CErr);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LinkModuleTest, NewCAPIFailure) {
|
|
|
|
// Symbol clash between two modules
|
|
|
|
LLVMContext Ctx;
|
|
|
|
std::string Err;
|
|
|
|
LLVMContextSetDiagnosticHandler(wrap(&Ctx), diagnosticHandler, &Err);
|
|
|
|
|
|
|
|
std::unique_ptr<Module> DestM(getExternal(Ctx, "foo"));
|
|
|
|
std::unique_ptr<Module> SourceM(getExternal(Ctx, "foo"));
|
|
|
|
LLVMBool Result =
|
|
|
|
LLVMLinkModules2(wrap(DestM.get()), wrap(SourceM.release()));
|
|
|
|
EXPECT_EQ(1, Result);
|
|
|
|
EXPECT_EQ("Linking globals named 'foo': symbol multiply defined!", Err);
|
|
|
|
}
|
|
|
|
|
2015-08-04 01:09:38 +08:00
|
|
|
TEST_F(LinkModuleTest, MoveDistinctMDs) {
|
|
|
|
LLVMContext C;
|
|
|
|
SMDiagnostic Err;
|
|
|
|
|
|
|
|
const char *SrcStr = "define void @foo() !attach !0 {\n"
|
|
|
|
"entry:\n"
|
|
|
|
" call void @llvm.md(metadata !1)\n"
|
|
|
|
" ret void, !attach !2\n"
|
|
|
|
"}\n"
|
|
|
|
"declare void @llvm.md(metadata)\n"
|
|
|
|
"!named = !{!3, !4}\n"
|
|
|
|
"!0 = distinct !{}\n"
|
|
|
|
"!1 = distinct !{}\n"
|
|
|
|
"!2 = distinct !{}\n"
|
|
|
|
"!3 = distinct !{}\n"
|
|
|
|
"!4 = !{!3}\n";
|
|
|
|
|
|
|
|
std::unique_ptr<Module> Src = parseAssemblyString(SrcStr, Err, C);
|
|
|
|
assert(Src);
|
|
|
|
ASSERT_TRUE(Src.get());
|
|
|
|
|
|
|
|
// Get the addresses of the Metadata before merging.
|
|
|
|
Function *F = &*Src->begin();
|
|
|
|
ASSERT_EQ("foo", F->getName());
|
|
|
|
BasicBlock *BB = &F->getEntryBlock();
|
|
|
|
auto *CI = cast<CallInst>(&BB->front());
|
|
|
|
auto *RI = cast<ReturnInst>(BB->getTerminator());
|
|
|
|
NamedMDNode *NMD = &*Src->named_metadata_begin();
|
|
|
|
|
|
|
|
MDNode *M0 = F->getMetadata("attach");
|
|
|
|
MDNode *M1 =
|
|
|
|
cast<MDNode>(cast<MetadataAsValue>(CI->getArgOperand(0))->getMetadata());
|
|
|
|
MDNode *M2 = RI->getMetadata("attach");
|
|
|
|
MDNode *M3 = NMD->getOperand(0);
|
|
|
|
MDNode *M4 = NMD->getOperand(1);
|
|
|
|
|
|
|
|
// Confirm a few things about the IR.
|
|
|
|
EXPECT_TRUE(M0->isDistinct());
|
|
|
|
EXPECT_TRUE(M1->isDistinct());
|
|
|
|
EXPECT_TRUE(M2->isDistinct());
|
|
|
|
EXPECT_TRUE(M3->isDistinct());
|
|
|
|
EXPECT_TRUE(M4->isUniqued());
|
|
|
|
EXPECT_EQ(M3, M4->getOperand(0));
|
|
|
|
|
|
|
|
// Link into destination module.
|
|
|
|
auto Dst = llvm::make_unique<Module>("Linked", C);
|
|
|
|
ASSERT_TRUE(Dst.get());
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2015-12-17 07:16:33 +08:00
|
|
|
Linker::linkModules(*Dst, std::move(Src));
|
2015-08-04 01:09:38 +08:00
|
|
|
|
|
|
|
// Check that distinct metadata was moved, not cloned. Even !4, the uniqued
|
|
|
|
// node, should effectively be moved, since its only operand hasn't changed.
|
|
|
|
F = &*Dst->begin();
|
|
|
|
BB = &F->getEntryBlock();
|
|
|
|
CI = cast<CallInst>(&BB->front());
|
|
|
|
RI = cast<ReturnInst>(BB->getTerminator());
|
|
|
|
NMD = &*Dst->named_metadata_begin();
|
|
|
|
|
|
|
|
EXPECT_EQ(M0, F->getMetadata("attach"));
|
|
|
|
EXPECT_EQ(M1, cast<MetadataAsValue>(CI->getArgOperand(0))->getMetadata());
|
|
|
|
EXPECT_EQ(M2, RI->getMetadata("attach"));
|
|
|
|
EXPECT_EQ(M3, NMD->getOperand(0));
|
|
|
|
EXPECT_EQ(M4, NMD->getOperand(1));
|
|
|
|
|
|
|
|
// Confirm a few things about the IR. This shouldn't have changed.
|
|
|
|
EXPECT_TRUE(M0->isDistinct());
|
|
|
|
EXPECT_TRUE(M1->isDistinct());
|
|
|
|
EXPECT_TRUE(M2->isDistinct());
|
|
|
|
EXPECT_TRUE(M3->isDistinct());
|
|
|
|
EXPECT_TRUE(M4->isUniqued());
|
|
|
|
EXPECT_EQ(M3, M4->getOperand(0));
|
|
|
|
}
|
|
|
|
|
2016-06-24 23:10:29 +08:00
|
|
|
TEST_F(LinkModuleTest, RemangleIntrinsics) {
|
|
|
|
LLVMContext C;
|
|
|
|
SMDiagnostic Err;
|
|
|
|
|
|
|
|
// We load two modules inside the same context C. In both modules there is a
|
|
|
|
// "struct.rtx_def" type. In the module loaded the second (Bar) this type will
|
|
|
|
// be renamed to "struct.rtx_def.0". Check that the intrinsics which have this
|
|
|
|
// type in the signature are properly remangled.
|
|
|
|
const char *FooStr =
|
|
|
|
"%struct.rtx_def = type { i16 }\n"
|
|
|
|
"define void @foo(%struct.rtx_def* %a, i8 %b, i32 %c) {\n"
|
2017-02-16 07:16:20 +08:00
|
|
|
" call void @llvm.memset.p0s_struct.rtx_defs.i32(%struct.rtx_def* %a, i8 %b, i32 %c, i32 4, i1 true)\n"
|
2016-06-24 23:10:29 +08:00
|
|
|
" ret void\n"
|
|
|
|
"}\n"
|
2017-02-16 07:16:20 +08:00
|
|
|
"declare void @llvm.memset.p0s_struct.rtx_defs.i32(%struct.rtx_def*, i8, i32, i32, i1)\n";
|
2016-06-24 23:10:29 +08:00
|
|
|
|
|
|
|
const char *BarStr =
|
|
|
|
"%struct.rtx_def = type { i16 }\n"
|
|
|
|
"define void @bar(%struct.rtx_def* %a, i8 %b, i32 %c) {\n"
|
2017-02-16 07:16:20 +08:00
|
|
|
" call void @llvm.memset.p0s_struct.rtx_defs.i32(%struct.rtx_def* %a, i8 %b, i32 %c, i32 4, i1 true)\n"
|
2016-06-24 23:10:29 +08:00
|
|
|
" ret void\n"
|
|
|
|
"}\n"
|
2017-02-16 07:16:20 +08:00
|
|
|
"declare void @llvm.memset.p0s_struct.rtx_defs.i32(%struct.rtx_def*, i8, i32, i32, i1)\n";
|
2016-06-24 23:10:29 +08:00
|
|
|
|
|
|
|
std::unique_ptr<Module> Foo = parseAssemblyString(FooStr, Err, C);
|
|
|
|
assert(Foo);
|
|
|
|
ASSERT_TRUE(Foo.get());
|
|
|
|
// Foo is loaded first, so the type and the intrinsic have theis original
|
|
|
|
// names.
|
2017-02-16 07:16:20 +08:00
|
|
|
ASSERT_TRUE(Foo->getFunction("llvm.memset.p0s_struct.rtx_defs.i32"));
|
|
|
|
ASSERT_FALSE(Foo->getFunction("llvm.memset.p0s_struct.rtx_defs.0.i32"));
|
2016-06-24 23:10:29 +08:00
|
|
|
|
|
|
|
std::unique_ptr<Module> Bar = parseAssemblyString(BarStr, Err, C);
|
|
|
|
assert(Bar);
|
|
|
|
ASSERT_TRUE(Bar.get());
|
|
|
|
// Bar is loaded after Foo, so the type is renamed to struct.rtx_def.0. Check
|
|
|
|
// that the intrinsic is also renamed.
|
2017-02-16 07:16:20 +08:00
|
|
|
ASSERT_FALSE(Bar->getFunction("llvm.memset.p0s_struct.rtx_defs.i32"));
|
|
|
|
ASSERT_TRUE(Bar->getFunction("llvm.memset.p0s_struct.rtx_def.0s.i32"));
|
2016-06-24 23:10:29 +08:00
|
|
|
|
|
|
|
// Link two modules together.
|
|
|
|
auto Dst = llvm::make_unique<Module>("Linked", C);
|
|
|
|
ASSERT_TRUE(Dst.get());
|
2017-09-16 05:12:13 +08:00
|
|
|
Ctx.setDiagnosticHandlerCallBack(expectNoDiags);
|
2016-06-24 23:10:29 +08:00
|
|
|
bool Failed = Linker::linkModules(*Foo, std::move(Bar));
|
|
|
|
ASSERT_FALSE(Failed);
|
|
|
|
|
|
|
|
// "struct.rtx_def" from Foo and "struct.rtx_def.0" from Bar are isomorphic
|
|
|
|
// types, so they must be uniquified by linker. Check that they use the same
|
|
|
|
// intrinsic definition.
|
2017-02-16 07:16:20 +08:00
|
|
|
Function *F = Foo->getFunction("llvm.memset.p0s_struct.rtx_defs.i32");
|
2016-06-24 23:10:29 +08:00
|
|
|
ASSERT_EQ(F->getNumUses(), (unsigned)2);
|
|
|
|
}
|
|
|
|
|
2014-01-16 14:29:36 +08:00
|
|
|
} // end anonymous namespace
|