Skip to content

Conversation

@michaelrj-google
Copy link
Contributor

@michaelrj-google michaelrj-google commented Feb 12, 2025

On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.

Fixes:

error: implicit conversion loses integer precision: 'int64_t' (aka 'long long') to 'time_t' (aka 'int') [-Werror,-Wshorten-64-to-32]
  332 |     return mktime_internal(timeptr);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~

On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.
@llvmbot llvmbot added the libc label Feb 12, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 12, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.


Full diff: https://github.com/llvm/llvm-project/pull/126947.diff

1 Files Affected:

  • (modified) libc/src/time/time_utils.h (+3-1)
diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 324e129f6f780..68eaac8c04f11 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -328,7 +328,9 @@ class TMReader final {
     return BASE_YEAR + IS_NEXT_YEAR;
   }
 
-  LIBC_INLINE time_t get_epoch() const { return mktime_internal(timeptr); }
+  LIBC_INLINE time_t get_epoch() const {
+    return static_cast<time_t>(mktime_internal(timeptr));
+  }
 
   // returns the timezone offset in microwave time:
   // return (hours * 100) + minutes;

@nickdesaulniers
Copy link
Member

mktime_internal can probably be converted to use time_t instead of int64_t.

@Prabhuk
Copy link
Contributor

Prabhuk commented Feb 12, 2025

LGTM. I am trying a local build.

@michaelrj-google michaelrj-google merged commit 16a5f7e into llvm:main Feb 12, 2025
13 of 14 checks passed
@michaelrj-google michaelrj-google deleted the libcTimeTConvert branch February 12, 2025 18:27
flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.

Fixes:

error: implicit conversion loses integer precision: 'int64_t' (aka 'long
long') to 'time_t' (aka 'int') [-Werror,-Wshorten-64-to-32]
      332 |     return mktime_internal(timeptr);
          |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.

Fixes:

error: implicit conversion loses integer precision: 'int64_t' (aka 'long
long') to 'time_t' (aka 'int') [-Werror,-Wshorten-64-to-32]
      332 |     return mktime_internal(timeptr);
          |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
On some systems time_t is 32 bit, causing build errors (with -Werror)
in get_epoch which attempts to implicitly convert an int64_t to a
time_t.

Fixes:

error: implicit conversion loses integer precision: 'int64_t' (aka 'long
long') to 'time_t' (aka 'int') [-Werror,-Wshorten-64-to-32]
      332 |     return mktime_internal(timeptr);
          |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants