This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Null pointer bug with -Wunreachable-code
- From: Marek Michalkiewicz <marekm at amelek dot gda dot pl>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 28 Apr 2003 18:32:53 +0200
- Subject: Null pointer bug with -Wunreachable-code
Hello,
I suspect that the PR middle-end/10336 bug is not really fixed yet.
No check for insn != NULL is done in jump.c (never_reached_warning),
simple test case (tested on AVR target, mainline and 3.3 branch):
$ cat >bug.c
void foo(char a)
{
while (1);
}
$ avr-gcc -O2 -Wall -Wunreachable-code -c bug.c
bug.c: In function `foo':
bug.c:4: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.
The patch below fixes it, and was already proposed, but not applied.
Is this the correct fix, or is there a better one?
Thanks,
Marek
Index: jump.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/jump.c,v
retrieving revision 1.214.2.5
diff -c -3 -p -r1.214.2.5 jump.c
*** jump.c 15 Apr 2003 16:16:02 -0000 1.214.2.5
--- jump.c 28 Apr 2003 15:56:08 -0000
*************** never_reached_warning (avoided_insn, fin
*** 1939,1945 ****
/* Back up to the first of any NOTEs preceding avoided_insn; flow passes
us the head of a block, a NOTE_INSN_BASIC_BLOCK, which often follows
the line note. */
! for (insn = PREV_INSN (avoided_insn); ; insn = PREV_INSN (insn))
if (GET_CODE (insn) != NOTE
|| NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
{
--- 1939,1945 ----
/* Back up to the first of any NOTEs preceding avoided_insn; flow passes
us the head of a block, a NOTE_INSN_BASIC_BLOCK, which often follows
the line note. */
! for (insn = PREV_INSN (avoided_insn); insn; insn = PREV_INSN (insn))
if (GET_CODE (insn) != NOTE
|| NOTE_LINE_NUMBER (insn) == NOTE_INSN_FUNCTION_BEG)
{