int fs_exec(int ino) { void *src = 0; if (ino) src = (void*)0xe000; goto *src; } Reduced from http://gcc.gnu.org/ml/gcc-bugs/2007-02/msg02973.html.
Confirmed, a regression from 4.0.x.
A regression hunt on powerpc-linux using the submitter's test case identified this patch: http://gcc.gnu.org/viewcvs?view=rev&rev=96084 r96084 | law | 2005-03-08 03:39:19 +0000 (Tue, 08 Mar 2005)
Subject: Re: [4.1/4.2/4.3 Regression] ICE with computed goto and constants On Mon, 2007-03-12 at 19:45 +0000, janis at gcc dot gnu dot org wrote: > > ------- Comment #2 from janis at gcc dot gnu dot org 2007-03-12 19:45 ------- > A regression hunt on powerpc-linux using the submitter's test case identified > this patch: > > http://gcc.gnu.org/viewcvs?view=rev&rev=96084 > > r96084 | law | 2005-03-08 03:39:19 +0000 (Tue, 08 Mar 2005) Thanks for alerting me to this problem. I think the right fix is going to simply be to enforce a rule that we can only optimize a computed goto if the argument collapses down to a local LABEL_REF rather than a generic invariant. In the case where we have a constant or non-local LABEL_REF, the CFG (before optimizing) ought to be conservatively correct(*). Optimizing is impossible because we don't know which outgoing edge to keep and which ones to throw away. This ought to be a 1-2 line fix. Jeff (*) If the argument referred to a constant address in the current function which does not correspond to any known addressable LABEL_REF then we're hosed as the original unoptimized CFG is probably bogus.
This little patch below seems to get around the problem, though I'm not really sure this is sufficient or not. Index: tree-cfg.c =================================================================== --- tree-cfg.c (revision 122871) +++ tree-cfg.c (working copy) @@ -2039,7 +2039,9 @@ find_taken_edge (basic_block bb, tree va return find_taken_edge_switch_expr (bb, val); if (computed_goto_p (stmt)) - return find_taken_edge_computed_goto (bb, TREE_OPERAND( val, 0)); + return (TREE_CODE (val) == LABEL_EXPR) + ? find_taken_edge_computed_goto (bb, TREE_OPERAND(val, 0)) + : NULL; gcc_unreachable (); } @@ -2054,6 +2056,8 @@ find_taken_edge_computed_goto (basic_blo basic_block dest; edge e = NULL; + gcc_assert (TREE_CODE (val) == LABEL_EXPR); + dest = label_to_block (val); if (dest) {
Subject: Re: [4.1/4.2/4.3 Regression] ICE with computed goto and constants On Mon, 2007-03-12 at 23:46 +0000, spark at gcc dot gnu dot org wrote: > > ------- Comment #4 from spark at gcc dot gnu dot org 2007-03-12 23:46 ------- > This little patch below seems to get around the problem, > though I'm not really sure this is sufficient or not. It's functionally equivalent to what I'm running through the standard test procedures right now. jeff
Subject: Re: [4.1/4.2/4.3 Regression] ICE with computed goto and constants On Mon, 2007-03-12 at 23:46 +0000, spark at gcc dot gnu dot org wrote: > > ------- Comment #4 from spark at gcc dot gnu dot org 2007-03-12 23:46 ------- > This little patch below seems to get around the problem, > though I'm not really sure this is sufficient or not. FWIW, ADDR_EXPR needs to be handled as well. Otherwise you'll get testsuite regressions. New test cycle running now :-) jeff
Fixed with today's patch to tree-cfg.c.
Subject: Bug 30984 Author: law Date: Mon Mar 19 19:52:19 2007 New Revision: 123067 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123067 Log: * tree-cfg.c (find_taken_edge): Tighten conditions for optimizing computed gotos. * PR tree-optimization/30984 * gcc.c-torture/pr30984.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/compile/pr30984.c Modified: trunk/gcc/ChangeLog trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-cfg.c
Subject: Bug 30984 Author: law Date: Mon Mar 19 20:03:07 2007 New Revision: 123068 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123068 Log: 2007-03-19 Jeff Law <law@redhat.com> * tree-cfg.c (find_taken_edge): Tighten conditions for optimizing computed gotos. 2007-03-19 Jeff Law <law@redhat.com> * PR tree-optimization/30984 * gcc.c-torture/pr30984.c: New test. Added: branches/gcc-4_1-branch/gcc/testsuite/gcc.c-torture/compile/pr30984.c Modified: branches/gcc-4_1-branch/gcc/ChangeLog branches/gcc-4_1-branch/gcc/testsuite/ChangeLog branches/gcc-4_1-branch/gcc/tree-cfg.c
Fix committed to mainline, gcc-4.1 and gcc-4.2 branches
Subject: Bug 30984 Author: law Date: Mon Mar 19 20:04:04 2007 New Revision: 123069 URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=123069 Log: 2007-03-19 Jeff Law <law@redhat.com> * tree-cfg.c (find_taken_edge): Tighten conditions for optimizing computed gotos. 2007-03-19 Jeff Law <law@redhat.com> * PR tree-optimization/30984 * gcc.c-torture/pr30984.c: New test. Added: branches/gcc-4_2-branch/gcc/testsuite/gcc.c-torture/compile/pr30984.c Modified: branches/gcc-4_2-branch/gcc/ChangeLog branches/gcc-4_2-branch/gcc/testsuite/ChangeLog branches/gcc-4_2-branch/gcc/tree-cfg.c