[llvm] r222725 - Link the type of aliases.

Rafael Espindola rafael.espindola at gmail.com
Mon Nov 24 20:44:00 PST 2014


Author: rafael
Date: Mon Nov 24 22:43:59 2014
New Revision: 222725

URL: http://llvm.org/viewvc/llvm-project?rev=222725&view=rev
Log:
Link the type of aliases.

They are not more or less "well typed" than GlobalVariables.

Added:
    llvm/trunk/test/Linker/Inputs/type-unique-alias.ll
    llvm/trunk/test/Linker/type-unique-alias.ll
Modified:
    llvm/trunk/lib/Linker/LinkModules.cpp

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=222725&r1=222724&r2=222725&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Mon Nov 24 22:43:59 2014
@@ -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();

Added: llvm/trunk/test/Linker/Inputs/type-unique-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/Inputs/type-unique-alias.ll?rev=222725&view=auto
==============================================================================
--- llvm/trunk/test/Linker/Inputs/type-unique-alias.ll (added)
+++ llvm/trunk/test/Linker/Inputs/type-unique-alias.ll Mon Nov 24 22:43:59 2014
@@ -0,0 +1,4 @@
+%u = type { i8 }
+
+ at g2 = global %u zeroinitializer
+ at a = weak alias %u* @g2

Added: llvm/trunk/test/Linker/type-unique-alias.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/type-unique-alias.ll?rev=222725&view=auto
==============================================================================
--- llvm/trunk/test/Linker/type-unique-alias.ll (added)
+++ llvm/trunk/test/Linker/type-unique-alias.ll Mon Nov 24 22:43:59 2014
@@ -0,0 +1,10 @@
+; RUN: llvm-link -S %s %p/Inputs/type-unique-alias.ll | FileCheck %s
+
+%t = type { i8 }
+
+ at g = global %t zeroinitializer
+ at a = weak alias %t* @g
+
+; CHECK: @g = global %t zeroinitializer
+; CHECK: @g2 = global %t zeroinitializer
+; CHECK: @a = weak alias %t* @g





More information about the llvm-commits mailing list