[libc-commits] [PATCH] D159125: [libc] Make time_t 64 bits long on all platforms but arm32

Phabricator via libc-commits libc-commits at lists.llvm.org
Wed Sep 13 06:51:15 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG75398f28ebdb: [libc] Make time_t 64 bits long on all platforms but arm32 (authored by Mikhail R. Gadelha <mikhail at igalia.com>).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159125/new/

https://reviews.llvm.org/D159125

Files:
  libc/include/llvm-libc-types/time_t.h
  libc/src/time/linux/clockGetTimeImpl.h
  libc/src/time/linux/nanosleep.cpp


Index: libc/src/time/linux/nanosleep.cpp
===================================================================
--- libc/src/time/linux/nanosleep.cpp
+++ libc/src/time/linux/nanosleep.cpp
@@ -12,6 +12,7 @@
 #include "src/__support/common.h"
 #include "src/errno/libc_errno.h"
 
+#include <stdint.h>      // For int64_t.
 #include <sys/syscall.h> // For syscall numbers.
 
 namespace __llvm_libc {
@@ -21,8 +22,11 @@
 #if SYS_nanosleep
   int ret = __llvm_libc::syscall_impl<int>(SYS_nanosleep, req, rem);
 #elif defined(SYS_clock_nanosleep_time64)
-  int ret =
-      __llvm_libc::syscall_impl<int>(SYS_clock_nanosleep_time64, req, rem);
+  static_assert(
+      sizeof(time_t) == sizeof(int64_t),
+      "SYS_clock_gettime64 requires struct timespec with 64-bit members.");
+  int ret = __llvm_libc::syscall_impl<int>(SYS_clock_nanosleep_time64,
+                                           CLOCK_REALTIME, 0, req, rem);
 #else
 #error "SYS_nanosleep and SYS_clock_nanosleep_time64 syscalls not available."
 #endif
Index: libc/src/time/linux/clockGetTimeImpl.h
===================================================================
--- libc/src/time/linux/clockGetTimeImpl.h
+++ libc/src/time/linux/clockGetTimeImpl.h
@@ -14,6 +14,7 @@
 #include "src/__support/error_or.h"
 #include "src/errno/libc_errno.h"
 
+#include <stdint.h>      // For int64_t.
 #include <sys/syscall.h> // For syscall numbers.
 #include <time.h>
 
@@ -27,12 +28,12 @@
                                            static_cast<long>(clockid),
                                            reinterpret_cast<long>(ts));
 #elif defined(SYS_clock_gettime64)
-  struct timespec64 ts64;
+  static_assert(
+      sizeof(time_t) == sizeof(int64_t),
+      "SYS_clock_gettime64 requires struct timespec with 64-bit members.");
   int ret = __llvm_libc::syscall_impl<int>(SYS_clock_gettime64,
                                            static_cast<long>(clockid),
-                                           reinterpret_cast<long>(&ts64));
-  ts->tv_sec = static_cast<time_t>(ts64.tv_sec);
-  ts->tv_nsec = static_cast<long>(ts64.tv_nsec);
+                                           reinterpret_cast<long>(ts));
 #else
 #error "SYS_clock_gettime and SYS_clock_gettime64 syscalls not available."
 #endif
Index: libc/include/llvm-libc-types/time_t.h
===================================================================
--- libc/include/llvm-libc-types/time_t.h
+++ libc/include/llvm-libc-types/time_t.h
@@ -9,6 +9,10 @@
 #ifndef __LLVM_LIBC_TYPES_TIME_T_H__
 #define __LLVM_LIBC_TYPES_TIME_T_H__
 
+#if (defined(__arm__) || defined(_M_ARM))
 typedef __INTPTR_TYPE__ time_t;
+#else
+typedef __INT64_TYPE__ time_t;
+#endif
 
 #endif // __LLVM_LIBC_TYPES_TIME_T_H__


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D159125.556660.patch
Type: text/x-patch
Size: 2716 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20230913/e8204c72/attachment-0001.bin>


More information about the libc-commits mailing list