OSDN Git Service

Keep unnamed_addr when linking.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 13 Jan 2011 05:12:34 +0000 (05:12 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 13 Jan 2011 05:12:34 +0000 (05:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123364 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Linker/LinkModules.cpp
test/Linker/unnamed-addr1-a.ll [new file with mode: 0644]
test/Linker/unnamed-addr1-b.ll [new file with mode: 0644]
test/Linker/unnamed-addr2-a.ll [new file with mode: 0644]
test/Linker/unnamed-addr2-b.ll [new file with mode: 0644]

index 3b3d3a4..4b4c72b 100644 (file)
@@ -352,6 +352,8 @@ static void CopyGVAttributes(GlobalValue *DestGV, const GlobalValue *SrcGV) {
   unsigned Alignment = std::max(DestGV->getAlignment(), SrcGV->getAlignment());
   DestGV->copyAttributesFrom(SrcGV);
   DestGV->setAlignment(Alignment);
+  if (SrcGV->hasUnnamedAddr())
+    DestGV->setUnnamedAddr(true);
 }
 
 /// GetLinkageResult - This analyzes the two global values and determines what
diff --git a/test/Linker/unnamed-addr1-a.ll b/test/Linker/unnamed-addr1-a.ll
new file mode 100644 (file)
index 0000000..4be797c
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: llvm-link %s %p/unnamed-addr1-b.ll -S -o - | FileCheck %s
+
+@foo = external global i32
+
+define i32 @bar() {
+entry:
+  %tmp = load i32* @foo, align 4
+  ret i32 %tmp
+}
+
+; CHECK: @foo = common unnamed_addr global i32 0, align 4
diff --git a/test/Linker/unnamed-addr1-b.ll b/test/Linker/unnamed-addr1-b.ll
new file mode 100644 (file)
index 0000000..3bfc4ea
--- /dev/null
@@ -0,0 +1,4 @@
+; This file is for use with unnamed-addr1-a.ll
+; RUN: true
+
+@foo = common unnamed_addr global i32 0, align 4
diff --git a/test/Linker/unnamed-addr2-a.ll b/test/Linker/unnamed-addr2-a.ll
new file mode 100644 (file)
index 0000000..f43f19a
--- /dev/null
@@ -0,0 +1,11 @@
+; RUN: llvm-link %s %p/unnamed-addr2-b.ll -S -o - | FileCheck %s
+
+define i32 @bar() {
+entry:
+  %call = tail call i32 @foo()
+  ret i32 %call
+}
+
+declare i32 @foo()
+
+; CHECK: define unnamed_addr i32 @foo()
diff --git a/test/Linker/unnamed-addr2-b.ll b/test/Linker/unnamed-addr2-b.ll
new file mode 100644 (file)
index 0000000..8327912
--- /dev/null
@@ -0,0 +1,7 @@
+; This file is for use with unnamed-addr2-a.ll
+; RUN: true
+
+define unnamed_addr i32 @foo() {
+entry:
+  ret i32 42
+}