[PATCH] D139683: [APInt] provide a safe API for zext value and sext value.

Peter Rong via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 12:28:40 PST 2022


Peter added inline comments.


================
Comment at: llvm/unittests/ADT/APSIntTest.cpp:94
+  // posMax128.setAllBits();
+  // EXPECT_EQ(42, APSInt(posMax128, true).tryExtValue().value_or(42));
+}
----------------
This test is explicitly commented out. It will trigger a bug in `getExtValue`. Do we want to fix it in this patch or another?

Bug description: There is an inconsistency in `getExtValue`. When checking if the operation is possible, it is **always** treated as a signed integer (`getMinSignedBits`), but when casting, it may be treated as an unsigned.

This inconsistency will crash all unsigned integer > 64 bits, with all high bits set to 1. (e.g. here its u128_max). `getExtValue` will determine the cast to unsigned int64 is possible(because it's treated as -1) but when casting `getZExtValue` will find it impossible.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D139683



More information about the llvm-commits mailing list