[libc-commits] [libc] 6bbfd6a - [libc] Fix type errors on Windows

Michael Jones via libc-commits libc-commits at lists.llvm.org
Tue Aug 24 12:42:17 PDT 2021


Author: Michael Jones
Date: 2021-08-24T19:42:13Z
New Revision: 6bbfd6a9c1847f94ab94604d228b989891d2133a

URL: https://github.com/llvm/llvm-project/commit/6bbfd6a9c1847f94ab94604d228b989891d2133a
DIFF: https://github.com/llvm/llvm-project/commit/6bbfd6a9c1847f94ab94604d228b989891d2133a.diff

LOG: [libc] Fix type errors on Windows

Fix the errors caused by having some numbers too large for a 32 bit
number in the tests for windows. Also fix the base causing some type
confusion.

Reviewed By: sivachandra

Differential Revision: https://reviews.llvm.org/D108653

Added: 
    

Modified: 
    libc/test/src/stdlib/strtol_test.cpp
    libc/test/src/stdlib/strtoll_test.cpp
    libc/test/src/stdlib/strtoul_test.cpp
    libc/test/src/stdlib/strtoull_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/stdlib/strtol_test.cpp b/libc/test/src/stdlib/strtol_test.cpp
index c6633e58f4a0..b611503ed0cf 100644
--- a/libc/test/src/stdlib/strtol_test.cpp
+++ b/libc/test/src/stdlib/strtol_test.cpp
@@ -46,18 +46,18 @@ TEST(LlvmLibcStrToLTest, CleanBaseTenDecode) {
   ASSERT_EQ(errno, 0);
   EXPECT_EQ(str_end - negative, ptr
diff _t(4));
 
-  const char *big_number = "123456789012345";
+  const char *big_number = "1234567890";
   errno = 0;
-  ASSERT_EQ(__llvm_libc::strtol(big_number, &str_end, 10), 123456789012345l);
+  ASSERT_EQ(__llvm_libc::strtol(big_number, &str_end, 10), 1234567890l);
   ASSERT_EQ(errno, 0);
-  EXPECT_EQ(str_end - big_number, ptr
diff _t(15));
+  EXPECT_EQ(str_end - big_number, ptr
diff _t(10));
 
-  const char *big_negative_number = "-123456789012345";
+  const char *big_negative_number = "-1234567890";
   errno = 0;
   ASSERT_EQ(__llvm_libc::strtol(big_negative_number, &str_end, 10),
-            -123456789012345l);
+            -1234567890l);
   ASSERT_EQ(errno, 0);
-  EXPECT_EQ(str_end - big_negative_number, ptr
diff _t(16));
+  EXPECT_EQ(str_end - big_negative_number, ptr
diff _t(11));
 
   const char *too_big_number = "123456789012345678901";
   errno = 0;
@@ -155,7 +155,7 @@ static char int_to_b36_char(int input) {
 
 TEST(LlvmLibcStrToLTest, DecodeInOtherBases) {
   char small_string[4] = {'\0', '\0', '\0', '\0'};
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long base = 2; base <= 36; ++base) {
     for (long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       if (first_digit < base) {
@@ -171,7 +171,7 @@ TEST(LlvmLibcStrToLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long base = 2; base <= 36; ++base) {
     for (long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (long second_digit = 0; second_digit <= 36; ++second_digit) {
@@ -195,7 +195,7 @@ TEST(LlvmLibcStrToLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long base = 2; base <= 36; ++base) {
     for (long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (long second_digit = 0; second_digit <= 36; ++second_digit) {

diff  --git a/libc/test/src/stdlib/strtoll_test.cpp b/libc/test/src/stdlib/strtoll_test.cpp
index 1bb3c2a2638d..f46524bf72c1 100644
--- a/libc/test/src/stdlib/strtoll_test.cpp
+++ b/libc/test/src/stdlib/strtoll_test.cpp
@@ -179,7 +179,7 @@ static char int_to_b36_char(int input) {
 
 TEST(LlvmLibcStrToLLTest, DecodeInOtherBases) {
   char small_string[4] = {'\0', '\0', '\0', '\0'};
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long long base = 2; base <= 36; ++base) {
     for (long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       if (first_digit < base) {
@@ -195,7 +195,7 @@ TEST(LlvmLibcStrToLLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long long base = 2; base <= 36; ++base) {
     for (long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (long long second_digit = 0; second_digit <= 36; ++second_digit) {
@@ -219,7 +219,7 @@ TEST(LlvmLibcStrToLLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (long long base = 2; base <= 36; ++base) {
     for (long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (long long second_digit = 0; second_digit <= 36; ++second_digit) {

diff  --git a/libc/test/src/stdlib/strtoul_test.cpp b/libc/test/src/stdlib/strtoul_test.cpp
index 5b93832e36ae..0ae6594f2816 100644
--- a/libc/test/src/stdlib/strtoul_test.cpp
+++ b/libc/test/src/stdlib/strtoul_test.cpp
@@ -147,7 +147,7 @@ static char int_to_b36_char(int input) {
 
 TEST(LlvmLibcStrToULTest, DecodeInOtherBases) {
   char small_string[4] = {'\0', '\0', '\0', '\0'};
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long base = 2; base <= 36; ++base) {
     for (unsigned long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       if (first_digit < base) {
@@ -163,7 +163,7 @@ TEST(LlvmLibcStrToULTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long base = 2; base <= 36; ++base) {
     for (unsigned long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (unsigned long second_digit = 0; second_digit <= 36; ++second_digit) {
@@ -187,7 +187,7 @@ TEST(LlvmLibcStrToULTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long base = 2; base <= 36; ++base) {
     for (unsigned long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (unsigned long second_digit = 0; second_digit <= 36; ++second_digit) {

diff  --git a/libc/test/src/stdlib/strtoull_test.cpp b/libc/test/src/stdlib/strtoull_test.cpp
index a552042c816d..2dc787263200 100644
--- a/libc/test/src/stdlib/strtoull_test.cpp
+++ b/libc/test/src/stdlib/strtoull_test.cpp
@@ -155,7 +155,7 @@ static char int_to_b36_char(int input) {
 
 TEST(LlvmLibcStrToULLTest, DecodeInOtherBases) {
   char small_string[4] = {'\0', '\0', '\0', '\0'};
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long long base = 2; base <= 36; ++base) {
     for (unsigned long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       if (first_digit < base) {
@@ -171,7 +171,7 @@ TEST(LlvmLibcStrToULLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long long base = 2; base <= 36; ++base) {
     for (unsigned long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (unsigned long long second_digit = 0; second_digit <= 36;
@@ -196,7 +196,7 @@ TEST(LlvmLibcStrToULLTest, DecodeInOtherBases) {
     }
   }
 
-  for (unsigned int base = 2; base <= 36; ++base) {
+  for (unsigned long long base = 2; base <= 36; ++base) {
     for (unsigned long long first_digit = 0; first_digit <= 36; ++first_digit) {
       small_string[0] = int_to_b36_char(first_digit);
       for (unsigned long long second_digit = 0; second_digit <= 36;


        


More information about the libc-commits mailing list