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

Chris Lattner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 9 18:25:19 PDT 2021


lattner added inline comments.


================
Comment at: llvm/include/llvm/ADT/APInt.h:1440-1444
   uint64_t getZExtValue() const {
-    if (isSingleWord())
+    if (isSingleWord()) {
+      assert(BitWidth && "zero width values not allowed");
       return U.VAL;
+    }
----------------
youngar wrote:
> youngar wrote:
> > In the initial comment block you mention that zext is defined, should this assert be removed?
> Oh, this should be moved to `getSExtValue()`
What I meant is the `zext()` method which zero extends an APInt (by adding new zeros and not caring about what is already there).  I chose to make this undefined on zero bit values because it is accessing the (non-existent) value.

We could change this (in this, or in a future patch), and make `getZExtValue()` also work.  That would definitely enable a bunch of stuff to "just work" with zero bit APInts, I just started out conservative with this patch.


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