Bug 14838 - [3.3/3.4/4.0 Regression] ICE when building with -O2 -g
Summary: [3.3/3.4/4.0 Regression] ICE when building with -O2 -g
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: rtl-optimization (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: 3.3.6
Assignee: Not yet assigned to anyone
URL:
Keywords: ice-on-valid-code
: 17858 18593 18647 19752 (view as bug list)
Depends on:
Blocks:
 
Reported: 2004-04-03 22:16 UTC by Randolph Chung
Modified: 2005-02-02 14:33 UTC (History)
8 users (show)

See Also:
Host: hppa-linux
Target: hppa-linux
Build: hppa-linux
Known to work: 3.4.4 3.3.6 4.0.0
Known to fail: 3.4.1 4.0.0 3.4.3 3.3.5
Last reconfirmed: 2004-08-05 06:58:37


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Randolph Chung 2004-04-03 22:16:40 UTC
legolas[14:13] make% /opt/gcc/gcc-3.5/bin/gcc -O2 -g -c bug.c
bug.c: In function `Buf_GetAll':
bug.c:13: error: unrecognizable insn:
(insn 31 25 55 bug.c:13 (use (reg/i:SI 28 %r28 [ <result> ])) -1 (insn_list 41 
(nil))
    (nil))
bug.c:13: internal compiler error: in insn_default_length, at insn-attrtab.c:825
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

ICE doesn't happen without -g, or with -O1 -g

code snippet extracted from freebsd-buildutils 

-------- bug.c --------
typedef struct Buffer {
    char    *inPtr;
    char    *outPtr;
} *Buffer;

char *
Buf_GetAll (Buffer bp, int *numcharsPtr)
{
    if (numcharsPtr != 0)
  *numcharsPtr = bp->inPtr - bp->outPtr;

    return (bp->outPtr);
}
-------- bug.c --------
Comment 1 John David Anglin 2004-04-04 20:54:09 UTC
The ICE is generated by a call to insn_default_length in 
pa_output_function_epilogue.  It does a call to get_last_nonnote_insn
to get the last nonnote insn.  However, in this case, get_last_nonnote_insn
doesn't actually return the last nonnote insn.  It returns the next to
last nonnote insn which is the `use' insn which insn_default_length
doesn't like.

The code in get_last_nonnote_insn assumes that the last insn in the
current sequence or current function is a note.  However, when
get_last_nonnote_insn is called, the last insn is

(jump_insn 55 31 0 (parallel [
            (return)
            (use (reg:SI 2 %r2))
            (const_int 0 [0x0])
        ]) 184 {return} (insn_list:REG_DEP_ANTI 31 (insn_list 41 (nil)))
    (expr_list:REG_BR_PRED (const_int 12 [0xc])
        (expr_list:REG_DEAD (reg:SI 2 %r2)
            (nil))))

We did have the following note:

(note 71 55 0 NOTE_INSN_DELETED)

However, it is removed by a call to remove_insn:

Breakpoint 13, remove_insn (insn=0x40196580) at ../../gcc/gcc/emit-rtl.c:3578
3578      rtx next = NEXT_INSN (insn);
(gdb) bt
#0  remove_insn (insn=0x40196580) at ../../gcc/gcc/emit-rtl.c:3578
#1  0x0011bb8c in delete_insn (insn=0x40196580) at ../../gcc/gcc/cfgrtl.c:149
#2  0x00113f5c in reemit_insn_block_notes () at ../../gcc/gcc/cfglayout.c:559
#3  0x001ebef0 in final_start_function (first=0x401961a0, file=0x66ddd0,
    optimize=2) at ../../gcc/gcc/final.c:1374
#4  0x00470108 in rest_of_handle_final (decl=0x4021af50, insns=0x401961a0)
    at ../../gcc/gcc/passes.c:447

The comment for NOTE_INSN_DELETED says

  /* This note is used to get rid of an insn
     when it isn't safe to patch the insn out of the chain.  */

So, I don't think delete_insn should be trying to remove this note.  If
the note isn't removed, then get_last_nonnote_insn will work correctly
and we shouldn't get the ICE.
Comment 2 Andrew Pinski 2004-08-05 06:26:40 UTC
Moving the target to 3.4.2 as per GDR and regressions on the 3.4 branch.
Comment 3 Giovanni Bajo 2004-08-05 06:58:37 UTC
Confirmed by JDA.
Comment 4 Mark Mitchell 2004-08-29 18:11:52 UTC
Postponed until GCC 3.4.3.
Comment 5 Mark Mitchell 2004-08-29 18:14:41 UTC
Postponed until GCC 3.4.3.
Comment 6 Andrew Pinski 2004-10-06 11:31:30 UTC
*** Bug 17858 has been marked as a duplicate of this bug. ***
Comment 7 Mark Mitchell 2004-11-01 00:45:25 UTC
Postponed until GCC 3.4.4.
Comment 8 Andrew Pinski 2004-11-21 14:26:13 UTC
*** Bug 18593 has been marked as a duplicate of this bug. ***
Comment 9 GCC Commits 2004-11-23 02:15:35 UTC
Subject: Bug 14838

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	danglin@gcc.gnu.org	2004-11-23 02:15:19

Modified files:
	gcc            : ChangeLog emit-rtl.c 

Log message:
	PR rtl-optimization/14838
	* emit-rtl.c (get_first_nonnote_insn): Don't assume first insn is a
	note.
	(get_last_nonnote_insn): Don't assume last insn is a note.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.6475&r2=2.6476
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/emit-rtl.c.diff?cvsroot=gcc&r1=1.425&r2=1.426

Comment 10 GCC Commits 2004-11-23 03:01:46 UTC
Subject: Bug 14838

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	danglin@gcc.gnu.org	2004-11-23 03:01:19

Modified files:
	gcc            : ChangeLog emit-rtl.c 

Log message:
	PR rtl-optimization/14838
	* emit-rtl.c (get_first_nonnote_insn): Don't assume first insn is a
	note.
	(get_last_nonnote_insn): Don't assume last insn is a note.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.696&r2=2.2326.2.697
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/emit-rtl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.365.4.5&r2=1.365.4.6

Comment 11 GCC Commits 2004-11-23 03:38:11 UTC
Subject: Bug 14838

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	danglin@gcc.gnu.org	2004-11-23 03:37:53

Modified files:
	gcc            : ChangeLog emit-rtl.c 

Log message:
	PR rtl-optimization/14838
	* emit-rtl.c (get_first_nonnote_insn): Don't assume first insn is a
	note.
	(get_last_nonnote_insn): Don't assume last insn is a note.

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.1024&r2=1.16114.2.1025
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/emit-rtl.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.303.2.5&r2=1.303.2.6

Comment 12 John David Anglin 2004-11-23 03:39:55 UTC
Fixed.
Comment 13 Andrew Pinski 2004-11-24 14:06:17 UTC
*** Bug 18647 has been marked as a duplicate of this bug. ***
Comment 14 Andrew Pinski 2005-02-02 14:33:15 UTC
*** Bug 19752 has been marked as a duplicate of this bug. ***