From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 75302385801A; Mon, 27 Nov 2023 14:12:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75302385801A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1701094346; bh=rvmzyvmbZozii/kuEseK9ybSwtASqI0wv5tjacRB3CM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N1qHWICRc70BrggAVwidKpny3sU0qTV9oKsUbtTV5TRvmUqQooEtWbvIF8Uvpy5fo zD352u9zvh5fcFV5se03D1MEGa4wJB9vTcitZeqFwIJUoLzzTVz/xmQGjltUHtG+H/ 6Pzk5UPUeys5HQ/XUpDwjrgVQ6rYJ7aq8oR1F3ro= From: "post+gcc at ralfj dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/32667] block copy with exact overlap is expanded as memcpy Date: Mon, 27 Nov 2023 14:12:24 +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: post+gcc at ralfj dot de 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 #49 from post+gcc at ralfj dot de --- Even glibc itself seems to use `restrict`: https://codebrowser.dev/glibc/glibc/string/string.h.html#43 So the compiler building glibc might inadvertently rely on the memory writt= en through dst and the memory read through src being disjoint, making even the perfectly-overlapping case UB (unless the implementation has a guard somewh= ere that skips the copy when src=3D=3Ddst, but I was not able to find such a gu= ard). (The implementation at https://codebrowser.dev/glibc/glibc/string/memcpy.c.= html does not have the `restrict`, but it includes the string.h header and I thi= nk the compiler is allowed to apply attributes from the declaration to the definition. Or, alternatively, it might even be UB to have `restrict` in one place and not the other: "All declarations that refer to the same object or function shall have compatible type; otherwise, the behavior is undefined" = [C23 =C2=A76.2.7.2] and "For two qualified types to be compatible, both shall ha= ve the identically qualified version of a compatible type; the order of type qualifiers within a list of specifiers or qualifiers does not affect the specified type" [C23 =C2=A76.7.3.11].)=