[clang] 24faf90 - [Clang] Add AttrDocs entry for OverflowBehavior (#203392)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 12 19:06:20 PDT 2026
Author: Justin Stitt
Date: 2026-06-12T19:06:16-07:00
New Revision: 24faf90b03a16c248764fb7ab33d9e7cb1d39908
URL: https://github.com/llvm/llvm-project/commit/24faf90b03a16c248764fb7ab33d9e7cb1d39908
DIFF: https://github.com/llvm/llvm-project/commit/24faf90b03a16c248764fb7ab33d9e7cb1d39908.diff
LOG: [Clang] Add AttrDocs entry for OverflowBehavior (#203392)
These docs were previously missing.
Fixes: #203322
Signed-off-by: Justin Stitt <justinstitt at google.com>
Added:
Modified:
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/test/AST/undocumented-attrs.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/Attr.td b/clang/include/clang/Basic/Attr.td
index a1e02e1478df1..1745c5a4f4c2a 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -5483,7 +5483,7 @@ def OverflowBehavior : TypeAttr {
let Args = [IdentifierArgument<"BehaviorKind">];
let Subjects = SubjectList<[Var, TypedefName, Field], WarnDiag,
"variables, typedefs, and data members">;
- let Documentation = [Undocumented];
+ let Documentation = [OverflowBehaviorDocs];
}
def Personality : InheritableAttr {
diff --git a/clang/include/clang/Basic/AttrDocs.td b/clang/include/clang/Basic/AttrDocs.td
index 857015e1c7476..59d4b7ef63d9e 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -10052,6 +10052,51 @@ The following aspects are currently supported:
}];
}
+def OverflowBehaviorDocs : Documentation {
+ let Category = DocCatType;
+ let Content = [{
+The ``overflow_behavior`` attribute provides fine-grained, type-level control
+over how arithmetic operations on an integer type behave on overflow. It may be
+applied to a ``typedef``, to a variable or data member, or to an integer type
+directly, and accepts one of two behaviors as its argument:
+
+* ``wrap``: arithmetic on the attributed type wraps on overflow, using two's
+ complement semantics. This is equivalent to ``-fwrapv`` but scoped to the
+ attributed type, and works for both signed and unsigned types. UBSan's
+ ``signed-integer-overflow``, ``unsigned-integer-overflow``,
+ ``implicit-signed-integer-truncation``, and
+ ``implicit-unsigned-integer-truncation`` checks are suppressed for the type.
+
+* ``trap``: arithmetic on the attributed type is checked for overflow, enabling
+ overflow checks for the type even when ``-fwrapv`` is in effect globally.
+
+.. code-block:: c++
+
+ typedef unsigned int __attribute__((overflow_behavior(trap))) non_wrapping_uint;
+
+ non_wrapping_uint add_one(non_wrapping_uint a) {
+ return a + 1; // Overflow is checked for this operation.
+ }
+
+ int mul_alot(int n) {
+ int __attribute__((overflow_behavior(wrap))) a = n;
+ return a * 1337; // Overflow is not checked and is well-defined.
+ }
+
+The keyword spellings ``__ob_wrap`` and ``__ob_trap`` are equivalent to
+``overflow_behavior(wrap)`` and ``overflow_behavior(trap)`` respectively.
+
+The attribute wholly overrides global flags (``-ftrapv``, ``-fwrapv``,
+sanitizers, and Sanitizer Special Case Lists) for the attributed type. It can
+only be applied to integer types.
+
+This feature is experimental and must be enabled with the ``-cc1`` option
+``-fexperimental-overflow-behavior-types``. For full details on promotion and
+conversion rules, pointer semantics, diagnostics, and interaction with
+sanitizers, see :doc:`OverflowBehaviorTypes`.
+ }];
+}
+
def MSStructDocs : Documentation {
let Category = DocCatDecl;
let Content = [{
diff --git a/clang/test/AST/undocumented-attrs.cpp b/clang/test/AST/undocumented-attrs.cpp
index c7a2c74631ea2..eeebd7f938644 100644
--- a/clang/test/AST/undocumented-attrs.cpp
+++ b/clang/test/AST/undocumented-attrs.cpp
@@ -69,7 +69,6 @@ CHECK-NEXT: ObjCPreciseLifetime
CHECK-NEXT: ObjCRequiresPropertyDefs
CHECK-NEXT: ObjCReturnsInnerPointer
CHECK-NEXT: ObjCRootClass
-CHECK-NEXT: OverflowBehavior
CHECK-NEXT: Packed
CHECK-NEXT: Pascal
CHECK-NEXT: PointerFieldProtection
@@ -91,4 +90,4 @@ CHECK-NEXT: Visibility
CHECK-NEXT: WeakImport
CHECK-NEXT: WeakRef
CHECK-NEXT: WorkGroupSizeHint
-CHECK-NEXT: Total: 85
+CHECK-NEXT: Total: 84
More information about the cfe-commits
mailing list