From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A4DF93858C20; Tue, 21 Nov 2023 15:30:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A4DF93858C20 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1700580644; bh=2Ifh4VCIT4qr5HQykEilObQI34wJglyn29I55jHQlEc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vEqSesljqhA5nNBJumTboyplP4CZzM14DEOea6UiwGMauAN3OvBcM2gpmQ1/uk5d2 nfjomXgx0Jx39XY9XvLQ0EGjiOHM7ZmE4t2i/8AKq42b50KCXRu/q8RHZZIUQkfBod /Yfj8nkdlfZMVIWMCeRxSqo0UlMREKxMGfzTf3zE= From: "adhemerval.zanella at linaro dot org" To: glibc-bugs@sourceware.org Subject: [Bug string/31055] Request: guarantee that memcpy(x, x, n) is well-defined Date: Tue, 21 Nov 2023 15:30:43 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: string X-Bugzilla-Version: 2.38 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: adhemerval.zanella at linaro dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot 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://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D31055 --- Comment #3 from Adhemerval Zanella --- (In reply to Ralf Jung from comment #2) > > From the draft proposal document [1], it means that memcpy and other st= ring/memory functions might accept NULL/invalid arguments.=20 >=20 > Yes, that too. Though I opened this issue specifically about the src=3D= =3Ddest > case. I think with this extra constraint we can't really mark the memcpy as having 'restrict' arguments, which would also have extra performance implications.= It would also mean deviating from C standard which I am not sure would be real= ly the correct approach. (I may be reading the restrict keyword definition wrongly, and thus the C standard does allow restrict with a pointer to alias to itself). >=20 > > I am also not sure if *all* the architecture memcpy implementation hand= les memcpy(x, x, n) correctly, although I expect it would not be an issue (= GCC is already generating code with this assumption). >=20 > That's the thing. Either they fail for that case and we have a problem si= nce > GCC (and clang and rustc) generate bad code. Or they are all fine for that > case and de-facto they can't change that anyway because GCC (and clang and > rustc) rely on it, and it's better to just officially document this rather > than continue with this annoying situation where something's clearly brok= en > but nobody wants to fix it. My understanding is if the compiler can not ensure the memory ranges don't overlap, it should emit a memmove instead. But this is really a corner case that won't really trigger the wrong result because afaiu all glibc memcpy implementations do not issue any tricks as the powerpc one valgrind describ= ed. >=20 > (And this issue is not purely theoretical, it leads to real problems such= as > https://bugs.kde.org/show_bug.cgi?id=3D148543. The valgrind devs are wait= ing > for *someone* to clarify what the contract for memcpy actually is.) And I think valgrind will need to at least keep this warning for non-glibc targets, which I am not it would simplify things. Maybe the best way would= to follow the __memcmpeq route, where it was added solely for compile usage. [1] https://sourceware.org/pipermail/libc-alpha/2021-September/131099.html --=20 You are receiving this mail because: You are on the CC list for the bug.=