return Error(NameLoc,
"symbol with local linkage must have default visibility");
+ Type *Ty;
+ LocTy ExplicitTypeLoc = Lex.getLoc();
+ if (ParseType(Ty) ||
+ ParseToken(lltok::comma, "expected comma after alias's type"))
+ return true;
+
Constant *Aliasee;
LocTy AliaseeLoc = Lex.getLoc();
if (Lex.getKind() != lltok::kw_bitcast &&
auto *PTy = dyn_cast<PointerType>(AliaseeType);
if (!PTy)
return Error(AliaseeLoc, "An alias must have pointer type");
+ unsigned AddrSpace = PTy->getAddressSpace();
+
+ if (Ty != PTy->getElementType())
+ return Error(
+ ExplicitTypeLoc,
+ "explicit pointee type doesn't match operand's pointee type");
// Okay, create the alias but do not insert it into the module yet.
std::unique_ptr<GlobalAlias> GA(
- GlobalAlias::create(PTy, (GlobalValue::LinkageTypes)Linkage, Name,
- Aliasee, /*Parent*/ nullptr));
+ GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage,
+ Name, Aliasee, /*Parent*/ nullptr));
GA->setThreadLocalMode(TLM);
GA->setVisibility((GlobalValue::VisibilityTypes)Visibility);
GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass);
// GlobalValue Reference/Resolution Routines.
//===----------------------------------------------------------------------===//
+static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy,
+ const std::string &Name) {
+ if (auto *FT = dyn_cast<FunctionType>(PTy->getElementType()))
+ return Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
+ else
+ return new GlobalVariable(*M, PTy->getElementType(), false,
+ GlobalValue::ExternalWeakLinkage, nullptr, Name,
+ nullptr, GlobalVariable::NotThreadLocal,
+ PTy->getAddressSpace());
+}
+
/// GetGlobalVal - Get a value with the specified name or ID, creating a
/// forward reference record if needed. This can return null if the value
/// exists but does not have the right type.
}
// Otherwise, create a new forward reference for this value and remember it.
- GlobalValue *FwdVal;
- if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
- FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, Name, M);
- else
- FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, nullptr, Name,
- nullptr, GlobalVariable::NotThreadLocal,
- PTy->getAddressSpace());
-
+ GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, Name);
ForwardRefVals[Name] = std::make_pair(FwdVal, Loc);
return FwdVal;
}
}
// Otherwise, create a new forward reference for this value and remember it.
- GlobalValue *FwdVal;
- if (FunctionType *FT = dyn_cast<FunctionType>(PTy->getElementType()))
- FwdVal = Function::Create(FT, GlobalValue::ExternalWeakLinkage, "", M);
- else
- FwdVal = new GlobalVariable(*M, PTy->getElementType(), false,
- GlobalValue::ExternalWeakLinkage, nullptr, "");
-
+ GlobalValue *FwdVal = createGlobalFwdRef(M, PTy, "");
ForwardRefValIDs[ID] = std::make_pair(FwdVal, Loc);
return FwdVal;
}
switch (ID.Kind) {
case ValID::t_APSInt:
case ValID::t_APFloat:
+ case ValID::t_Undef:
case ValID::t_Constant:
case ValID::t_ConstantStruct:
case ValID::t_PackedConstantStruct: {