@@ -43,6 +43,10 @@ Where ``behavior`` can be one of the following:
43
43
44
44
This attribute can be applied to ``typedef `` declarations and to integer types directly.
45
45
46
+ Arithmetic operations containing one or more overflow behavior types may have
47
+ result types that do not match standard integer promotion rules. The
48
+ characteristics of result types across all scenarios are described under `Promotion Rules `_.
49
+
46
50
Examples
47
51
========
48
52
@@ -75,46 +79,6 @@ integral types.
75
79
Note that C++ overload set formation rules treat promotions to and from
76
80
overflow behavior types the same as normal integral promotions and conversions.
77
81
78
- Interaction with Command-Line Flags and Sanitizer Special Case Lists
79
- ====================================================================
80
-
81
- The ``overflow_behavior `` attribute interacts with sanitizers, ``-ftrapv ``,
82
- ``-fwrapv ``, and Sanitizer Special Case Lists (SSCL) by wholly overriding these
83
- global flags. The following table summarizes the interactions:
84
-
85
- .. list-table :: Overflow Behavior Precedence
86
- :widths: 15 15 15 15 20 15
87
- :header-rows: 1
88
-
89
- * - Behavior
90
- - Default(No Flags)
91
- - -ftrapv
92
- - -fwrapv
93
- - Sanitizers
94
- - SSCL
95
- * - ``overflow_behavior(wrap) ``
96
- - Wraps
97
- - No trap
98
- - Wraps
99
- - No report
100
- - Overrides SSCL
101
- * - ``overflow_behavior(no_wrap) ``
102
- - Traps
103
- - Traps
104
- - Traps
105
- - Reports
106
- - Overrides SSCL
107
-
108
- It is important to note the distinction between signed and unsigned types. For
109
- unsigned integers, which wrap on overflow by default, ``overflow_behavior(no_wrap) ``
110
- is particularly useful for enabling overflow checks. For signed integers, whose
111
- overflow behavior is undefined by default, ``overflow_behavior(wrap) `` provides
112
- a guaranteed wrapping behavior.
113
-
114
- The ``overflow_behavior `` attribute can be used to override the behavior of
115
- entries from a :doc: `SanitizerSpecialCaseList `. This is useful for allowlisting
116
- specific types into overflow instrumentation.
117
-
118
82
Promotion Rules
119
83
===============
120
84
@@ -123,6 +87,9 @@ specified overflow behavior throughout an arithmetic expression. They differ
123
87
from standard C/C++ integer promotions but in a predictable way, similar to
124
88
how ``_Complex `` and ``_BitInt `` have their own promotion rules.
125
89
90
+ The resulting type characteristics for overflow behavior types (OBTs) across a
91
+ variety of scenarios is detailed below.
92
+
126
93
* **OBT and Standard Integer Type **: In an operation involving an overflow
127
94
behavior type (OBT) and a standard integer type, the result will have the
128
95
type of the OBT, including its overflow behavior, sign, and bit-width. The
@@ -156,6 +123,59 @@ how ``_Complex`` and ``_BitInt`` have their own promotion rules.
156
123
Regardless, the resulting type matches the bit-width, sign and behavior of
157
124
the ``no_wrap `` type.
158
125
126
+ .. list-table :: Promotion Rules Summary
127
+ :widths: 30 70
128
+ :header-rows: 1
129
+
130
+ * - Operation Type
131
+ - Result Type
132
+ * - OBT + Standard Integer
133
+ - OBT type (preserves overflow behavior, sign, and bit-width)
134
+ * - Same Kind OBTs (both ``wrap `` or both ``no_wrap ``)
135
+ - Larger bit-width; unsigned favored if same width
136
+ * - Different Kind OBTs (``wrap `` + ``no_wrap ``)
137
+ - ``no_wrap `` type (matches ``no_wrap `` operand's characteristics)
138
+
139
+ Interaction with Command-Line Flags and Sanitizer Special Case Lists
140
+ ====================================================================
141
+
142
+ The ``overflow_behavior `` attribute interacts with sanitizers, ``-ftrapv ``,
143
+ ``-fwrapv ``, and Sanitizer Special Case Lists (SSCL) by wholly overriding these
144
+ global flags. The following table summarizes the interactions:
145
+
146
+ .. list-table :: Overflow Behavior Precedence
147
+ :widths: 15 15 15 15 20 15
148
+ :header-rows: 1
149
+
150
+ * - Behavior
151
+ - Default(No Flags)
152
+ - -ftrapv
153
+ - -fwrapv
154
+ - Sanitizers
155
+ - SSCL
156
+ * - ``overflow_behavior(wrap) ``
157
+ - Wraps
158
+ - Wraps
159
+ - Wraps
160
+ - No report
161
+ - Overrides SSCL
162
+ * - ``overflow_behavior(no_wrap) ``
163
+ - Traps
164
+ - Traps
165
+ - Traps
166
+ - Reports
167
+ - Overrides SSCL
168
+
169
+ It is important to note the distinction between signed and unsigned types. For
170
+ unsigned integers, which wrap on overflow by default, ``overflow_behavior(no_wrap) ``
171
+ is particularly useful for enabling overflow checks. For signed integers, whose
172
+ overflow behavior is undefined by default, ``overflow_behavior(wrap) `` provides
173
+ a guaranteed wrapping behavior.
174
+
175
+ The ``overflow_behavior `` attribute can be used to override the behavior of
176
+ entries from a :doc: `SanitizerSpecialCaseList `. This is useful for allowlisting
177
+ specific types into overflow instrumentation.
178
+
159
179
Diagnostics
160
180
===========
161
181
0 commit comments