llir / llvm

Library for interacting with LLVM IR in pure Go.
https://llir.github.io/document/
BSD Zero Clause License
1.19k stars 78 forks source link

update llir/llvm to support 14.0 #220

Closed mewmew closed 2 years ago

mewmew commented 2 years ago

ref: #205.

LLVM 14.0 has been released: https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.0

wget https://github.com/llvm/llvm-project/archive/llvmorg-13.0.1.tar.gz
wget https://github.com/llvm/llvm-project/archive/llvmorg-14.0.6.tar.gz
tar zxf llvmorg-13.0.1.tar.gz
tar zxf llvmorg-14.0.6.tar.gz
git diff -w llvm-project-llvmorg-13.0.1/llvm/lib/AsmParser llvm-project-llvmorg-14.0.6/llvm/lib/AsmParser > llvm14.diff
git diff -w llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Attributes.td llvm-project-llvmorg-14.0.6/llvm/include/llvm/IR/Attributes.td >> llvm14.diff
mewmew commented 2 years ago
diff between LLVM 13.0 and LLVM 14.0 ```diff diff --git a/llvm-project-llvmorg-13.0.1/llvm/lib/AsmParser/LLLexer.cpp b/llvm-project-llvmorg-14.0.6/llvm/lib/AsmParser/LLLexer.cpp index 4f72c6f..e3bf41c 100644 --- a/llvm-project-llvmorg-13.0.1/llvm/lib/AsmParser/LLLexer.cpp +++ b/llvm-project-llvmorg-14.0.6/llvm/lib/AsmParser/LLLexer.cpp @@ -643,6 +643,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(convergent); KEYWORD(dereferenceable); KEYWORD(dereferenceable_or_null); + KEYWORD(disable_sanitizer_instrumentation); KEYWORD(elementtype); KEYWORD(inaccessiblememonly); KEYWORD(inaccessiblemem_or_argmemonly); @@ -732,6 +733,7 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(x); KEYWORD(blockaddress); KEYWORD(dso_local_equivalent); + KEYWORD(no_cfi); // Metadata types. KEYWORD(distinct); @@ -769,6 +771,10 @@ lltok::Kind LLLexer::LexIdentifier() { KEYWORD(returnDoesNotAlias); KEYWORD(noInline); KEYWORD(alwaysInline); + KEYWORD(noUnwind); + KEYWORD(mayThrow); + KEYWORD(hasUnknownCall); + KEYWORD(mustBeUnreachable); KEYWORD(calls); KEYWORD(callee); KEYWORD(params); @@ -848,7 +854,15 @@ lltok::Kind LLLexer::LexIdentifier() { TYPEKEYWORD("x86_mmx", Type::getX86_MMXTy(Context)); TYPEKEYWORD("x86_amx", Type::getX86_AMXTy(Context)); TYPEKEYWORD("token", Type::getTokenTy(Context)); - TYPEKEYWORD("ptr", PointerType::getUnqual(Context)); + + if (Keyword == "ptr") { + if (Context.supportsTypedPointers()) { + Warning("ptr type is only supported in -opaque-pointers mode"); + return lltok::Error; + } + TyVal = PointerType::getUnqual(Context); + return lltok::Type; + } #undef TYPEKEYWORD diff --git a/llvm-project-llvmorg-13.0.1/llvm/lib/AsmParser/LLParser.cpp b/llvm-project-llvmorg-14.0.6/llvm/lib/AsmParser/LLParser.cpp index 799cb03..432ec15 100644 --- a/llvm-project-llvmorg-13.0.1/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm-project-llvmorg-14.0.6/llvm/lib/AsmParser/LLParser.cpp @@ -124,8 +124,8 @@ void LLParser::restoreParsingState(const SlotMapping *Slots) { std::make_pair(I.first, std::make_pair(I.second, LocTy()))); } -/// validateEndOfModule - Do final validity and sanity checks at the end of the -/// module. +/// validateEndOfModule - Do final validity and basic correctness checks at the +/// end of the module. bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { if (!M) return false; @@ -133,15 +133,18 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { for (const auto &RAG : ForwardRefAttrGroups) { Value *V = RAG.first; const std::vector &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(V)) { AttributeList AS = Fn->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); @@ -152,35 +155,31 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { FnAttrs.removeAttribute(Attribute::Alignment); } - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, FnAttrs); Fn->setAttributes(AS); } else if (CallInst *CI = dyn_cast(V)) { AttributeList AS = CI->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, FnAttrs); CI->setAttributes(AS); } else if (InvokeInst *II = dyn_cast(V)) { AttributeList AS = II->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, FnAttrs); II->setAttributes(AS); } else if (CallBrInst *CBI = dyn_cast(V)) { AttributeList AS = CBI->getAttributes(); - AttrBuilder FnAttrs(AS.getFnAttributes()); - AS = AS.removeAttributes(Context, AttributeList::FunctionIndex); + AttrBuilder FnAttrs(M->getContext(), AS.getFnAttrs()); + AS = AS.removeFnAttributes(Context); FnAttrs.merge(B); - AS = AS.addAttributes(Context, AttributeList::FunctionIndex, - AttributeSet::get(Context, FnAttrs)); + AS = AS.addFnAttributes(Context, FnAttrs); CBI->setAttributes(AS); } else if (auto *GV = dyn_cast(V)) { - AttrBuilder Attrs(GV->getAttributes()); + AttrBuilder Attrs(M->getContext(), GV->getAttributes()); Attrs.merge(B); GV->setAttributes(AttributeSet::get(Context,Attrs)); } else { @@ -239,18 +238,18 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { Inst->setMetadata(LLVMContext::MD_tbaa, UpgradedMD); } - // Look for intrinsic functions and CallInst that need to be upgraded - for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) - UpgradeCallsToIntrinsic(&*FI++); // must be post-increment, as we remove + // Look for intrinsic functions and CallInst that need to be upgraded. We use + // make_early_inc_range here because we may remove some functions. + for (Function &F : llvm::make_early_inc_range(*M)) + UpgradeCallsToIntrinsic(&F); // Some types could be renamed during loading if several modules are // loaded in the same LLVMContext (LTO scenario). In this case we should // remangle intrinsics names as well. - for (Module::iterator FI = M->begin(), FE = M->end(); FI != FE; ) { - Function *F = &*FI++; - if (auto Remangled = Intrinsic::remangleIntrinsicFunction(F)) { - F->replaceAllUsesWith(Remangled.getValue()); - F->eraseFromParent(); + for (Function &F : llvm::make_early_inc_range(*M)) { + if (auto Remangled = Intrinsic::remangleIntrinsicFunction(&F)) { + F.replaceAllUsesWith(Remangled.getValue()); + F.eraseFromParent(); } } @@ -275,7 +274,7 @@ bool LLParser::validateEndOfModule(bool UpgradeDebugInfo) { return false; } -/// Do final validity and sanity checks at the end of the index. +/// Do final validity and basic correctness checks at the end of the index. bool LLParser::validateEndOfIndex() { if (!Index) return false; @@ -605,13 +604,16 @@ bool LLParser::parseUnnamedGlobal() { parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr)) return true; - if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc) + switch (Lex.getKind()) { + default: return parseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); - - return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility, + case lltok::kw_alias: + case lltok::kw_ifunc: + return parseAliasOrIFunc(Name, NameLoc, Linkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); } +} /// parseNamedGlobal: /// GlobalVar '=' OptionalVisibility (ALIAS | IFUNC) ... @@ -635,13 +637,16 @@ bool LLParser::parseNamedGlobal() { parseOptionalThreadLocal(TLM) || parseOptionalUnnamedAddr(UnnamedAddr)) return true; - if (Lex.getKind() != lltok::kw_alias && Lex.getKind() != lltok::kw_ifunc) + switch (Lex.getKind()) { + default: return parseGlobal(Name, NameLoc, Linkage, HasLinkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); - - return parseIndirectSymbol(Name, NameLoc, Linkage, Visibility, + case lltok::kw_alias: + case lltok::kw_ifunc: + return parseAliasOrIFunc(Name, NameLoc, Linkage, Visibility, DLLStorageClass, DSOLocal, TLM, UnnamedAddr); } +} bool LLParser::parseComdat() { assert(Lex.getKind() == lltok::ComdatVar); @@ -913,21 +918,21 @@ static std::string typeComparisonErrorMessage(StringRef Message, Type *Ty1, return ErrOS.str(); } -/// parseIndirectSymbol: +/// parseAliasOrIFunc: /// ::= GlobalVar '=' OptionalLinkage OptionalPreemptionSpecifier /// OptionalVisibility OptionalDLLStorageClass /// OptionalThreadLocal OptionalUnnamedAddr -/// 'alias|ifunc' IndirectSymbol IndirectSymbolAttr* +/// 'alias|ifunc' AliaseeOrResolver SymbolAttrs* /// -/// IndirectSymbol +/// AliaseeOrResolver /// ::= TypeAndValue /// -/// IndirectSymbolAttr +/// SymbolAttrs /// ::= ',' 'partition' StringConstant /// /// Everything through OptionalUnnamedAddr has already been parsed. /// -bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, +bool LLParser::parseAliasOrIFunc(const std::string &Name, LocTy NameLoc, unsigned L, unsigned Visibility, unsigned DLLStorageClass, bool DSOLocal, GlobalVariable::ThreadLocalMode TLM, @@ -980,15 +985,16 @@ bool LLParser::parseIndirectSymbol(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)) { + if (IsAlias) { + if (!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()) { + PTy->getNonOpaquePointerElementType())); + } else { + if (!PTy->isOpaque() && + !PTy->getNonOpaquePointerElementType()->isFunctionTy()) return error(ExplicitTypeLoc, "explicit pointee type should be a function type"); } @@ -1013,21 +1019,26 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, } } - // Okay, create the alias but do not insert it into the module yet. - std::unique_ptr GA; - if (IsAlias) + // Okay, create the alias/ifunc but do not insert it into the module yet. + std::unique_ptr GA; + std::unique_ptr GI; + GlobalValue *GV; + if (IsAlias) { GA.reset(GlobalAlias::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee, /*Parent*/ nullptr)); - else - GA.reset(GlobalIFunc::create(Ty, AddrSpace, + GV = GA.get(); + } else { + GI.reset(GlobalIFunc::create(Ty, AddrSpace, (GlobalValue::LinkageTypes)Linkage, Name, Aliasee, /*Parent*/ nullptr)); - GA->setThreadLocalMode(TLM); - GA->setVisibility((GlobalValue::VisibilityTypes)Visibility); - GA->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); - GA->setUnnamedAddr(UnnamedAddr); - maybeSetDSOLocal(DSOLocal, *GA); + GV = GI.get(); + } + GV->setThreadLocalMode(TLM); + GV->setVisibility((GlobalValue::VisibilityTypes)Visibility); + GV->setDLLStorageClass((GlobalValue::DLLStorageClassTypes)DLLStorageClass); + GV->setUnnamedAddr(UnnamedAddr); + maybeSetDSOLocal(DSOLocal, *GV); // At this point we've parsed everything except for the IndirectSymbolAttrs. // Now parse them if there are any. @@ -1036,7 +1047,7 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, if (Lex.getKind() == lltok::kw_partition) { Lex.Lex(); - GA->setPartition(Lex.getStrVal()); + GV->setPartition(Lex.getStrVal()); if (parseToken(lltok::StringConstant, "expected partition string")) return true; } else { @@ -1045,30 +1056,27 @@ bool LLParser::parseIndirectSymbol(const std::string &Name, LocTy NameLoc, } if (Name.empty()) - NumberedVals.push_back(GA.get()); + NumberedVals.push_back(GV); if (GVal) { // Verify that types agree. - if (GVal->getType() != GA->getType()) + if (GVal->getType() != GV->getType()) return error( ExplicitTypeLoc, "forward reference and definition of alias have different types"); // If they agree, just RAUW the old value with the alias and remove the // forward ref info. - GVal->replaceAllUsesWith(GA.get()); + GVal->replaceAllUsesWith(GV); GVal->eraseFromParent(); } // Insert into the module, we know its name won't collide now. if (IsAlias) - M->getAliasList().push_back(cast(GA.get())); + M->getAliasList().push_back(GA.release()); else - M->getIFuncList().push_back(cast(GA.get())); - assert(GA->getName() == Name && "Should not be a name conflict!"); - - // The module owns this now - GA.release(); + M->getIFuncList().push_back(GI.release()); + assert(GV->getName() == Name && "Should not be a name conflict!"); return false; } @@ -1202,7 +1210,7 @@ bool LLParser::parseGlobal(const std::string &Name, LocTy NameLoc, } } - AttrBuilder Attrs; + AttrBuilder Attrs(M->getContext()); LocTy BuiltinLoc; std::vector FwdRefAttrGrps; if (parseFnAttributeValuePairs(Attrs, FwdRefAttrGrps, false, BuiltinLoc)) @@ -1231,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; @@ -1302,7 +1315,8 @@ bool LLParser::parseEnumAttribute(Attribute::AttrKind Attr, AttrBuilder &B, unsigned MinValue, MaxValue; if (parseVScaleRangeArguments(MinValue, MaxValue)) return true; - B.addVScaleRangeAttr(MinValue, MaxValue); + B.addVScaleRangeAttr(MinValue, + MaxValue > 0 ? MaxValue : Optional()); return false; } case Attribute::Dereferenceable: { @@ -1397,25 +1411,21 @@ static inline GlobalValue *createGlobalFwdRef(Module *M, PointerType *PTy) { nullptr, GlobalVariable::NotThreadLocal, PTy->getAddressSpace()); - if (auto *FT = dyn_cast(PTy->getPointerElementType())) + Type *ElemTy = PTy->getNonOpaquePointerElementType(); + if (auto *FT = dyn_cast(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, - Value *Val, bool IsCall) { + Value *Val) { Type *ValTy = Val->getType(); if (ValTy == Ty) return Val; - // For calls, we also allow opaque pointers. - if (IsCall && ValTy == PointerType::get(Ty->getContext(), - Ty->getPointerAddressSpace())) - return Val; if (Ty->isLabelTy()) error(Loc, "'" + Name + "' is not a basic block"); else @@ -1429,7 +1439,7 @@ Value *LLParser::checkValidVariableType(LocTy Loc, const Twine &Name, Type *Ty, /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, - LocTy Loc, bool IsCall) { + LocTy Loc) { PointerType *PTy = dyn_cast(Ty); if (!PTy) { error(Loc, "global variable reference must have pointer type"); @@ -1451,7 +1461,7 @@ GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) return cast_or_null( - checkValidVariableType(Loc, "@" + Name, Ty, Val, IsCall)); + checkValidVariableType(Loc, "@" + Name, Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. GlobalValue *FwdVal = createGlobalFwdRef(M, PTy); @@ -1459,8 +1469,7 @@ GlobalValue *LLParser::getGlobalVal(const std::string &Name, Type *Ty, return FwdVal; } -GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc, - bool IsCall) { +GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc) { PointerType *PTy = dyn_cast(Ty); if (!PTy) { error(Loc, "global variable reference must have pointer type"); @@ -1480,7 +1489,7 @@ GlobalValue *LLParser::getGlobalVal(unsigned ID, Type *Ty, LocTy Loc, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) return cast_or_null( - checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val, IsCall)); + checkValidVariableType(Loc, "@" + Twine(ID), Ty, Val)); // Otherwise, create a new forward reference for this value and remember it. GlobalValue *FwdVal = createGlobalFwdRef(M, PTy); @@ -1936,7 +1945,7 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) { if (!EatIfPresent(lltok::kw_align)) return false; LocTy AlignLoc = Lex.getLoc(); - uint32_t Value = 0; + uint64_t Value = 0; LocTy ParenLoc = Lex.getLoc(); bool HaveParens = false; @@ -1945,13 +1954,13 @@ bool LLParser::parseOptionalAlignment(MaybeAlign &Alignment, bool AllowParens) { HaveParens = true; } - if (parseUInt32(Value)) + if (parseUInt64(Value)) return true; if (HaveParens && !EatIfPresent(lltok::rparen)) return error(ParenLoc, "expected ')'"); - if (!isPowerOf2_32(Value)) + if (!isPowerOf2_64(Value)) return error(AlignLoc, "alignment is not a power of two"); if (Value > Value::MaximumAlignment) return error(AlignLoc, "huge alignments are not supported yet"); @@ -2221,6 +2230,26 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) { // Type ::= 'float' | 'void' (etc) Result = Lex.getTyVal(); Lex.Lex(); + + // Handle "ptr" opaque pointer type. + // + // Type ::= ptr ('addrspace' '(' uint32 ')')? + if (Result->isOpaquePointerTy()) { + unsigned AddrSpace; + if (parseOptionalAddrSpace(AddrSpace)) + return true; + Result = PointerType::get(getContext(), AddrSpace); + + // Give a nice error for 'ptr*'. + if (Lex.getKind() == lltok::star) + return tokError("ptr* is invalid - use ptr instead"); + + // Fall through to parsing the type suffixes only if this 'ptr' is a + // function return. Otherwise, return success, implicitly rejecting other + // suffixes. + if (Lex.getKind() != lltok::lparen) + return false; + } break; case lltok::lbrace: // Type ::= StructType @@ -2274,26 +2303,6 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) { } } - // Handle (explicit) opaque pointer types (not --force-opaque-pointers). - // - // Type ::= ptr ('addrspace' '(' uint32 ')')? - if (Result->isOpaquePointerTy()) { - unsigned AddrSpace; - if (parseOptionalAddrSpace(AddrSpace)) - return true; - Result = PointerType::get(getContext(), AddrSpace); - - // Give a nice error for 'ptr*'. - if (Lex.getKind() == lltok::star) - return tokError("ptr* is invalid - use ptr instead"); - - // Fall through to parsing the type suffixes only if this 'ptr' is a - // function return. Otherwise, return success, implicitly rejecting other - // suffixes. - if (Lex.getKind() != lltok::lparen) - return false; - } - // parse the type suffixes. while (true) { switch (Lex.getKind()) { @@ -2372,11 +2381,12 @@ bool LLParser::parseParameterList(SmallVectorImpl &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 &ArgList, } else { LocTy TypeLoc = Lex.getLoc(); Type *ArgTy = nullptr; - AttrBuilder Attrs; + AttrBuilder Attrs(M->getContext()); std::string Name; if (parseType(ArgTy) || parseOptionalParamAttrs(Attrs)) @@ -2798,7 +2808,7 @@ bool LLParser::PerFunctionState::finishFunction() { /// forward reference record if needed. This can return null if the value /// exists but does not have the right type. Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, - LocTy Loc, bool IsCall) { + LocTy Loc) { // Look this name up in the normal function symbol table. Value *Val = F.getValueSymbolTable()->lookup(Name); @@ -2812,7 +2822,7 @@ Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return P.checkValidVariableType(Loc, "%" + Name, Ty, Val, IsCall); + return P.checkValidVariableType(Loc, "%" + Name, Ty, Val); // Don't make placeholders with invalid type. if (!Ty->isFirstClassType()) { @@ -2832,8 +2842,7 @@ Value *LLParser::PerFunctionState::getVal(const std::string &Name, Type *Ty, return FwdVal; } -Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc, - bool IsCall) { +Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc) { // Look this name up in the normal function symbol table. Value *Val = ID < NumberedVals.size() ? NumberedVals[ID] : nullptr; @@ -2847,7 +2856,7 @@ Value *LLParser::PerFunctionState::getVal(unsigned ID, Type *Ty, LocTy Loc, // If we have the value in the symbol table or fwd-ref table, return it. if (Val) - return P.checkValidVariableType(Loc, "%" + Twine(ID), Ty, Val, IsCall); + return P.checkValidVariableType(Loc, "%" + Twine(ID), Ty, Val); if (!Ty->isFirstClassType()) { P.error(Loc, "invalid use of a non-first-class type"); @@ -2934,12 +2943,12 @@ bool LLParser::PerFunctionState::setInstName(int NameID, BasicBlock *LLParser::PerFunctionState::getBB(const std::string &Name, LocTy Loc) { return dyn_cast_or_null( - getVal(Name, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false)); + getVal(Name, Type::getLabelTy(F.getContext()), Loc)); } BasicBlock *LLParser::PerFunctionState::getBB(unsigned ID, LocTy Loc) { return dyn_cast_or_null( - getVal(ID, Type::getLabelTy(F.getContext()), Loc, /*IsCall=*/false)); + getVal(ID, Type::getLabelTy(F.getContext()), Loc)); } /// defineBB - Define the specified basic block, which is either named or @@ -2991,9 +3000,10 @@ BasicBlock *LLParser::PerFunctionState::defineBB(const std::string &Name, /// parseValID - parse an abstract value that doesn't necessarily have a /// type implied. For example, if we parse "4" we don't know what integer type /// it has. The value will later be combined with its type and checked for -/// sanity. PFS is used to convert function-local operands of metadata (since -/// metadata operands are not just parsed here but also converted to values). -/// PFS can be null when we are not parsing metadata values inside a function. +/// basic correctness. PFS is used to convert function-local operands of +/// metadata (since metadata operands are not just parsed here but also +/// converted to values). PFS can be null when we are not parsing metadata +/// values inside a function. bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { ID.Loc = Lex.getLoc(); switch (Lex.getKind()) { @@ -3288,6 +3298,20 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { return false; } + case lltok::kw_no_cfi: { + // ValID ::= 'no_cfi' @foo + Lex.Lex(); + + if (parseValID(ID, PFS)) + return true; + + if (ID.Kind != ValID::t_GlobalID && ID.Kind != ValID::t_GlobalName) + return error(ID.Loc, "expected global value name in no_cfi"); + + ID.NoCFI = true; + return false; + } + case lltok::kw_trunc: case lltok::kw_zext: case lltok::kw_sext: @@ -3565,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 = @@ -3652,7 +3676,7 @@ bool LLParser::parseGlobalValue(Type *Ty, Constant *&C) { ValID ID; Value *V = nullptr; bool Parsed = parseValID(ID, /*PFS=*/nullptr, Ty) || - convertValIDToValue(Ty, ID, V, nullptr, /*IsCall=*/false); + convertValIDToValue(Ty, ID, V, nullptr); if (V && !(C = dyn_cast(V))) return error(ID.Loc, "global values must be constants"); return Parsed; @@ -3876,10 +3900,6 @@ struct MDField : public MDFieldImpl { MDField(bool AllowNull = true) : ImplTy(nullptr), AllowNull(AllowNull) {} }; -struct MDConstant : public MDFieldImpl { - MDConstant() : ImplTy(nullptr) {} -}; - struct MDStringField : public MDFieldImpl { bool AllowEmpty; MDStringField(bool AllowEmpty = true) @@ -3914,22 +3934,6 @@ struct MDSignedOrMDField : MDEitherFieldImpl { } }; -struct MDSignedOrUnsignedField - : MDEitherFieldImpl { - MDSignedOrUnsignedField() : ImplTy(MDSignedField(0), MDUnsignedField(0)) {} - - bool isMDSignedField() const { return WhatIs == IsTypeA; } - bool isMDUnsignedField() const { return WhatIs == IsTypeB; } - int64_t getMDSignedValue() const { - assert(isMDSignedField() && "Wrong field type"); - return A.Val; - } - uint64_t getMDUnsignedValue() const { - assert(isMDUnsignedField() && "Wrong field type"); - return B.Val; - } -}; - } // end anonymous namespace namespace llvm { @@ -4547,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; } @@ -4578,7 +4583,8 @@ bool LLParser::parseDIDerivedType(MDNode *&Result, bool IsDistinct) { OPTIONAL(offset, MDUnsignedField, (0, UINT64_MAX)); \ OPTIONAL(flags, DIFlagField, ); \ OPTIONAL(extraData, MDField, ); \ - OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); + OPTIONAL(dwarfAddressSpace, MDUnsignedField, (UINT32_MAX, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4590,7 +4596,7 @@ bool LLParser::parseDIDerivedType(MDNode *&Result, bool IsDistinct) { (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, offset.Val, DWARFAddressSpace, flags.Val, - extraData.Val)); + extraData.Val, annotations.Val)); return false; } @@ -4615,7 +4621,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { OPTIONAL(dataLocation, MDField, ); \ OPTIONAL(associated, MDField, ); \ OPTIONAL(allocated, MDField, ); \ - OPTIONAL(rank, MDSignedOrMDField, ); + OPTIONAL(rank, MDSignedOrMDField, ); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4633,7 +4640,7 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val, discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, - Rank)) { + Rank, annotations.Val)) { Result = CT; return false; } @@ -4645,8 +4652,8 @@ bool LLParser::parseDICompositeType(MDNode *&Result, bool IsDistinct) { (Context, tag.Val, name.Val, file.Val, line.Val, scope.Val, baseType.Val, size.Val, align.Val, offset.Val, flags.Val, elements.Val, runtimeLang.Val, vtableHolder.Val, templateParams.Val, identifier.Val, - discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, - Rank)); + discriminator.Val, dataLocation.Val, associated.Val, allocated.Val, Rank, + annotations.Val)); return false; } @@ -4746,7 +4753,8 @@ bool LLParser::parseDICompileUnit(MDNode *&Result, bool IsDistinct) { /// virtuality: DW_VIRTUALTIY_pure_virtual, /// virtualIndex: 10, thisAdjustment: 4, flags: 11, /// spFlags: 10, isOptimized: false, templateParams: !4, -/// declaration: !5, retainedNodes: !6, thrownTypes: !7) +/// declaration: !5, retainedNodes: !6, thrownTypes: !7, +/// annotations: !8) bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { auto Loc = Lex.getLoc(); #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ @@ -4770,7 +4778,8 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { OPTIONAL(templateParams, MDField, ); \ OPTIONAL(declaration, MDField, ); \ OPTIONAL(retainedNodes, MDField, ); \ - OPTIONAL(thrownTypes, MDField, ); + OPTIONAL(thrownTypes, MDField, ); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4789,7 +4798,7 @@ bool LLParser::parseDISubprogram(MDNode *&Result, bool IsDistinct) { (Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val, type.Val, scopeLine.Val, containingType.Val, virtualIndex.Val, thisAdjustment.Val, flags.Val, SPFlags, unit.Val, templateParams.Val, - declaration.Val, retainedNodes.Val, thrownTypes.Val)); + declaration.Val, retainedNodes.Val, thrownTypes.Val, annotations.Val)); return false; } @@ -4966,7 +4975,8 @@ bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) { OPTIONAL(isDefinition, MDBoolField, (true)); \ OPTIONAL(templateParams, MDField, ); \ OPTIONAL(declaration, MDField, ); \ - OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); + OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS @@ -4974,7 +4984,8 @@ bool LLParser::parseDIGlobalVariable(MDNode *&Result, bool IsDistinct) { GET_OR_DISTINCT(DIGlobalVariable, (Context, scope.Val, name.Val, linkageName.Val, file.Val, line.Val, type.Val, isLocal.Val, isDefinition.Val, - declaration.Val, templateParams.Val, align.Val)); + declaration.Val, templateParams.Val, align.Val, + annotations.Val)); return false; } @@ -4994,13 +5005,15 @@ bool LLParser::parseDILocalVariable(MDNode *&Result, bool IsDistinct) { OPTIONAL(line, LineField, ); \ OPTIONAL(type, MDField, ); \ OPTIONAL(flags, DIFlagField, ); \ - OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); + OPTIONAL(align, MDUnsignedField, (0, UINT32_MAX)); \ + OPTIONAL(annotations, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS Result = GET_OR_DISTINCT(DILocalVariable, (Context, scope.Val, name.Val, file.Val, line.Val, - type.Val, arg.Val, flags.Val, align.Val)); + type.Val, arg.Val, flags.Val, align.Val, + annotations.Val)); return false; } @@ -5136,7 +5149,7 @@ bool LLParser::parseDIObjCProperty(MDNode *&Result, bool IsDistinct) { /// parseDIImportedEntity: /// ::= !DIImportedEntity(tag: DW_TAG_imported_module, scope: !0, entity: !1, -/// line: 7, name: "foo") +/// line: 7, name: "foo", elements: !2) bool LLParser::parseDIImportedEntity(MDNode *&Result, bool IsDistinct) { #define VISIT_MD_FIELDS(OPTIONAL, REQUIRED) \ REQUIRED(tag, DwarfTagField, ); \ @@ -5144,13 +5157,14 @@ bool LLParser::parseDIImportedEntity(MDNode *&Result, bool IsDistinct) { OPTIONAL(entity, MDField, ); \ OPTIONAL(file, MDField, ); \ OPTIONAL(line, LineField, ); \ - OPTIONAL(name, MDStringField, ); + OPTIONAL(name, MDStringField, ); \ + OPTIONAL(elements, MDField, ); PARSE_MD_FIELDS(); #undef VISIT_MD_FIELDS - Result = GET_OR_DISTINCT( - DIImportedEntity, - (Context, tag.Val, scope.Val, entity.Val, file.Val, line.Val, name.Val)); + Result = GET_OR_DISTINCT(DIImportedEntity, + (Context, tag.Val, scope.Val, entity.Val, file.Val, + line.Val, name.Val, elements.Val)); return false; } @@ -5254,7 +5268,7 @@ bool LLParser::parseMetadata(Metadata *&MD, PerFunctionState *PFS) { //===----------------------------------------------------------------------===// bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, - PerFunctionState *PFS, bool IsCall) { + PerFunctionState *PFS) { if (Ty->isFunctionTy()) return error(ID.Loc, "functions are not values, refer to them as pointers"); @@ -5262,12 +5276,12 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, case ValID::t_LocalID: if (!PFS) return error(ID.Loc, "invalid use of function-local name"); - V = PFS->getVal(ID.UIntVal, Ty, ID.Loc, IsCall); + V = PFS->getVal(ID.UIntVal, Ty, ID.Loc); return V == nullptr; case ValID::t_LocalName: if (!PFS) return error(ID.Loc, "invalid use of function-local name"); - V = PFS->getVal(ID.StrVal, Ty, ID.Loc, IsCall); + V = PFS->getVal(ID.StrVal, Ty, ID.Loc); return V == nullptr; case ValID::t_InlineAsm: { if (!ID.FTy || !InlineAsm::Verify(ID.FTy, ID.StrVal2)) @@ -5278,10 +5292,14 @@ bool LLParser::convertValIDToValue(Type *Ty, ValID &ID, Value *&V, return false; } case ValID::t_GlobalName: - V = getGlobalVal(ID.StrVal, Ty, ID.Loc, IsCall); + V = getGlobalVal(ID.StrVal, Ty, ID.Loc); + if (V && ID.NoCFI) + V = NoCFIValue::get(cast(V)); return V == nullptr; case ValID::t_GlobalID: - V = getGlobalVal(ID.UIntVal, Ty, ID.Loc, IsCall); + V = getGlobalVal(ID.UIntVal, Ty, ID.Loc); + if (V && ID.NoCFI) + V = NoCFIValue::get(cast(V)); return V == nullptr; case ValID::t_APSInt: if (!Ty->isIntegerTy()) @@ -5405,7 +5423,7 @@ bool LLParser::parseConstantValue(Type *Ty, Constant *&C) { case ValID::t_ConstantStruct: case ValID::t_PackedConstantStruct: { Value *V; - if (convertValIDToValue(Ty, ID, V, /*PFS=*/nullptr, /*IsCall=*/false)) + if (convertValIDToValue(Ty, ID, V, /*PFS=*/nullptr)) return true; assert(isa(V) && "Expected a constant value"); C = cast(V); @@ -5423,7 +5441,7 @@ bool LLParser::parseValue(Type *Ty, Value *&V, PerFunctionState *PFS) { V = nullptr; ValID ID; return parseValID(ID, PFS, Ty) || - convertValIDToValue(Ty, ID, V, PFS, /*IsCall=*/false); + convertValIDToValue(Ty, ID, V, PFS); } bool LLParser::parseTypeAndValue(Value *&V, PerFunctionState *PFS) { @@ -5455,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; @@ -5518,7 +5536,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) { SmallVector ArgList; bool IsVarArg; - AttrBuilder FuncAttrs; + AttrBuilder FuncAttrs(M->getContext()); std::vector FwdRefAttrGrps; LocTy BuiltinLoc; std::string Section; @@ -5571,7 +5589,7 @@ bool LLParser::parseFunctionHeader(Function *&Fn, bool IsDefine) { AttributeList::get(Context, AttributeSet::get(Context, FuncAttrs), AttributeSet::get(Context, RetAttrs), Attrs); - if (PAL.hasAttribute(1, Attribute::StructRet) && !RetType->isVoidTy()) + if (PAL.hasParamAttr(0, Attribute::StructRet) && !RetType->isVoidTy()) return error(RetTypeLoc, "functions with 'sret' argument must return void"); FunctionType *FT = FunctionType::get(RetType, ParamTypeList, IsVarArg); @@ -5586,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) @@ -5718,7 +5736,7 @@ bool LLParser::PerFunctionState::resolveForwardRefBlockAddresses() { Value *ResolvedVal = BlockAddress::get(&F, BB); ResolvedVal = P.checkValidVariableType(BBID.Loc, BBID.StrVal, GV->getType(), - ResolvedVal, false); + ResolvedVal); if (!ResolvedVal) return true; GV->replaceAllUsesWith(ResolvedVal); @@ -6241,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 FwdRefAttrGrps; LocTy NoBuiltinLoc; unsigned CC; @@ -6287,7 +6305,7 @@ bool LLParser::parseInvoke(Instruction *&Inst, PerFunctionState &PFS) { // Look up the callee. Value *Callee; if (convertValIDToValue(PointerType::get(Ty, InvokeAddrSpace), CalleeID, - Callee, &PFS, /*IsCall=*/true)) + Callee, &PFS)) return true; // Set up the Attribute for the function. @@ -6551,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 FwdRefAttrGrps; LocTy NoBuiltinLoc; unsigned CC; @@ -6612,8 +6630,7 @@ bool LLParser::parseCallBr(Instruction *&Inst, PerFunctionState &PFS) { // Look up the callee. Value *Callee; - if (convertValIDToValue(PointerType::getUnqual(Ty), CalleeID, Callee, &PFS, - /*IsCall=*/true)) + if (convertValIDToValue(PointerType::getUnqual(Ty), CalleeID, Callee, &PFS)) return true; // Set up the Attribute for the function. @@ -6969,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 FwdRefAttrGrps; LocTy BuiltinLoc; unsigned CallAddrSpace; @@ -7019,7 +7036,7 @@ bool LLParser::parseCall(Instruction *&Inst, PerFunctionState &PFS, // Look up the callee. Value *Callee; if (convertValIDToValue(PointerType::get(Ty, CallAddrSpace), CalleeID, Callee, - &PFS, /*IsCall=*/true)) + &PFS)) return true; // Set up the Attribute for the function. @@ -7190,7 +7207,7 @@ int LLParser::parseLoad(Instruction *&Inst, PerFunctionState &PFS) { ExplicitTypeLoc, typeComparisonErrorMessage( "explicit pointee type doesn't match operand's pointee type", Ty, - cast(Val->getType())->getElementType())); + Val->getType()->getNonOpaquePointerElementType())); } SmallPtrSet Visited; if (!Alignment && !Ty->isSized(&Visited)) @@ -7450,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 Indices; @@ -8543,12 +8560,16 @@ bool LLParser::parseFlag(unsigned &Val) { /// [',' 'returnDoesNotAlias' ':' Flag]? ')' /// [',' 'noInline' ':' Flag]? ')' /// [',' 'alwaysInline' ':' Flag]? ')' +/// [',' 'noUnwind' ':' Flag]? ')' +/// [',' 'mayThrow' ':' Flag]? ')' +/// [',' 'hasUnknownCall' ':' Flag]? ')' +/// [',' 'mustBeUnreachable' ':' Flag]? ')' bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) { assert(Lex.getKind() == lltok::kw_funcFlags); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in funcFlags") | + if (parseToken(lltok::colon, "expected ':' in funcFlags") || parseToken(lltok::lparen, "expected '(' in funcFlags")) return true; @@ -8591,6 +8612,30 @@ bool LLParser::parseOptionalFFlags(FunctionSummary::FFlags &FFlags) { return true; FFlags.AlwaysInline = Val; break; + case lltok::kw_noUnwind: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.NoUnwind = Val; + break; + case lltok::kw_mayThrow: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.MayThrow = Val; + break; + case lltok::kw_hasUnknownCall: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.HasUnknownCall = Val; + break; + case lltok::kw_mustBeUnreachable: + Lex.Lex(); + if (parseToken(lltok::colon, "expected ':'") || parseFlag(Val)) + return true; + FFlags.MustBeUnreachable = Val; + break; default: return error(Lex.getLoc(), "expected function flag type"); } @@ -8610,7 +8655,7 @@ bool LLParser::parseOptionalCalls(std::vector &Calls) { assert(Lex.getKind() == lltok::kw_calls); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in calls") | + if (parseToken(lltok::colon, "expected ':' in calls") || parseToken(lltok::lparen, "expected '(' in calls")) return true; @@ -8702,7 +8747,7 @@ bool LLParser::parseOptionalVTableFuncs(VTableFuncList &VTableFuncs) { assert(Lex.getKind() == lltok::kw_vTableFuncs); Lex.Lex(); - if (parseToken(lltok::colon, "expected ':' in vTableFuncs") | + if (parseToken(lltok::colon, "expected ':' in vTableFuncs") || parseToken(lltok::lparen, "expected '(' in vTableFuncs")) return true; diff --git a/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Attributes.td b/llvm-project-llvmorg-14.0.6/llvm/include/llvm/IR/Attributes.td index 99b4741..40c554c 100644 --- a/llvm-project-llvmorg-13.0.1/llvm/include/llvm/IR/Attributes.td +++ b/llvm-project-llvmorg-14.0.6/llvm/include/llvm/IR/Attributes.td @@ -86,6 +86,9 @@ def Dereferenceable : IntAttr<"dereferenceable", [ParamAttr, RetAttr]>; def DereferenceableOrNull : IntAttr<"dereferenceable_or_null", [ParamAttr, RetAttr]>; +/// Do not instrument function with sanitizers. +def DisableSanitizerInstrumentation: EnumAttr<"disable_sanitizer_instrumentation", [FnAttr]>; + /// Provide pointer element type to intrinsic. def ElementType : TypeAttr<"elementtype", [ParamAttr]>; @@ -342,3 +345,6 @@ def : MergeRule<"adjustCallerStackProbeSize">; def : MergeRule<"adjustMinLegalVectorWidth">; def : MergeRule<"adjustNullPointerValidAttr">; def : MergeRule<"setAND">; + +// Target dependent attributes +include "llvm/IR/AttributesAMDGPU.td" ```
mewmew commented 2 years ago

@dannypsnl, could you prepare the v0.3.5 (LLVM 13.0) and v0.3.6 (LLVM 14.0) releases so they show up on https://github.com/llir/llvm/releases? (I've not done that before)

Cheers, Robin