This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] Fix a segfault in reload
- To: gcc-patches at gcc dot gnu dot org
- Subject: [PATCH] Fix a segfault in reload
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Mon, 9 Oct 2000 16:38:54 +0200
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
Hi!
Attached testcase causes cc1 segfault on i386 (both in RH7 gcc and today's
CVS).
The issue is that calculate_needs_all_insns deletes a noop set insn
(set (reg:DF 272) (reg:DF 272))
(well, turns it into NOTE_INSN_DELETED), but later on caller-save.c's
save_call_clobbered_regs() it calls insert_restore and segfaults because it calls
note_stores on the note.
Below is one attempt to fix this (by removing the deleted insn from
reload_insn_chain - passed i386 bootstrap and regression tests), the other
options I see are checking for NOTEs in caller-save.c and continue instead
of doing anything or kill the optimization in calculate_needs_all_insns
altogether.
2000-10-09 Jakub Jelinek <jakub@redhat.com>
* reload1.c (calculate_needs_all_insns): If deleting an instruction,
remove its insn_chain structure as well.
* gcc.dg/20001009-1.c: New test.
--- gcc/reload1.c.jj Thu Sep 28 10:33:03 2000
+++ gcc/reload1.c Mon Oct 9 13:14:51 2000
@@ -1330,15 +1330,17 @@ calculate_needs_all_insns (global)
int global;
{
struct insn_chain **pprev_reload = &insns_need_reload;
- struct insn_chain *chain;
+ struct insn_chain *chain, *next = 0;
something_needs_elimination = 0;
reload_insn_firstobj = (char *) obstack_alloc (&reload_obstack, 0);
- for (chain = reload_insn_chain; chain != 0; chain = chain->next)
+ for (chain = reload_insn_chain; chain != 0; chain = next)
{
rtx insn = chain->insn;
+ next = chain->next;
+
/* Clear out the shortcuts. */
chain->n_reloads = 0;
chain->need_elim = 0;
@@ -1394,6 +1396,15 @@ calculate_needs_all_insns (global)
PUT_CODE (insn, NOTE);
NOTE_SOURCE_FILE (insn) = 0;
NOTE_LINE_NUMBER (insn) = NOTE_INSN_DELETED;
+ /* Delete it from the reload chain */
+ if (chain->prev)
+ chain->prev->next = next;
+ else
+ reload_insn_chain = next;
+ if (next)
+ next->prev = chain->prev;
+ chain->next = unused_insn_chains;
+ unused_insn_chains = chain;
continue;
}
}
--- gcc/testsuite/gcc.dg/20001009-1.c.jj Mon Oct 9 13:16:02 2000
+++ gcc/testsuite/gcc.dg/20001009-1.c Mon Oct 9 13:17:22 2000
@@ -0,0 +1,47 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fpic" } */
+
+extern void foo (void *a, double x, double y);
+void
+bar (void *a, double b, double c, double d, double e, double f, double g, double h, double i, double j, double k[6])
+{
+ double l, m, n, o, p;
+ double q, r, s, t, u;
+ double x, y, v, w;
+ double z = 0.5 * j;
+ double aa;
+ l = b - 3 * d;
+ m = 4 * f;
+ n = f - h;
+ q = c + 3 * g - i;
+ r = 2 * (e - 2 * g + i);
+ s = g - i;
+ if (l != 0.0)
+ {
+ aa = 0.0;
+ o = (- m + aa);
+ p = (- m - aa);
+ if (o > 0.0)
+ {
+ x = ((b-h)*o + 3*(d+h)*o + 3*(f-h)*o);
+ y = ((c-i)*o + 3*(e+i)*o + 3*(g-i)*o);
+ foo (a, z, w);
+ foo (a, -z, w);
+ }
+ if (p > 0.0)
+ {
+ x = ((b+3*f-h)*p + 3*(d-2*f+h)*p + 3*p);
+ y = ((c+3*g-i)*p + 3*(e-2*g+i)*p + 3*p);
+ v = x * k[0] + y * k[2];
+ w = x * k[1] + y * k[3];
+ foo (a, z, w);
+ foo (a, - z, w);
+ }
+ }
+ if (q != 0.0)
+ {
+ aa = 0.0;
+ t = (- r + aa) / (2 * q);
+ u = (- r - aa) / (2 * q);
+ }
+}
Jakub