From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 434503858C53; Mon, 8 May 2023 15:59:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 434503858C53 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1683561564; bh=gQV7RJt86SCK26mf9KkdZJZ6P5XcLd3AaiMx8853S60=; h=From:To:Subject:Date:In-Reply-To:References:From; b=wYqbWfHjBTeY2dgHcS312GroIbvl/pLyAohTsfevOh7znVnd79d7M7oTblRwcJbvd ARNygMGK+tjy4j4REVv7fulmTJceHLGq2jp/FQVMk8aQWuH2ev3f/5+l1CQqAD/+mu Fg0XVoAnJ0PneRJ9sxih+v7iFFqDuGydMMtzgDig= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/109772] Memory layout optimization of std::chrono::hh_mm_ss is wrong Date: Mon, 08 May 2023 15:59:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 13.1.0 X-Bugzilla-Keywords: ABI X-Bugzilla-Severity: normal X-Bugzilla-Who: redi at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: redi at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.2 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109772 --- Comment #2 from Jonathan Wakely --- (In reply to Jonathan Wakely from comment #0) > std::chrono::hh_mm_ss hms(std::chrono::duration>= {1511}); The bug affects this example because __fits is true, because duration_values::max() <=3D duration_values::max() is = true. So the library decides it can use uint_least32_t to store the subseconds pa= rt. However, the value we need to store is duration>(4755859375) not duration(1511 % 1024) = and so we truncate 9990234375 to 32 bits. The bug doesn't affect uses of hh_mm_ss with the standard duration aliases = in , e.g. hh_mm_ss, because the standard chrono aliases w= ith higher precision than one second all use 64-bit rep types, so __fits is false. And in practice the number of users of hh_mm_ss with durations with unusual periods and 32-bit rep types is probab= ly tiny. And hh_mm_ss should not be used for storage, only as a short-lived st= ack variable ... so I think we can probably just fix this for 13.2 even though that's theoretically an ABI break (the C++20 ABI isn't final yet, but we usually try to keep it stable between minor releases like 13.1 and 13.2). We can consider adding an abi_tag attribute to hh_mm_ss for 13.2 (but not on trunk).=