This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix for infinite loop on x86_64 (PR 18300)
- From: Zak Kipling <zak at transversal dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 10 Nov 2004 12:26:08 +0000
- Subject: Fix for infinite loop on x86_64 (PR 18300)
- Organization: Transveresal Corporation Limited
DESCRIPTION
This patch (against current CVS HEAD) fixes the infinite loop bug
described in PR 18300 (http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18300).
Briefly, this causes the compiler to go into an infinite loop when an
object with > 3 base classes is passes as an argument by value in C++ on
the x86_64 architecture. It is caused by the re-use of a loop index
variable without a shadowing declaration in the classify_argument
function in gcc/config/i386/i386.c
It's a tiny patch, so I'm assuming copyright assignment papers won't be
needed.
Note that there are now *three* declarations of i in nested blocks. The
variables should probably be given distinct names instead to avoid any
further confusion.
CHANGELOG
Fixes PR target/18300: Infinite loop when passing object with 3+ base
classes by value.
TESTING
The patch also includes a new testcase,
gcc/testsuite/g++.dg/other/infloop-1.C. I have tested the patch on both
i686-pc-linux-gnu and x86_64-pc-linux-gnu, and have observed no new
testsuite failures, save some seemingly-nondeterministic changes in the
number of iterations of the libmudflap.cth tests which failed. On both
architectures, the new test passes when the i386.c patch is applied; on
x86_64 it fails without the patch, correctly picking up the bug.
PATCH follows as attachment
Index: gcc/config/i386/i386.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/config/i386/i386.c,v
retrieving revision 1.735
diff -u -4 -r1.735 i386.c
--- gcc/config/i386/i386.c 12 Oct 2004 17:14:42 -0000 1.735
+++ gcc/config/i386/i386.c 9 Nov 2004 16:53:47 -0000
@@ -2121,9 +2121,9 @@
for (binfo = TYPE_BINFO (type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
- int num;
+ int num, i;
int offset = tree_low_cst (BINFO_OFFSET (base_binfo), 0) * 8;
tree type = BINFO_TYPE (base_binfo);
num = classify_argument (TYPE_MODE (type),
@@ -2208,9 +2208,9 @@
for (binfo = TYPE_BINFO (type), i = 0;
BINFO_BASE_ITERATE (binfo, i, base_binfo); i++)
{
- int num;
+ int num, i;
int offset = tree_low_cst (BINFO_OFFSET (base_binfo), 0) * 8;
tree type = BINFO_TYPE (base_binfo);
num = classify_argument (TYPE_MODE (type),
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ gcc/testsuite/g++.dg/other/infloop-1.C 2004-11-08 15:43:59.000000000 +0000
@@ -0,0 +1,16 @@
+// PR 18300: This sends old compilers into an infinite loop on x86_64
+// Testcase and patch contributed by Zak Kipling <zak@transversal.com>
+
+struct base1 { };
+struct base2 { };
+struct base3 { };
+
+struct derived : base1, base2, base3 { };
+
+void foo(derived);
+
+int main()
+{
+ foo(derived());
+}
+