[llvm] 2cc79ba - [LLParser] Remove checks related to typed pointers (NFC)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 14 01:44:41 PDT 2023
Author: Nikita Popov
Date: 2023-07-14T10:41:34+02:00
New Revision: 2cc79baf027ed90aea67172030038c0bb548451f
URL: https://github.com/llvm/llvm-project/commit/2cc79baf027ed90aea67172030038c0bb548451f
DIFF: https://github.com/llvm/llvm-project/commit/2cc79baf027ed90aea67172030038c0bb548451f.diff
LOG: [LLParser] Remove checks related to typed pointers (NFC)
Added:
Modified:
llvm/lib/AsmParser/LLParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index ed9e1d6ebfa210..5f0d1a76de7939 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -974,14 +974,6 @@ static void maybeSetDSOLocal(bool DSOLocal, GlobalValue &GV) {
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
@@ -1053,20 +1045,6 @@ bool LLParser::parseAliasOrIFunc(const std::string &Name, LocTy NameLoc,
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
@@ -1583,22 +1561,12 @@ bool LLParser::parseFnAttributeValuePairs(AttrBuilder &B,
//===----------------------------------------------------------------------===//
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,
@@ -4034,7 +4002,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
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"))
@@ -4053,15 +4020,6 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
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()
@@ -6095,10 +6053,6 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
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 "
@@ -7679,13 +7633,6 @@ int LLParser::parseLoad(Instruction *&Inst, PerFunctionState &PFS) {
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");
@@ -7730,9 +7677,6 @@ int LLParser::parseStore(Instruction *&Inst, PerFunctionState &PFS) {
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 ||
@@ -7784,12 +7728,6 @@ int LLParser::parseCmpXchg(Instruction *&Inst, PerFunctionState &PFS) {
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())
@@ -7875,9 +7813,6 @@ int LLParser::parseAtomicRMW(Instruction *&Inst, PerFunctionState &PFS) {
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() &&
@@ -7946,7 +7881,6 @@ int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
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))
@@ -7957,14 +7891,6 @@ int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &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.
More information about the llvm-commits
mailing list