[llvm-commits] [llvm] r123358 - in /llvm/trunk: lib/AsmParser/LLParser.cpp lib/AsmParser/LLParser.h lib/VMCore/Verifier.cpp test/Assembler/declare-unnamed-addr.ll test/Assembler/external-unnamed-addr.ll unittests/VMCore/VerifierTest.cpp
Rafael Espindola
rafael.espindola at gmail.com
Wed Jan 12 17:30:31 PST 2011
Author: rafael
Date: Wed Jan 12 19:30:30 2011
New Revision: 123358
URL: http://llvm.org/viewvc/llvm-project?rev=123358&view=rev
Log:
Reject uses of unnamed_addr in declarations.
Added:
llvm/trunk/test/Assembler/declare-unnamed-addr.ll
llvm/trunk/test/Assembler/external-unnamed-addr.ll
Modified:
llvm/trunk/lib/AsmParser/LLParser.cpp
llvm/trunk/lib/AsmParser/LLParser.h
llvm/trunk/lib/VMCore/Verifier.cpp
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=123358&r1=123357&r2=123358&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.cpp (original)
+++ llvm/trunk/lib/AsmParser/LLParser.cpp Wed Jan 12 19:30:30 2011
@@ -694,12 +694,14 @@
unsigned Visibility) {
unsigned AddrSpace;
bool ThreadLocal, IsConstant, UnnamedAddr;
+ LocTy UnnamedAddrLoc;
LocTy TyLoc;
PATypeHolder Ty(Type::getVoidTy(Context));
if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
ParseOptionalAddrSpace(AddrSpace) ||
- ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr) ||
+ ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
+ &UnnamedAddrLoc) ||
ParseGlobalType(IsConstant) ||
ParseType(Ty, TyLoc))
return true;
@@ -714,6 +716,9 @@
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");
@@ -2669,6 +2674,7 @@
unsigned Visibility, RetAttrs;
bool UnnamedAddr;
+ LocTy UnnamedAddrLoc;
CallingConv::ID CC;
PATypeHolder RetType(Type::getVoidTy(Context));
LocTy RetTypeLoc = Lex.getLoc();
@@ -2676,10 +2682,14 @@
ParseOptionalVisibility(Visibility) ||
ParseOptionalCallingConv(CC) ||
ParseOptionalAttrs(RetAttrs, 1) ||
- ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr) ||
+ ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
+ &UnnamedAddrLoc) ||
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/AsmParser/LLParser.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/AsmParser/LLParser.h?rev=123358&r1=123357&r2=123358&view=diff
==============================================================================
--- llvm/trunk/lib/AsmParser/LLParser.h (original)
+++ llvm/trunk/lib/AsmParser/LLParser.h Wed Jan 12 19:30:30 2011
@@ -162,10 +162,12 @@
Lex.Lex();
return true;
}
- bool ParseOptionalToken(lltok::Kind T, bool &Present) {
+ bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
if (Lex.getKind() != T) {
Present = false;
} else {
+ if (Loc)
+ *Loc = Lex.getLoc();
Lex.Lex();
Present = true;
}
Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=123358&r1=123357&r2=123358&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Wed Jan 12 19:30:30 2011
@@ -469,6 +469,8 @@
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);
@@ -725,6 +727,7 @@
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.
Added: llvm/trunk/test/Assembler/declare-unnamed-addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/declare-unnamed-addr.ll?rev=123358&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/declare-unnamed-addr.ll (added)
+++ llvm/trunk/test/Assembler/declare-unnamed-addr.ll Wed Jan 12 19:30:30 2011
@@ -0,0 +1,8 @@
+; 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: ^
Added: llvm/trunk/test/Assembler/external-unnamed-addr.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Assembler/external-unnamed-addr.ll?rev=123358&view=auto
==============================================================================
--- llvm/trunk/test/Assembler/external-unnamed-addr.ll (added)
+++ llvm/trunk/test/Assembler/external-unnamed-addr.ll Wed Jan 12 19:30:30 2011
@@ -0,0 +1,8 @@
+; 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/unittests/VMCore/VerifierTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/VMCore/VerifierTest.cpp?rev=123358&r1=123357&r2=123358&view=diff
==============================================================================
--- llvm/trunk/unittests/VMCore/VerifierTest.cpp (original)
+++ llvm/trunk/unittests/VMCore/VerifierTest.cpp Wed Jan 12 19:30:30 2011
@@ -61,5 +61,31 @@
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