bwendling wrote:

> So the idea here is that if the struct in question uses counted_by, you 
> automatically set the count... and if, for whatever reason, the compiler 
> can't find the corresponding field, you just throw away the count? That seems 
> like an terrifying API; it's impossible to predict what it will do with a 
> given bit of code.

I agree and it was mentioned in the [GCC bug 
thread](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116016). This builtin will 
have very limited utility (none?) outside of the Linux kernel and it's 
`kmalloc()` implementation. I would go so far as to place large warnings about 
its usage in the documentation, or omit documentation altogether.

> Maybe it makes sense to return null if you find the field, but it doesn't 
> have a counted_by attribute at all. But there should still be diagnostics for 
> all the other failure modes.

I agree, with one exception. We're planning on extending the `counted_by` 
attribute to support pointers in structures. So we'll have to remove the 
diagnostic in those situations when that support finally lands.

https://github.com/llvm/llvm-project/pull/102549
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to