static StringRef getNameFromAttrKind(Attribute::AttrKind AttrKind);
+ /// Return true if and only if the attribute has an Argument.
+ static bool doesAttrKindHaveArgument(Attribute::AttrKind AttrKind);
+
//===--------------------------------------------------------------------===//
// Attribute Accessors
//===--------------------------------------------------------------------===//
public:
IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
: EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
- assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment ||
- Kind == Attribute::Dereferenceable ||
- Kind == Attribute::DereferenceableOrNull ||
- Kind == Attribute::AllocSize) &&
+ assert(Attribute::doesAttrKindHaveArgument(Kind) &&
"Wrong kind for int attribute!");
}
}
}
+bool Attribute::doesAttrKindHaveArgument(Attribute::AttrKind AttrKind) {
+ return AttrKind == Attribute::Alignment ||
+ AttrKind == Attribute::StackAlignment ||
+ AttrKind == Attribute::Dereferenceable ||
+ AttrKind == Attribute::AllocSize ||
+ AttrKind == Attribute::DereferenceableOrNull;
+}
+
//===----------------------------------------------------------------------===//
// Attribute Accessor Methods
//===----------------------------------------------------------------------===//
AttrBuilder &AttrBuilder::addAttribute(Attribute::AttrKind Val) {
assert((unsigned)Val < Attribute::EndAttrKinds && "Attribute out of range!");
- assert(Val != Attribute::Alignment && Val != Attribute::StackAlignment &&
- Val != Attribute::Dereferenceable && Val != Attribute::AllocSize &&
+ assert(!Attribute::doesAttrKindHaveArgument(Val) &&
"Adding integer attribute without adding a value!");
Attrs[Val] = true;
return *this;
if (A.isStringAttribute())
continue;
+ if (A.isIntAttribute() !=
+ Attribute::doesAttrKindHaveArgument(A.getKindAsEnum())) {
+ CheckFailed("Attribute '" + A.getAsString() + "' should have an Argument",
+ V);
+ return;
+ }
+
if (isFuncOnlyAttr(A.getKindAsEnum())) {
if (!IsFunction) {
CheckFailed("Attribute '" + A.getAsString() +
SmallVector<OperandBundleDef, 8> OpBundle;
for (const AssumedKnowledge &Elem : AssumedKnowledgeSet) {
SmallVector<Value *, 2> Args;
+ assert(Attribute::getAttrKindFromName(Elem.Name) ==
+ Attribute::AttrKind::None ||
+ static_cast<bool>(Elem.Argument) ==
+ Attribute::doesAttrKindHaveArgument(
+ Attribute::getAttrKindFromName(Elem.Name)));
if (Elem.WasOn.getPointer())
Args.push_back(Elem.WasOn.getPointer());
if (Elem.Argument)