[clang] [Bounds-Safety] Add sized_by, counted_by_or_null & sized_by_or_null (PR #93231)

Dan Liew via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 8 09:15:34 PDT 2024


================
@@ -425,6 +425,12 @@ Attribute Changes in Clang
        size_t count;
      };
 
+- The attributes ``sized_by``, ``counted_by_or_null`` and ``sized_by_or_null```
+  have been added as variants on ``counted_by``, each with slightly different semantics.
+  ``sized_by`` takes a byte size parameter instead of an element count, allowing pointees
+  with unknown size. The ``counted_by_or_null`` and ``sized_by_or_null`` variants are equivalent
+  to their base variants, except the pointer can be null regardless of count/size value.
----------------
delcypher wrote:

Nit: Maybe it's worth calling out (because it's really not obvious) that the only valid count for `__sized_by` when the pointer is `NULL` is `0`, `__sized_by_or_null` allows **any** count value when the pointer is `NULL`. We could also note that this isn't currently enforced.

https://github.com/llvm/llvm-project/pull/93231


More information about the cfe-commits mailing list