On 1/29/19 11:23 AM, Jakub Jelinek wrote:
--- gcc/gimple-fold.c   (revision 268086)
+++ gcc/gimple-fold.c   (working copy)
@@ -6715,12 +6715,14 @@ fold_array_ctor_reference (tree type, tree ctor,
    elt_size = wi::to_offset (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (ctor))));
/* When TYPE is non-null, verify that it specifies a constant-sized
-     accessed not larger than size of array element.  */
-  if (type
-      && (!TYPE_SIZE_UNIT (type)
-         || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
-         || elt_size < wi::to_offset (TYPE_SIZE_UNIT (type))
-         || elt_size == 0))
+     accessed not larger than size of array element.  Avoid using zero
+     ELT_SIZE, the result of an empty initializer for a zero-length
+     array.  */

The comment is misleading, there are many reasons why you could have
zero elt_size, C struct S {}, or int x[10][0], etc.  Just don't change
anything in the comment at all, or say
Punt if element size is zero to avoid division by zero.
or something similar.

Thanks.  The goal of the comment is to give an example of the unusual
case when the size of an array element may be zero, not suggest there
is just one such case, or enumerate all all of them.  I've adjusted
the text and added tests for the empty zero struct.


+  if (elt_size == 0
+      || (type
+         && (!TYPE_SIZE_UNIT (type)
+             || TREE_CODE (TYPE_SIZE_UNIT (type)) != INTEGER_CST
+             || elt_size < wi::to_offset (TYPE_SIZE_UNIT (type)))))
      return NULL_TREE;

Otherwise LGTM.

If you could fix also the two comments a few lines above this:
   /* Static constructors for variably sized objects makes no sense.  */
to
   /* Static constructors for variably sized objects make no sense.  */
it would be appreciated.

Sure, I don't mind doing that.

Committed in r268378.

Martin

Reply via email to