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]

[PATCH] Fix infinite recursion in variably_modified_type_p


Hi,

The attached minimal Ada testcase triggers an infinite recursion in 
variably_modified_type_p because there is a POINTER_TYPE pointing to an 
ARRAY_TYPE whose element type is the aforementioned POINTER_TYPE.  This is a 
regression from the 3.x series, although variably_modified_type_p has not 
been modified(!) since then; it was simply not called on the POINTER_TYPE in 
this case with the 3.x series.

The proposed fix is to break the circularity in the ARRAY_TYPE case by looking 
"manually" at the element type instead of recursing, much like what is done 
for RECORD_TYPE and UNION_TYPE.

Bootstrapped/regtested on i586-suse-linux.  OK for mainline?


2006-05-15  Eric Botcazou  <ebotcazou@adacore.com>

	* tree.c (variably_modified_type_p) <ARRAY_TYPE>: Return true
	if the element type is variably modified without recursing.


-- 
Eric Botcazou
Index: tree.c
===================================================================
--- tree.c	(revision 113755)
+++ tree.c	(working copy)
@@ -5635,13 +5635,12 @@ variably_modified_type_p (tree type, tre
      When a representation is chosen, this function should be modified
      to test for that case as well.  */
   RETURN_TRUE_IF_VAR (TYPE_SIZE (type));
-  RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT(type));
+  RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (type));
 
   switch (TREE_CODE (type))
     {
     case POINTER_TYPE:
     case REFERENCE_TYPE:
-    case ARRAY_TYPE:
     case VECTOR_TYPE:
       if (variably_modified_type_p (TREE_TYPE (type), fn))
 	return true;
@@ -5690,6 +5689,13 @@ variably_modified_type_p (tree type, tre
 	  }
 	break;
 
+    case ARRAY_TYPE:
+      /* Do not call ourselves to avoid infinite recursion.  This is
+	 variably modified if the element type is.  */
+      RETURN_TRUE_IF_VAR (TYPE_SIZE (TREE_TYPE (type)));
+      RETURN_TRUE_IF_VAR (TYPE_SIZE_UNIT (TREE_TYPE (type)));
+      break;
+
     default:
       break;
     }
procedure P is

   type Node;
   type Node_Ptr is access Node;
   type Node is array (1..10) of Node_Ptr;

   procedure Process (N : Node_Ptr) is
   begin
      null;
   end;

begin
   null;
end;

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