mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-27 16:17:17 +00:00
Reject uses of unnamed_addr in declarations.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123358 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -694,12 +694,14 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
|
|||||||
unsigned Visibility) {
|
unsigned Visibility) {
|
||||||
unsigned AddrSpace;
|
unsigned AddrSpace;
|
||||||
bool ThreadLocal, IsConstant, UnnamedAddr;
|
bool ThreadLocal, IsConstant, UnnamedAddr;
|
||||||
|
LocTy UnnamedAddrLoc;
|
||||||
LocTy TyLoc;
|
LocTy TyLoc;
|
||||||
|
|
||||||
PATypeHolder Ty(Type::getVoidTy(Context));
|
PATypeHolder Ty(Type::getVoidTy(Context));
|
||||||
if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
|
if (ParseOptionalToken(lltok::kw_thread_local, ThreadLocal) ||
|
||||||
ParseOptionalAddrSpace(AddrSpace) ||
|
ParseOptionalAddrSpace(AddrSpace) ||
|
||||||
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr) ||
|
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
|
||||||
|
&UnnamedAddrLoc) ||
|
||||||
ParseGlobalType(IsConstant) ||
|
ParseGlobalType(IsConstant) ||
|
||||||
ParseType(Ty, TyLoc))
|
ParseType(Ty, TyLoc))
|
||||||
return true;
|
return true;
|
||||||
@@ -714,6 +716,9 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!Init && UnnamedAddr)
|
||||||
|
return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr");
|
||||||
|
|
||||||
if (Ty->isFunctionTy() || Ty->isLabelTy())
|
if (Ty->isFunctionTy() || Ty->isLabelTy())
|
||||||
return Error(TyLoc, "invalid type for global variable");
|
return Error(TyLoc, "invalid type for global variable");
|
||||||
|
|
||||||
@@ -2669,6 +2674,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
|||||||
|
|
||||||
unsigned Visibility, RetAttrs;
|
unsigned Visibility, RetAttrs;
|
||||||
bool UnnamedAddr;
|
bool UnnamedAddr;
|
||||||
|
LocTy UnnamedAddrLoc;
|
||||||
CallingConv::ID CC;
|
CallingConv::ID CC;
|
||||||
PATypeHolder RetType(Type::getVoidTy(Context));
|
PATypeHolder RetType(Type::getVoidTy(Context));
|
||||||
LocTy RetTypeLoc = Lex.getLoc();
|
LocTy RetTypeLoc = Lex.getLoc();
|
||||||
@@ -2676,10 +2682,14 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) {
|
|||||||
ParseOptionalVisibility(Visibility) ||
|
ParseOptionalVisibility(Visibility) ||
|
||||||
ParseOptionalCallingConv(CC) ||
|
ParseOptionalCallingConv(CC) ||
|
||||||
ParseOptionalAttrs(RetAttrs, 1) ||
|
ParseOptionalAttrs(RetAttrs, 1) ||
|
||||||
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr) ||
|
ParseOptionalToken(lltok::kw_unnamed_addr, UnnamedAddr,
|
||||||
|
&UnnamedAddrLoc) ||
|
||||||
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
|
ParseType(RetType, RetTypeLoc, true /*void allowed*/))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
if (!isDefine && UnnamedAddr)
|
||||||
|
return Error(UnnamedAddrLoc, "only definitions can have unnamed_addr");
|
||||||
|
|
||||||
// Verify that the linkage is ok.
|
// Verify that the linkage is ok.
|
||||||
switch ((GlobalValue::LinkageTypes)Linkage) {
|
switch ((GlobalValue::LinkageTypes)Linkage) {
|
||||||
case GlobalValue::ExternalLinkage:
|
case GlobalValue::ExternalLinkage:
|
||||||
|
@@ -162,10 +162,12 @@ namespace llvm {
|
|||||||
Lex.Lex();
|
Lex.Lex();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool ParseOptionalToken(lltok::Kind T, bool &Present) {
|
bool ParseOptionalToken(lltok::Kind T, bool &Present, LocTy *Loc = 0) {
|
||||||
if (Lex.getKind() != T) {
|
if (Lex.getKind() != T) {
|
||||||
Present = false;
|
Present = false;
|
||||||
} else {
|
} else {
|
||||||
|
if (Loc)
|
||||||
|
*Loc = Lex.getLoc();
|
||||||
Lex.Lex();
|
Lex.Lex();
|
||||||
Present = true;
|
Present = true;
|
||||||
}
|
}
|
||||||
|
@@ -469,6 +469,8 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
|
|||||||
Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
|
Assert1(GV.hasExternalLinkage() || GV.hasDLLImportLinkage() ||
|
||||||
GV.hasExternalWeakLinkage(),
|
GV.hasExternalWeakLinkage(),
|
||||||
"invalid linkage type for global declaration", &GV);
|
"invalid linkage type for global declaration", &GV);
|
||||||
|
Assert1(!GV.hasUnnamedAddr(), "only definitions can have unnamed_addr",
|
||||||
|
&GV);
|
||||||
}
|
}
|
||||||
|
|
||||||
visitGlobalValue(GV);
|
visitGlobalValue(GV);
|
||||||
@@ -725,6 +727,7 @@ void Verifier::visitFunction(Function &F) {
|
|||||||
Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
|
Assert1(F.hasExternalLinkage() || F.hasDLLImportLinkage() ||
|
||||||
F.hasExternalWeakLinkage(),
|
F.hasExternalWeakLinkage(),
|
||||||
"invalid linkage type for function declaration", &F);
|
"invalid linkage type for function declaration", &F);
|
||||||
|
Assert1(!F.hasUnnamedAddr(), "only definitions can have unnamed_addr", &F);
|
||||||
} else {
|
} else {
|
||||||
// Verify that this function (which has a body) is not named "llvm.*". It
|
// Verify that this function (which has a body) is not named "llvm.*". It
|
||||||
// is not legal to define intrinsics.
|
// is not legal to define intrinsics.
|
||||||
|
8
test/Assembler/declare-unnamed-addr.ll
Normal file
8
test/Assembler/declare-unnamed-addr.ll
Normal file
@@ -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: ^
|
8
test/Assembler/external-unnamed-addr.ll
Normal file
8
test/Assembler/external-unnamed-addr.ll
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
; 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: ^
|
@@ -61,5 +61,31 @@ TEST(VerifierTest, AliasUnnamedAddr) {
|
|||||||
EXPECT_TRUE(StringRef(Error).startswith("Alias cannot have unnamed_addr"));
|
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"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user