[llvm] 138a975 - Revert "[APSInt] Fix bug in APSInt mentioned in https://github.com/llvm/llvm-project/issues/59515"

Peter Rong via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 18 14:05:29 PST 2022


Author: Peter Rong
Date: 2022-12-18T14:05:17-08:00
New Revision: 138a97578b9d96a3071ff63b1ec46c1974c28307

URL: https://github.com/llvm/llvm-project/commit/138a97578b9d96a3071ff63b1ec46c1974c28307
DIFF: https://github.com/llvm/llvm-project/commit/138a97578b9d96a3071ff63b1ec46c1974c28307.diff

LOG: Revert "[APSInt] Fix bug in APSInt mentioned in https://github.com/llvm/llvm-project/issues/59515"

This reverts commit 7859d6e79ca90df2f3f206192a1dfa89e3cb10f1.

Signed-off-by: Peter Rong <PeterRong96 at gmail.com>

Added: 
    

Modified: 
    llvm/include/llvm/ADT/APSInt.h
    llvm/unittests/ADT/APSIntTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/APSInt.h b/llvm/include/llvm/ADT/APSInt.h
index 90b988875a24d..c64cf303d4c04 100644
--- a/llvm/include/llvm/ADT/APSInt.h
+++ b/llvm/include/llvm/ADT/APSInt.h
@@ -85,26 +85,12 @@ class [[nodiscard]] APSInt : public APInt {
   }
   using APInt::toString;
 
-  /// If this int is representable using an int64_t.
-  bool isRepresentableByInt64() const {
-    // For unsigned values with 64 active bits, they technically fit into a
-    // int64_t, but the user may get negative numbers and has to manually cast
-    // them to unsigned. Let's not bet the user has the sanity to do that and
-    // not give them a vague value at the first place.
-    return isSigned() ? isSignedIntN(64) : isIntN(63);
-  }
-
   /// Get the correctly-extended \c int64_t value.
   int64_t getExtValue() const {
-    assert(isRepresentableByInt64() && "Too many bits for int64_t");
+    assert(getMinSignedBits() <= 64 && "Too many bits for int64_t");
     return isSigned() ? getSExtValue() : getZExtValue();
   }
 
-  std::optional<int64_t> tryExtValue() const {
-    return isRepresentableByInt64() ? std::optional<int64_t>(getExtValue())
-                                    : std::nullopt;
-  }
-
   APSInt trunc(uint32_t width) const {
     return APSInt(APInt::trunc(width), IsUnsigned);
   }

diff  --git a/llvm/unittests/ADT/APSIntTest.cpp b/llvm/unittests/ADT/APSIntTest.cpp
index f804eba3ca83e..932f54c19f18d 100644
--- a/llvm/unittests/ADT/APSIntTest.cpp
+++ b/llvm/unittests/ADT/APSIntTest.cpp
@@ -62,13 +62,6 @@ TEST(APSIntTest, getUnsigned) {
   EXPECT_EQ(UINT64_C(0) - 7, APSInt::getUnsigned(-7).getZExtValue());
 }
 
-TEST(APSIntTest, isRepresentableByInt64) {
-  ASSERT_TRUE(APSInt(APInt(3, 7), true).isRepresentableByInt64());
-  ASSERT_TRUE(APSInt(APInt(128, 7), true).isRepresentableByInt64());
-  ASSERT_TRUE(APSInt(APInt(128, 7), false).isRepresentableByInt64());
-  ASSERT_TRUE(APSInt(APInt(64, -1), false).isRepresentableByInt64());
-  ASSERT_FALSE(APSInt(APInt(64, (uint64_t)-1), true).isRepresentableByInt64());
-}
 TEST(APSIntTest, getExtValue) {
   EXPECT_TRUE(APSInt(APInt(3, 7), true).isUnsigned());
   EXPECT_TRUE(APSInt(APInt(3, 7), false).isSigned());
@@ -83,16 +76,6 @@ TEST(APSIntTest, getExtValue) {
   EXPECT_EQ(9, APSInt(APInt(4, -7), true).getExtValue());
   EXPECT_EQ(-7, APSInt(APInt(4, -7), false).getExtValue());
 }
-TEST(APSIntTest, tryExtValue) {
-  ASSERT_EQ(-7, APSInt(APInt(64, -7), false).tryExtValue().value_or(42));
-  ASSERT_EQ(42, APSInt(APInt(128, -7), false).tryExtValue().value_or(42));
-  ASSERT_EQ(-1,
-            APSInt(APInt::getAllOnes(128), false).tryExtValue().value_or(42));
-  ASSERT_EQ(42, APSInt(APInt(64, -7), true).tryExtValue().value_or(42));
-  ASSERT_EQ(1, APSInt(APInt(128, 1), true).tryExtValue().value_or(42));
-  ASSERT_EQ(42,
-            APSInt(APInt::getAllOnes(128), true).tryExtValue().value_or(42));
-}
 
 TEST(APSIntTest, compareValues) {
   auto U = [](uint64_t V) { return APSInt::getUnsigned(V); };


        


More information about the llvm-commits mailing list