User account creation filtered due to spam.

Bug 9365 - [3.3 regression] [SH] segfault in gen_far_branch (config/sh/sh.c)
Summary: [3.3 regression] [SH] segfault in gen_far_branch (config/sh/sh.c)
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 3.3
: P3 critical
Target Milestone: 3.3.3
Assignee: Jorn Wolfgang Rennecke
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2003-01-18 21:26 UTC by marcus
Modified: 2004-01-15 06:26 UTC (History)
5 users (show)

See Also:
Host:
Target: sh-unknown-elf
Build:
Known to work:
Known to fail:
Last reconfirmed: 2003-08-05 04:43:28


Attachments
modified testcase to show problem in 3.4 (214 bytes, text/plain)
2004-01-14 15:36 UTC, Jorn Wolfgang Rennecke
Details

Note You need to log in before you can comment on or make changes to this bug.
Description marcus 2003-01-18 21:26:00 UTC
	The compiler segfaults at the following place:

(gdb) bt
#0  0x2f422c in gen_far_branch (bp=0xefffe568)
    at /home/marcus/gcc-20030113/gcc/config/sh/sh.c:3228
#1  0x2f55a8 in split_branches (first=0x3ef400)
    at /home/marcus/gcc-20030113/gcc/config/sh/sh.c:4114
#2  0x2f49f0 in machine_dependent_reorg (first=0x48f420)
    at /home/marcus/gcc-20030113/gcc/config/sh/sh.c:3854
#3  0x2b9d0c in rest_of_compilation (decl=0x4d0280)
    at /home/marcus/gcc-20030113/gcc/toplev.c:3508
#4  0x58f94 in c_expand_body (fndecl=0x4d0280, nested_p=0, can_defer_p=3766272)
    at /home/marcus/gcc-20030113/gcc/c-decl.c:6525
#5  0x58b68 in finish_function (nested=0, can_defer_p=1)
    at /home/marcus/gcc-20030113/gcc/c-decl.c:6396
#6  0x38cbc in yyparse () at c-parse.y:403
#7  0x460fc in c_common_parse_file (set_yydebug=0)
    at /home/marcus/gcc-20030113/gcc/c-lex.c:159
#8  0x2b8364 in compile_file () at /home/marcus/gcc-20030113/gcc/toplev.c:2126
#9  0x2be260 in do_compile () at /home/marcus/gcc-20030113/gcc/toplev.c:5354
#10 0x2be328 in toplev_main (argc=17, argv=0xeffffa6c)
    at /home/marcus/gcc-20030113/gcc/toplev.c:5385
(gdb) list
3223        emit_barrier_after (jump);
3224      emit_label_after (bp->near_label, insn);
3225      JUMP_LABEL (jump) = bp->far_label;
3226      if (! invert_jump (insn, label, 1))
3227        abort ();
3228      (emit_insn_after
3229       (gen_stuff_delay_slot
3230        (GEN_INT (INSN_UID (XEXP (SET_SRC (PATTERN (jump)), 0))),
3231         GEN_INT (recog_memoized (insn) == CODE_FOR_branch_false)),
3232        insn));

Release:
3.3 20030113 (prerelease)

Environment:
System: SunOS continuity 5.8 Generic_108528-10 sun4m sparc SUNW,SPARCstation-10
Architecture: sun4

	
host: sparc-sun-solaris2.8
build: sparc-sun-solaris2.8
target: sh-unknown-elf
configured with: /home/marcus/gcc-20030113/configure --target=sh-elf --with-newlib --enable-languages=c,c++

How-To-Repeat:
	Compile the following program with
	`sh-elf-gcc -v -O2 -fomit-frame-pointer -c foo.c' :

	---8<--- foo.c ---8<---

void foo(int n, int *p)
{
  switch(n) {
   case 100: case 110: case 120: case 130: case 140:
   case 200: case 210: case 220: case 230: case 240:
   case 300: case 310: case 320: case 330: case 340:
   case 400: case 410: case 420: case 430: case 440:
   case 500: case 510: case 520: case 530: case 540:
   case 600: case 610: case 620: case 630: case 640:
   case 700: case 710: case 720: case 730: case 740:
   case 800: case 810: case 820: case 830: case 840:
   case 900: case 910: case 920: case 930: case 940:
     break;
   default:
     *p = n;
     break;
  }
}

	---8<---
Comment 1 marcus 2003-01-18 21:26:00 UTC
Fix:
	Use less optimization, or don't specify -fomit-frame-pointer.
Comment 2 Dara Hazeghi 2003-05-09 22:42:27 UTC
From: Dara Hazeghi <dhazeghi@yahoo.com>
To: gcc-gnats@gcc.gnu.org, marcus@mc.pp.se
Cc:  
Subject: Re: target/9365: [SH] segfault in gen_far_branch (config/sh/sh.c)
Date: Fri, 9 May 2003 22:42:27 -0700

 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit- 
 trail&database=gcc&pr=9365
 
 Hello,
 
 I can confirm that on 3.3 branch the testcase in this report fails, but  
 on 3.2.3 and mainline (20030509) it compiles fine.
 
 Dara
 
Comment 3 Giovanni Bajo 2003-05-12 11:35:57 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: Confirmed with 3.3
Comment 4 Mark Mitchell 2003-07-11 22:55:13 UTC
Postponed until GCC 3.3.2 -- SH is not a primary platform.
Comment 5 Eric Botcazou 2003-09-07 15:53:54 UTC
Confirmed on i586-redhat-linux-gnu as of gcc version 3.3.2 20030904
(prerelease). Here is a dumb patch that makes the segfault go away, but I can't
judge if the assembly code is valid.


Index: config/sh/sh.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/sh/sh.c,v
retrieving revision 1.188.2.6
diff -u -p -r1.188.2.6 sh.c
--- config/sh/sh.c      25 Jun 2003 17:38:01 -0000      1.188.2.6
+++ config/sh/sh.c      7 Sep 2003 15:48:28 -0000
@@ -3233,13 +3233,16 @@ gen_far_branch (bp)
   JUMP_LABEL (jump) = bp->far_label;
   if (! invert_jump (insn, label, 1))
     abort ();
-  (emit_insn_after
-   (gen_stuff_delay_slot
-    (GEN_INT (INSN_UID (XEXP (SET_SRC (PATTERN (jump)), 0))),
-     GEN_INT (recog_memoized (insn) == CODE_FOR_branch_false)),
-    insn));
-  /* Prevent reorg from undoing our splits.  */
-  gen_block_redirect (jump, bp->address += 2, 2);
+  if (bp->far_label)
+    {
+      emit_insn_after (
+       gen_stuff_delay_slot (
+         GEN_INT (INSN_UID (XEXP (SET_SRC (PATTERN (jump)), 0))),
+         GEN_INT (recog_memoized (insn) == CODE_FOR_branch_false)),
+       insn);
+      /* Prevent reorg from undoing our splits.  */
+      gen_block_redirect (jump, bp->address += 2, 2);
+    }
 }

 /* Fix up ADDR_DIFF_VECs.  */


I removed the 'host' field because the bug is not SPARC-specific.
Comment 6 dank 2003-09-12 07:44:56 UTC
Is there a testcase in the test suite for this yet?
Comment 7 dank 2003-09-15 17:39:05 UTC
I've prepared a patch to add a testcase for this PR to the testsuite; see
http://www.kegel.com/crosstool/current/patches/gcc-3.3.1/pr9365-1-test.patch
I'll submit it to gcc-patches in a couple days if nobody squawks.
Comment 8 Mark Mitchell 2003-10-02 21:31:05 UTC
Postponed until GCC 3.3.3; SH is not a primary platform.
Comment 9 Gabriel Dos Reis 2003-12-21 18:26:59 UTC
Joern, Alexandre --
Do you think you would have a chance to look
into this?

-- Gaby
Comment 10 Gabriel Dos Reis 2004-01-14 08:05:50 UTC
(In reply to comment #9)
> Joern, Alexandre --
> Do you think you would have a chance to look
> into this?

So no one of you can't comment on this PR?

Comment 11 Jorn Wolfgang Rennecke 2004-01-14 15:36:46 UTC
Created attachment 5480 [details]
modified testcase to show problem in 3.4

The code generated by the 3.4 compiler is more compact, so it needs a larger
testcase to trigger the problem.
Since this test is derived from the original one, we still have to resolve the
question of the copyright status.
Comment 12 CVS Commits 2004-01-14 18:02:49 UTC
Subject: Bug 9365

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amylaar@gcc.gnu.org	2004-01-14 18:02:44

Modified files:
	gcc            : ChangeLog 
	gcc/config/sh  : sh.c 

Log message:
	PR target/9365
	* sh.c (gen_block_redirect): Add special handling of RETURN.
	(gen_far_branch) Don't call gen_stuff_delay_slot if there is no
	far branch target (i.e. it's a return).

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.2286&r2=2.2287
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.c.diff?cvsroot=gcc&r1=1.245&r2=1.246

Comment 13 CVS Commits 2004-01-14 18:11:40 UTC
Subject: Bug 9365

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	amylaar@gcc.gnu.org	2004-01-14 18:11:37

Modified files:
	gcc            : ChangeLog 
	gcc/config/sh  : sh.c 

Log message:
	PR target/9365
	* sh.c (gen_block_redirect): Add special handling of RETURN.
	(gen_far_branch) Don't call gen_stuff_delay_slot if there is no
	far branch target (i.e. it's a return).

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.881&r2=1.16114.2.882
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/config/sh/sh.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.188.2.8&r2=1.188.2.9

Comment 14 Andrew Pinski 2004-01-14 18:41:16 UTC
Fixed for 3.3.3 and 3.4.
Comment 15 joern.rennecke 2004-01-14 18:52:56 UTC
Subject: Re:  [3.3 regression] [SH] segfault in gen_far_branch (config/sh/sh.c)

> ------- Additional Comments From pinskia at gcc dot gnu dot org  2004-01-14 18:41 -------
> Fixed for 3.3.3 and 3.4.
> 
> -- 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Status|ASSIGNED                    |RESOLVED
>          Resolution|                            |FIXED

What about the Copyright of the testcase?  Can add it to the gcc testsuite?
Comment 16 marcus 2004-01-14 23:38:15 UTC
Subject: Re:  [3.3 regression] [SH] segfault in
 gen_far_branch (config/sh/sh.c)


"joern dot rennecke at superh dot com" <gcc-bugzilla@gcc.gnu.org> writes:

> What about the Copyright of the testcase?  Can add it to the gcc testsuite?

Is that question directed at me?  I consider my original testcase to
be in the Public Domain.  The code is trivial anyway.


  // Marcus


Comment 17 dank 2004-01-15 06:26:59 UTC
My tweaks to Marcus's testcase,
http://www.kegel.com/crosstool/current/patches/gcc-3.3.1/pr9365-1-test.patch,
are public domain and trivial.
Comment 18 CVS Commits 2004-01-15 12:40:11 UTC
Subject: Bug 9365

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	amylaar@gcc.gnu.org	2004-01-15 12:40:06

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/gcc.dg: pr9365-1.c 

Log message:
	2004-01-15  Marcus Comstedt <marcus@mc.pp.se>
	Dan Kegel <dank@kegel.com>
	J"orn Rennecke <joern.rennecke@superh.com>
	
	PR target/9365
	* gcc.dg/pr9365-1.c: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.3377&r2=1.3378
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.dg/pr9365-1.c.diff?cvsroot=gcc&r1=NONE&r2=1.1