static const unsigned NumTypeAttrKinds = LastTypeAttr - FirstTypeAttr + 1;
+ static bool isEnumAttrKind(AttrKind Kind) {
+ return Kind >= FirstEnumAttr && Kind <= LastEnumAttr;
+ }
+ static bool isIntAttrKind(AttrKind Kind) {
+ return Kind >= FirstIntAttr && Kind <= LastIntAttr;
+ }
static bool isTypeAttrKind(AttrKind Kind) {
return Kind >= FirstTypeAttr && Kind <= LastTypeAttr;
}
B.addStructRetAttr(nullptr);
else if (Kind == Attribute::InAlloca)
B.addInAllocaAttr(nullptr);
-
- B.addAttribute(Kind);
+ else if (Attribute::isEnumAttrKind(Kind))
+ B.addAttribute(Kind);
+ else
+ return error("Not an enum attribute");
} else if (Record[i] == 1) { // Integer attribute
Attribute::AttrKind Kind;
if (Error Err = parseAttrKind(Record[++i], &Kind))
return Err;
+ if (!Attribute::isIntAttrKind(Kind))
+ return error("Not an int attribute");
if (Kind == Attribute::Alignment)
B.addAlignmentAttr(Record[++i]);
else if (Kind == Attribute::StackAlignment)
Attribute Attribute::get(LLVMContext &Context, Attribute::AttrKind Kind,
uint64_t Val) {
+ if (Val)
+ assert(Attribute::isIntAttrKind(Kind) && "Not an int attribute");
+ else
+ assert(Attribute::isEnumAttrKind(Kind) && "Not an enum attribute");
+
LLVMContextImpl *pImpl = Context.pImpl;
FoldingSetNodeID ID;
ID.AddInteger(Kind);