diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -597,6 +597,8 @@ } bool AttributeImpl::operator<(const AttributeImpl &AI) const { + if (this == &AI) + return false; // This sorts the attributes with Attribute::AttrKinds coming first (sorted // relative to their enum value) and then strings. if (isEnumAttribute()) { diff --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp --- a/llvm/unittests/IR/AttributesTest.cpp +++ b/llvm/unittests/IR/AttributesTest.cpp @@ -44,6 +44,7 @@ Attribute ByVal = Attribute::get(C, Attribute::ByVal, Type::getInt32Ty(C)); EXPECT_FALSE(ByVal < Attribute::get(C, Attribute::ZExt)); EXPECT_TRUE(ByVal < Align4); + EXPECT_FALSE(ByVal < ByVal); AttributeList ASs[] = {AttributeList::get(C, 2, Attribute::ZExt), AttributeList::get(C, 1, Attribute::SExt)};