public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "arthur.j.odwyer at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/108846] std::copy, std::copy_n and std::copy_backward on potentially overlapping subobjects
Date: Thu, 20 Apr 2023 14:12:14 +0000	[thread overview]
Message-ID: <bug-108846-4-E5Zpfoazcc@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

--- Comment #23 from Arthur O'Dwyer <arthur.j.odwyer at gmail dot com> ---
(In reply to Jonathan Wakely from comment #22)
> 
> Richi suggested that we could avoid these runtime branches (which hurt
> optimization, see PR 109445) if we knew how many bytes of tail padding there
> are in _Tp [...]
> We don't have a built-in to tell us the number of [trailing] padding bytes, but we
> might be able to use something like this

Three thoughts that might be helpful:
- There may be padding in the middle of an object, and I'm not confident that
the Standard actually forbids it from being used. Of course your approach works
fine on the Itanium ABI, and probably works everywhere that actually exists. If
you've got chapter+verse proving that it must work *everywhere*, I'd appreciate
seeing it, just for my own information.
- If GCC were ever to add a builtin for this notion, IMO the proper name would
be `__datasizeof(T)`. See
https://danakj.github.io/2023/01/15/trivially-relocatable.html#data-size
- You can implement your library trait like this; see
https://quuxplusone.github.io/blog/2023/03/04/trivial-swap-prize-update/#step-1.-std-swap-can-t-assume-it

    template <class _Tp>
    struct __libcpp_datasizeof {
        struct _Up {
            [[__no_unique_address__]] _Tp __t_;
            char __c_;
        };
        static const size_t value = __builtin_offsetof(_Up, __c_);
    };

Unfortunately it looks like GCC doesn't support
`__attribute__((__no_unique_address__))` in C++03 mode. (Neither does Clang.
What is up with that!)

Your suggested trait implementation is slightly wrong for `is_final` types: you
return 0 but really a final type _can_ have usable tail padding. See
https://godbolt.org/z/P6x459MEq

  parent reply	other threads:[~2023-04-20 14:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-18 21:22 [Bug libstdc++/108846] New: std::copy, std::copy_n " 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
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 [this message]
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-E5Zpfoazcc@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: link
Be 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).