[mlir] NFC - Fix OperationSupport.cpp::findNamedAttr
authorNicolas Vasilache <ntv@google.com>
Mon, 18 May 2020 13:33:35 +0000 (09:33 -0400)
committerNicolas Vasilache <ntv@google.com>
Mon, 18 May 2020 13:36:00 +0000 (09:36 -0400)
Summary:
When NamedAttrList::get is called against a StringRef and the
entry is not present, the Identifier::operator== crashes.
Interestingly there seems to be no use of the NamedAttrList::get(StringRef) in
the codebase so far. A subsequent commit will introduce such a use.

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

mlir/lib/IR/OperationSupport.cpp

index f326d62..ef2b377 100644 (file)
@@ -97,7 +97,7 @@ static auto *findAttr(SmallVectorImpl<NamedAttribute> &attrs, T name,
   }
 
   auto *it = llvm::lower_bound(attrs, name);
-  if (it->first != name)
+  if (it == attrs.end() || it->first != name)
     return attrs.end();
   return it;
 }