public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug other/94165] New: Wrong "warning: this statement may fall through" after __builtin_unreachable().
@ 2020-03-13 10:47 gjl at gcc dot gnu.org
  2020-03-13 12:16 ` [Bug other/94165] " jakub at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: gjl at gcc dot gnu.org @ 2020-03-13 10:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94165

            Bug ID: 94165
           Summary: Wrong "warning: this statement may fall through" after
                    __builtin_unreachable().
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: other
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gjl at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48026
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48026&action=edit
C/C++ test case.

The compiler gcc, g++ incorrectly complain about fall-through case after
__builtin_unreachable().

Compiler test case with

$ g++ -c -W -Wall

w.c: In function ‘int func(int, int)’:
w.c:7:15: warning: this statement may fall through [-Wimplicit-fallthrough=]
     (__extension__({                            \
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             int _r = error_at (msg);            \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             __builtin_unreachable();            \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             _r;                                 \
             ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         }))
         ~~~    
w.c:15:9: note: in expansion of macro ‘error’
         error ("bug");
         ^~~~~
w.c:16:5: note: here
     case 1:     case 2:
     ^~~~

The only route to the fall-through is via __builtin_unreachable(), thus this
warning is wrong.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug other/94165] Wrong "warning: this statement may fall through" after __builtin_unreachable().
  2020-03-13 10:47 [Bug other/94165] New: Wrong "warning: this statement may fall through" after __builtin_unreachable() gjl at gcc dot gnu.org
@ 2020-03-13 12:16 ` jakub at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-03-13 12:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94165

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This warning is an early warning (during gimplification) and can handle only
some constructs that clearly can't fall thru.
E.g. we do warn for:
extern void foo (const char *) __attribute__((noreturn));

int
bar (int x)
{
  switch (x)
    {
    default:
      foo ("bug");
      x++;
    case 1:
      return x + 2;
    }
}
but if you take the unreachable code after the noreturn call, we won't warn.
The expression statement is similar, there is code after the noreturn call.
Finding noreturn stuff in the middle of sequences would be difficult and
expensive.  Only the cfg pass is then able to figure out that some code is
unreachable.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-13 12:16 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-13 10:47 [Bug other/94165] New: Wrong "warning: this statement may fall through" after __builtin_unreachable() gjl at gcc dot gnu.org
2020-03-13 12:16 ` [Bug other/94165] " jakub at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).