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]

[Committed] Fix PR objc/29195 ICE with array decaying to a pointer in a method


The problem here is that we change the type of the decl but we had
already layout'ed the decl so we get a mix match for some arrays.  This
patch fixes the problem by relaying out the decl after the type has
changed.

Committed as obvious after a bootstrap and test on i686-linux-gnu.

Thanks,
Andrew Pinski

objc/ChangeLog:
	* objc-act.c (objc_push_parm): If we change the type of the
	decl, relayout the decl.

testsuite/ChangeLog:
	* objc/compile/method-1.m: New test.
Index: objc/objc-act.c
===================================================================
--- objc/objc-act.c	(revision 117190)
+++ objc/objc-act.c	(working copy)
@@ -8223,11 +8223,22 @@ static GTY(()) tree objc_parmlist = NULL
 static void
 objc_push_parm (tree parm)
 {
+  bool relayout_needed = false;
   /* Decay arrays and functions into pointers.  */
   if (TREE_CODE (TREE_TYPE (parm)) == ARRAY_TYPE)
-    TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (TREE_TYPE (parm)));
+    {
+      TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (TREE_TYPE (parm)));
+      relayout_needed = true;
+    }
   else if (TREE_CODE (TREE_TYPE (parm)) == FUNCTION_TYPE)
-    TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (parm));
+    {
+      TREE_TYPE (parm) = build_pointer_type (TREE_TYPE (parm));
+      relayout_needed = true;
+    }
+
+  if (relayout_needed)
+    relayout_decl (parm);
+  
 
   DECL_ARG_TYPE (parm)
     = lang_hooks.types.type_promotes_to (TREE_TYPE (parm));
Index: testsuite/objc/compile/method-1.m
===================================================================
--- testsuite/objc/compile/method-1.m	(revision 0)
+++ testsuite/objc/compile/method-1.m	(revision 0)
@@ -0,0 +1,12 @@
+/* PR objc/29195 */
+/* Test that array decls are changed to a pointer type
+   correctly and make sure we don't crash because the
+   decl was not relayed out.   */
+
+@ implementation NGActiveSocket 
++ (void) socketPair:(int [2])
+     _pair 
+{
+  _pair[0] = 0;
+}
+@end

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