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;
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");
unsigned Visibility, RetAttrs;
bool UnnamedAddr;
+ LocTy UnnamedAddrLoc;
CallingConv::ID CC;
PATypeHolder RetType(Type::getVoidTy(Context));
LocTy RetTypeLoc = Lex.getLoc();
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:
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;
}
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);
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.
--- /dev/null
+; 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: ^
--- /dev/null
+; RUN: not llvm-as %s -o /dev/null 2>%t
+; RUN: FileCheck -input-file=%t %s
+
+@foo = external unnamed_addr global i8*
+
+// CHECK: error: only definitions can have unnamed_addr
+// CHECK: @foo = external unnamed_addr global i8*
+// CHECK: ^
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"));
+}
}
}