diff options
author | Bill Wendling <morbo@google.com> | 2025-05-13 16:01:36 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-05-13 16:01:36 -0700 |
commit | 9ae3bce17543f92ce0237597cc66503d58cce317 (patch) | |
tree | 22967a72c40b010c52ab71af525830ca81760511 /clang/lib/AST/ByteCode/Compiler.cpp | |
parent | 4e604d46681f722b1def10ce72c89046dac39e63 (diff) | |
download | llvm-9ae3bce17543f92ce0237597cc66503d58cce317.zip llvm-9ae3bce17543f92ce0237597cc66503d58cce317.tar.gz llvm-9ae3bce17543f92ce0237597cc66503d58cce317.tar.bz2 |
[Clang][counted_by] Add support for 'counted_by' on struct pointers (#137250)
The 'counted_by' attribute is now available for pointers in structs.
It generates code for sanity checks as well as
__builtin_dynamic_object_size()
calculations. For example:
struct annotated_ptr {
int count;
char *buf __attribute__((counted_by(count)));
};
If the pointer's type is 'void *', use the 'sized_by' attribute, which
works similarly to 'counted_by', but can handle the 'void' base type:
struct annotated_ptr {
int count;
void *buf __attribute__((sized_by(count)));
};
If the 'count' field member occurs after the pointer, use the
'-fexperimental-late-parse-attributes' flag during compilation.
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 <morbo@google.com>
Diffstat (limited to 'clang/lib/AST/ByteCode/Compiler.cpp')
0 files changed, 0 insertions, 0 deletions