-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Open
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"
Description
Using __builtin_object_size
(and __builtin_dynamic_object_size
) on a composite structure's member that has a flexible array loses the sense of how large it is.
For example, on a struct that has a flexible array, __bdos
correctly says it doesn't know the size (bounded here by alloc_size
):
expect(__builtin_object_size(wrap->msg.nlmsg_content, 1), 4076);
expect(__builtin_object_size(wrap, 0), 4096);
expect(__builtin_object_size(wrap, 1), 4096);
But if it is part of a wrapper, it start behaving like sizeof()
:
expect(__builtin_object_size(wrap->msg.nlmsg_content, 1), 4076);
expect(__builtin_object_size(&wrap->msg, 0), 4092);
/* But suddenly gets it wrong? */
expect(__builtin_object_size(&wrap->msg, 1), 4092);
https://godbolt.org/z/YrGsh8Ybs
This was recently fixed in GCC:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101832
PoC:
composite.c.txt
Metadata
Metadata
Assignees
Labels
clang:frontendLanguage frontend issues, e.g. anything involving "Sema"Language frontend issues, e.g. anything involving "Sema"