Add a GlobalAlias::isValidLinkage to reduce code duplication.

Thanks to Reid Kleckner for the suggestion.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192298 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola 2013-10-09 16:07:32 +00:00
parent 3b73dea538
commit 1a525e8c80
3 changed files with 7 additions and 6 deletions

View File

@ -81,6 +81,11 @@ public:
return const_cast<GlobalAlias *>(this)->resolveAliasedGlobal(stopOnWeak);
}
static bool isValidLinkage(LinkageTypes L) {
return isExternalLinkage(L) || isLocalLinkage(L) ||
isWeakLinkage(L) || isLinkOnceLinkage(L);
}
// Methods for support type inquiry through isa, cast, and dyn_cast:
static inline bool classof(const Value *V) {
return V->getValueID() == Value::GlobalAliasVal;

View File

@ -634,10 +634,7 @@ bool LLParser::ParseAlias(const std::string &Name, LocTy NameLoc,
GlobalValue::LinkageTypes Linkage = (GlobalValue::LinkageTypes) L;
if(!GlobalValue::isExternalLinkage(Linkage) &&
!GlobalValue::isLocalLinkage(Linkage) &&
!GlobalValue::isWeakLinkage(Linkage) &&
!GlobalValue::isLinkOnceLinkage(Linkage))
if(!GlobalAlias::isValidLinkage(Linkage))
return Error(LinkageLoc, "invalid linkage type for alias");
Constant *Aliasee;

View File

@ -529,8 +529,7 @@ void Verifier::visitGlobalVariable(GlobalVariable &GV) {
void Verifier::visitGlobalAlias(GlobalAlias &GA) {
Assert1(!GA.getName().empty(),
"Alias name cannot be empty!", &GA);
Assert1(GA.hasExternalLinkage() || GA.hasLocalLinkage() ||
GA.hasWeakLinkage() || GA.hasLinkOnceLinkage(),
Assert1(GlobalAlias::isValidLinkage(GA.getLinkage()),
"Alias should have external or external weak linkage!", &GA);
Assert1(GA.getAliasee(),
"Aliasee cannot be NULL!", &GA);