[NFC] Factor out function to detect if an attribute has an argument.

This commit is contained in:
Tyker 2020-02-02 14:47:00 +01:00
parent 47cda0cb36
commit 15f54d348b
5 changed files with 25 additions and 6 deletions

View File

@ -111,6 +111,9 @@ public:
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
//===--------------------------------------------------------------------===//

View File

@ -134,10 +134,7 @@ class IntAttributeImpl : public EnumAttributeImpl {
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!");
}

View File

@ -199,6 +199,14 @@ StringRef Attribute::getNameFromAttrKind(Attribute::AttrKind AttrKind) {
}
}
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
//===----------------------------------------------------------------------===//
@ -1472,8 +1480,7 @@ void AttrBuilder::clear() {
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;

View File

@ -1572,6 +1572,13 @@ void Verifier::verifyAttributeTypes(AttributeSet Attrs, bool IsFunction,
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() +

View File

@ -128,6 +128,11 @@ struct AssumeBuilderState {
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)