Blame SOURCES/gcc32-pr18300.patch

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