* [PATCH] #52291 - clarify sync_fetch_and_OP for pointers
@ 2016-01-21 0:11 Martin Sebor
2016-01-21 2:48 ` Jeff Law
0 siblings, 1 reply; 2+ messages in thread
From: Martin Sebor @ 2016-01-21 0:11 UTC (permalink / raw)
To: Gcc Patch List
[-- Attachment #1: Type: text/plain, Size: 505 bytes --]
The bug points out that while the __sync_fetch_and_OP intrinsics are
documented to have semantics equivalent to the "x OP= y" compound
assignment expressions, when used with pointer operands they actually
behave as if they operated on integers. I.e., they are not scaled by
the size of the pointed-to type.
The attached patch brings the documentation of both the __sync_ and
the __atomic_ intrinsics into alignment with their actual effects.
Martin
PS See also c/64843 for some additional background.
[-- Attachment #2: gcc-52291.patch --]
[-- Type: text/x-patch, Size: 3759 bytes --]
2016-01-20 Martin Sebor <msebor@redhat.com>
PR c/52291
* extend.texi (__sync Builtins): Clarify the semantics aof
__sync_fetch_and_OP built-ins on pointers.
(__atomic Builtins): Same.
Index: gcc/doc/extend.texi
===================================================================
--- gcc/doc/extend.texi (revision 232636)
+++ gcc/doc/extend.texi (working copy)
@@ -9262,8 +9262,11 @@ work on multiple types.
The definition given in the Intel documentation allows only for the use of
the types @code{int}, @code{long}, @code{long long} or their unsigned
-counterparts. GCC allows any integral scalar or pointer type that is
-1, 2, 4 or 8 bytes in length.
+counterparts. GCC allows any scalar type that is 1, 2, 4 or 8 bytes in
+size other than the C type @code{_Bool} or the C++ type @code{bool}.
+Operations on pointer operands are performed as if the operands were
+of the @code{uintptr_t} type. That is, they are not scaled by the size
+of the type to which the pointer points.
These functions are implemented in terms of the @samp{__atomic}
builtins (@pxref{__atomic Builtins}). They should not be used for new
@@ -9309,7 +9312,11 @@ accessible variables should be protected
@findex __sync_fetch_and_xor
@findex __sync_fetch_and_nand
These built-in functions perform the operation suggested by the name, and
-returns the value that had previously been in memory. That is,
+returns the value that had previously been in memory. That is, operations
+on integer operands have the following semantics. Operations on pointer
+operands are performed as if the operands were of the @code{uintptr_t}
+type. That is, they are not scaled by the size of the type to which
+the pointer points.
@smallexample
@{ tmp = *ptr; *ptr @var{op}= value; return tmp; @}
@@ -9335,7 +9342,9 @@ as @code{*ptr = ~(tmp & value)} instead
@findex __sync_xor_and_fetch
@findex __sync_nand_and_fetch
These built-in functions perform the operation suggested by the name, and
-return the new value. That is,
+return the new value. That is, operations on integer operands have
+the following semantics. Operations on pointer operands are performed as
+if the operands were of the @code{uintptr_t} type. That is, they are not
+scaled by the size of the type to which the pointer points.
@smallexample
@{ *ptr @var{op}= value; return *ptr; @}
@@ -9592,7 +9601,9 @@ pointer.
@deftypefnx {Built-in Function} @var{type} __atomic_or_fetch (@var{type} *ptr, @var{type} val, int memorder)
@deftypefnx {Built-in Function} @var{type} __atomic_nand_fetch (@var{type} *ptr, @var{type} val, int memorder)
These built-in functions perform the operation suggested by the name, and
-return the result of the operation. That is,
+return the result of the operation. Operations on pointer operands are
+performed as if the operands were of the @code{uintptr_t} type. That is,
+they are not scaled by the size of the type to which the pointer points.
@smallexample
@{ *ptr @var{op}= val; return *ptr; @}
@@ -9610,7 +9621,10 @@ type. It must not be a Boolean type. A
@deftypefnx {Built-in Function} @var{type} __atomic_fetch_or (@var{type} *ptr, @var{type} val, int memorder)
@deftypefnx {Built-in Function} @var{type} __atomic_fetch_nand (@var{type} *ptr, @var{type} val, int memorder)
These built-in functions perform the operation suggested by the name, and
-return the value that had previously been in @code{*@var{ptr}}. That is,
+return the value that had previously been in @code{*@var{ptr}}. Operations
+on pointer operands are performed as if the operands were of
+the @code{uintptr_t} type. That is, they are not scaled by the size of
+the type to which the pointer points.
@smallexample
@{ tmp = *ptr; *ptr @var{op}= val; return tmp; @}
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] #52291 - clarify sync_fetch_and_OP for pointers
2016-01-21 0:11 [PATCH] #52291 - clarify sync_fetch_and_OP for pointers Martin Sebor
@ 2016-01-21 2:48 ` Jeff Law
0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2016-01-21 2:48 UTC (permalink / raw)
To: Martin Sebor, Gcc Patch List
On 01/20/2016 05:11 PM, Martin Sebor wrote:
> The bug points out that while the __sync_fetch_and_OP intrinsics are
> documented to have semantics equivalent to the "x OP= y" compound
> assignment expressions, when used with pointer operands they actually
> behave as if they operated on integers. I.e., they are not scaled by
> the size of the pointed-to type.
>
> The attached patch brings the documentation of both the __sync_ and
> the __atomic_ intrinsics into alignment with their actual effects.
>
> Martin
>
> PS See also c/64843 for some additional background.
>
> gcc-52291.patch
>
>
> 2016-01-20 Martin Sebor<msebor@redhat.com>
>
> PR c/52291
> * extend.texi (__sync Builtins): Clarify the semantics aof
> __sync_fetch_and_OP built-ins on pointers.
> (__atomic Builtins): Same.
OK
jeff
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-01-21 2:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-21 0:11 [PATCH] #52291 - clarify sync_fetch_and_OP for pointers Martin Sebor
2016-01-21 2:48 ` Jeff Law
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).