This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/11270] [tree-ssa] Strange warning with -Wunreachable-code.


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11270


steven at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2003-08-15 03:37:06         |2003-09-14 21:10:03
               date|                            |


------- Additional Comments From steven at gcc dot gnu dot org  2003-09-14 21:10 -------
Analysis of this bug: never_reached_warning() is just plain stupid.  Lemme tell
you why:

>From mainline:

(jump_insn 19 18 20 (set (pc)
        (if_then_else (eq (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 11)
            (pc))) -1 (nil)
    (nil))
                                                                                
(jump_insn 20 19 21 (set (pc)
        (label_ref 17)) -1 (nil)
    (nil))
                                                                                
(barrier 21 20 9)
                                                                                
(note 9 21 10 NOTE_INSN_DELETED)
                                                                                
(note 10 9 11 NOTE_INSN_DELETED)
                                                                                
(code_label 11 10 12 3 "" [0 uses])

(note 12 11 13 [ 20 0 ]  NOTE_INSN_PREDICTION)
                                                                                
(note 13 12 14 ("t.c") 6)
                                                                                
(jump_insn 14 13 15 (set (pc)
        (label_ref 22)) -1 (nil)
    (nil))
                                                                                
(barrier 15 14 16)


>From tree-ssa:
(jump_insn 18 17 19 (set (pc)
        (if_then_else (eq (reg:CCZ 17 flags)
                (const_int 0 [0x0]))
            (label_ref 10)
            (pc))) -1 (nil)
    (nil))
                                                                                
(jump_insn 19 18 20 (set (pc)
        (label_ref 16)) -1 (nil)
    (nil))
                                                                                
(barrier 20 19 9)
                                                                                
(note 9 20 10 ("t.c") 5)
                                                                                
(code_label 10 9 11 2 "" [0 uses])
                                                                                
(note 11 10 12 ("t.c") 6)
                                                                                
(jump_insn 12 11 13 (set (pc)
        (label_ref 21)) -1 (nil)
    (nil))
                                                                                
(barrier 13 12 14)



Note the extra line note we emit in tree-ssa before the code_label. This fools
jump.c:never_reached_warning() into thinking that this "unreachable" block, that
in reality is simply removed because the switch body is empty, has more than two
statements in it: two_avoided_lines == true, and you get the warning. Yes, it's
true, never_reached_warning() relies on line notes...

Conclusion: -Wunreachable-code is broken in all sorts of ways.

It's funny to see that such a seemingly trivial warning can cause so many PRs. I
think this is the fourth or fifth or something that I've analyzed in about a
years' time...

I am tempted to suspend this one until one or both of the following ideas get
implemented:

- Mark Mitchell says we should just whack -Wunreachable-code as it
  is now, and only warn for obviously unreachable code in the front
  ends, i.e. the middle end should not issue the warning, and the
  code that you'd warn about don't need CFG information.
  (I like the idea for a trivial -Wunreachable-code, but I'd also
   like to keep a CFG-based approach. The first could maybe turned
   on by default with -Wextra...)
- Remove all the "-Wunreachable-code"-code entirely from jump.c on
  the tree-ssa branch and re-implement it based on the tree-cfg.
  (I don't recall this ever being discussed, but it seems like an
   obvious and not-too-hard-to-implement solution..)

Thoughts?

P.S.
The irony is that this actually is an improvement. Mainline does not put out a
line note for the case label, but tree-ssa does :-)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]