GV.setDSOLocal(true);
}
-static std::string typeComparisonErrorMessage(StringRef Message, Type *Ty1,
- Type *Ty2) {
- std::string ErrString;
- raw_string_ostream ErrOS(ErrString);
- ErrOS << Message << " (" << *Ty1 << " vs " << *Ty2 << ")";
- return ErrOS.str();
-}
-
/// parseAliasOrIFunc:
/// ::= GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier
/// OptionalVisibility OptionalDLLStorageClass
return error(AliaseeLoc, "An alias or ifunc must have pointer type");
unsigned AddrSpace = PTy->getAddressSpace();
- if (IsAlias) {
- if (!PTy->isOpaqueOrPointeeTypeMatches(Ty))
- return error(
- ExplicitTypeLoc,
- typeComparisonErrorMessage(
- "explicit pointee type doesn't match operand's pointee type", Ty,
- PTy->getNonOpaquePointerElementType()));
- } else {
- if (!PTy->isOpaque() &&
- !PTy->getNonOpaquePointerElementType()->isFunctionTy())
- return error(ExplicitTypeLoc,
- "explicit pointee type should be a function type");
- }
-
GlobalValue *GVal = nullptr;
// See if the alias was forward referenced, if so, prepare to replace the
//===----------------------------------------------------------------------===//
static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy) {
- // For opaque pointers, the used global type does not matter. We will later
- // RAUW it with a global/function of the correct type.
- if (PTy->isOpaque())
- return new GlobalVariable(*M, Type::getInt8Ty(M->getContext()), false,
- GlobalValue::ExternalWeakLinkage, nullptr, "",
- nullptr, GlobalVariable::NotThreadLocal,
- PTy->getAddressSpace());
-
- Type *ElemTy = PTy->getNonOpaquePointerElementType();
- if (auto *FT = dyn_cast<FunctionType>(ElemTy))
- return Function::Create(FT, GlobalValue::ExternalWeakLinkage,
- PTy->getAddressSpace(), "", M);
- else
- return new GlobalVariable(
- *M, ElemTy, false, GlobalValue::ExternalWeakLinkage, nullptr, "",
- nullptr, GlobalVariable::NotThreadLocal, PTy->getAddressSpace());
+ // The used global type does not matter. We will later RAUW it with a
+ // global/function of the correct type.
+ return new GlobalVariable(*M, Type::getInt8Ty(M->getContext()), false,
+ GlobalValue::ExternalWeakLinkage, nullptr, "",
+ nullptr, GlobalVariable::NotThreadLocal,
+ PTy->getAddressSpace());
}
Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
if (parseToken(lltok::lparen, "expected '(' in constantexpr"))
return true;
- LocTy ExplicitTypeLoc = Lex.getLoc();
if (Opc == Instruction::GetElementPtr) {
if (parseType(Ty) ||
parseToken(lltok::comma, "expected comma after getelementptr's type"))
return error(ID.Loc, "base of getelementptr must be a pointer");
Type *BaseType = Elts[0]->getType();
- auto *BasePointerType = cast<PointerType>(BaseType->getScalarType());
- if (!BasePointerType->isOpaqueOrPointeeTypeMatches(Ty)) {
- return error(
- ExplicitTypeLoc,
- typeComparisonErrorMessage(
- "explicit pointee type doesn't match operand's pointee type",
- Ty, BasePointerType->getNonOpaquePointerElementType()));
- }
-
unsigned GEPWidth =
BaseType->isVectorTy()
? cast<FixedVectorType>(BaseType)->getNumElements()
auto FRVI = ForwardRefVals.find(FunctionName);
if (FRVI != ForwardRefVals.end()) {
FwdFn = FRVI->second.first;
- if (!FwdFn->getType()->isOpaque() &&
- !FwdFn->getType()->getNonOpaquePointerElementType()->isFunctionTy())
- return error(FRVI->second.second, "invalid forward reference to "
- "function as global value!");
if (FwdFn->getType() != PFT)
return error(FRVI->second.second,
"invalid forward reference to "
Ordering == AtomicOrdering::AcquireRelease)
return error(Loc, "atomic load cannot use Release ordering");
- if (!cast<PointerType>(Val->getType())->isOpaqueOrPointeeTypeMatches(Ty)) {
- return error(
- ExplicitTypeLoc,
- typeComparisonErrorMessage(
- "explicit pointee type doesn't match operand's pointee type", Ty,
- Val->getType()->getNonOpaquePointerElementType()));
- }
SmallPtrSet<Type *, 4> Visited;
if (!Alignment && !Ty->isSized(&Visited))
return error(ExplicitTypeLoc, "loading unsized types is not allowed");
return error(PtrLoc, "store operand must be a pointer");
if (!Val->getType()->isFirstClassType())
return error(Loc, "store operand must be a first class value");
- if (!cast<PointerType>(Ptr->getType())
- ->isOpaqueOrPointeeTypeMatches(Val->getType()))
- return error(Loc, "stored value and pointer type do not match");
if (isAtomic && !Alignment)
return error(Loc, "atomic store must have explicit non-zero alignment");
if (Ordering == AtomicOrdering::Acquire ||
return tokError("invalid cmpxchg failure ordering");
if (!Ptr->getType()->isPointerTy())
return error(PtrLoc, "cmpxchg operand must be a pointer");
- if (!cast<PointerType>(Ptr->getType())
- ->isOpaqueOrPointeeTypeMatches(Cmp->getType()))
- return error(CmpLoc, "compare value and pointer type do not match");
- if (!cast<PointerType>(Ptr->getType())
- ->isOpaqueOrPointeeTypeMatches(New->getType()))
- return error(NewLoc, "new value and pointer type do not match");
if (Cmp->getType() != New->getType())
return error(NewLoc, "compare value and new value type do not match");
if (!New->getType()->isFirstClassType())
return tokError("atomicrmw cannot be unordered");
if (!Ptr->getType()->isPointerTy())
return error(PtrLoc, "atomicrmw operand must be a pointer");
- if (!cast<PointerType>(Ptr->getType())
- ->isOpaqueOrPointeeTypeMatches(Val->getType()))
- return error(ValLoc, "atomicrmw value and pointer type do not match");
if (Operation == AtomicRMWInst::Xchg) {
if (!Val->getType()->isIntegerTy() &&
bool InBounds = EatIfPresent(lltok::kw_inbounds);
Type *Ty = nullptr;
- LocTy ExplicitTypeLoc = Lex.getLoc();
if (parseType(Ty) ||
parseToken(lltok::comma, "expected comma after getelementptr's type") ||
parseTypeAndValue(Ptr, Loc, PFS))
if (!BasePointerType)
return error(Loc, "base of getelementptr must be a pointer");
- if (!BasePointerType->isOpaqueOrPointeeTypeMatches(Ty)) {
- return error(
- ExplicitTypeLoc,
- typeComparisonErrorMessage(
- "explicit pointee type doesn't match operand's pointee type", Ty,
- BasePointerType->getNonOpaquePointerElementType()));
- }
-
SmallVector<Value*, 16> Indices;
bool AteExtraComma = false;
// GEP returns a vector of pointers if at least one of parameters is a vector.