From 453ce91dbcf25f80fe84a55f348b1c19cb04aa95 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Tue, 25 Nov 2014 04:43:59 +0000 Subject: [PATCH] Link the type of aliases. They are not more or less "well typed" than GlobalVariables. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@222725 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Linker/LinkModules.cpp | 7 +++++-- test/Linker/Inputs/type-unique-alias.ll | 4 ++++ test/Linker/type-unique-alias.ll | 10 ++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 test/Linker/Inputs/type-unique-alias.ll create mode 100644 test/Linker/type-unique-alias.ll diff --git a/lib/Linker/LinkModules.cpp b/lib/Linker/LinkModules.cpp index 9664e3f5618..a8dc324daa2 100644 --- a/lib/Linker/LinkModules.cpp +++ b/lib/Linker/LinkModules.cpp @@ -786,6 +786,11 @@ void ModuleLinker::computeTypeMapping() { TypeMap.addTypeMapping(DGV->getType(), SGV.getType()); } + for (GlobalValue &SGV : SrcM->aliases()) { + if (GlobalValue *DGV = getLinkedToGlobal(&SGV)) + TypeMap.addTypeMapping(DGV->getType(), SGV.getType()); + } + // Incorporate types by name, scanning all the types in the source module. // At this point, the destination module may have a type "%foo = { i32 }" for // example. When the source module got loaded into the same LLVMContext, if @@ -829,8 +834,6 @@ void ModuleLinker::computeTypeMapping() { TypeMap.addTypeMapping(DST, ST); } - // Don't bother incorporating aliases, they aren't generally typed well. - // Now that we have discovered all of the type equivalences, get a body for // any 'opaque' types in the dest module that are now resolved. TypeMap.linkDefinedTypeBodies(); diff --git a/test/Linker/Inputs/type-unique-alias.ll b/test/Linker/Inputs/type-unique-alias.ll new file mode 100644 index 00000000000..3ee162ccfcf --- /dev/null +++ b/test/Linker/Inputs/type-unique-alias.ll @@ -0,0 +1,4 @@ +%u = type { i8 } + +@g2 = global %u zeroinitializer +@a = weak alias %u* @g2 diff --git a/test/Linker/type-unique-alias.ll b/test/Linker/type-unique-alias.ll new file mode 100644 index 00000000000..e43450fbbeb --- /dev/null +++ b/test/Linker/type-unique-alias.ll @@ -0,0 +1,10 @@ +; RUN: llvm-link -S %s %p/Inputs/type-unique-alias.ll | FileCheck %s + +%t = type { i8 } + +@g = global %t zeroinitializer +@a = weak alias %t* @g + +; CHECK: @g = global %t zeroinitializer +; CHECK: @g2 = global %t zeroinitializer +; CHECK: @a = weak alias %t* @g -- 2.34.1