Skip to content

[libc] create TimeReader to look at a struct tm #126138

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 3 commits into from
Feb 11, 2025

Conversation

michaelrj-google
Copy link
Contributor

In the process of adding strftime (#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.

In the process of adding strftime (llvm#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
@llvmbot
Copy link
Member

llvmbot commented Feb 6, 2025

@llvm/pr-subscribers-libc

Author: Michael Jones (michaelrj-google)

Changes

In the process of adding strftime (#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.


Patch is 21.50 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/126138.diff

6 Files Affected:

  • (modified) libc/include/llvm-libc-types/struct_tm.h (+1)
  • (modified) libc/src/time/CMakeLists.txt (+2)
  • (modified) libc/src/time/mktime.cpp (+1-93)
  • (modified) libc/src/time/time_constants.h (+16-1)
  • (modified) libc/src/time/time_utils.cpp (+92)
  • (modified) libc/src/time/time_utils.h (+256)
diff --git a/libc/include/llvm-libc-types/struct_tm.h b/libc/include/llvm-libc-types/struct_tm.h
index 9fef7c5718ea4a5..2ec74ecac0293b6 100644
--- a/libc/include/llvm-libc-types/struct_tm.h
+++ b/libc/include/llvm-libc-types/struct_tm.h
@@ -19,6 +19,7 @@ struct tm {
   int tm_wday;  // days since Sunday
   int tm_yday;  // days since January
   int tm_isdst; // Daylight Saving Time flag
+  // TODO: add tm_gmtoff and tm_zone? (posix extensions)
 };
 
 #endif // LLVM_LIBC_TYPES_STRUCT_TM_H
diff --git a/libc/src/time/CMakeLists.txt b/libc/src/time/CMakeLists.txt
index ef9bfe57bc4ec29..dd28aa67280b7f3 100644
--- a/libc/src/time/CMakeLists.txt
+++ b/libc/src/time/CMakeLists.txt
@@ -22,6 +22,8 @@ add_object_library(
   DEPENDS
     libc.include.time
     libc.src.__support.CPP.limits
+    libc.src.__support.CPP.string_view
+    libc.src.__support.CPP.optional
     libc.src.errno.errno
     .time_constants
     libc.hdr.types.time_t
diff --git a/libc/src/time/mktime.cpp b/libc/src/time/mktime.cpp
index 3874cad02facbd6..fc05ff2930434f9 100644
--- a/libc/src/time/mktime.cpp
+++ b/libc/src/time/mktime.cpp
@@ -14,100 +14,8 @@
 
 namespace LIBC_NAMESPACE_DECL {
 
-// Returns number of years from (1, year).
-static constexpr int64_t get_num_of_leap_years_before(int64_t year) {
-  return (year / 4) - (year / 100) + (year / 400);
-}
-
-// Returns True if year is a leap year.
-static constexpr bool is_leap_year(const int64_t year) {
-  return (((year) % 4) == 0 && (((year) % 100) != 0 || ((year) % 400) == 0));
-}
-
 LLVM_LIBC_FUNCTION(time_t, mktime, (struct tm * tm_out)) {
-  // Unlike most C Library functions, mktime doesn't just die on bad input.
-  // TODO(rtenneti); Handle leap seconds.
-  int64_t tm_year_from_base = tm_out->tm_year + time_constants::TIME_YEAR_BASE;
-
-  // 32-bit end-of-the-world is 03:14:07 UTC on 19 January 2038.
-  if (sizeof(time_t) == 4 &&
-      tm_year_from_base >= time_constants::END_OF32_BIT_EPOCH_YEAR) {
-    if (tm_year_from_base > time_constants::END_OF32_BIT_EPOCH_YEAR)
-      return time_utils::out_of_range();
-    if (tm_out->tm_mon > 0)
-      return time_utils::out_of_range();
-    if (tm_out->tm_mday > 19)
-      return time_utils::out_of_range();
-    else if (tm_out->tm_mday == 19) {
-      if (tm_out->tm_hour > 3)
-        return time_utils::out_of_range();
-      else if (tm_out->tm_hour == 3) {
-        if (tm_out->tm_min > 14)
-          return time_utils::out_of_range();
-        else if (tm_out->tm_min == 14) {
-          if (tm_out->tm_sec > 7)
-            return time_utils::out_of_range();
-        }
-      }
-    }
-  }
-
-  // Years are ints.  A 32-bit year will fit into a 64-bit time_t.
-  // A 64-bit year will not.
-  static_assert(
-      sizeof(int) == 4,
-      "ILP64 is unimplemented. This implementation requires 32-bit integers.");
-
-  // Calculate number of months and years from tm_mon.
-  int64_t month = tm_out->tm_mon;
-  if (month < 0 || month >= time_constants::MONTHS_PER_YEAR - 1) {
-    int64_t years = month / 12;
-    month %= 12;
-    if (month < 0) {
-      years--;
-      month += 12;
-    }
-    tm_year_from_base += years;
-  }
-  bool tm_year_is_leap = is_leap_year(tm_year_from_base);
-
-  // Calculate total number of days based on the month and the day (tm_mday).
-  int64_t total_days = tm_out->tm_mday - 1;
-  for (int64_t i = 0; i < month; ++i)
-    total_days += time_constants::NON_LEAP_YEAR_DAYS_IN_MONTH[i];
-  // Add one day if it is a leap year and the month is after February.
-  if (tm_year_is_leap && month > 1)
-    total_days++;
-
-  // Calculate total numbers of days based on the year.
-  total_days += (tm_year_from_base - time_constants::EPOCH_YEAR) *
-                time_constants::DAYS_PER_NON_LEAP_YEAR;
-  if (tm_year_from_base >= time_constants::EPOCH_YEAR) {
-    total_days += get_num_of_leap_years_before(tm_year_from_base - 1) -
-                  get_num_of_leap_years_before(time_constants::EPOCH_YEAR);
-  } else if (tm_year_from_base >= 1) {
-    total_days -= get_num_of_leap_years_before(time_constants::EPOCH_YEAR) -
-                  get_num_of_leap_years_before(tm_year_from_base - 1);
-  } else {
-    // Calculate number of leap years until 0th year.
-    total_days -= get_num_of_leap_years_before(time_constants::EPOCH_YEAR) -
-                  get_num_of_leap_years_before(0);
-    if (tm_year_from_base <= 0) {
-      total_days -= 1; // Subtract 1 for 0th year.
-      // Calculate number of leap years until -1 year
-      if (tm_year_from_base < 0) {
-        total_days -= get_num_of_leap_years_before(-tm_year_from_base) -
-                      get_num_of_leap_years_before(1);
-      }
-    }
-  }
-
-  // TODO: https://github.com/llvm/llvm-project/issues/121962
-  // Need to handle timezone and update of tm_isdst.
-  int64_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;
+  int64_t seconds = time_utils::mktime_internal(tm_out);
 
   // Update the tm structure's year, month, day, etc. from seconds.
   if (time_utils::update_from_seconds(seconds, tm_out) < 0)
diff --git a/libc/src/time/time_constants.h b/libc/src/time/time_constants.h
index 3e25f741745ab53..ab17862fdd957b9 100644
--- a/libc/src/time/time_constants.h
+++ b/libc/src/time/time_constants.h
@@ -18,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
 namespace time_constants {
 
 enum Month : int {
-  JANUARY,
+  JANUARY = 0,
   FEBRUARY,
   MARCH,
   APRIL,
@@ -32,6 +32,16 @@ enum Month : int {
   DECEMBER
 };
 
+enum WeekDay : int {
+  SUNDAY = 0,
+  MONDAY,
+  TUESDAY,
+  WEDNESDAY,
+  THURSDAY,
+  FRIDAY,
+  SATURDAY
+};
+
 constexpr int SECONDS_PER_MIN = 60;
 constexpr int MINUTES_PER_HOUR = 60;
 constexpr int HOURS_PER_DAY = 24;
@@ -40,6 +50,9 @@ constexpr int MONTHS_PER_YEAR = 12;
 constexpr int DAYS_PER_NON_LEAP_YEAR = 365;
 constexpr int DAYS_PER_LEAP_YEAR = 366;
 
+constexpr int LAST_DAY_OF_NON_LEAP_YEAR = DAYS_PER_NON_LEAP_YEAR - 1;
+constexpr int LAST_DAY_OF_LEAP_YEAR = DAYS_PER_LEAP_YEAR - 1;
+
 constexpr int SECONDS_PER_HOUR = SECONDS_PER_MIN * MINUTES_PER_HOUR;
 constexpr int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
 constexpr int NUMBER_OF_SECONDS_IN_LEAP_YEAR =
@@ -49,6 +62,8 @@ constexpr int TIME_YEAR_BASE = 1900;
 constexpr int EPOCH_YEAR = 1970;
 constexpr int EPOCH_WEEK_DAY = 4;
 
+constexpr int ISO_FIRST_DAY_OF_YEAR = 3; // the 4th day of the year, 0-indexed.
+
 // For asctime the behavior is undefined if struct tm's tm_wday or tm_mon are
 // not within the normal ranges as defined in <time.h>, or if struct tm's
 // tm_year exceeds {INT_MAX}-1990, or if the below asctime_internal algorithm
diff --git a/libc/src/time/time_utils.cpp b/libc/src/time/time_utils.cpp
index abc93b8cb961ed7..585cae0fc33ce6a 100644
--- a/libc/src/time/time_utils.cpp
+++ b/libc/src/time/time_utils.cpp
@@ -15,6 +15,98 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace time_utils {
 
+// TODO: clean this up in a followup patch
+int64_t mktime_internal(const struct tm *tm_out) {
+  // Unlike most C Library functions, mktime doesn't just die on bad input.
+  // TODO(rtenneti); Handle leap seconds.
+  int64_t tm_year_from_base = tm_out->tm_year + time_constants::TIME_YEAR_BASE;
+
+  // 32-bit end-of-the-world is 03:14:07 UTC on 19 January 2038.
+  if (sizeof(time_t) == 4 &&
+      tm_year_from_base >= time_constants::END_OF32_BIT_EPOCH_YEAR) {
+    if (tm_year_from_base > time_constants::END_OF32_BIT_EPOCH_YEAR)
+      return time_utils::out_of_range();
+    if (tm_out->tm_mon > 0)
+      return time_utils::out_of_range();
+    if (tm_out->tm_mday > 19)
+      return time_utils::out_of_range();
+    else if (tm_out->tm_mday == 19) {
+      if (tm_out->tm_hour > 3)
+        return time_utils::out_of_range();
+      else if (tm_out->tm_hour == 3) {
+        if (tm_out->tm_min > 14)
+          return time_utils::out_of_range();
+        else if (tm_out->tm_min == 14) {
+          if (tm_out->tm_sec > 7)
+            return time_utils::out_of_range();
+        }
+      }
+    }
+  }
+
+  // Years are ints.  A 32-bit year will fit into a 64-bit time_t.
+  // A 64-bit year will not.
+  static_assert(
+      sizeof(int) == 4,
+      "ILP64 is unimplemented. This implementation requires 32-bit integers.");
+
+  // Calculate number of months and years from tm_mon.
+  int64_t month = tm_out->tm_mon;
+  if (month < 0 || month >= time_constants::MONTHS_PER_YEAR - 1) {
+    int64_t years = month / 12;
+    month %= 12;
+    if (month < 0) {
+      years--;
+      month += 12;
+    }
+    tm_year_from_base += years;
+  }
+  bool tm_year_is_leap = time_utils::is_leap_year(tm_year_from_base);
+
+  // Calculate total number of days based on the month and the day (tm_mday).
+  int64_t total_days = tm_out->tm_mday - 1;
+  for (int64_t i = 0; i < month; ++i)
+    total_days += time_constants::NON_LEAP_YEAR_DAYS_IN_MONTH[i];
+  // Add one day if it is a leap year and the month is after February.
+  if (tm_year_is_leap && month > 1)
+    total_days++;
+
+  // Calculate total numbers of days based on the year.
+  total_days += (tm_year_from_base - time_constants::EPOCH_YEAR) *
+                time_constants::DAYS_PER_NON_LEAP_YEAR;
+  if (tm_year_from_base >= time_constants::EPOCH_YEAR) {
+    total_days +=
+        time_utils::get_num_of_leap_years_before(tm_year_from_base - 1) -
+        time_utils::get_num_of_leap_years_before(time_constants::EPOCH_YEAR);
+  } else if (tm_year_from_base >= 1) {
+    total_days -=
+        time_utils::get_num_of_leap_years_before(time_constants::EPOCH_YEAR) -
+        time_utils::get_num_of_leap_years_before(tm_year_from_base - 1);
+  } else {
+    // Calculate number of leap years until 0th year.
+    total_days -=
+        time_utils::get_num_of_leap_years_before(time_constants::EPOCH_YEAR) -
+        time_utils::get_num_of_leap_years_before(0);
+    if (tm_year_from_base <= 0) {
+      total_days -= 1; // Subtract 1 for 0th year.
+      // Calculate number of leap years until -1 year
+      if (tm_year_from_base < 0) {
+        total_days -=
+            time_utils::get_num_of_leap_years_before(-tm_year_from_base) -
+            time_utils::get_num_of_leap_years_before(1);
+      }
+    }
+  }
+
+  // TODO: https://github.com/llvm/llvm-project/issues/121962
+  // Need to handle timezone and update of tm_isdst.
+  int64_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;
+  return seconds;
+}
+
 static int64_t computeRemainingYears(int64_t daysPerYears,
                                      int64_t quotientYears,
                                      int64_t *remainingDays) {
diff --git a/libc/src/time/time_utils.h b/libc/src/time/time_utils.h
index 5e0a692d4db0486..f8521b0e8ec33cd 100644
--- a/libc/src/time/time_utils.h
+++ b/libc/src/time/time_utils.h
@@ -12,6 +12,8 @@
 #include "hdr/types/size_t.h"
 #include "hdr/types/struct_tm.h"
 #include "hdr/types/time_t.h"
+#include "src/__support/CPP/optional.h"
+#include "src/__support/CPP/string_view.h"
 #include "src/__support/common.h"
 #include "src/__support/macros/config.h"
 #include "src/errno/libc_errno.h"
@@ -22,6 +24,10 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace time_utils {
 
+// calculates the seconds from the epoch for tm_in. Does not update the struct,
+// you must call update_from_seconds for that.
+int64_t mktime_internal(const struct tm *tm_out);
+
 // Update the "tm" structure's year, month, etc. members from seconds.
 // "total_seconds" is the number of seconds since January 1st, 1970.
 extern int64_t update_from_seconds(int64_t total_seconds, struct tm *tm);
@@ -61,6 +67,7 @@ LIBC_INLINE char *asctime(const struct tm *timeptr, char *buffer,
   }
 
   // TODO(michaelr): move this to use the strftime machinery
+  // equivalent to strftime(buffer, bufferLength, "%a %b %T %Y\n", timeptr)
   int written_size = __builtin_snprintf(
       buffer, bufferLength, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
       time_constants::WEEK_DAY_NAMES[timeptr->tm_wday].data(),
@@ -94,6 +101,255 @@ LIBC_INLINE struct tm *localtime(const time_t *t_ptr) {
   return time_utils::gmtime_internal(t_ptr, &result);
 }
 
+// Returns number of years from (1, year).
+LIBC_INLINE constexpr int64_t get_num_of_leap_years_before(int64_t year) {
+  return (year / 4) - (year / 100) + (year / 400);
+}
+
+// Returns True if year is a leap year.
+LIBC_INLINE constexpr bool is_leap_year(const int64_t year) {
+  return (((year) % 4) == 0 && (((year) % 100) != 0 || ((year) % 400) == 0));
+}
+
+LIBC_INLINE constexpr int get_days_in_year(const int year) {
+  return is_leap_year(year) ? time_constants::DAYS_PER_LEAP_YEAR
+                            : time_constants::DAYS_PER_NON_LEAP_YEAR;
+}
+
+// This is a helper class that takes a struct tm and lets you inspect its
+// values. Where relevant, results are bounds checked and returned as optionals.
+// This class does not, however, do data normalization except where necessary.
+// It will faithfully return a date of 9999-99-99, even though that makes no
+// sense.
+class TMReader final {
+  const tm *timeptr;
+
+public:
+  LIBC_INLINE constexpr TMReader(const tm *tmptr) : timeptr(tmptr) { ; }
+
+  // Strings
+  LIBC_INLINE constexpr cpp::optional<cpp::string_view>
+  get_weekday_short_name() const {
+    if (timeptr->tm_wday >= 0 &&
+        timeptr->tm_wday < time_constants::DAYS_PER_WEEK)
+      return time_constants::WEEK_DAY_NAMES[timeptr->tm_wday];
+
+    return cpp::nullopt;
+  }
+
+  LIBC_INLINE constexpr cpp::optional<cpp::string_view>
+  get_weekday_full_name() const {
+    if (timeptr->tm_wday >= 0 &&
+        timeptr->tm_wday < time_constants::DAYS_PER_WEEK)
+      return time_constants::WEEK_DAY_FULL_NAMES[timeptr->tm_wday];
+
+    return cpp::nullopt;
+  }
+
+  LIBC_INLINE constexpr cpp::optional<cpp::string_view>
+  get_month_short_name() const {
+    if (timeptr->tm_mon >= 0 &&
+        timeptr->tm_mon < time_constants::MONTHS_PER_YEAR)
+      return time_constants::MONTH_NAMES[timeptr->tm_mon];
+
+    return cpp::nullopt;
+  }
+
+  LIBC_INLINE constexpr cpp::optional<cpp::string_view>
+  get_month_full_name() const {
+    if (timeptr->tm_mon >= 0 &&
+        timeptr->tm_mon < time_constants::MONTHS_PER_YEAR)
+      return time_constants::MONTH_FULL_NAMES[timeptr->tm_mon];
+
+    return cpp::nullopt;
+  }
+
+  LIBC_INLINE constexpr cpp::string_view get_am_pm() const {
+    if (timeptr->tm_hour < 12)
+      return "AM";
+    return "PM";
+  }
+
+  LIBC_INLINE constexpr cpp::string_view get_timezone_name() const {
+    // TODO: timezone support
+    return "UTC";
+  }
+
+  // Numbers
+  LIBC_INLINE constexpr int get_sec() const { return timeptr->tm_sec; }
+  LIBC_INLINE constexpr int get_min() const { return timeptr->tm_min; }
+  LIBC_INLINE constexpr int get_hour() const { return timeptr->tm_hour; }
+  LIBC_INLINE constexpr int get_mday() const { return timeptr->tm_mday; }
+  LIBC_INLINE constexpr int get_mon() const { return timeptr->tm_mon; }
+  LIBC_INLINE constexpr int get_yday() const { return timeptr->tm_yday; }
+  LIBC_INLINE constexpr int get_wday() const { return timeptr->tm_wday; }
+  LIBC_INLINE constexpr int get_isdst() const { return timeptr->tm_isdst; }
+
+  // returns the year, counting from 1900
+  LIBC_INLINE constexpr int get_year_raw() const { return timeptr->tm_year; }
+  // returns the year, counting from 0
+  LIBC_INLINE constexpr int get_year() const {
+    return timeptr->tm_year + time_constants::TIME_YEAR_BASE;
+  }
+
+  LIBC_INLINE constexpr int is_leap_year() const {
+    return time_utils::is_leap_year(get_year());
+  }
+
+  LIBC_INLINE constexpr int get_iso_wday() const {
+    // ISO uses a week that starts on Monday, but struct tm starts its week on
+    // Sunday. This function normalizes the weekday so that it always returns a
+    // value 0-6
+    const int NORMALIZED_WDAY =
+        timeptr->tm_wday % time_constants::DAYS_PER_WEEK;
+    return (NORMALIZED_WDAY + (time_constants::DAYS_PER_WEEK - 1)) % 7;
+  }
+
+  // returns the week of the current year, with weeks starting on start_day.
+  LIBC_INLINE constexpr int get_week(time_constants::WeekDay start_day) const {
+    // The most recent start_day. The rest of the days into the current week
+    // don't count, so ignore them.
+    // Also add 7 to handle start_day > tm_wday
+    const int start_of_cur_week =
+        timeptr->tm_yday -
+        ((timeptr->tm_wday + time_constants::DAYS_PER_WEEK - start_day) %
+         time_constants::DAYS_PER_WEEK);
+
+    // Add 1 since the first week may start with day 0
+    const int ceil_weeks_since_start =
+        ((start_of_cur_week + 1) + (time_constants::DAYS_PER_WEEK - 1)) /
+        time_constants::DAYS_PER_WEEK;
+    return ceil_weeks_since_start;
+  }
+
+  LIBC_INLINE constexpr int get_iso_week() const {
+    const time_constants::WeekDay start_day = time_constants::MONDAY;
+
+    // The most recent start_day. The rest of the days into the current week
+    // don't count, so ignore them.
+    // Also add 7 to handle start_day > tm_wday
+    const int start_of_cur_week =
+        timeptr->tm_yday -
+        ((timeptr->tm_wday + time_constants::DAYS_PER_WEEK - start_day) %
+         time_constants::DAYS_PER_WEEK);
+
+    // if the week starts in the previous year, and also if the 4th of this year
+    // is not in this week.
+    if (start_of_cur_week < -3) {
+      const int days_into_prev_year =
+          get_days_in_year(get_year() - 1) + start_of_cur_week;
+      // Each year has at least 52 weeks, but a year's last week will be 53 if
+      // its first week starts in the previous year and its last week ends
+      // in the next year. We know get_year() - 1 must extend into get_year(),
+      // so here we check if it also extended into get_year() - 2 and add 1 week
+      // if it does.
+      return 52 + ((days_into_prev_year % time_constants::DAYS_PER_WEEK) >
+                           time_constants::ISO_FIRST_DAY_OF_YEAR
+                       ? 1
+                       : 0);
+    }
+
+    // subtract 1 to account for yday being 0 indexed
+    const int days_until_end_of_year =
+        get_days_in_year(get_year()) - start_of_cur_week - 1;
+
+    // if there are less than 3 days from the start of this week to the end of
+    // the year, then there must be 4 days in this week in the next year, which
+    // means that this week is the first week of that year.
+    if (days_until_end_of_year < 3)
+      return 1;
+
+    // else just calculate the current week like normal.
+    const int ceil_weeks_since_start =
+        ((start_of_cur_week + 1) + (time_constants::DAYS_PER_WEEK - 1)) /
+        time_constants::DAYS_PER_WEEK;
+
+    // add 1 if this year's first week starts in the previous year.
+    return ceil_weeks_since_start +
+           (((start_of_cur_week + time_constants::DAYS_PER_WEEK) %
+             time_constants::DAYS_PER_WEEK) >
+                    time_constants::ISO_FIRST_DAY_OF_YEAR
+                ? 1
+                : 0);
+  }
+
+  LIBC_INLINE constexpr int get_iso_year() const {
+    const int BASE_YEAR = get_year();
+    // The ISO year is the same as a standard year for all dates after the start
+    // of the first week and before the last week. Since the first ISO week of a
+    // year starts on the 4th, anything after that is in this year.
+    if (timeptr->tm_yday >= time_constants::ISO_FIRST_DAY_OF_YEAR &&
+        timeptr->tm_yday < time_constants::DAYS_PER_NON_LEAP_YEAR -
+                               time_constants::DAYS_PER_WEEK)
+      return BASE_YEAR;
+
+    const int ISO_WDAY = get_iso_wday();
+    // The first week of the ISO year is defined as the week containing the
+    // 4th day of January.
+
+    // first week
+    if (timeptr->tm_yday < time_constants::ISO_FIRST_DAY_OF_YEAR) {
+      /*
+      If jan 4 is in this week, then we're in BASE_YEAR, else we're in the
+      previous year. The formula's been rearranged so here's the derivation:
+
+              +--------+-- days until jan 4
+              |        |
+       wday + (4 - yday) < 7
+       |               |
+       +---------------+-- weekday of jan 4
+
+       rearranged to get all the constants on one side:
+
+       wday - ...
[truncated]

Copy link
Member

@nickdesaulniers nickdesaulniers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, first pass with minor comments related to readability.

Will do another pass trying to understand the logic+comments better. Will ignore mktime_internal since it looks like that was simply moved and not modified AFAICT.

Comment on lines 203 to 205
const int NORMALIZED_WDAY =
timeptr->tm_wday % time_constants::DAYS_PER_WEEK;
return (NORMALIZED_WDAY + (time_constants::DAYS_PER_WEEK - 1)) % 7;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we use ALL_CAPS identifiers for constexpr? NORMALIZED_WDAY isn't constexpr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like we have a specific case for just const variables in libc/.clang_tidy. I generally try to use all caps for things that I can't change, so constexpr but also const. I'm not particularly picky here but we should probably look into fixing this as a followup

Comment on lines 246 to 249
return 52 + ((days_into_prev_year % time_constants::DAYS_PER_WEEK) >
time_constants::ISO_FIRST_DAY_OF_YEAR
? 1
: 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The type of an expression in the form of x > y evaluates to int in C and bool in C++. But C++ will still add an implicit cast to int when used as a subexpression to one side of binary +.

So I think you can omit the ternary expression in the form + (x > y ? 1 : 0) and replace it with + (x > y), here and below, if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I generally prefer to avoid the implicit cast from bool to int, but here it does simplify the code so I have changed it as suggested.

Comment on lines 133 to 134
if (timeptr->tm_wday >= 0 &&
timeptr->tm_wday < time_constants::DAYS_PER_WEEK)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is shorter than

Suggested change
if (timeptr->tm_wday >= 0 &&
timeptr->tm_wday < time_constants::DAYS_PER_WEEK)
if (timeptr->tm_wday >= 0 &&
timeptr->tm_wday < time_constants::WEEK_DAY_NAMES.size())

but I think you could further share the bounds check and have less code:

cpp::string_view bounds_check(const cpp::span<cpp::string_view> &arr, int index) {
  return index >= 0 && index < arr.size() ? arr[index] : {};
}
cpp::string_view get_weekday_short_name() const {
  return bounds_check(time_constants::WEEK_DAY_NAMES, timeptr->tm_wday);
}
cpp::string_view get_weekday_full_name() const {
  return bounds_check(time_constants::WEEK_DAY_FULL_NAMES, timeptr->tm_wday);
}
cpp::string_view get_month_short_name const {
  return bounds_check(time_constants::MONTH_NAMES, timeptr->tm_mon);
}
cpp::string_view get_month_full_name const {
  return bounds_check(time_constants::MONTH_FULL_NAMES, timeptr->tm_mon);
}

but perhaps our cpp::array doesn't (yet) convert to cpp::span?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote something similar, but not quite the same. Basically, instead of converting to a span I just templated the input array by size. Since it's getting inlined it should be identical, but this way I don't need to worry about conversion.


// Add 1 since the first week may start with day 0
const int ceil_weeks_since_start =
((start_of_cur_week + 1) + (time_constants::DAYS_PER_WEEK - 1)) /
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I parsing the parens correctly? This looks like ((x + 1) + (y - 1)) which could just be (x + y)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so this is supposed to be ceil((start_of_cur_week + 1) / DAYS_PER_WEEK), which is why there was the DAYS_PER_WEEK - 1. I've rewritten it to be simpler but idk if it's still understandable.

Comment on lines 262 to 265
// else just calculate the current week like normal.
const int ceil_weeks_since_start =
((start_of_cur_week + 1) + (time_constants::DAYS_PER_WEEK - 1)) /
time_constants::DAYS_PER_WEEK;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is duplicated between get_iso_week and get_week. Would it make sense to have a helper fn be reused from either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after simplifying the formula, I think it might not be necessary.

return mktime_internal(timeptr);
}

// returns the timezone offset in microwave time:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol

Comment on lines +127 to +129
template <size_t N>
LIBC_INLINE constexpr cpp::optional<cpp::string_view>
bounds_check(const cpp::array<cpp::string_view, N> &arr, int index) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you get a chance to try our cpp::span here? I think you could avoid the template by using cpp::span.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work with our current span implementation due to issues with accepting a const array. I'll leave it as-is for now, but I'm not opposed to moving this to be span in future.

@michaelrj-google michaelrj-google merged commit a760e7f into llvm:main Feb 11, 2025
13 checks passed
@michaelrj-google michaelrj-google deleted the libcTimeReader branch February 11, 2025 22:41
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 11, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/16077

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[49/153] Generating header sys/select.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/select.yaml
[50/152] Generating header pthread.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/pthread.yaml
[51/90] Generating header elf.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/elf.yaml
[52/90] Generating header setjmp.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/setjmp.yaml
[53/90] Generating header sys/types.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/types.yaml
[54/88] Generating header sched.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sched.yaml
[55/80] Generating header time.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/time.yaml
[56/80] Generating header unistd.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/unistd.yaml
[57/68] Generating header math.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/math.yaml
[58/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp:13:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);
        ^
1 error generated.
[59/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp:13:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);
        ^
1 error generated.
[60/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp:12:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);

@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 11, 2025

LLVM Buildbot has detected a new failure on builder libc-x86_64-debian-gcc-fullbuild-dbg running on libc-x86_64-debian-fullbuild while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/131/builds/15820

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[50/103] Generating header uchar.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/uchar.yaml
[51/103] Generating header sys/utsname.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/utsname.yaml
[52/102] Generating header time.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/time.yaml
[53/102] Generating header sys/mman.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/mman.yaml
[54/84] Generating header sys/uio.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/uio.yaml
[55/84] Generating header poll.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/poll.yaml
[56/84] Generating header termios.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/termios.yaml
[57/73] Generating header sys/wait.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/wait.yaml
[58/70] Generating header wchar.h from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/runtimes/../libc/include/wchar.yaml
[59/70] Building CXX object libc/src/time/CMakeFiles/libc.src.time.gmtime.dir/gmtime.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.gmtime.dir/gmtime.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/12//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.gmtime.dir/gmtime.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.gmtime.dir/gmtime.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.gmtime.dir/gmtime.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/gmtime.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/gmtime.cpp:12:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h: In member function ‘constexpr time_t __llvm_libc_20_0_0_git::time_utils::TMReader::get_epoch() const’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:27: error: call to non-‘constexpr’ function ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’
  332 |     return mktime_internal(timeptr);
      |            ~~~~~~~~~~~~~~~^~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’ declared here
   29 | int64_t mktime_internal(const tm *tm_out);
      |         ^~~~~~~~~~~~~~~
[60/70] Building CXX object libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/12//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp:13:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h: In member function ‘constexpr time_t __llvm_libc_20_0_0_git::time_utils::TMReader::get_epoch() const’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:27: error: call to non-‘constexpr’ function ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’
  332 |     return mktime_internal(timeptr);
      |            ~~~~~~~~~~~~~~~^~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’ declared here
   29 | int64_t mktime_internal(const tm *tm_out);
      |         ^~~~~~~~~~~~~~~
[61/70] Building CXX object libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/12//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp:12:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h: In member function ‘constexpr time_t __llvm_libc_20_0_0_git::time_utils::TMReader::get_epoch() const’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:27: error: call to non-‘constexpr’ function ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’
  332 |     return mktime_internal(timeptr);
      |            ~~~~~~~~~~~~~~~^~~~~~~~~
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’ declared here
   29 | int64_t mktime_internal(const tm *tm_out);
      |         ^~~~~~~~~~~~~~~
[62/70] Building CXX object libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o 
/usr/bin/g++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc -isystem /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/build/libc/include -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -Wimplicit-fallthrough -Wno-nonnull -Wno-class-memaccess -Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -isystem/usr/lib/gcc/x86_64-linux-gnu/12//include -nostdinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -fext-numeric-literals -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -c /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp
In file included from /home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp:13:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h: In member function ‘constexpr time_t __llvm_libc_20_0_0_git::time_utils::TMReader::get_epoch() const’:
/home/llvm-libc-buildbot/buildbot-worker/libc-x86_64-debian-fullbuild/libc-x86_64-debian-gcc-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:27: error: call to non-‘constexpr’ function ‘int64_t __llvm_libc_20_0_0_git::time_utils::mktime_internal(const tm*)’
  332 |     return mktime_internal(timeptr);

Icohedron pushed a commit to Icohedron/llvm-project that referenced this pull request Feb 11, 2025
In the process of adding strftime (llvm#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
@llvm-ci
Copy link
Collaborator

llvm-ci commented Feb 11, 2025

LLVM Buildbot has detected a new failure on builder fuchsia-x86_64-linux running on fuchsia-debian-64-us-central1-a-1 while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/11/builds/12453

Here is the relevant piece of the build log for the reference
Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/fuchsia-linux.py ...' (failure)
...
[450/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strchrnul.dir/strchrnul.cpp.obj
[451/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlen.dir/strlen.cpp.obj
[452/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.difftime.dir/difftime.cpp.obj
[453/2777] Copying CXX header __algorithm/lower_bound.h
[454/2777] Copying CXX header __algorithm/make_heap.h
[455/2777] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nanf.dir/nanf.cpp.obj
[456/2777] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nanl.dir/nanl.cpp.obj
[457/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcspn.dir/strcspn.cpp.obj
[458/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlcpy.dir/strlcpy.cpp.obj
[459/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/asctime_r.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/asctime_r.cpp:13:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[460/2777] Copying CXX header __algorithm/make_projected.h
[461/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcpy.dir/strcpy.cpp.obj
[462/2777] Copying CXX header __algorithm/max.h
[463/2777] Copying CXX header __algorithm/max_element.h
[464/2777] Copying CXX header __algorithm/partition.h
[465/2777] Copying CXX header __algorithm/partition_copy.h
[466/2777] Copying CXX header __algorithm/partition_point.h
[467/2777] Copying CXX header __algorithm/pop_heap.h
[468/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/ctime.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/ctime.cpp:14:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[469/2777] Copying CXX header __algorithm/prev_permutation.h
[470/2777] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtoull.dir/strtoull.cpp.obj
[471/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memset.dir/memset.cpp.obj
[472/2777] Copying CXX header __algorithm/push_heap.h
[473/2777] Copying CXX header __algorithm/pstl.h
[474/2777] Copying CXX header __algorithm/radix_sort.h
[475/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlcat.dir/strlcat.cpp.obj
[476/2777] Copying CXX header __algorithm/ranges_all_of.h
[477/2777] Copying CXX header __algorithm/ranges_adjacent_find.h
[478/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -MD -MT libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.cpp:9:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
Step 6 (build) failure: build (failure)
...
[450/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strchrnul.dir/strchrnul.cpp.obj
[451/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlen.dir/strlen.cpp.obj
[452/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.difftime.dir/difftime.cpp.obj
[453/2777] Copying CXX header __algorithm/lower_bound.h
[454/2777] Copying CXX header __algorithm/make_heap.h
[455/2777] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nanf.dir/nanf.cpp.obj
[456/2777] Building CXX object libc/src/math/generic/CMakeFiles/libc.src.math.generic.nanl.dir/nanl.cpp.obj
[457/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcspn.dir/strcspn.cpp.obj
[458/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlcpy.dir/strlcpy.cpp.obj
[459/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/asctime_r.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/asctime_r.cpp:13:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[460/2777] Copying CXX header __algorithm/make_projected.h
[461/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strcpy.dir/strcpy.cpp.obj
[462/2777] Copying CXX header __algorithm/max.h
[463/2777] Copying CXX header __algorithm/max_element.h
[464/2777] Copying CXX header __algorithm/partition.h
[465/2777] Copying CXX header __algorithm/partition_copy.h
[466/2777] Copying CXX header __algorithm/partition_point.h
[467/2777] Copying CXX header __algorithm/pop_heap.h
[468/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -MD -MT libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.ctime.dir/ctime.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/ctime.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/ctime.cpp:14:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
[469/2777] Copying CXX header __algorithm/prev_permutation.h
[470/2777] Building CXX object libc/src/stdlib/CMakeFiles/libc.src.stdlib.strtoull.dir/strtoull.cpp.obj
[471/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.memset.dir/memset.cpp.obj
[472/2777] Copying CXX header __algorithm/push_heap.h
[473/2777] Copying CXX header __algorithm/pstl.h
[474/2777] Copying CXX header __algorithm/radix_sort.h
[475/2777] Building CXX object libc/src/string/CMakeFiles/libc.src.string.strlcat.dir/strlcat.cpp.obj
[476/2777] Copying CXX header __algorithm/ranges_all_of.h
[477/2777] Copying CXX header __algorithm/ranges_adjacent_find.h
[478/2777] Building CXX object libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj
FAILED: libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj 
/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/bin/clang++ --target=armv8m.main-none-eabi -DLIBC_NAMESPACE=__llvm_libc_21_0_0_git -I/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc -isystem /var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/include/armv8m.main-unknown-none-eabi --target=armv8m.main-none-eabi -Wno-atomic-alignment "-Dvfprintf(stream, format, vlist)=vprintf(format, vlist)" "-Dfprintf(stream, format, ...)=printf(format)" -D_LIBCPP_PRINT=1 -mthumb -mfloat-abi=softfp -march=armv8m.main+fp+dsp -mcpu=cortex-m33 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -ffunction-sections -fdata-sections -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/build/llvm-build-3nselvtn/runtimes/runtimes-armv8m.main-none-eabi-bins=../../../../llvm-project -ffile-prefix-map=/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/= -no-canonical-prefixes -Os -DNDEBUG -std=gnu++17 --target=armv8m.main-none-eabi -DLIBC_QSORT_IMPL=LIBC_QSORT_HEAP_SORT -DLIBC_TYPES_TIME_T_IS_32_BIT -DLIBC_ADD_NULL_CHECKS "-DLIBC_MATH=(LIBC_MATH_SKIP_ACCURATE_PASS | LIBC_MATH_SMALL_TABLES)" -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -ffixed-point -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -MD -MT libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj -MF libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj.d -o libc/src/time/CMakeFiles/libc.src.time.time_utils.dir/time_utils.cpp.obj -c /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.cpp
In file included from /var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.cpp:9:
/var/lib/buildbot/fuchsia-x86_64-linux/llvm-project/libc/src/time/time_utils.h:332:12: 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);
      |     ~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~

@Prabhuk
Copy link
Contributor

Prabhuk commented Feb 12, 2025

LLVM Buildbot has detected a new failure on builder libc-aarch64-ubuntu-fullbuild-dbg running on libc-aarch64-ubuntu while building libc at step 4 "annotate".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/71/builds/16077

Here is the relevant piece of the build log for the reference

Step 4 (annotate) failure: 'python ../llvm-zorg/zorg/buildbot/builders/annotated/libc-linux.py ...' (failure)
...
[49/153] Generating header sys/select.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/select.yaml
[50/152] Generating header pthread.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/pthread.yaml
[51/90] Generating header elf.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/elf.yaml
[52/90] Generating header setjmp.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/setjmp.yaml
[53/90] Generating header sys/types.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sys/types.yaml
[54/88] Generating header sched.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/sched.yaml
[55/80] Generating header time.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/time.yaml
[56/80] Generating header unistd.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/unistd.yaml
[57/68] Generating header math.h from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/runtimes/../libc/include/math.yaml
[58/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.mktime.dir/mktime.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/mktime.cpp:13:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);
        ^
1 error generated.
[59/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.asctime_r.dir/asctime_r.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/asctime_r.cpp:13:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);
        ^
1 error generated.
[60/68] Building CXX object libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o
FAILED: libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o 
/usr/bin/clang++ -DLIBC_NAMESPACE=__llvm_libc_20_0_0_git -D_DEBUG -I/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc -isystem libc/include -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment -Wstring-conversion -fdiagnostics-color -g -DLIBC_QSORT_IMPL=LIBC_QSORT_QUICK_SORT -DLIBC_ADD_NULL_CHECKS -fpie -ffreestanding -DLIBC_FULL_BUILD -nostdlibinc -idirafter/usr/include -fno-builtin -fno-exceptions -fno-lax-vector-conversions -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-rtti -ftrivial-auto-var-init=pattern -fno-omit-frame-pointer -Wall -Wextra -Werror -Wconversion -Wno-sign-conversion -Wdeprecated -Wno-c99-extensions -Wno-gnu-imaginary-constant -Wno-pedantic -Wimplicit-fallthrough -Wwrite-strings -Wextra-semi -Wnewline-eof -Wnonportable-system-include-path -Wstrict-prototypes -Wthread-safety -Wglobal-constructors -DLIBC_COPT_PUBLIC_PACKAGING -std=gnu++17 -MD -MT libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -MF libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o.d -o libc/src/time/CMakeFiles/libc.src.time.gmtime_r.dir/gmtime_r.cpp.o -c /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp
In file included from /home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/gmtime_r.cpp:12:
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:331:32: error: constexpr function never produces a constant expression [-Winvalid-constexpr]
  LIBC_INLINE constexpr time_t get_epoch() const {
                               ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:332:12: note: non-constexpr function 'mktime_internal' cannot be used in a constant expression
    return mktime_internal(timeptr);
           ^
/home/libc-buildbot/libc-aarch64-ubuntu/libc-aarch64-ubuntu-fullbuild-dbg/llvm-project/libc/src/time/time_utils.h:29:9: note: declared here
int64_t mktime_internal(const tm *tm_out);

@michaelrj-google We are seeing the same build failure in our Fuchsia toolchain builders as well.
Bot link: https://luci-milo.appspot.com/ui/p/fuchsia/builders/toolchain.ci/clang-linux-arm64/b8723188067084510049/overview
Logs: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8723188067084510049/+/u/clang/build/stdout

flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
In the process of adding strftime (llvm#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
In the process of adding strftime (llvm#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
In the process of adding strftime (llvm#122556) I wrote this utility class
to simplify reading from a struct tm. It provides helper functions that
return basically everything needed by strftime. It's not tested
directly, but it is thoroughly exercised by the strftime tests.
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.

5 participants