[PATCH] D109555: [APInt] Enable APInt to support zero bit integers.

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 13 09:17:47 PDT 2021


foad added inline comments.


================
Comment at: llvm/include/llvm/ADT/APInt.h:352
+      if (BitWidth == 0)
+        return false;
       return U.VAL == WORDTYPE_MAX >> (APINT_BITS_PER_WORD - BitWidth);
----------------
lattner wrote:
> foad wrote:
> > Should be true, surely?
> Welcome to the weirdness of zero bit integers :)
I'm not joking. I assert that isAllOnes(getZeroWidth()) should return true, for the same reason that std::all_of() returns true on an empty range.

To put it another way, all of the bits in a zero-width integer //are// 1, and I challenge you to show me one that isn't!

To put it another way, isAllOnes(X) should be the same as X == (1 << X.getBitWidth()) - 1.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D109555



More information about the llvm-commits mailing list