public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: "François Dumont" <frs.dumont@gmail.com>
Cc: "libstdc++@gcc.gnu.org" <libstdc++@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Help compiler detect invalid code
Date: Thu, 10 Oct 2019 20:27:00 -0000	[thread overview]
Message-ID: <20191010200319.GE4169@redhat.com> (raw)
In-Reply-To: <829af710-d6e2-5a1f-e80f-dbf3e29d5c2a@gmail.com>

On 01/10/19 22:05 +0200, François Dumont wrote:
>On 9/27/19 1:24 PM, Jonathan Wakely wrote:
>>On 20/09/19 07:08 +0200, François Dumont wrote:
>>>I already realized that previous patch will be too controversial 
>>>to be accepted.
>>>
>>>In this new version I just implement a real memmove in __memmove 
>>>so
>>
>>A real memmove doesn't just work backwards, it needs to detect any
>>overlaps and work forwards *or* backwards, as needed.
>ok, good to know, I understand now why using __builtin_memcopy didn't 
>show any performance enhancement when I tested it !
>>
>>I think your change will break this case:
>>
>>#include <algorithm>
>>
>>constexpr int f(int i, int j, int k)
>>{
>> int arr[5] = { 0, 0, i, j, k };
>> std::move(arr+2, arr+5, arr);
>> return arr[0] + arr[1] + arr[2];
>>}
>>
>>static_assert( f(1, 2, 3) == 6 );
>>
>>This is valid because std::move only requires that the result iterator
>>is not in the input range, but it's OK for the two ranges to overlap.
>>
>>I haven't tested it, but I think with your change the array will end
>>up containing {3, 2, 3, 2, 3} instead of {1, 2, 3, 2, 3}.
>>
>Indeed, I've added a std::move constexpr test in this new proposal 
>which demonstrate that.
>
>C++ Standard clearly states that [copy|move]_backward is done 
>backward. So in this new proposal I propose to add a __memcopy used in 
>copy/move and keep __memmove for *_backward algos. Both are using 
>__builtin_memmove as before.

Then they *really* need better names now (__memmove was already a bad
name, but now it's terrible). If the difference is that one goes
forwards and one goes backwards, the names should reflect that.

I'll review it properly tomorrow.

  reply	other threads:[~2019-10-10 20:03 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19 20:28 François Dumont
2019-09-20  5:08 ` François Dumont
2019-09-25 20:40   ` François Dumont
2019-09-27 11:24   ` Jonathan Wakely
2019-10-01 20:05     ` François Dumont
2019-10-10 20:27       ` Jonathan Wakely [this message]
2019-10-16 20:35         ` François Dumont
2019-09-27 12:11 ` Jonathan Wakely
2019-09-27 16:24   ` François Dumont
2019-09-27 16:45     ` Jonathan Wakely
2019-09-28 21:12       ` [PATCH] Fix algo constexpr tests in Debug mode François Dumont
2019-09-30  9:03         ` Jonathan Wakely
2019-09-30 20:21           ` François Dumont
2019-10-01 11:21             ` Jonathan Wakely
2019-10-23 16:02         ` Jonathan Wakely

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=20191010200319.GE4169@redhat.com \
    --to=jwakely@redhat.com \
    --cc=frs.dumont@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@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).