[Bug middle-end/77301] __builtin_object_size incorrect for an array in a struct referenced by a pointer
msebor at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Aug 20 21:34:00 GMT 2016
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77301
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |wrong-code
Status|RESOLVED |REOPENED
Last reconfirmed| |2016-08-20
Resolution|INVALID |---
Ever confirmed|0 |1
--- Comment #3 from Martin Sebor <msebor at gcc dot gnu.org> ---
I've reduced the problem in comment #2 to the test case below. The built-in
returns a different result for the same member array depending on whether the
object of which the array is a member is referenced directly by its id or
indirectly, via a pointer, and whether the subscript operator is used to
reference an element of the array or some other form of indirection (the ->
operator or the * operator).
This may be related or even the same bug as PR77294 but I'm reopening this bug
in case it isn't, and also to update the documentation and clarify what you
explained in comment #1. There has been quite some confusion and uncertainty
about the expected return value for arrays (PR44384 and PR77293 are a couple of
examples) as well as about the meaning of the phrase "objects are whole
variables" and the term "closest surrounding subobject." Clarifying the manual
to explain what these mean should help set the right expectations.
$ cat z.c && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -O2
-Wall -Wextra z.c && ./a.out
struct S { char a [2]; };
struct S s [2];
int main (void)
{
__builtin_printf ("%zu %zu %zu\n",
__builtin_object_size (s->a, 1),
__builtin_object_size ((*s).a, 1),
__builtin_object_size (s [0].a, 1));
struct S *p = s;
__builtin_printf ("%zu %zu %zu\n",
__builtin_object_size (p->a, 1),
__builtin_object_size ((*p).a, 1),
__builtin_object_size (p [0].a, 1));
}
4 4 2
4 4 4
More information about the Gcc-bugs
mailing list