https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016

--- Comment #62 from Alejandro Colomar <alx at kernel dot org> ---
(In reply to qinzhao from comment #61)
> (In reply to qinzhao from comment #60)
> > I came up with the following draft for the documentation of the new
> > __builtin_get_counted_by, let me know your comments and suggestions:
> 
> After discussing with Bill on the Clang side, I confirmed that Clang does
> not have the same builtin __builtin_has_attributes as in GCC. So, in order
> to keep the user interface consistent between these two compilers. the new
> __builtin_get_counted_by is defined as following:
> 
> Builtin-in Function: type __builtin_get_counted_by (ptr) 
> 
> The built-in function __builtin_get_counted_by checks whether the array
> object pointed by the pointer PTR has another object associated with it that
> represents the number of elements in the array object through counted_by
> attribute (i.e, the counted-by object). If so, returns a pointer to the
> corresponding counted-by object. If such counted-by object does not exist,
> return a NULL pointer.

What's the value of returning NULL instead of just failing the compilation with
an error?

I expect it will be easier to write safe code if it's impossible to misuse this
API, by having a hard compiler error if it's misused.  Just like ARRAY_SIZE()
(and a future __lengthof__) breaks compilation if you use it on a non-array.

Reply via email to