On 25/02/21 14:19 +0000, Jonathan Wakely wrote:
On 25/02/21 14:02 +0000, Jonathan Wakely wrote:
On 25/02/21 13:46 +0000, Cassio Neri via Libstdc++ wrote:
Hi Jonathan,
The issue is that I didn't cast __dp.count() to uint32_t:
- const auto __r0 = __dp.count() + __r2_e3;
+ const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
The above would be a better fix. Indeed, __r0 belongs to [0, 2^32[ which allows
all arithmetics that follow to be performed on uint32_t values. For performance
this is better than using signed integers.
OK, I'll make that change shortly, thanks.
We still need to cast to int for the return value though, because
converting from uint32_t to int is still narrowing.
I've committed this now.
Tested powerpc64le-linux, committed to trunk.
commit a47cec4ca7302e65f63490ad7f251c5a469bc0e0
Author: Jonathan Wakely <jwak...@redhat.com>
Date: Thu Feb 25 16:57:20 2021
libstdc++: Use uint32_t for all year_month_day::_S_from_days arithmetic
libstdc++-v3/ChangeLog:
* include/std/chrono (year_month_day::_S_from_days): Perform
all calculations with type uint32_t.
diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono
index eef503af274..fcdaee7328e 100644
--- a/libstdc++-v3/include/std/chrono
+++ b/libstdc++-v3/include/std/chrono
@@ -2455,7 +2455,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
constexpr auto __z2 = static_cast<uint32_t>(-1468000);
constexpr auto __r2_e3 = static_cast<uint32_t>(536895458);
- const auto __r0 = __dp.count() + __r2_e3;
+ const auto __r0 = static_cast<uint32_t>(__dp.count()) + __r2_e3;
const auto __n1 = 4 * __r0 + 3;
const auto __q1 = __n1 / 146097;