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