+// VerifyAttrs - Check the given parameter attributes for an argument or return
+// value of the specified type. The value V is printed in error messages.
+void Verifier::VerifyAttrs(ParameterAttributes Attrs, const Type *Ty,
+ bool isReturnValue, const Value *V) {
+ if (Attrs == ParamAttr::None)
+ return;
+
+ if (isReturnValue) {
+ ParameterAttributes RetI = Attrs & ParamAttr::ParameterOnly;
+ Assert1(!RetI, "Attribute " + ParamAttr::getAsString(RetI) +
+ "does not apply to return values!", V);
+ } else {
+ ParameterAttributes ParmI = Attrs & ParamAttr::ReturnOnly;
+ Assert1(!ParmI, "Attribute " + ParamAttr::getAsString(ParmI) +
+ "only applies to return values!", V);
+ }
+
+ for (unsigned i = 0;
+ i < array_lengthof(ParamAttr::MutuallyIncompatible); ++i) {
+ ParameterAttributes MutI = Attrs & ParamAttr::MutuallyIncompatible[i];
+ Assert1(!(MutI & (MutI - 1)), "Attributes " +
+ ParamAttr::getAsString(MutI) + "are incompatible!", V);
+ }
+
+ ParameterAttributes TypeI = Attrs & ParamAttr::typeIncompatible(Ty);
+ Assert1(!TypeI, "Wrong type for attribute " +
+ ParamAttr::getAsString(TypeI), V);
+}
+
+// VerifyFunctionAttrs - Check parameter attributes against a function type.
+// The value V is printed in error messages.
+void Verifier::VerifyFunctionAttrs(const FunctionType *FT,
+ const PAListPtr &Attrs,
+ const Value *V) {
+ if (Attrs.isEmpty())
+ return;
+
+ bool SawNest = false;
+
+ for (unsigned i = 0, e = Attrs.getNumSlots(); i != e; ++i) {
+ const ParamAttrsWithIndex &Attr = Attrs.getSlot(i);
+
+ const Type *Ty;
+ if (Attr.Index == 0)
+ Ty = FT->getReturnType();
+ 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);
+
+ if (Attr.Attrs & ParamAttr::Nest) {
+ Assert1(!SawNest, "More than one parameter has attribute nest!", V);
+ SawNest = true;
+ }
+
+ if (Attr.Attrs & ParamAttr::StructRet)
+ Assert1(Attr.Index == 1, "Attribute sret not on first parameter!", V);
+ }
+}
+