Skip to content

Commit 6940157

Browse files
committed
[Clang] Add release note for pointer overflow optimization change
1 parent c39500f commit 6940157

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,26 @@ code bases.
5858
containing strict-aliasing violations. The new default behavior can be
5959
disabled using ``-fno-pointer-tbaa``.
6060

61+
- Clang will now more aggressively use undefined behavior on pointer addition
62+
overflow for optimization purposes. For example, a check like
63+
``ptr + unsigned_offset < ptr`` will now optimize to ``false``, because
64+
``ptr + unsigned_offset`` will cause undefined behavior if it overflows (or
65+
advances past the end of the object).
66+
67+
Previously, ``ptr + unsigned_offset < ptr`` was optimized (by both Clang and
68+
GCC) to ``(ssize_t)unsigned_offset < 0``. This also results in an incorrect
69+
overflow check, but in a way that is less apparent when only testing with
70+
pointers in the low half of the address space.
71+
72+
To avoid pointer addition overflow, it is necessary to perform the addition
73+
on integers, for example using
74+
``(uintptr_t)ptr + unsigned_offset < (uintptr_t)ptr``.
75+
76+
Undefined behavior due to pointer addition overflow can be reliably detected
77+
using ``-fsanitize=pointer-overflow``. It is also possible to use
78+
``-fno-strict-overflow`` to opt-in to a language dialect where signed integer
79+
and pointer overflow are well-defined.
80+
6181
C/C++ Language Potentially Breaking Changes
6282
-------------------------------------------
6383

0 commit comments

Comments
 (0)