public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap requirement
@ 2023-11-23  8:00 Richard Biener
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Biener @ 2023-11-23  8:00 UTC (permalink / raw)
  To: gcc-patches; +Cc: Jakub Jelinek, jlaw

The following amends the cpymem documentation to mention that exact
overlap needs to be handled gracefully, also noting that the target
runtime is expected to behave the same way.

OK?

Thanks,
Richard.

	PR middle-end/32667
	* md.texi (cpymem): Document that exact overlap of source
	and destination needs to work.  Mention the target runtime
	may not treat this case as undefined.
---
 gcc/doc/md.texi | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index df6725ffc9c..8743b393b3c 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -6915,8 +6915,11 @@ individually copied data units in the block.
 
 The @code{cpymem@var{m}} patterns need not give special consideration
 to the possibility that the source and destination strings might
-overlap. These patterns are used to do inline expansion of
-@code{__builtin_memcpy}.
+overlap.  An exeption is the case where source and destination are
+equal.  These patterns are used to do inline expansion of
+@code{__builtin_memcpy}.  The target runtime is expected to handle
+the case of an exact overlap of source and destination gracefully
+as GCC does not consider that undefined behavior.
 
 @cindex @code{movmem@var{m}} instruction pattern
 @item @samp{movmem@var{m}}
-- 
2.35.3

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap requirement
  2023-11-23  8:13   ` Richard Biener
@ 2023-11-23  8:28     ` Jakub Jelinek
  0 siblings, 0 replies; 4+ messages in thread
From: Jakub Jelinek @ 2023-11-23  8:28 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, jlaw

On Thu, Nov 23, 2023 at 08:13:47AM +0000, Richard Biener wrote:
> On Thu, 23 Nov 2023, Jakub Jelinek wrote:
> 
> > On Thu, Nov 23, 2023 at 08:00:49AM +0000, Richard Biener wrote:
> > > The following amends the cpymem documentation to mention that exact
> > > overlap needs to be handled gracefully, also noting that the target
> > > runtime is expected to behave the same way.
> > > 
> > > OK?
> > > 
> > > Thanks,
> > > Richard.
> > > 
> > > 	PR middle-end/32667
> > > 	* md.texi (cpymem): Document that exact overlap of source
> > > 	and destination needs to work.  Mention the target runtime
> > > 	may not treat this case as undefined.
> > 
> > The first added sentence is ok, for the second see the spot
> > Florian mentioned in the PR.
> 
> Like this?
> 
> Thanks,
> Richard.
> 
> >From 93f4d22374ad2ea8bb5821083d2422c8b0a3313b Mon Sep 17 00:00:00 2001
> From: Richard Biener <rguenther@suse.de>
> Date: Thu, 23 Nov 2023 08:54:56 +0100
> Subject: [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap
>  requirement
> To: gcc-patches@gcc.gnu.org
> 
> The following amends the cpymem documentation to mention that exact
> overlap needs to be handled gracefully, also noting that the target
> runtime is expected to behave the same way where -ffreestanding
> docs mention the set of routines required.
> 
> 	PR middle-end/32667
> 	* md.texi (cpymem): Document that exact overlap of source
> 	and destination needs to work.
> 	* standards.texi (ffreestanding): Mention memcpy is required
> 	to handle the exact overlap case.
> ---
>  gcc/doc/md.texi        | 5 +++--
>  gcc/doc/standards.texi | 4 +++-
>  2 files changed, 6 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
> index df6725ffc9c..87e1c9ed20e 100644
> --- a/gcc/doc/md.texi
> +++ b/gcc/doc/md.texi
> @@ -6915,8 +6915,9 @@ individually copied data units in the block.
>  
>  The @code{cpymem@var{m}} patterns need not give special consideration
>  to the possibility that the source and destination strings might
> -overlap. These patterns are used to do inline expansion of
> -@code{__builtin_memcpy}.
> +overlap.  An exeption is the case where source and destination are

s/exeption/exception/

> +equal, this case needs to be handled correctly.
> +These patterns are used to do inline expansion of @code{__builtin_memcpy}.
>  
>  @cindex @code{movmem@var{m}} instruction pattern
>  @item @samp{movmem@var{m}}
> diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
> index 4eb43f14f90..6eebb9426f3 100644
> --- a/gcc/doc/standards.texi
> +++ b/gcc/doc/standards.texi
> @@ -184,7 +184,9 @@ GNU C library).  @xref{Standard Libraries,,Standard Libraries}.
>  Most of the compiler support routines used by GCC are present in
>  @file{libgcc}, but there are a few exceptions.  GCC requires the
>  freestanding environment provide @code{memcpy}, @code{memmove},
> -@code{memset} and @code{memcmp}.
> +@code{memset} and @code{memcmp}.  Contrary to the standards
> +covering @code{memcpy} GCC expects the case of an exact overlap
> +of source and destination to work and not invoke undefined behavior.
>  Finally, if @code{__builtin_trap} is used, and the target does
>  not implement the @code{trap} pattern, then GCC emits a call
>  to @code{abort}.

Ok with that typo fix.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap requirement
  2023-11-23  8:05 ` Jakub Jelinek
@ 2023-11-23  8:13   ` Richard Biener
  2023-11-23  8:28     ` Jakub Jelinek
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2023-11-23  8:13 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: gcc-patches, jlaw

On Thu, 23 Nov 2023, Jakub Jelinek wrote:

> On Thu, Nov 23, 2023 at 08:00:49AM +0000, Richard Biener wrote:
> > The following amends the cpymem documentation to mention that exact
> > overlap needs to be handled gracefully, also noting that the target
> > runtime is expected to behave the same way.
> > 
> > OK?
> > 
> > Thanks,
> > Richard.
> > 
> > 	PR middle-end/32667
> > 	* md.texi (cpymem): Document that exact overlap of source
> > 	and destination needs to work.  Mention the target runtime
> > 	may not treat this case as undefined.
> 
> The first added sentence is ok, for the second see the spot
> Florian mentioned in the PR.

Like this?

Thanks,
Richard.

From 93f4d22374ad2ea8bb5821083d2422c8b0a3313b Mon Sep 17 00:00:00 2001
From: Richard Biener <rguenther@suse.de>
Date: Thu, 23 Nov 2023 08:54:56 +0100
Subject: [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap
 requirement
To: gcc-patches@gcc.gnu.org

The following amends the cpymem documentation to mention that exact
overlap needs to be handled gracefully, also noting that the target
runtime is expected to behave the same way where -ffreestanding
docs mention the set of routines required.

	PR middle-end/32667
	* md.texi (cpymem): Document that exact overlap of source
	and destination needs to work.
	* standards.texi (ffreestanding): Mention memcpy is required
	to handle the exact overlap case.
---
 gcc/doc/md.texi        | 5 +++--
 gcc/doc/standards.texi | 4 +++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/gcc/doc/md.texi b/gcc/doc/md.texi
index df6725ffc9c..87e1c9ed20e 100644
--- a/gcc/doc/md.texi
+++ b/gcc/doc/md.texi
@@ -6915,8 +6915,9 @@ individually copied data units in the block.
 
 The @code{cpymem@var{m}} patterns need not give special consideration
 to the possibility that the source and destination strings might
-overlap. These patterns are used to do inline expansion of
-@code{__builtin_memcpy}.
+overlap.  An exeption is the case where source and destination are
+equal, this case needs to be handled correctly.
+These patterns are used to do inline expansion of @code{__builtin_memcpy}.
 
 @cindex @code{movmem@var{m}} instruction pattern
 @item @samp{movmem@var{m}}
diff --git a/gcc/doc/standards.texi b/gcc/doc/standards.texi
index 4eb43f14f90..6eebb9426f3 100644
--- a/gcc/doc/standards.texi
+++ b/gcc/doc/standards.texi
@@ -184,7 +184,9 @@ GNU C library).  @xref{Standard Libraries,,Standard Libraries}.
 Most of the compiler support routines used by GCC are present in
 @file{libgcc}, but there are a few exceptions.  GCC requires the
 freestanding environment provide @code{memcpy}, @code{memmove},
-@code{memset} and @code{memcmp}.
+@code{memset} and @code{memcmp}.  Contrary to the standards
+covering @code{memcpy} GCC expects the case of an exact overlap
+of source and destination to work and not invoke undefined behavior.
 Finally, if @code{__builtin_trap} is used, and the target does
 not implement the @code{trap} pattern, then GCC emits a call
 to @code{abort}.
-- 
2.35.3


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap requirement
       [not found] <98253.123112303005100688@us-mta-495.us.mimecast.lan>
@ 2023-11-23  8:05 ` Jakub Jelinek
  2023-11-23  8:13   ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: Jakub Jelinek @ 2023-11-23  8:05 UTC (permalink / raw)
  To: Richard Biener; +Cc: gcc-patches, jlaw

On Thu, Nov 23, 2023 at 08:00:49AM +0000, Richard Biener wrote:
> The following amends the cpymem documentation to mention that exact
> overlap needs to be handled gracefully, also noting that the target
> runtime is expected to behave the same way.
> 
> OK?
> 
> Thanks,
> Richard.
> 
> 	PR middle-end/32667
> 	* md.texi (cpymem): Document that exact overlap of source
> 	and destination needs to work.  Mention the target runtime
> 	may not treat this case as undefined.

The first added sentence is ok, for the second see the spot
Florian mentioned in the PR.

	Jakub


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-11-23  8:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-23  8:00 [PATCH] middle-end/32667 - document cpymem and memcpy exact overlap requirement Richard Biener
     [not found] <98253.123112303005100688@us-mta-495.us.mimecast.lan>
2023-11-23  8:05 ` Jakub Jelinek
2023-11-23  8:13   ` Richard Biener
2023-11-23  8:28     ` Jakub Jelinek

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).