re PR objc/25348 (ICE encoding zero sized struct array)
authorAndrew Pinski <pinskia@physics.uc.edu>
Mon, 12 Dec 2005 23:58:16 +0000 (23:58 +0000)
committerAndrew Pinski <pinskia@gcc.gnu.org>
Mon, 12 Dec 2005 23:58:16 +0000 (15:58 -0800)
2005-12-12  Andrew Pinski  <pinskia@physics.uc.edu>

        PR objc/25348
        * objc-act.c (encode_array): Handle arrays to zero sized types.
2005-12-12  Andrew Pinski  <pinskia@physics.uc.edu>

        PR objc/25348
        * objc.dg/encode-9.m: New test.

From-SVN: r108432

gcc/objc/ChangeLog
gcc/objc/objc-act.c
gcc/testsuite/ChangeLog
gcc/testsuite/objc.dg/encode-9.m [new file with mode: 0644]

index f2a6fd692acbedd2e8f0f5b082871e5b8b1e45ee..5f7951f82db4bd98c19e648fe9733a4348c751d7 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-12  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR objc/25348
+       * objc-act.c (encode_array): Handle arrays to zero sized types.
+
 2005-12-07  Rafael Ávila de Espíndola  <rafael.espindola@gmail.com>
 
        * Make-lang.in (objc.all.build, objc.install-normal): Remove.
index 817553a1eed3716b1a29c6eb35f3465a012258ad..201a722c2321376129845bafd3b9b2ecad345174 100644 (file)
@@ -7920,9 +7920,12 @@ encode_array (tree type, int curtype, int format)
       return;
     }
 
-  sprintf (buffer, "[" HOST_WIDE_INT_PRINT_DEC,
-                  (TREE_INT_CST_LOW (an_int_cst)
-                   / TREE_INT_CST_LOW (TYPE_SIZE (array_of))));
+  if (TREE_INT_CST_LOW (TYPE_SIZE (array_of)) == 0)
+   sprintf (buffer, "[" HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)0);
+  else 
+    sprintf (buffer, "[" HOST_WIDE_INT_PRINT_DEC,
+            TREE_INT_CST_LOW (an_int_cst)
+             / TREE_INT_CST_LOW (TYPE_SIZE (array_of)));
 
   obstack_grow (&util_obstack, buffer, strlen (buffer));
   encode_type (array_of, curtype, format);
index 208450acf88a55d6205787cae9140a7a0aa29e3a..8617accc364a4d82fc63a51b99a59a7e5a422028 100644 (file)
@@ -1,3 +1,8 @@
+2005-12-12  Andrew Pinski  <pinskia@physics.uc.edu>
+
+       PR objc/25348
+       * objc.dg/encode-9.m: New test.
+
 2005-12-12  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        PR testsuite/20772
diff --git a/gcc/testsuite/objc.dg/encode-9.m b/gcc/testsuite/objc.dg/encode-9.m
new file mode 100644 (file)
index 0000000..3b00575
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-runtime " } */
+
+/* There was an ICE due to diving by zero in the objc front-end. */
+
+struct f
+{
+  int i;
+  struct{} g[4];
+  int tt;
+};
+
+char *e = @encode(struct f);