From d6de30ceea69ee9ce6dded4bb3ae5881861cb090 Mon Sep 17 00:00:00 2001 From: Duncan Sands Date: Thu, 11 Jun 2009 08:11:03 +0000 Subject: [PATCH] Cosmetic changes to parameter attribute verification. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@73188 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Attributes.h | 5 +++-- lib/VMCore/Verifier.cpp | 35 ++++++++++++++++++----------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/include/llvm/Attributes.h b/include/llvm/Attributes.h index a594e3223d4..134e3502028 100644 --- a/include/llvm/Attributes.h +++ b/include/llvm/Attributes.h @@ -61,7 +61,8 @@ const Attributes NoImplicitFloat = 1<<23; /// disable implicit floating point /// @brief Attributes that only apply to function parameters. const Attributes ParameterOnly = ByVal | Nest | StructRet | NoCapture; -/// @brief Attributes that only apply to function. +/// @brief Attributes that may be applied to the function itself. These cannot +/// be used on return values or function parameters. const Attributes FunctionOnly = NoReturn | NoUnwind | ReadNone | ReadOnly | NoInline | AlwaysInline | OptimizeForSize | StackProtect | StackProtectReq | NoRedZone | NoImplicitFloat; @@ -186,7 +187,7 @@ public: /// getFnAttributes - The function attributes are returned. Attributes getFnAttributes() const { - return getAttributes(~0); + return getAttributes(~0U); } /// paramHasAttr - Return true if the specified parameter index has the diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp index b1297ff2256..e9f2acda28d 100644 --- a/lib/VMCore/Verifier.cpp +++ b/lib/VMCore/Verifier.cpp @@ -276,8 +276,8 @@ namespace { int VT, unsigned ArgNo, std::string &Suffix); void VerifyIntrinsicPrototype(Intrinsic::ID ID, Function *F, unsigned RetNum, unsigned ParamNum, ...); - void VerifyAttrs(Attributes Attrs, const Type *Ty, - bool isReturnValue, const Value *V); + void VerifyParameterAttrs(Attributes Attrs, const Type *Ty, + bool isReturnValue, const Value *V); void VerifyFunctionAttrs(const FunctionType *FT, const AttrListPtr &Attrs, const Value *V); @@ -437,22 +437,23 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { void Verifier::verifyTypeSymbolTable(TypeSymbolTable &ST) { } -// VerifyAttrs - Check the given parameter attributes for an argument or return +// VerifyParameterAttrs - Check the given attributes for an argument or return // value of the specified type. The value V is printed in error messages. -void Verifier::VerifyAttrs(Attributes Attrs, const Type *Ty, - bool isReturnValue, const Value *V) { +void Verifier::VerifyParameterAttrs(Attributes Attrs, const Type *Ty, + bool isReturnValue, const Value *V) { if (Attrs == Attribute::None) return; + Attributes FnCheckAttr = Attrs & Attribute::FunctionOnly; + Assert1(!FnCheckAttr, "Attribute " + Attribute::getAsString(FnCheckAttr) + + " only applies to the function!", V); + if (isReturnValue) { Attributes RetI = Attrs & Attribute::ParameterOnly; Assert1(!RetI, "Attribute " + Attribute::getAsString(RetI) + " does not apply to return values!", V); } - Attributes FnCheckAttr = Attrs & Attribute::FunctionOnly; - Assert1(!FnCheckAttr, "Attribute " + Attribute::getAsString(FnCheckAttr) + - " only applies to functions!", V); - + for (unsigned i = 0; i < array_lengthof(Attribute::MutuallyIncompatible); ++i) { Attributes MutI = Attrs & Attribute::MutuallyIncompatible[i]; @@ -495,9 +496,9 @@ void Verifier::VerifyFunctionAttrs(const FunctionType *FT, else if (Attr.Index-1 < FT->getNumParams()) Ty = FT->getParamType(Attr.Index-1); else - break; // VarArgs attributes, don't verify. - - VerifyAttrs(Attr.Attrs, Ty, Attr.Index == 0, V); + break; // VarArgs attributes, verified elsewhere. + + VerifyParameterAttrs(Attr.Attrs, Ty, Attr.Index == 0, V); if (Attr.Attrs & Attribute::Nest) { Assert1(!SawNest, "More than one parameter has attribute nest!", V); @@ -509,10 +510,10 @@ void Verifier::VerifyFunctionAttrs(const FunctionType *FT, } Attributes FAttrs = Attrs.getFnAttributes(); - Assert1(!(FAttrs & (~Attribute::FunctionOnly)), - "Attribute " + Attribute::getAsString(FAttrs) + - " does not apply to function!", V); - + Attributes NotFn = FAttrs & (~Attribute::FunctionOnly); + Assert1(!NotFn, "Attribute " + Attribute::getAsString(NotFn) + + " does not apply to the function!", V); + for (unsigned i = 0; i < array_lengthof(Attribute::MutuallyIncompatible); ++i) { Attributes MutI = FAttrs & Attribute::MutuallyIncompatible[i]; @@ -1025,7 +1026,7 @@ void Verifier::VerifyCallSite(CallSite CS) { for (unsigned Idx = 1 + FTy->getNumParams(); Idx <= CS.arg_size(); ++Idx) { Attributes Attr = Attrs.getParamAttributes(Idx); - VerifyAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I); + VerifyParameterAttrs(Attr, CS.getArgument(Idx-1)->getType(), false, I); Attributes VArgI = Attr & Attribute::VarArgsIncompatible; Assert1(!VArgI, "Attribute " + Attribute::getAsString(VArgI) +