[llvm-commits] [llvm] r165038 - /llvm/trunk/lib/Support/StringRef.cpp

David Blaikie dblaikie at gmail.com
Tue Oct 2 23:45:26 PDT 2012


On Tue, Oct 2, 2012 at 1:01 PM, Nick Kledzik <kledzik at apple.com> wrote:
> Author: kledzik
> Date: Tue Oct  2 15:01:48 2012
> New Revision: 165038
>
> URL: http://llvm.org/viewvc/llvm-project?rev=165038&view=rev
> Log:
> Improve overflow detection in StringRef::getAsUnsignedInteger().

Are there existing unit tests you could update to validate this change?

>
> Modified:
>     llvm/trunk/lib/Support/StringRef.cpp
>
> Modified: llvm/trunk/lib/Support/StringRef.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/StringRef.cpp?rev=165038&r1=165037&r2=165038&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Support/StringRef.cpp (original)
> +++ llvm/trunk/lib/Support/StringRef.cpp Tue Oct  2 15:01:48 2012
> @@ -350,8 +350,8 @@
>      unsigned long long PrevResult = Result;
>      Result = Result*Radix+CharVal;
>
> -    // Check for overflow.
> -    if (Result < PrevResult)
> +    // Check for overflow by shifting back and seeing if bits were lost.
> +    if (Result/Radix < PrevResult)
>        return true;
>
>      Str = Str.substr(1);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list