On 2023-08-01 17:35, Qing Zhao wrote:
typedef struct
{
   int a;
} A;
size_t f()
{
   A *p = malloc (1);
   return __builtin_object_size (p, 0);

Correction, that should be __builtin_object_size (p->a, 0).

Actually, it should be __builtin_object_size(p->a, 1).
For __builtin_object_size(p->a,0), gcc always uses the allocation size for the 
whole object.

Right, sorry, I mistyped, twice in fact; it should have been __bos(&p->a, 1) :)


GCC’s current behavior is:

For the size of the whole object, GCC currently always uses the allocation size.
And for the size in the sub-object, GCC chose the smaller one among the 
allocation size and the TYPE_SIZE.

Is this correct behavior?

Yes, it's deliberate; it specifically checks on var != pt_var, which can only be true for subobjects.

Thanks,
Sid

Reply via email to