public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "de34 at live dot cn" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/108846] std::copy, std::copy_n on potentially overlapping subobjects Date: Mon, 20 Feb 2023 08:38:19 +0000 [thread overview] Message-ID: <bug-108846-4-oyM3tzEDuX@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-108846-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108846 Jiang An <de34 at live dot cn> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |de34 at live dot cn --- Comment #4 from Jiang An <de34 at live dot cn> --- (In reply to Andrew Pinski from comment #2) > Related to https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2403 > but instead of language, it is the library methods. CWG2403 looks like an unfortunate result of ABI design. If any non-padding byte of a potentially-overlapping subobject X is actually overlapping with a padding byte of subobject Y, Y should be initialized before X, because all bytes of Y may be written in initialization. However, on Itanium ABI virtual base class subobjects violate such intuitive rule. But I think it's only closedly related to uninitialized memory algorithms (which perform initialization instead of assignment), and there's already a note saying that it's UB to use them to initialize potentially-overlapping objects ([specialized.algorithms.general]/3). (In reply to Andrew Pinski from comment #3) > Even https://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#2544 is > very much related. (As the submitter) I think this issue only legitimates current implementation of pointer arithmetic. For example, assuming both sizeof(B) and sizeof(D) are 8, which means the last 2 bytes of B are padding (true for common implementations on Itanium ABI): struct B { int32_t x; int16_t y; }; struct D : B { int16_t z; }; The current wording in [basic.compound]/3 requires that given `B b{};` and `D d{};`, `static_cast<B*>(&d) + 1` represents the address of the byte at offset 6, which is almost unimplementable. However, subtraction between pointers are performed as usual for even for potentially-overlapping subobjects, which is correctly implemented. In the case of copy family algorithms, I believe it's OK to specially handle cases where last - first == 1. BTW, there's CWG2527 that is closed as NAD, which seemingly means that an array subobject can be potentially-overlapping, even if element subobjects can't.
next prev parent reply other threads:[~2023-02-20 8:38 UTC|newest] Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top 2023-02-18 21:22 [Bug libstdc++/108846] New: " arthur.j.odwyer at gmail dot com 2023-02-18 21:55 ` [Bug libstdc++/108846] " pinskia at gcc dot gnu.org 2023-02-18 21:58 ` pinskia at gcc dot gnu.org 2023-02-18 22:00 ` pinskia at gcc dot gnu.org 2023-02-20 8:38 ` de34 at live dot cn [this message] 2023-02-20 23:42 ` dangelog at gmail dot com 2023-02-21 1:58 ` de34 at live dot cn 2023-02-21 7:21 ` [Bug libstdc++/108846] std::copy, std::copy_n and std::copy_backward " pinskia at gcc dot gnu.org 2023-02-23 17:20 ` redi at gcc dot gnu.org 2023-02-23 17:25 ` redi at gcc dot gnu.org 2023-02-23 17:27 ` redi at gcc dot gnu.org 2023-02-23 17:29 ` arthur.j.odwyer at gmail dot com 2023-02-24 19:31 ` dangelog at gmail dot com 2023-02-25 9:06 ` redi at gcc dot gnu.org 2023-02-25 9:07 ` redi at gcc dot gnu.org 2023-02-25 11:40 ` dangelog at gmail dot com 2023-02-25 14:13 ` redi at gcc dot gnu.org 2023-02-25 14:16 ` redi at gcc dot gnu.org 2023-02-25 14:19 ` redi at gcc dot gnu.org 2023-02-25 14:29 ` redi at gcc dot gnu.org 2023-02-28 9:50 ` cvs-commit at gcc dot gnu.org 2023-03-02 10:49 ` dangelog at gmail dot com 2023-03-02 11:19 ` redi at gcc dot gnu.org 2023-04-20 13:50 ` redi at gcc dot gnu.org 2023-04-20 14:12 ` arthur.j.odwyer at gmail dot com 2023-04-20 17:10 ` redi at gcc dot gnu.org 2023-04-20 17:11 ` redi at gcc dot gnu.org 2024-03-18 14:05 ` cvs-commit at gcc dot gnu.org 2024-03-18 14:13 ` redi at gcc dot gnu.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-108846-4-oyM3tzEDuX@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.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).