@@ -8076,6 +8076,7 @@ This example shows some basic usage of ``__attribute__((wraps))`` on a type
80768076definition when building with ``-fsanitize=signed-integer-overflow``
80778077
80788078.. code-block:: c
8079+
80798080 typedef int __attribute__((wraps)) wrapping_int;
80808081
80818082 void foo() {
@@ -8084,17 +8085,17 @@ definition when building with ``-fsanitize=signed-integer-overflow``
80848085 }
80858086
80868087 int main() { foo(); }
8087- }
80888088
80898089In the following example, we use ``__attribute__((wraps))`` on a variable to
80908090disable overflow instrumentation for arithmetic expressions it appears in. We
80918091do so with a popular overflow-checking pattern which we might not want to trip
80928092sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
80938093
80948094.. code-block:: c
8095+
80958096 void foo(int offset) {
80968097 unsigned int A __attribute__((wraps)) = UINT_MAX;
8097-
8098+
80988099 // to check for overflow using this pattern, we may perform a real overflow
80998100 // thus triggering sanitizers to step in. Since A is "wrapping", we can be
81008101 // sure there are no sanitizer warnings.
@@ -8104,10 +8105,8 @@ sanitizers (like ``-fsanitize=unsigned-integer-overflow``).
81048105 return;
81058106 }
81068107
8107- // now, handle non-overflow case
8108- // ...
8108+ // now, handle non-overflow case ...
81098109 }
8110- }
81118110
81128111The above example demonstrates some of the power and elegance this attribute
81138112provides. 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
81238122still has an impact on the definedness of arithmetic expressions containing
81248123wrapping components. Since the behavior of said expressions is now technically
81258124defined, the compiler will forgo some eager optimizations that are used on
8126- expressions containing UB.}];
8125+ expressions containing UB.
8126+ }];
81278127}
0 commit comments