public inbox for glibc-bugs@sourceware.org help / color / mirror / Atom feed
From: "adhemerval.zanella at linaro dot org" <sourceware-bugzilla@sourceware.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 [thread overview] Message-ID: <bug-31055-131-XGX4N93vQD@http.sourceware.org/bugzilla/> (raw) In-Reply-To: <bug-31055-131@http.sourceware.org/bugzilla/> https://sourceware.org/bugzilla/show_bug.cgi?id=31055 --- Comment #3 from Adhemerval Zanella <adhemerval.zanella at linaro dot org> --- (In reply to Ralf Jung from comment #2) > > From the draft proposal document [1], it means that memcpy and other string/memory functions might accept NULL/invalid arguments. > > Yes, that too. Though I opened this issue specifically about the src==dest > 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 really 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). > > > I am also not sure if *all* the architecture memcpy implementation handles memcpy(x, x, n) correctly, although I expect it would not be an issue (GCC is already generating code with this assumption). > > That's the thing. Either they fail for that case and we have a problem since > 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 broken > 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 described. > > (And this issue is not purely theoretical, it leads to real problems such as > https://bugs.kde.org/show_bug.cgi?id=148543. The valgrind devs are waiting > 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 -- You are receiving this mail because: You are on the CC list for the bug.
next prev parent reply other threads:[~2023-11-21 15:30 UTC|newest] Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-11-11 17:37 [Bug string/31055] New: " post+sourceware.org at ralfj dot de 2023-11-11 18:41 ` [Bug string/31055] " sam at gentoo dot org 2023-11-13 18:47 ` adhemerval.zanella at linaro dot org 2023-11-18 17:56 ` post+sourceware.org at ralfj dot de 2023-11-21 15:30 ` adhemerval.zanella at linaro dot org [this message] 2023-11-23 7:36 ` post+sourceware.org at ralfj dot de 2023-11-23 11:53 ` adhemerval.zanella at linaro dot org 2023-11-23 14:48 ` sam at gentoo dot org 2023-11-23 15:18 ` post+sourceware.org at ralfj dot de 2023-11-24 7:46 ` rguenth at gcc dot gnu.org 2023-11-24 8:52 ` post+sourceware.org at ralfj dot de 2023-11-24 9:37 ` rguenth at gcc dot gnu.org 2023-11-28 7:18 ` sam at gentoo dot org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-31055-131-XGX4N93vQD@http.sourceware.org/bugzilla/ \ --to=sourceware-bugzilla@sourceware.org \ --cc=glibc-bugs@sourceware.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).