[llvm] [clang] [Clang] Correct __builtin_dynamic_object_size for subobject types (PR #78526)

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 18 09:04:17 PST 2024


zygoloid wrote:

> When you say that we can't detect what the front-end considers the "closest surrounding subobject" to be, is that mostly due to corner cases or is it a more general concern?

It's a more general concern: LLVM simply has no idea what the frontend considers to be a subobject. The LLVM type doesn't carry that information.

> ```
> struct suspend_stats {
>         //...
>         char    failed_devs[REC_FAILED_NUM][40];
>         int     last_failed_errno;
>         int     bar;
> };
> //...
> ```
> 
> Without the change, the last line is:
> 
> ```
> __builtin_dynamic_object_size(foo.failed_devs[argc], 1): 48
> ```
> 
> Which isn't correct according to GNU's documentation. So if we can't honor the TYPE bit, then we should return `-1 / 0` here, right?

Perhaps according to the GCC documentation as written. But mode 0 and 1 are in general asking for an upper bound on the accessible bytes (that is, an N so any.access beyond N bytes is definitely out of bounds), so it seems to me that returning -1 is strictly worse than returning 48. Do you have a use case for which -1 is a better answer?

I suspect the only change we're missing here is a change to our documentation to explicitly say that we give an upper/lower bound when we can't compute an exact size.

https://github.com/llvm/llvm-project/pull/78526


More information about the cfe-commits mailing list