@@ -8076,6 +8076,7 @@ This example shows some basic usage of ``__attribute__((wraps))`` on a type
8076
8076
definition when building with ``-fsanitize=signed-integer-overflow``
8077
8077
8078
8078
.. code-block:: c
8079
+
8079
8080
typedef int __attribute__((wraps)) wrapping_int;
8080
8081
8081
8082
void foo() {
@@ -8084,17 +8085,17 @@ definition when building with ``-fsanitize=signed-integer-overflow``
8084
8085
}
8085
8086
8086
8087
int main() { foo(); }
8087
- }
8088
8088
8089
8089
In the following example, we use ``__attribute__((wraps))`` on a variable to
8090
8090
disable overflow instrumentation for arithmetic expressions it appears in. We
8091
8091
do so with a popular overflow-checking pattern which we might not want to trip
8092
8092
sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
8093
8093
8094
8094
.. code-block:: c
8095
+
8095
8096
void foo(int offset) {
8096
8097
unsigned int A __attribute__((wraps)) = UINT_MAX;
8097
-
8098
+
8098
8099
// to check for overflow using this pattern, we may perform a real overflow
8099
8100
// thus triggering sanitizers to step in. Since A is "wrapping", we can be
8100
8101
// sure there are no sanitizer warnings.
@@ -8104,10 +8105,8 @@ sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
8104
8105
return;
8105
8106
}
8106
8107
8107
- // now, handle non-overflow case
8108
- // ...
8108
+ // now, handle non-overflow case ...
8109
8109
}
8110
- }
8111
8110
8112
8111
The above example demonstrates some of the power and elegance this attribute
8113
8112
provides. We can use code patterns we are already familiar with (like ``if (x +
@@ -8123,5 +8122,6 @@ When using this attribute without ``-fwrapv`` and without any sanitizers, it
8123
8122
still has an impact on the definedness of arithmetic expressions containing
8124
8123
wrapping components. Since the behavior of said expressions is now technically
8125
8124
defined, the compiler will forgo some eager optimizations that are used on
8126
- expressions containing UB.}];
8125
+ expressions containing UB.
8126
+ }];
8127
8127
}
0 commit comments