aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/AsmParser/LLParser.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r--llvm/lib/AsmParser/LLParser.cpp99
1 files changed, 55 insertions, 44 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 35c615522fe2..432ec151cf8a 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -133,14 +133,17 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
for (const auto &RAG : ForwardRefAttrGroups) {
Value *V = RAG.first;
const std::vector<unsigned> &Attrs = RAG.second;
- AttrBuilder B;
+ AttrBuilder B(Context);
- for (const auto &Attr : Attrs)
- B.merge(NumberedAttrBuilders[Attr]);
+ for (const auto &Attr : Attrs) {
+ auto R = NumberedAttrBuilders.find(Attr);
+ if (R != NumberedAttrBuilders.end())
+ B.merge(R->second);
+ }
if (Function *Fn = dyn_cast<Function>(V)) {
AttributeList AS = Fn->getAttributes();
- AttrBuilder FnAttrs(AS.getFnAttrs());
+ AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
AS = AS.removeFnAttributes(Context);
FnAttrs.merge(B);
@@ -156,27 +159,27 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) {
Fn->setAttributes(AS);
} else if (CallInst *CI = dyn_cast<CallInst>(V)) {
AttributeList AS = CI->getAttributes();
- AttrBuilder FnAttrs(AS.getFnAttrs());
+ AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
AS = AS.removeFnAttributes(Context);
FnAttrs.merge(B);
AS = AS.addFnAttributes(Context, FnAttrs);
CI->setAttributes(AS);
} else if (InvokeInst *II = dyn_cast<InvokeInst>(V)) {
AttributeList AS = II->getAttributes();
- AttrBuilder FnAttrs(AS.getFnAttrs());
+ AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
AS = AS.removeFnAttributes(Context);
FnAttrs.merge(B);
AS = AS.addFnAttributes(Context, FnAttrs);
II->setAttributes(AS);
} else if (CallBrInst *CBI = dyn_cast<CallBrInst>(V)) {
AttributeList AS = CBI->getAttributes();
- AttrBuilder FnAttrs(AS.getFnAttrs());
+ AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs());
AS = AS.removeFnAttributes(Context);
FnAttrs.merge(B);
AS = AS.addFnAttributes(Context, FnAttrs);
CBI->setAttributes(AS);
} else if (auto *GV = dyn_cast<GlobalVariable>(V)) {
- AttrBuilder Attrs(GV->getAttributes());
+ AttrBuilder Attrs(M->getContext(), GV->getAttributes());
Attrs.merge(B);
GV->setAttributes(AttributeSet::get(Context,Attrs));
} else {
@@ -982,17 +985,18 @@ 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 && !PTy->isOpaqueOrPointeeTypeMatches(Ty)) {
- return error(
- ExplicitTypeLoc,
- typeComparisonErrorMessage(
- "explicit pointee type doesn't match operand's pointee type", Ty,
- PTy->getElementType()));
- }
-
- if (!IsAlias && !PTy->getElementType()->isFunctionTy()) {
- return error(ExplicitTypeLoc,
- "explicit pointee type should be a function type");
+ 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;
@@ -1206,7 +1210,7 @@ bool LLParser::parseGlobal(const std::string &Name, LocTy NameLoc,
}
}
- AttrBuilder Attrs;
+ AttrBuilder Attrs(M->getContext());
LocTy BuiltinLoc;
std::vector<unsigned> FwdRefAttrGrps;
if (parseFnAttributeValuePairs(Attrs, FwdRefAttrGrps, false, BuiltinLoc))
@@ -1235,13 +1239,18 @@ bool LLParser::parseUnnamedAttrGrp() {
Lex.Lex();
if (parseToken(lltok::equal, "expected '=' here") ||
- parseToken(lltok::lbrace, "expected '{' here") ||
- parseFnAttributeValuePairs(NumberedAttrBuilders[VarID], unused, true,
- BuiltinLoc) ||
+ parseToken(lltok::lbrace, "expected '{' here"))
+ return true;
+
+ auto R = NumberedAttrBuilders.find(VarID);
+ if (R == NumberedAttrBuilders.end())
+ R = NumberedAttrBuilders.emplace(VarID, AttrBuilder(M->getContext())).first;
+
+ if (parseFnAttributeValuePairs(R->second, unused, true, BuiltinLoc) ||
parseToken(lltok::rbrace, "expected end of attribute group"))
return true;
- if (!NumberedAttrBuilders[VarID].hasAttributes())
+ if (!R->second.hasAttributes())
return error(AttrGrpLoc, "attribute group has no attributes");
return false;
@@ -1402,14 +1411,14 @@ static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy) {
nullptr, GlobalVariable::NotThreadLocal,
PTy->getAddressSpace());
- if (auto *FT = dyn_cast<FunctionType>(PTy->getPointerElementType()))
+ 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, PTy->getPointerElementType(), false,
- GlobalValue::ExternalWeakLinkage, nullptr, "",
- nullptr, GlobalVariable::NotThreadLocal,
- PTy->getAddressSpace());
+ return new GlobalVariable(
+ *M, ElemTy, false, GlobalValue::ExternalWeakLinkage, nullptr, "",
+ nullptr, GlobalVariable::NotThreadLocal, PTy->getAddressSpace());
}
Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty,
@@ -2372,11 +2381,12 @@ bool LLParser::parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
// parse the argument.
LocTy ArgLoc;
Type *ArgTy = nullptr;
- AttrBuilder ArgAttrs;
Value *V;
if (parseType(ArgTy, ArgLoc))
return true;
+ AttrBuilder ArgAttrs(M->getContext());
+
if (ArgTy->isMetadataTy()) {
if (parseMetadataAsValue(V, PFS))
return true;
@@ -2493,7 +2503,7 @@ bool LLParser::parseArgumentList(SmallVectorImpl<ArgInfo> &ArgList,
} else {
LocTy TypeLoc = Lex.getLoc();
Type *ArgTy = nullptr;
- AttrBuilder Attrs;
+ AttrBuilder Attrs(M->getContext());
std::string Name;
if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs))
@@ -3579,7 +3589,7 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) {
ExplicitTypeLoc,
typeComparisonErrorMessage(
"explicit pointee type doesn't match operand's pointee type",
- Ty, BasePointerType->getElementType()));
+ Ty, BasePointerType->getNonOpaquePointerElementType()));
}
unsigned GEPWidth =
@@ -4541,16 +4551,17 @@ bool LLParser::parseDIStringType(MDNode *&Result, bool IsDistinct) {
OPTIONAL(name, MDStringField, ); \
OPTIONAL(stringLength, MDField, ); \
OPTIONAL(stringLengthExpression, MDField, ); \
+ OPTIONAL(stringLocationExpression, MDField, ); \
OPTIONAL(size, MDUnsignedField, (0, UINT64_MAX)); \
OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \
OPTIONAL(encoding, DwarfAttEncodingField, );
PARSE_MD_FIELDS();
#undef VISIT_MD_FIELDS
- Result = GET_OR_DISTINCT(DIStringType,
- (Context, tag.Val, name.Val, stringLength.Val,
- stringLengthExpression.Val, size.Val, align.Val,
- encoding.Val));
+ Result = GET_OR_DISTINCT(
+ DIStringType,
+ (Context, tag.Val, name.Val, stringLength.Val, stringLengthExpression.Val,
+ stringLocationExpression.Val, size.Val, align.Val, encoding.Val));
return false;
}
@@ -5462,7 +5473,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
unsigned Visibility;
unsigned DLLStorageClass;
bool DSOLocal;
- AttrBuilder RetAttrs;
+ AttrBuilder RetAttrs(M->getContext());
unsigned CC;
bool HasLinkage;
Type *RetType = nullptr;
@@ -5525,7 +5536,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
SmallVector<ArgInfo, 8> ArgList;
bool IsVarArg;
- AttrBuilder FuncAttrs;
+ AttrBuilder FuncAttrs(M->getContext());
std::vector<unsigned> FwdRefAttrGrps;
LocTy BuiltinLoc;
std::string Section;
@@ -5593,7 +5604,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) {
if (FRVI != ForwardRefVals.end()) {
FwdFn = FRVI->second.first;
if (!FwdFn->getType()->isOpaque()) {
- if (!FwdFn->getType()->getPointerElementType()->isFunctionTy())
+ if (!FwdFn->getType()->getNonOpaquePointerElementType()->isFunctionTy())
return error(FRVI->second.second, "invalid forward reference to "
"function as global value!");
if (FwdFn->getType() != PFT)
@@ -6248,7 +6259,7 @@ bool LLParser::parseIndirectBr(Instruction *&Inst, PerFunctionState &PFS) {
/// OptionalAttrs 'to' TypeAndValue 'unwind' TypeAndValue
bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) {
LocTy CallLoc = Lex.getLoc();
- AttrBuilder RetAttrs, FnAttrs;
+ AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
std::vector<unsigned> FwdRefAttrGrps;
LocTy NoBuiltinLoc;
unsigned CC;
@@ -6558,7 +6569,7 @@ bool LLParser::parseUnaryOp(Instruction *&Inst, PerFunctionState &PFS,
/// '[' LabelList ']'
bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) {
LocTy CallLoc = Lex.getLoc();
- AttrBuilder RetAttrs, FnAttrs;
+ AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
std::vector<unsigned> FwdRefAttrGrps;
LocTy NoBuiltinLoc;
unsigned CC;
@@ -6975,7 +6986,7 @@ bool LLParser::parseFreeze(Instruction *&Inst, PerFunctionState &PFS) {
/// OptionalAttrs Type Value ParameterList OptionalAttrs
bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS,
CallInst::TailCallKind TCK) {
- AttrBuilder RetAttrs, FnAttrs;
+ AttrBuilder RetAttrs(M->getContext()), FnAttrs(M->getContext());
std::vector<unsigned> FwdRefAttrGrps;
LocTy BuiltinLoc;
unsigned CallAddrSpace;
@@ -7196,7 +7207,7 @@ int LLParser::parseLoad(Instruction *&Inst, PerFunctionState &PFS) {
ExplicitTypeLoc,
typeComparisonErrorMessage(
"explicit pointee type doesn't match operand's pointee type", Ty,
- cast<PointerType>(Val->getType())->getElementType()));
+ Val->getType()->getNonOpaquePointerElementType()));
}
SmallPtrSet<Type *, 4> Visited;
if (!Alignment && !Ty->isSized(&Visited))
@@ -7456,7 +7467,7 @@ int LLParser::parseGetElementPtr(Instruction *&Inst, PerFunctionState &PFS) {
ExplicitTypeLoc,
typeComparisonErrorMessage(
"explicit pointee type doesn't match operand's pointee type", Ty,
- BasePointerType->getElementType()));
+ BasePointerType->getNonOpaquePointerElementType()));
}
SmallVector<Value*, 16> Indices;