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

--- Comment #1 from qinzhao at gcc dot gnu.org ---
with gcc -O1 -fdump-tree-all t.c, in a-t.c.112t.objsz1, we see the object size
is generated as _22:

  sizetype _26(D);

  _12 = &p_18->n;
  _23 = MEM <int> [(void *)_12];
  _24 = MAX_EXPR <_23, 0>;
  _25 = (sizetype) _24;
  _22 = _26(D) * _25;

In the above, _25 is the # of element of the array, which is loaded from
&p_18->n, the counted_by field of the structure,  _26 is the size of each
element, which is the size of A[m], is got as "element_size" in the following
code in gcc/tree-object-size.cc:

  /* The type of the 6th argument type is the pointer TYPE to the original
     flexible array type.  */
  tree pointer_to_array_type = TREE_TYPE (gimple_call_arg (call, 5));
  gcc_assert (POINTER_TYPE_P (pointer_to_array_type));
  tree element_type = TREE_TYPE (TREE_TYPE (pointer_to_array_type));
  tree element_size = TYPE_SIZE_UNIT (element_type);


we can cleanly see that _26 is an uninitialized variable, whose initialization
has been eliminated by the previous optimization already due to it's not used
in IL at all. 

>From a-t.c.007.gimple, the initialization to the "element_size" is still
available as:

  _7 = (sizetype) m.0;
  _8 = _7 * 4;
  D.4602 = _8;

the above is eliminated by dse1. 

So, it's not reliable to get the "element_size" from the TYPE_SIZE_UNIT of the
TYPE of the VLA type.

Reply via email to