Skip to content

[libc][time] Fix -Wshorten-64-to-32 warning #132947

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025

Conversation

ilovepi
Copy link
Contributor

@ilovepi ilovepi commented Mar 25, 2025

This breaks builds of libc with top of tree clang under -Werror.

This breaks builds of libc with top of tree clang under -Werror.
Copy link
Contributor Author

ilovepi commented Mar 25, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@ilovepi ilovepi marked this pull request as ready for review March 25, 2025 15:46
@llvmbot llvmbot added the libc label Mar 25, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 25, 2025

@llvm/pr-subscribers-libc

Author: Paul Kirth (ilovepi)

Changes

This breaks builds of libc with top of tree clang under -Werror.


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

1 Files Affected:

  • (modified) libc/src/time/time_utils.cpp (+4-4)
diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp
index 6e06deb30e354..1c519c3ff8aec 100644
--- a/libc/src/time/time_utils.cpp
+++ b/libc/src/time/time_utils.cpp
@@ -102,10 +102,10 @@ cpp::optional<time_t> mktime_internal(const tm *tm_out) {
 
   // TODO: https://github.com/llvm/llvm-project/issues/121962
   // Need to handle timezone and update of tm_isdst.
-  time_t seconds = tm_out->tm_sec +
-                   tm_out->tm_min * time_constants::SECONDS_PER_MIN +
-                   tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
-                   total_days * time_constants::SECONDS_PER_DAY;
+  time_t seconds = static_cast<time_t>(
+      tm_out->tm_sec + tm_out->tm_min * time_constants::SECONDS_PER_MIN +
+      tm_out->tm_hour * time_constants::SECONDS_PER_HOUR +
+      total_days * time_constants::SECONDS_PER_DAY);
   return seconds;
 }
 

Copy link
Contributor Author

ilovepi commented Mar 25, 2025

Merge activity

  • Mar 25, 11:51 AM EDT: A user started a stack merge that includes this pull request via Graphite.
  • Mar 25, 11:53 AM EDT: A user merged this pull request with Graphite.

@ilovepi ilovepi merged commit 9fb7924 into main Mar 25, 2025
16 of 19 checks passed
@ilovepi ilovepi deleted the users/ilovepi/libc-implicit-cast branch March 25, 2025 15:53
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.

3 participants