[llvm-commits] [llvm] r123529 - in /llvm/trunk: lib/AsmParser/LLParser.cpp lib/Linker/LinkModules.cpp lib/VMCore/Verifier.cpp test/Assembler/declare-unnamed-addr.ll test/Assembler/external-unnamed-addr.ll test/Linker/unnamed-addr1-a.ll test/Linker/unnamed-addr1-b.ll test/Linker/unnamed-addr2-a.ll test/Linker/unnamed-addr2-b.ll unittests/VMCore/VerifierTest.cpp
Rafael Espindola
rafael.espindola at gmail.com
Sat Jan 15 00:15:01 PST 2011
Author: rafael
Date: Sat Jan 15 02:15:00 2011
New Revision: 123529
URL: http://llvm.org/viewvc/llvm-project?rev=123529&view=rev
Log:
Allow unnamed_addr on declarations.
Removed:
llvm/trunk/test/Assembler/declare-unnamed-addr.ll
llvm/trunk/test/Assembler/external-unnamed-addr.ll
llvm/trunk/test/Linker/unnamed-addr2-a.ll
llvm/trunk/test/Linker/unnamed-addr2-b.ll
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/Linker/LinkModules.cpp
llvm/trunk/lib/VMCore/Verifier.cpp
llvm/trunk/test/Linker/unnamed-addr1-a.ll
llvm/trunk/test/Linker/unnamed-addr1-b.ll
llvm/trunk/unittests/VMCore/VerifierTest.cpp
Modified: llvm/trunk/lib/AsmParser/LLParser.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.cpp?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Sat Jan 15 02:15:00 2011
@@ -716,9 +716,6 @@
return true;
}
- if (!Init && UnnamedAddr)
- return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr");
-
if (Ty->isFunctionTy() || Ty->isLabelTy())
return Error(TyLoc, "invalid type for global variable");
@@ -2687,9 +2684,6 @@
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
return true;
- if (!isDefine && UnnamedAddr)
- return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr");
-
// Verify that the linkage is ok.
switch ((GlobalValue::LinkageTypes)Linkage) {
case GlobalValue::ExternalLinkage:
Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Sat Jan 15 02:15:00 2011
@@ -352,8 +352,6 @@
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
@@ -521,6 +519,8 @@
continue;
}
+ bool HasUnnamedAddr = SGV->hasUnnamedAddr() && DGV->hasUnnamedAddr();
+
// If the visibilities of the symbols disagree and the destination is a
// prototype, take the visibility of its input.
if (DGV->isDeclaration())
@@ -565,6 +565,9 @@
DGV->getName(), 0, false,
SGV->getType()->getAddressSpace());
+ // Set the unnamed_addr.
+ NewDGV->setUnnamedAddr(HasUnnamedAddr);
+
// Propagate alignment, section, and visibility info.
CopyGVAttributes(NewDGV, SGV);
DGV->replaceAllUsesWith(ConstantExpr::getBitCast(NewDGV,
@@ -609,8 +612,9 @@
"': symbol multiple defined");
}
- // Set calculated linkage
+ // Set calculated linkage and unnamed_addr
DGV->setLinkage(NewLinkage);
+ DGV->setUnnamedAddr(HasUnnamedAddr);
// Make sure to remember this mapping...
ValueMap[SGV] = ConstantExpr::getBitCast(DGV, SGV->getType());
Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Sat Jan 15 02:15:00 2011
@@ -469,8 +469,6 @@
Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
GV.hasExternalWeakLinkage(),
"invalid linkage type for global declaration", &GV);
- Assert1(!GV.hasUnnamedAddr(), "only definitions can have unnamed_addr",
- &GV);
}
visitGlobalValue(GV);
@@ -727,7 +725,6 @@
Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
F.hasExternalWeakLinkage(),
"invalid linkage type for function declaration", &F);
- Assert1(!F.hasUnnamedAddr(), "only definitions can have unnamed_addr", &F);
} else {
// Verify that this function (which has a body) is not named "llvm.*". It
// is not legal to define intrinsics.
Removed: llvm/trunk/test/Assembler/declare-unnamed-addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/declare-unnamed-addr.ll?rev=123528&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/declare-unnamed-addr.ll (original)
+++ llvm/trunk/test/Assembler/declare-unnamed-addr.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: not llvm-as %s -o /dev/null 2>%t
-; RUN: FileCheck -input-file=%t %s
-
-declare unnamed_addr i32 @zed()
-
-// CHECK: error: only definitions can have unnamed_addr
-// CHECK: declare unnamed_addr i32 @zed()
-// CHECK: ^
Removed: llvm/trunk/test/Assembler/external-unnamed-addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/external-unnamed-addr.ll?rev=123528&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/external-unnamed-addr.ll (original)
+++ llvm/trunk/test/Assembler/external-unnamed-addr.ll (removed)
@@ -1,8 +0,0 @@
-; RUN: not llvm-as %s -o /dev/null 2>%t
-; RUN: FileCheck -input-file=%t %s
-
- at foo = external unnamed_addr global i8*
-
-// CHECK: error: only definitions can have unnamed_addr
-// CHECK: @foo = external unnamed_addr global i8*
-// CHECK: ^
Modified: llvm/trunk/test/Linker/unnamed-addr1-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/unnamed-addr1-a.ll?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/test/Linker/unnamed-addr1-a.ll (original)
+++ llvm/trunk/test/Linker/unnamed-addr1-a.ll Sat Jan 15 02:15:00 2011
@@ -1,11 +1,27 @@
-; RUN: llvm-link %s %p/unnamed-addr1-b.ll -S -o - | FileCheck %s
+; RUN: llvm-link %s %p/unnamed-addr1-b.ll -S -o - | sort | FileCheck %s
- at foo = external global i32
+; Only in this file
+ at a = common global i32 0
+; CHECK: @a = common global i32 0
+ at b = common unnamed_addr global i32 0
+; CHECK: @b = common unnamed_addr global i32 0
-define i32 @bar() {
-entry:
- %tmp = load i32* @foo, align 4
- ret i32 %tmp
-}
+; Other file has unnamed_addr definition
+ at c = common unnamed_addr global i32 0
+; CHECK: @c = common unnamed_addr global i32 0
+ at d = external global i32
+; CHECK: @d = global i32 42
+ at e = external unnamed_addr global i32
+; CHECK: @e = unnamed_addr global i32 42
+ at f = weak global i32 42
+; CHECK: @f = global i32 42
-; CHECK: @foo = common unnamed_addr global i32 0, align 4
+; Other file has non-unnamed_addr definition
+ at g = common unnamed_addr global i32 0
+; CHECK: @g = common global i32 0
+ at h = external global i32
+; CHECK: @h = global i32 42
+ at i = external unnamed_addr global i32
+; CHECK: @i = global i32 42
+ at j = weak global i32 42
+; CHECK: @j = global i32 42
Modified: llvm/trunk/test/Linker/unnamed-addr1-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/unnamed-addr1-b.ll?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/test/Linker/unnamed-addr1-b.ll (original)
+++ llvm/trunk/test/Linker/unnamed-addr1-b.ll Sat Jan 15 02:15:00 2011
@@ -1,4 +1,12 @@
; This file is for use with unnamed-addr1-a.ll
; RUN: true
- at foo = common unnamed_addr global i32 0, align 4
+ at c = common unnamed_addr global i32 42
+ at d = unnamed_addr global i32 42
+ at e = unnamed_addr global i32 42
+ at f = unnamed_addr global i32 42
+
+ at g = common global i32 42
+ at h = global i32 42
+ at i = global i32 42
+ at j = global i32 42
Removed: llvm/trunk/test/Linker/unnamed-addr2-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/unnamed-addr2-a.ll?rev=123528&view=auto
==============================================================================
--- llvm/trunk/test/Linker/unnamed-addr2-a.ll (original)
+++ llvm/trunk/test/Linker/unnamed-addr2-a.ll (removed)
@@ -1,11 +0,0 @@
-; 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()
Removed: llvm/trunk/test/Linker/unnamed-addr2-b.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/unnamed-addr2-b.ll?rev=123528&view=auto
==============================================================================
--- llvm/trunk/test/Linker/unnamed-addr2-b.ll (original)
+++ llvm/trunk/test/Linker/unnamed-addr2-b.ll (removed)
@@ -1,7 +0,0 @@
-; This file is for use with unnamed-addr2-a.ll
-; RUN: true
-
-define unnamed_addr i32 @foo() {
-entry:
- ret i32 42
-}
Modified: llvm/trunk/unittests/VMCore/VerifierTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/VerifierTest.cpp?rev=123529&r1=123528&r2=123529&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/VerifierTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/VerifierTest.cpp Sat Jan 15 02:15:00 2011
@@ -60,32 +60,5 @@
EXPECT_TRUE(verifyModule(M, ReturnStatusAction, &Error));
EXPECT_TRUE(StringRef(Error).startswith("Alias cannot have unnamed_addr"));
}
-
-TEST(VerifierTest, ExternalUnnamedAddr) {
- LLVMContext &C = getGlobalContext();
- Module M("M", C);
- const Type *Ty = Type::getInt8Ty(C);
- GlobalVariable *GV = new GlobalVariable(M, Ty, true,
- GlobalValue::ExternalLinkage,
- NULL, "foo");
- GV->setUnnamedAddr(true);
- std::string Error;
- EXPECT_TRUE(verifyModule(M, ReturnStatusAction, &Error));
- EXPECT_TRUE(StringRef(Error)
- .startswith("only definitions can have unnamed_addr"));
-}
-
-TEST(VerifierTest, DeclarationUnnamedAddr) {
- LLVMContext &C = getGlobalContext();
- Module M("M", C);
- FunctionType *FTy = FunctionType::get(Type::getVoidTy(C), /*isVarArg=*/false);
- Function *F = Function::Create(FTy, GlobalValue::ExternalLinkage,
- "foo", &M);
- F->setUnnamedAddr(true);
- std::string Error;
- EXPECT_TRUE(verifyModule(M, ReturnStatusAction, &Error));
- EXPECT_TRUE(StringRef(Error)
- .startswith("only definitions can have unnamed_addr"));
-}
}
}
More information about the llvm-commits
mailing list