https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79269

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-01-29
                 CC|                            |msebor at gcc dot gnu.org
     Ever confirmed|0                           |1
           Severity|normal                      |enhancement

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
__builtin_object_size() returns the size of an object with a flexible array
member but it doesn't evaluate to a constant expression.  I don't see why it
couldn't evaluate to one in the simple cases so I'll confirm this as an
enhancement request.

In your second example, though, I doubt it will be feasible to extend the
builtin so as to let it obtain the size of an incomplete object.  I.e., the
object's initializer will need to have been fully evaluated before the object's
size can be computed, just like it isn't possible to use sizeof to compute the
size of an array with an unspecified bound in its initialized:

  char a[] = { sizeof a, 2, 3, 4 };

$ cat c.c && gcc -S -Wall -fdump-tree-optimized=/dev/stdout c.c
struct {
    char a;
    char b[];
} test = { 10, { 0, 1, 2, 3 } };

unsigned size (void)
{
  return __builtin_object_size (&test, 0);
}


;; Function size (size, funcdef_no=0, decl_uid=1799, cgraph_uid=0,
symbol_order=1)

size ()
{
  unsigned int D.1802;
  unsigned int _1;

  <bb 2> [0.00%]:
  _1 = 5;

<L0> [0.00%]:
  return _1;

}

Reply via email to