Skip to content

include/time.h: Typedef time_t to uint64_t when CONFIG_SYSTEM_TIME64 is true - #7975

Closed
xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:time
Closed

xiaoxiang781216 wants to merge 1 commit into
apache:masterfrom
xiaoxiang781216:time

Conversation

@xiaoxiang781216

@xiaoxiang781216 xiaoxiang781216 commented Dec 25, 2022 •

Copy link
Copy Markdown
Contributor

Summary

See the discussion here: #7115

Impact

time_t mapping

Testing

Pass CI

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

@yamt here is the change which map time_4 to uint64_t instead int64_t

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

libcxx report the following warning with this patch:

[2022-12-25T14:50:41.765Z] libcxx/src/condition_variable.cpp: In member function 'void std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long int, std::__1::ratio<1, 1000000000> > >)':
[2022-12-25T14:50:41.765Z] libcxx/src/condition_variable.cpp:64:19: error: comparison of integer expressions of different signedness: 'std::__1::chrono::duration<long long int>::rep' {aka 'long long int'} and 'const ts_sec' {aka 'const long long unsigned int'} [-Werror=sign-compare]
[2022-12-25T14:50:41.765Z]    64 |     if (s.count() < ts_sec_max)
[2022-12-25T14:50:41.765Z]       |         ~~~~~~~~~~^~~~~~~~~~~~

So, we have to keep the convention used by other OS.

@yamt

yamt commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

libcxx report the following warning with this patch:

[2022-12-25T14:50:41.765Z] libcxx/src/condition_variable.cpp: In member function 'void std::__1::condition_variable::__do_timed_wait(std::__1::unique_lock<std::__1::mutex>&, std::__1::chrono::time_point<std::__1::chrono::system_clock, std::__1::chrono::duration<long long int, std::__1::ratio<1, 1000000000> > >)':
[2022-12-25T14:50:41.765Z] libcxx/src/condition_variable.cpp:64:19: error: comparison of integer expressions of different signedness: 'std::__1::chrono::duration<long long int>::rep' {aka 'long long int'} and 'const ts_sec' {aka 'const long long unsigned int'} [-Werror=sign-compare]
[2022-12-25T14:50:41.765Z]    64 |     if (s.count() < ts_sec_max)
[2022-12-25T14:50:41.765Z]       |         ~~~~~~~~~~^~~~~~~~~~~~

So, we have to keep the convention used by other OS.

isn't it a problem for !CONFIG_SYSTEM_TIME64 case?

@xiaoxiang781216

xiaoxiang781216 commented Dec 26, 2022 •

Copy link
Copy Markdown
Contributor Author

No, it's problem when CONFIG_SYSTEM_TIME64 is enabled and time_t is map to uint64_t. So, if you don't have a good reason, it's better to map time_t to int64_t like other OS.
For !CONFIG_SYSTEM_TIME64 case, time_t is int32_t, but the other side is uint64_t, so it's safe to prompt int32_t(time_t) to uint64_t without warning.

@yamt

yamt commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

No, it's problem when CONFIG_SYSTEM_TIME64 is enabled and time_t is map to uint64_t. So, if you don't have a good reason, it's better to map time_t to int64_t like other OS. For !CONFIG_SYSTEM_TIME64 case, time_t is int32_t, but the other side is uint64_t, so it's safe to prompt int32_t(time_t) to uint64_t without warning.

  • the particular warning in libcxx seems ok to ignore.
  • anyway, our tree does not seem -Wsign-compare clean regardless of this
  • IMO consistency within nuttx is a good enough reason

@xiaoxiang781216

Copy link
Copy Markdown
Contributor Author

If so, why not change 32bit time_t to int32_t like other OS?

@yamt

yamt commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

If so, why not change 32bit time_t to int32_t like other OS?

because int32_t wraps too soon.

@xiaoxiang781216

xiaoxiang781216 commented Dec 26, 2022 •

Copy link
Copy Markdown
Contributor Author

No, it's problem when CONFIG_SYSTEM_TIME64 is enabled and time_t is map to uint64_t. So, if you don't have a good reason, it's better to map time_t to int64_t like other OS. For !CONFIG_SYSTEM_TIME64 case, time_t is int32_t, but the other side is uint64_t, so it's safe to prompt int32_t(time_t) to uint64_t without warning.

  • the particular warning in libcxx seems ok to ignore.

It exists in many places (the above warning is just a demo). I am afraid that not only libcxx but also many other libraries suffer the same issue.

  • anyway, our tree does not seem -Wsign-compare clean regardless of this

But it doesn't have any warning before we define time_t to uint64_t

  • IMO consistency within nuttx is a good enough reason

If so, why not change 32bit time_t to int32_t like other OS?

because int32_t wraps too soon.

int32_t can represent time correctly until 2038. The reliable fix is promoted time_t to int64_t like other OS. Typedef time_t to uint32_t mayn't work as your expectation (2106) since many software only test with signed integer(https://en.wikipedia.org/wiki/Year_2038_problem).

So, if you want to keep the consistence, I will prefer to map time_t to int32_t insteading map time_t to uint64_t.

@yamt

yamt commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

No, it's problem when CONFIG_SYSTEM_TIME64 is enabled and time_t is map to uint64_t. So, if you don't have a good reason, it's better to map time_t to int64_t like other OS. For !CONFIG_SYSTEM_TIME64 case, time_t is int32_t, but the other side is uint64_t, so it's safe to prompt int32_t(time_t) to uint64_t without warning.

  • the particular warning in libcxx seems ok to ignore.

It exists in many places (the above warning is just a demo). I am afraid that not only libcxx but also many other libraries suffer the same issue.

it seems like the only failure on the ci.

  • anyway, our tree does not seem -Wsign-compare clean regardless of this

But it doesn't have any warning before we define time_t to uint64_t

see #7979
i guess it's far from exhaustive.

  • IMO consistency within nuttx is a good enough reason

If so, why not change 32bit time_t to int32_t like other OS?

because int32_t wraps too soon.

int32_t can represent time correctly until 2038. The reliable fix is promoted time_t to int64_t like other OS. Typedef time_t to uint32_t mayn't work as your expectation (2106) since many software only test with signed integer(https://en.wikipedia.org/wiki/Year_2038_problem).

i suspect broken software is broken anyway, even with 64-bit time_t.

So, if you want to keep the consistence, I will prefer to map time_t to int32_t insteading map time_t to uint64_t.

i feel 2038 is too soon. but it's something the project can decide, i guess.

@xiaoxiang781216

xiaoxiang781216 commented Dec 26, 2022 •

Copy link
Copy Markdown
Contributor Author

see #7979 i guess it's far from exhaustive.

I guess 64bit signed/unsigned comparison is handled differently from 32bit signed/unsigned comparison by compiler. Since even -Wsign-compare isn't enabled, compiler still warn 64bit signed/unsigned comparison, but not for 32bit.

@yamt

yamt commented Dec 26, 2022

Copy link
Copy Markdown
Contributor

see #7979 i guess it's far from exhaustive.

I guess 64bit signed/unsigned comparison is handled differently from 32bit signed/unsigned comparison by compiler. Since even -Wsign-compare isn't enabled, compiler still warn 64bit signed/unsigned comparison, but not for 32bit.

my understanding is it's more about C vs C++.
gcc for some reasons uses a different set of warnings.
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=10604
https://github.com/gcc-mirror/gcc/blob/e54375d85d4aa5889869c2672158083b2106b623/gcc/c-family/c.opt#L1285-L1287

@yamt yamt mentioned this pull request Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants