Skip to content

Commit f188714

Browse files
Peter ZijlstraPaul E. McKenney
authored andcommitted
Documentation/atomic_t: Clarify signed vs unsigned
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> Acked-by: Will Deacon <will.deacon@arm.com> Acked-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>
1 parent db46714 commit f188714

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎Documentation/atomic_t.txt‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,23 @@ Barriers:
5656
smp_mb__{before,after}_atomic()
5757

5858

59+
TYPES (signed vs unsigned)
60+
-----
61+
62+
While atomic_t, atomic_long_t and atomic64_t use int, long and s64
63+
respectively (for hysterical raisins), the kernel uses -fno-strict-overflow
64+
(which implies -fwrapv) and defines signed overflow to behave like
65+
2s-complement.
66+
67+
Therefore, an explicitly unsigned variant of the atomic ops is strictly
68+
unnecessary and we can simply cast, there is no UB.
69+
70+
There was a bug in UBSAN prior to GCC-8 that would generate UB warnings for
71+
signed types.
72+
73+
With this we also conform to the C/C++ _Atomic behaviour and things like
74+
P1236R1.
75+
5976

6077
SEMANTICS
6178
---------

0 commit comments

Comments
 (0)