From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 99A1C3858C2F; Thu, 23 Nov 2023 18:56:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 99A1C3858C2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1700765760; bh=IQtoa1kFOXdUJiH5Vp9ifjhOIU6T9pcXKrAxPcozVvE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=PjrMSzanOniWxVawhs9hJN5gB9a5IOoGr5doV8Dr0+YUKeHkpu6Oy9RhRnWTbgbIc q1Wqt0poPI7KzZP2yuO8723q1SfSBrTGLByJKtm05Xgpx6lphYGfNGcimzwn7/qfOa Bus6d5wBXMf7n3tC7uQIv/XKJlfQNe2/ziMtNLKQ= From: "bugdal at aerifal dot cx" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/32667] block copy with exact overlap is expanded as memcpy Date: Thu, 23 Nov 2023 18:55:59 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: bugdal at aerifal dot cx X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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=3D32667 --- Comment #42 from Rich Felker --- > I'm not saying that such an implementation will be a good idea, but just = a remark: You could, in fact, keep restrict for the arguments in this case,= because the object pointed to by src and dest is not accessed at all when = src=3D=3Ddest. So this is correct code according to the standard. (The exac= t semantics of restrict are a bit involved...) Nope, UB is invoked as soon as you evaluate src=3D=3Ddest, even with no dereferencing. The semantics of restrict are such that the behavior of the = code must be unchanged if the pointer were replaced to a pointer to a relocated = copy of the pointed-to object. Since this would alter the result of the =3D=3D o= perator, that constraint is not satisfied and thereby the behavior is undefined.=