Apply function attributes (e.g., [[gnu::access()]]) to pointees too
Alejandro Colomar
alx@kernel.org
Thu Jul 11 09:35:46 GMT 2024
Hi,
I was wondering how we could extend attributes such as gnu::access() to
apply it to pointees too. Currently, there's no way to specify the
access mode of a pointee.
Let's take for example strsep(3):
With current syntax, this is what we can specify:
[[gnu::access(read_write, 1)]]
[[gnu::access(read_only, 2)]]
[[gnu::nonnull(1, 2)]]
[[gnu::null_terminated_string_arg(2)]]
char *
strsep(char **restrict sp, const char *delim);
I was thinking that with floating numbers, one could specify the number
of dereferences with a number after the decimal point. It's a bit
weird, since the floating point is interpreted as two separate integer
numbers separated by a '.', but could work. In this case:
[[gnu::access(read_write, 1)]]
[[gnu::access(read_write, 1.1)]]
[[gnu::access(read_only, 2)]]
[[gnu::nonnull(1, 2)]]
[[gnu::null_terminated_string_arg(1.1)]]
[[gnu::null_terminated_string_arg(2)]]
char *
strsep(char **restrict sp, const char *delim);
Which would mark the pointer *sp as read_write and a string. What do
you think about it?
Cheers,
Alex
--
<https://www.alejandro-colomar.es/>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc/attachments/20240711/24d18c29/attachment.sig>
More information about the Gcc
mailing list