Skip to content

Commit 025166a

Browse files
committed
[Clang][counted_by] Add support for 'counted_by' on struct pointers
The 'counted_by' attribute is now available for structs. It generates code for sanity checks as well as __builtin_dynamic_object_size() calculations. For example: struct annotated_ptr { int count; void *buf __attribute__((counted_by(count))); }; The attribute can be applied to a 'void *'. In that case, use the 'sized_by' attribute instead: struct annotated_ptr { void *buf __attribute__((sized_by(count))); size_t count; }; The 'count' field member may occur after the pointer. If it does, use the '-fexperimental-late-parse-attributes' flag (which will hopefully be made the default in future Clang versions). Note that 'counted_by' cannot be applied to a pointer to an incomplete type, because the size isn't known. struct foo; struct annotated_ptr { int count; struct foo *buf __attribute__((counted_by(count))); /* invalid */ }; Signed-off-by: Bill Wendling <[email protected]>
1 parent 661f90a commit 025166a

File tree

4 files changed

+619
-105
lines changed

4 files changed

+619
-105
lines changed

0 commit comments

Comments
 (0)