diff --git a/lib/Support/StringRef.cpp b/lib/Support/StringRef.cpp index 40b732c62db..c33ca6a2ebf 100644 --- a/lib/Support/StringRef.cpp +++ b/lib/Support/StringRef.cpp @@ -31,14 +31,14 @@ static bool ascii_isdigit(char x) { /// compare_lower - Compare strings, ignoring case. int StringRef::compare_lower(StringRef RHS) const { for (size_t I = 0, E = min(Length, RHS.Length); I != E; ++I) { - char LHC = ascii_tolower(Data[I]); - char RHC = ascii_tolower(RHS.Data[I]); + unsigned char LHC = ascii_tolower(Data[I]); + unsigned char RHC = ascii_tolower(RHS.Data[I]); if (LHC != RHC) return LHC < RHC ? -1 : 1; } if (Length == RHS.Length) - return 0; + return 0; return Length < RHS.Length ? -1 : 1; } @@ -62,7 +62,7 @@ int StringRef::compare_numeric(StringRef RHS) const { return Data[I] < RHS.Data[I] ? -1 : 1; } if (Length == RHS.Length) - return 0; + return 0; return Length < RHS.Length ? -1 : 1; } diff --git a/unittests/ADT/StringRefTest.cpp b/unittests/ADT/StringRefTest.cpp index 887ba5d1f9e..de5c349cd60 100644 --- a/unittests/ADT/StringRefTest.cpp +++ b/unittests/ADT/StringRefTest.cpp @@ -53,6 +53,14 @@ TEST(StringRefTest, StringOps) { EXPECT_EQ( 1, StringRef("aab").compare("aaa")); EXPECT_EQ(-1, StringRef("aab").compare("aabb")); EXPECT_EQ( 1, StringRef("aab").compare("aa")); + EXPECT_EQ( 1, StringRef("\xFF").compare("\1")); + + EXPECT_EQ(-1, StringRef("AaB").compare_lower("aAd")); + EXPECT_EQ( 0, StringRef("AaB").compare_lower("aab")); + EXPECT_EQ( 1, StringRef("AaB").compare_lower("AAA")); + EXPECT_EQ(-1, StringRef("AaB").compare_lower("aaBb")); + EXPECT_EQ( 1, StringRef("AaB").compare_lower("aA")); + EXPECT_EQ( 1, StringRef("\xFF").compare_lower("\1")); EXPECT_EQ(-1, StringRef("aab").compare_numeric("aad")); EXPECT_EQ( 0, StringRef("aab").compare_numeric("aab"));