[llvm] 38909f3 - [IR] Short-circuit comparison with itself for Attributes

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 06:07:41 PDT 2020


Author: Danila Malyutin
Date: 2020-07-03T16:07:14+03:00
New Revision: 38909f31bd085d255e4b20e6da1d74b147e5f76a

URL: https://github.com/llvm/llvm-project/commit/38909f31bd085d255e4b20e6da1d74b147e5f76a
DIFF: https://github.com/llvm/llvm-project/commit/38909f31bd085d255e4b20e6da1d74b147e5f76a.diff

LOG: [IR] Short-circuit comparison with itself for Attributes

Differential Revision: https://reviews.llvm.org/D82295

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 8573e7f2fb7e..4c4aa51d9e80 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -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()) {

diff  --git a/llvm/unittests/IR/AttributesTest.cpp b/llvm/unittests/IR/AttributesTest.cpp
index b1c455ea5793..2c191264a892 100644
--- a/llvm/unittests/IR/AttributesTest.cpp
+++ b/llvm/unittests/IR/AttributesTest.cpp
@@ -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)};


        


More information about the llvm-commits mailing list