[libc-commits] [libc] 4151859 - [libc] Fix gmtime test on systems with sizeof(time_t) == 4 (#65388)

via libc-commits libc-commits at lists.llvm.org
Thu Sep 7 06:28:51 PDT 2023


Author: Mikhail R. Gadelha
Date: 2023-09-07T09:28:47-04:00
New Revision: 41518597705c558409725d4ba2d3c1af9110ca0d

URL: https://github.com/llvm/llvm-project/commit/41518597705c558409725d4ba2d3c1af9110ca0d
DIFF: https://github.com/llvm/llvm-project/commit/41518597705c558409725d4ba2d3c1af9110ca0d.diff

LOG: [libc] Fix gmtime test on systems with sizeof(time_t) == 4 (#65388)

This test creates a time_t variable and assigns 0xfffffffffe1d7b01 which
overflows the maximum time_t value for 64-bit time_t, then checks if the
syscall fails and errno was set.

In systems with sizeof(time_t) == 4, the value is narrowed down to
0xfe1d7b01 and doesn't overflow, causing the test to fail.

This patch then disables the test on systems with 32 bits long time_t.

Added: 
    

Modified: 
    libc/test/src/time/gmtime_test.cpp

Removed: 
    


################################################################################
diff  --git a/libc/test/src/time/gmtime_test.cpp b/libc/test/src/time/gmtime_test.cpp
index 07e3950bdcf24a..4d990b3da5bc15 100644
--- a/libc/test/src/time/gmtime_test.cpp
+++ b/libc/test/src/time/gmtime_test.cpp
@@ -20,6 +20,8 @@ using __llvm_libc::testing::ErrnoSetterMatcher::Succeeds;
 using __llvm_libc::time_utils::TimeConstants;
 
 TEST(LlvmLibcGmTime, OutOfRange) {
+  if (sizeof(time_t) < sizeof(int64_t))
+    return;
   time_t seconds =
       1 + INT_MAX * static_cast<int64_t>(
                         TimeConstants::NUMBER_OF_SECONDS_IN_LEAP_YEAR);


        


More information about the libc-commits mailing list