[2/2] doc/implement-c.texi: About same-as-scalar-type volatile aggregate accesses, PR94600

Message ID 202007070402.06742cJT024117@ignucius.se.axis.com
State New
Headers show
Series
  • [1/2] PR94600: fix volatile access to the whole of a compound object.
Related show

Commit Message

Qing Zhao via Gcc-patches July 7, 2020, 4:02 a.m.
We say very little about reads and writes to aggregate /
compound objects, just scalar objects (i.e. assignments don't
cause reads).  Let's lets say something safe about aggregate
objects, but only for those that are the same size as a scalar
type.

There's an equal-sounding section (Volatiles) in extend.texi,
but this seems a more appropriate place, as specifying the
behavior of a standard qualifier.

gcc:
	PR middle-end/94600
	* doc/implement-c.texi (Qualifiers implementation): Add blurb
 	about access to the whole of a volatile aggregate object, only for
 	same-size as scalar object.
---
 gcc/doc/implement-c.texi | 4 ++++
 1 file changed, 4 insertions(+)

-- 
2.11.0

Comments

Qing Zhao via Gcc-patches July 7, 2020, 7 a.m. | #1
On Tue, Jul 7, 2020 at 6:03 AM Hans-Peter Nilsson via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>

> We say very little about reads and writes to aggregate /

> compound objects, just scalar objects (i.e. assignments don't

> cause reads).  Let's lets say something safe about aggregate

> objects, but only for those that are the same size as a scalar

> type.

>

> There's an equal-sounding section (Volatiles) in extend.texi,

> but this seems a more appropriate place, as specifying the

> behavior of a standard qualifier.


Hmm, might be true only up to word-mode size, not, say, __int128_t.
Also very likely only in case the object has the same alignment
as the naturally aligned integer type.

Richard.

> gcc:

>         PR middle-end/94600

>         * doc/implement-c.texi (Qualifiers implementation): Add blurb

>         about access to the whole of a volatile aggregate object, only for

>         same-size as scalar object.

> ---

>  gcc/doc/implement-c.texi | 4 ++++

>  1 file changed, 4 insertions(+)

>

> diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi

> index 692297b69c4..d64922b28ad 100644

> --- a/gcc/doc/implement-c.texi

> +++ b/gcc/doc/implement-c.texi

> @@ -576,6 +576,10 @@ are of scalar types, the expression is interpreted by GCC as a read of

>  the volatile object; in the other cases, the expression is only evaluated

>  for its side effects.

>

> +When an object of aggregate type has the same size as a scalar type, GCC

> +handles an access to the whole of that volatile aggregate type object

> +equal to an access to that volatile same-sized scalar type object.

> +

>  @end itemize

>

>  @node Declarators implementation

> --

> 2.11.0

>
Qing Zhao via Gcc-patches July 8, 2020, 12:09 a.m. | #2
On 7/6/20 10:02 PM, Hans-Peter Nilsson via Gcc-patches wrote:
> We say very little about reads and writes to aggregate /

> compound objects, just scalar objects (i.e. assignments don't

> cause reads).  Let's lets say something safe about aggregate

> objects, but only for those that are the same size as a scalar

> type.

> 

> There's an equal-sounding section (Volatiles) in extend.texi,

> but this seems a more appropriate place, as specifying the

> behavior of a standard qualifier.

> 

> gcc:

> 	PR middle-end/94600

> 	* doc/implement-c.texi (Qualifiers implementation): Add blurb

>   	about access to the whole of a volatile aggregate object, only for

>   	same-size as scalar object.

> ---

>   gcc/doc/implement-c.texi | 4 ++++

>   1 file changed, 4 insertions(+)

> 

> diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi

> index 692297b69c4..d64922b28ad 100644

> --- a/gcc/doc/implement-c.texi

> +++ b/gcc/doc/implement-c.texi

> @@ -576,6 +576,10 @@ are of scalar types, the expression is interpreted by GCC as a read of

>   the volatile object; in the other cases, the expression is only evaluated

>   for its side effects.

>   

> +When an object of aggregate type has the same size as a scalar type, GCC

> +handles an access to the whole of that volatile aggregate type object

> +equal to an access to that volatile same-sized scalar type object.


The grammar is a bit off here making the sentence difficult to
parse and interpret.  Richard already pointed out the alignment
requirement but I'm also wondering if the statement is meant to
apply to accesses by library functions such as memcpy.  I suspect
it should only apply to assignments (either simple or atomic),
correct?

Would something like this be more accurate?

   When an object of an aggregate type with the same size and
   alignment as a scalar type S is the subject of a volatile
   access by an assignment expression or an atomic function,
   the access to it is performed as if the object's declared
   type were volatile S.

Martin

> +

>   @end itemize

>   

>   @node Declarators implementation

>
Qing Zhao via Gcc-patches July 13, 2020, 6:59 a.m. | #3
On Mon, Jul 13, 2020 at 6:46 AM Hans-Peter Nilsson <hp@axis.com> wrote:
>

> > From: Richard Biener <richard.guenther@gmail.com>

> > Date: Tue, 7 Jul 2020 09:00:22 +0200

>

> > On Tue, Jul 7, 2020 at 6:03 AM Hans-Peter Nilsson via Gcc-patches

> > <gcc-patches@gcc.gnu.org> wrote:

> > >

> > > We say very little about reads and writes to aggregate /

> > > compound objects, just scalar objects (i.e. assignments don't

> > > cause reads).  Let's lets say something safe about aggregate

> > > objects, but only for those that are the same size as a scalar

> > > type.

> > >

> > > There's an equal-sounding section (Volatiles) in extend.texi,

> > > but this seems a more appropriate place, as specifying the

> > > behavior of a standard qualifier.

> >

> > Hmm, might be true only up to word-mode size, not, say, __int128_t.

>

> I'm not saying a *single* read or write, I'm saying exactly as

> (many as) would happen for the integer type.

>

> > Also very likely only in case the object has the same alignment

> > as the naturally aligned integer type.

>

> Again, just as needed for the integer type.

>

> So WDYT about Martin Sebor's suggestion?


That sounds good.

Thanks,
Richard.

> brgds, H-P

Patch

diff --git a/gcc/doc/implement-c.texi b/gcc/doc/implement-c.texi
index 692297b69c4..d64922b28ad 100644
--- a/gcc/doc/implement-c.texi
+++ b/gcc/doc/implement-c.texi
@@ -576,6 +576,10 @@  are of scalar types, the expression is interpreted by GCC as a read of
 the volatile object; in the other cases, the expression is only evaluated
 for its side effects.
 
+When an object of aggregate type has the same size as a scalar type, GCC
+handles an access to the whole of that volatile aggregate type object
+equal to an access to that volatile same-sized scalar type object.
+
 @end itemize
 
 @node Declarators implementation