[IR] Short-circuit comparison with itself for Attributes
authorDanila Malyutin <danila@synopsys.com>
Tue, 23 Jun 2020 11:43:02 +0000 (14:43 +0300)
committerDanila Malyutin <danila@synopsys.com>
Fri, 3 Jul 2020 13:07:14 +0000 (16:07 +0300)
Differential Revision: https://reviews.llvm.org/D82295

llvm/lib/IR/Attributes.cpp
llvm/unittests/IR/AttributesTest.cpp

index 8573e7f..4c4aa51 100644 (file)
@@ -597,6 +597,8 @@ Type *AttributeImpl::getValueAsType() const {
 }
 
 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()) {
index b1c455e..2c19126 100644 (file)
@@ -44,6 +44,7 @@ TEST(Attributes, Ordering) {
   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)};