[PATCH] D103491: [ADT] Move DenseMapInfo for ArrayRef/StringRef into respective headers (NFC)
Chris Lattner via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 2 10:58:24 PDT 2021
lattner added inline comments.
================
Comment at: llvm/include/llvm/ADT/ArrayRef.h:595-600
+ if (RHS.data() == getEmptyKey().data())
+ return LHS.data() == getEmptyKey().data();
+ if (RHS.data() == getTombstoneKey().data())
+ return LHS.data() == getTombstoneKey().data();
+ return LHS == RHS;
+ }
----------------
nikic wrote:
> lattner wrote:
> > craig.topper wrote:
> > > lattner wrote:
> > > > I'm pretty sure this method can just be "return LHS == RHS;" The tombstone/empty comparisons should work without special cases.
> > > Doesn't operator== on ArrayRef compare the elements of the arrays? So wouldn't that dereference the invalid pointers used by tombstone/empty?
> > Yes, implemented in terms of std::equal. However, both of these cases have zero elements, so the "pointer" is never dereferenced.
> As the length is zero, wouldn't the empty key, the tombstone key and an empty ArrayRef all be considered equal, as the data pointer is never compared?
Yes, you're right, this won't work. Good catch, thanks :-)
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D103491/new/
https://reviews.llvm.org/D103491
More information about the cfe-commits
mailing list