[llvm] [llvm] tighten estimate of bits needed when parsing an integer (PR #205947)

Eli Friedman via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 26 14:04:31 PDT 2026


================
@@ -522,12 +522,35 @@ bool StringRef::consumeInteger(unsigned Radix, APInt &Result) {
     return false;
   }
 
-  // (Over-)estimate the required number of bits.
+  // The string is too long to be reasonable
+  if (Str.size() > std::numeric_limits<unsigned>::max())
----------------
efriedma-quic wrote:

> your comment implies the original code (repeated below) was a bug, right

Yes.

-----

Probably the simplest thing to do is to just set the initial width to 64, then double the width whenever we run out of space.  Not fancy, but this isn't exactly a high-performance implementation in the first place.

https://github.com/llvm/llvm-project/pull/205947


More information about the llvm-commits mailing list