lkml.org 
[lkml]   [2019]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] Documentation/atomic_t: Clarify signed vs unsigned
On Tue, Feb 12, 2019 at 09:03:55AM +0800, Boqun Feng wrote:
> On Mon, Feb 11, 2019 at 06:09:43PM +0100, Peter Zijlstra wrote:
> >
> > Clarify the whole signed vs unsigned issue for atomic_t.
> >
> > There has been enough confusion on this topic to warrant a few explicit
> > words I feel.
> >
> > Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
>
> FWIW
>
> Acked-by: Boqun Feng <boqun.feng@gmail.com>

Applied, thank you!

Thanx, Paul

> Regards,
> Boqun
>
> > ---
> > Documentation/atomic_t.txt | 17 +++++++++++++++++
> > 1 file changed, 17 insertions(+)
> >
> > diff --git a/Documentation/atomic_t.txt b/Documentation/atomic_t.txt
> > index 913396ac5824..dca3fb0554db 100644
> > --- a/Documentation/atomic_t.txt
> > +++ b/Documentation/atomic_t.txt
> > @@ -56,6 +56,23 @@ The 'full' API consists of (atomic64_ and atomic_long_ prefixes omitted for
> > smp_mb__{before,after}_atomic()
> >
> >
> > +TYPES (signed vs unsigned)
> > +-----
> > +
> > +While atomic_t, atomic_long_t and atomic64_t use int, long and s64
> > +respectively (for hysterical raisins), the kernel uses -fno-strict-overflow
> > +(which implies -fwrapv) and defines signed overflow to behave like
> > +2s-complement.
> > +
> > +Therefore, an explicitly unsigned variant of the atomic ops is strictly
> > +unnecessary and we can simply cast, there is no UB.
> > +
> > +There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for
> > +signed types.
> > +
> > +With this we also conform to the C/C++ _Atomic behaviour and things like
> > +P1236R1.
> > +
> >
> > SEMANTICS
> > ---------


\
 
 \ /
  Last update: 2019-02-12 02:29    [W:0.075 / U:0.496 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site