diff options
author | Geoff Keating <geoffk@cygnus.com> | 1999-08-18 10:43:26 +0000 |
---|---|---|
committer | Geoffrey Keating <geoffk@gcc.gnu.org> | 1999-08-18 10:43:26 +0000 |
commit | 312f625598f2eed11718c43a649027bc760ef30a (patch) | |
tree | 4fb0b080db23c76c2853dadb847aff9aa64d9dc6 /gcc/jump.c | |
parent | 075ff1b238e01efca6c3a0dc6ddd82046fda4c5a (diff) | |
download | gcc-312f625598f2eed11718c43a649027bc760ef30a.zip gcc-312f625598f2eed11718c43a649027bc760ef30a.tar.gz gcc-312f625598f2eed11718c43a649027bc760ef30a.tar.bz2 |
cse.c (cse_insn): Call never_reached_warning when a jump is changed to be unconditional.
* cse.c (cse_insn): Call never_reached_warning when a jump is
changed to be unconditional.
* flags.h: Declare warn_notreached.
* flow.c (delete_block): Call never_reached_warning when
a block is deleted.
* jump.c (delete_barrier_successors): Call never_reached_warning
when we delete everything after a BARRIER.
(never_reached_warning): New function.
* rtl.h: Declare never_reached_warning.
* toplev.c (warn_notreached): New variable.
(lang_independent_options): Set warn_notreached
when -Wunreachable-code.
(compile_file): We need line numbers for -Wunreachable-code.
Also modify documentation to suit.
From-SVN: r28747
Diffstat (limited to 'gcc/jump.c')
-rw-r--r-- | gcc/jump.c | 49 |
1 files changed, 49 insertions, 0 deletions
@@ -2149,6 +2149,9 @@ delete_barrier_successors (f) if (GET_CODE (insn) == BARRIER) { insn = NEXT_INSN (insn); + + never_reached_warning (insn); + while (insn != 0 && GET_CODE (insn) != CODE_LABEL) { if (GET_CODE (insn) == NOTE @@ -4245,6 +4248,52 @@ delete_for_peephole (from, to) is also an unconditional jump in that case. */ } +/* We have determined that INSN is never reached, and are about to + delete it. Print a warning if the user asked for one. + + To try to make this warning more useful, this should only be called + once per basic block not reached, and it only warns when the basic + block contains more than one line from the current function, and + contains at least one operation. CSE and inlining can duplicate insns, + so it's possible to get spurious warnings from this. */ + +void +never_reached_warning (avoided_insn) + rtx avoided_insn; +{ + rtx insn; + rtx a_line_note = NULL; + int two_avoided_lines = 0; + int contains_insn = 0; + + if (! warn_notreached) + return; + + /* Scan forwards, looking at LINE_NUMBER notes, until + we hit a LABEL or we run out of insns. */ + + for (insn = avoided_insn; insn != NULL; insn = NEXT_INSN (insn)) + { + if (GET_CODE (insn) == CODE_LABEL) + break; + else if (GET_CODE (insn) == NOTE /* A line number note? */ + && NOTE_LINE_NUMBER (insn) >= 0) + { + if (a_line_note == NULL) + a_line_note = insn; + else + two_avoided_lines |= (NOTE_LINE_NUMBER (a_line_note) + != NOTE_LINE_NUMBER (insn)); + } + else if (GET_RTX_CLASS (GET_CODE (insn)) == 'i') + contains_insn = 1; + } + if (two_avoided_lines && contains_insn) + warning_with_file_and_line (NOTE_SOURCE_FILE (a_line_note), + NOTE_LINE_NUMBER (a_line_note), + "will never be executed"); +} + /* Invert the condition of the jump JUMP, and make it jump to label NLABEL instead of where it jumps now. */ |