Blame SOURCES/gcc32-pr18300.patch

4ac4fd
2005-09-07  Jakub Jelinek  <jakub@redhat.com>
4ac4fd
4ac4fd
	PR target/18300
4ac4fd
	* config/i386/i386.c (classify_argument): Only use different
4ac4fd
	iterators for nested loops if nested loops sharing the same
4ac4fd
	iterator would hang.
4ac4fd
4ac4fd
2004-11-13  Zak Kipling  <zak@transversal.com>
4ac4fd
4ac4fd
	PR target/18300
4ac4fd
	* config/i386/i386.c (classify_argument): Fix infinite loop when
4ac4fd
	passing object with 3 or more base classes by value.
4ac4fd
4ac4fd
--- gcc/config/i386/i386.c.jj	2005-07-21 11:01:36.000000000 +0200
4ac4fd
+++ gcc/config/i386/i386.c	2005-09-07 14:22:19.000000000 +0200
4ac4fd
@@ -1784,8 +1784,17 @@ classify_argument (mode, type, classes, 
4ac4fd
 	    {
4ac4fd
 	      tree bases = TYPE_BINFO_BASETYPES (type);
4ac4fd
 	      int n_bases = TREE_VEC_LENGTH (bases);
4ac4fd
-	      int i;
4ac4fd
-
4ac4fd
+	      int i, basenum;
4ac4fd
+	      enum x86_64_reg_class saveclasses[MAX_CLASSES];
4ac4fd
+	      bool seen[MAX_CLASSES];
4ac4fd
+
4ac4fd
+	      /* PR target/18300: The following code mistakenly uses the same
4ac4fd
+		 iterator variable in both nested for loops.  But to preserve
4ac4fd
+		 binary compatibility, do whatever this code used to do before
4ac4fd
+		 unless old GCC would hang in an infinite loop.  In that case
4ac4fd
+		 use whatever GCC 4.0+ does.  */
4ac4fd
+	      memset (seen, 0, sizeof (seen));
4ac4fd
+	      memcpy (saveclasses, classes, sizeof (saveclasses));
4ac4fd
 	      for (i = 0; i < n_bases; ++i)
4ac4fd
 		{
4ac4fd
 		   tree binfo = TREE_VEC_ELT (bases, i);
4ac4fd
@@ -1793,6 +1802,12 @@ classify_argument (mode, type, classes, 
4ac4fd
 		   int offset = tree_low_cst (BINFO_OFFSET (binfo), 0) * 8;
4ac4fd
 		   tree type = BINFO_TYPE (binfo);
4ac4fd
 
4ac4fd
+		   if (i < MAX_CLASSES)
4ac4fd
+		     {
4ac4fd
+		       if (seen[i])
4ac4fd
+			 break;
4ac4fd
+		       seen[i] = true;
4ac4fd
+		     }
4ac4fd
 		   num = classify_argument (TYPE_MODE (type),
4ac4fd
 					    type, subclasses,
4ac4fd
 					    (offset + bit_offset) % 256);
4ac4fd
@@ -1805,6 +1820,32 @@ classify_argument (mode, type, classes, 
4ac4fd
 			 merge_classes (subclasses[i], classes[i + pos]);
4ac4fd
 		     }
4ac4fd
 		}
4ac4fd
+	      if (i < n_bases)
4ac4fd
+		{
4ac4fd
+		  /* Older GCC 3.[0-4].x would hang in the above loop, so
4ac4fd
+		     don't worry about backwards compatibility and
4ac4fd
+		     just DTRT.  */
4ac4fd
+		  memcpy (classes, saveclasses, sizeof (saveclasses));
4ac4fd
+		  for (basenum = 0; basenum < n_bases; ++basenum)
4ac4fd
+		    {
4ac4fd
+		      tree binfo = TREE_VEC_ELT (bases, basenum);
4ac4fd
+		      int num;
4ac4fd
+		      int offset = tree_low_cst (BINFO_OFFSET (binfo), 0) * 8;
4ac4fd
+		      tree type = BINFO_TYPE (binfo);
4ac4fd
+
4ac4fd
+		      num = classify_argument (TYPE_MODE (type),
4ac4fd
+					       type, subclasses,
4ac4fd
+					       (offset + bit_offset) % 256);
4ac4fd
+		      if (!num)
4ac4fd
+			return 0;
4ac4fd
+		      for (i = 0; i < num; i++)
4ac4fd
+			{
4ac4fd
+			  int pos = (offset + (bit_offset % 64)) / 8 / 8;
4ac4fd
+			  classes[i + pos] =
4ac4fd
+			    merge_classes (subclasses[i], classes[i + pos]);
4ac4fd
+			}
4ac4fd
+		    }
4ac4fd
+		}
4ac4fd
 	    }
4ac4fd
 	  /* And now merge the fields of structure.   */
4ac4fd
 	  for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4ac4fd
@@ -1872,8 +1913,17 @@ classify_argument (mode, type, classes, 
4ac4fd
 	    {
4ac4fd
 	      tree bases = TYPE_BINFO_BASETYPES (type);
4ac4fd
 	      int n_bases = TREE_VEC_LENGTH (bases);
4ac4fd
-	      int i;
4ac4fd
-
4ac4fd
+	      int i, basenum;
4ac4fd
+	      enum x86_64_reg_class saveclasses[MAX_CLASSES];
4ac4fd
+	      bool seen[MAX_CLASSES];
4ac4fd
+
4ac4fd
+	      /* PR target/18300: The following code mistakenly uses the same
4ac4fd
+		 iterator variable in both nested for loops.  But to preserve
4ac4fd
+		 binary compatibility, do whatever this code used to do before
4ac4fd
+		 unless old GCC would hang in an infinite loop.  In that case
4ac4fd
+		 use whatever GCC 4.0+ does.  */
4ac4fd
+	      memset (seen, 0, sizeof (seen));
4ac4fd
+	      memcpy (saveclasses, classes, sizeof (saveclasses));
4ac4fd
 	      for (i = 0; i < n_bases; ++i)
4ac4fd
 		{
4ac4fd
 		   tree binfo = TREE_VEC_ELT (bases, i);
4ac4fd
@@ -1881,6 +1931,12 @@ classify_argument (mode, type, classes, 
4ac4fd
 		   int offset = tree_low_cst (BINFO_OFFSET (binfo), 0) * 8;
4ac4fd
 		   tree type = BINFO_TYPE (binfo);
4ac4fd
 
4ac4fd
+		   if (i < MAX_CLASSES)
4ac4fd
+		     {
4ac4fd
+		       if (seen[i])
4ac4fd
+			 break;
4ac4fd
+		       seen[i] = true;
4ac4fd
+		     }
4ac4fd
 		   num = classify_argument (TYPE_MODE (type),
4ac4fd
 					    type, subclasses,
4ac4fd
 					    (offset + (bit_offset % 64)) % 256);
4ac4fd
@@ -1893,6 +1949,32 @@ classify_argument (mode, type, classes, 
4ac4fd
 			 merge_classes (subclasses[i], classes[i + pos]);
4ac4fd
 		     }
4ac4fd
 		}
4ac4fd
+	      if (i < n_bases)
4ac4fd
+		{
4ac4fd
+		  /* Older GCC 3.[0-4].x would hang in the above loop, so
4ac4fd
+		     don't worry about backwards compatibility and
4ac4fd
+		     just DTRT.  */
4ac4fd
+		  memcpy (classes, saveclasses, sizeof (saveclasses));
4ac4fd
+		  for (basenum = 0; basenum < n_bases; ++basenum)
4ac4fd
+		    {
4ac4fd
+		      tree binfo = TREE_VEC_ELT (bases, basenum);
4ac4fd
+		      int num;
4ac4fd
+		      int offset = tree_low_cst (BINFO_OFFSET (binfo), 0) * 8;
4ac4fd
+		      tree type = BINFO_TYPE (binfo);
4ac4fd
+
4ac4fd
+		      num = classify_argument (TYPE_MODE (type),
4ac4fd
+					       type, subclasses,
4ac4fd
+					       (offset + (bit_offset % 64)) % 256);
4ac4fd
+		      if (!num)
4ac4fd
+			return 0;
4ac4fd
+		      for (i = 0; i < num; i++)
4ac4fd
+			{
4ac4fd
+			  int pos = (offset + (bit_offset % 64)) / 8 / 8;
4ac4fd
+			  classes[i + pos] =
4ac4fd
+			    merge_classes (subclasses[i], classes[i + pos]);
4ac4fd
+			}
4ac4fd
+		    }
4ac4fd
+		}
4ac4fd
 	    }
4ac4fd
 	  for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
4ac4fd
 	    {
4ac4fd
--- gcc/testsuite/g++.dg/other/infloop-1.C 1 Jan 1970 00:00:00 -0000
4ac4fd
+++ gcc/testsuite/g++.dg/other/infloop-1.C	13 Nov 2004 23:09:08 -0000	1.1
4ac4fd
@@ -0,0 +1,16 @@
4ac4fd
+// PR 18300: This sends old compilers into an infinite loop on x86_64
4ac4fd
+// Testcase and patch contributed by Zak Kipling <zak@transversal.com>
4ac4fd
+
4ac4fd
+struct base1 { };
4ac4fd
+struct base2 { };
4ac4fd
+struct base3 { };
4ac4fd
+
4ac4fd
+struct derived : base1, base2, base3 { };
4ac4fd
+
4ac4fd
+void foo(derived);
4ac4fd
+
4ac4fd
+int main()
4ac4fd
+{
4ac4fd
+  foo(derived());
4ac4fd
+}
4ac4fd
+