This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [RFC] PR C++/24138


> > Is it ok to special case max_index being -1?
> 
> Definitely.
> 
> This problem appears in various places; we represent array bounds using
> a number of the same precision as the set of valid indices, so edge-case
> representations require a little special handling.  (Of course, that

Without further ado...

The reshape_init_array_1 bit is the actual fix.  However, it doesn't
work because integer_all_onesp() returns false for an integer_cst of -1
(type is long unsigned int).

This code is fairly old, but I don't see why we can't indiscriminately
return TRUE for all ones in integer_all_onesp()-- after all, that's its 
name ;-).

The patch doesn't address whether zero-sized arrays should work on
C++; it only addresses the ICE.  The logic further up takes care of 
complaining about more initializers than expected.

This patch fixes the PR and has been successfully tested on ppc-linux.

OK for mainline?

	PR C++/24138
	* tree.c (integer_all_onesp): Always return true if all bits on.

	* cp/decl.c (reshape_init_array_1): Handle max_index of -1.

	* testsuite/g++.dg/init/array0.C: New.

Index: tree.c
===================================================================
--- tree.c	(revision 106703)
+++ tree.c	(working copy)
@@ -1194,9 +1194,11 @@ integer_all_onesp (tree expr)
     return 0;
 
   uns = TYPE_UNSIGNED (TREE_TYPE (expr));
+  if (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
+      && TREE_INT_CST_HIGH (expr) == -1)
+    return 1;
   if (!uns)
-    return (TREE_INT_CST_LOW (expr) == ~(unsigned HOST_WIDE_INT) 0
-	    && TREE_INT_CST_HIGH (expr) == -1);
+    return 0;
 
   /* Note that using TYPE_PRECISION here is wrong.  We care about the
      actual bits, not the (arbitrary) range of the type.  */
Index: cp/decl.c
===================================================================
--- cp/decl.c	(revision 106703)
+++ cp/decl.c	(working copy)
@@ -4183,6 +4183,10 @@ reshape_init_array_1 (tree elt_type, tre
 
   if (sized_array_p)
     {
+      /* Minus 1 is used for zero sized arrays.  */
+      if (integer_all_onesp (max_index))
+	return new_init;
+
       if (host_integerp (max_index, 1))
 	max_index_cst = tree_low_cst (max_index, 1);
       /* sizetype is sign extended, not zero extended.  */
Index: testsuite/g++.dg/init/array0.C
===================================================================
--- testsuite/g++.dg/init/array0.C	(revision 0)
+++ testsuite/g++.dg/init/array0.C	(revision 0)
@@ -0,0 +1,12 @@
+// { dg-do compile }
+// { dg-options "" }
+// PR C++/24138
+
+void foo()
+{
+  typedef struct {
+    unsigned char dir;
+    int data[0];
+  } yanito;
+  static const yanito horse = { 1,  { 2,  3 }  }; // { dg-error "too many" }
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]