From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5BE263858039; Sun, 20 Aug 2023 08:36:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5BE263858039 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1692520563; bh=293Gknj+nHDi88k0adYT0jK3kuhiUWimqv+d6cngMZs=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FL6EC6mTAKO4nn7mYh6nl91BCvTRa/UvcTH+VPYYcV0SvkLtUdYSc6iOMaBeudgSL F1awvJlbZ0ENSoBEZ955JXGvXSCYuDNL2t2LTZwoL6pAUcske/uV1lrIbvmnCwOZwR srCFwBcf1xwUczwPtoLJx666eM1sU7UXrfHiIpkw= From: "redi at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/111077] atomic_ref compare_exchange_strong doesn't properly ignore padding bits Date: Sun, 20 Aug 2023 08:35:55 +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: unknown X-Bugzilla-Keywords: 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.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: assigned_to cf_reconfirmed_on everconfirmed target_milestone bug_status 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=3D111077 Jonathan Wakely changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|unassigned at gcc dot gnu.org |redi at gcc dot gnu= .org Last reconfirmed| |2023-08-20 Ever confirmed|0 |1 Target Milestone|--- |13.3 Status|UNCONFIRMED |ASSIGNED --- Comment #7 from Jonathan Wakely --- (In reply to comexk from comment #0) > [See also: > https://github.com/rust-lang/unsafe-code-guidelines/issues/449#issuecomme= nt- > 1677985851, which has a comparison of different compilers.] "GCC does nothing to handle this" is incorrect. Only the case of an initial value with non-zero padding is not handled, because atomic_ref doesn't cont= rol the variable's initial value. atomic_ref::store and atomic_ref::exchange cl= ear padding bits, and so does a successful compare_exchange_{weak,strong}. But we do have a bug here, because if that initial value has non-zero paddi= ng bits even a compare_exchange_strong loop won't eventually settle, because we keep zeroing the padding in the 'expected' value, which means it never matc= hes. We return the current value (with padding bits preserved), but then the next call using that exact value will get the padding zeroed again, and fail to match.=