[PATCH] D77027: Make BitVector::operator== return false for different-sized vectors

Michael Kruse via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 7 11:58:14 PDT 2020


Meinersbur added inline comments.


================
Comment at: llvm/include/llvm/ADT/BitVector.h:542
-
-    // Verify that any extra words are all zeros.
-    if (i != ThisWords) {
----------------
Meinersbur wrote:
> dblaikie wrote:
> > Hmm - looking at this more closely (ie: I'm now actually looking at the code rather than just the commentary/discussion) this code makes me a bit uncomfortable - looks pretty intentionally designed to support potentially equal comparison of differently lengthed BitVectors. Is there any history of how/when this was added/potentially used?
> It was introduced in 2007 by Chris Lattner in r42860 with the commit message "make bitvector  &= do the right thing if vectors have mismatched length." and no other changes. Before that, it asserted on mismatching lengths.
> 
> By its name, it's a vector and a comparison that does something else than checking the same elements in the same order is confusing.
Sorry, looked at the wrong operator. 

The commit was r42889 also by Chris Lattner in 2007. It's commit message is: 
> make operator== work with non-equal sized bitvectors, as long as the extra bits are all zeros.  This allows  "010" and "010000" to be treated as equal.
without any other changes or justifications. Before that, it returned false on different sizes.

Note that "010" and "010000" can be very different depending on its interpretation, e.g. the former represents the decimal number 2, the latter is 16.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77027/new/

https://reviews.llvm.org/D77027





More information about the llvm-commits mailing list