Bug 30984 - [4.1/4.2/4.3 Regression] ICE with computed goto and constants
Summary: [4.1/4.2/4.3 Regression] ICE with computed goto and constants
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.3.0
: P1 normal
Target Milestone: 4.1.3
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2007-02-27 19:07 UTC by Andrew Pinski
Modified: 2007-03-19 20:04 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 4.0.2
Known to fail: 4.1.2 4.2.0 4.3.0
Last reconfirmed: 2007-03-03 21:47:29


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrew Pinski 2007-02-27 19:07:40 UTC
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.
Comment 1 Andrew Pinski 2007-03-03 21:47:29 UTC
Confirmed, a regression from 4.0.x.
Comment 2 Janis Johnson 2007-03-12 19:45:31 UTC
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)
Comment 3 Jeffrey A. Law 2007-03-12 20:06:26 UTC
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.

Comment 4 Seongbae Park 2007-03-12 23:46:51 UTC
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)
     {
Comment 5 Jeffrey A. Law 2007-03-13 00:06:44 UTC
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


Comment 6 Jeffrey A. Law 2007-03-13 16:33:23 UTC
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




Comment 7 Jeffrey A. Law 2007-03-19 19:52:03 UTC
Fixed with today's patch to tree-cfg.c.
Comment 8 Jeffrey A. Law 2007-03-19 19:52:36 UTC
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

Comment 9 Jeffrey A. Law 2007-03-19 20:03:29 UTC
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

Comment 10 Jeffrey A. Law 2007-03-19 20:04:00 UTC
Fix committed to mainline, gcc-4.1 and gcc-4.2 branches
Comment 11 Jeffrey A. Law 2007-03-19 20:04:33 UTC
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