[llvm-bugs] [Bug 39736] New: -Wunreachable-code complains about silenced code

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Nov 20 22:39:14 PST 2018


            Bug ID: 39736
           Summary: -Wunreachable-code complains about silenced code
           Product: clang
           Version: 7.0
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: -New Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: akim.demaille at gmail.com
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org,
                    neeilans at live.com, richard-llvm at metafoo.co.uk

Created attachment 21136
  --> https://bugs.llvm.org/attachment.cgi?id=21136&action=edit
generated output

I was unable to make a smaller example that still shows the problem, this
happens in code generated by GNU Bison.

The core of the generated parser is a state machine implemented with labels and
gotos.  Some of the labels might not be used, depending on the what the user
does in her actions, so to avoid warning about unreachable code, there's

  /* Pacify compilers like GCC when the user code never invokes
     YYERROR and the label yyerrorlab therefore never appears in user
     code.  */
  if ((0))
    goto yyerrorlab;

With -Wunreachable-code, clang still complains about this `if (0)`:

$ clang-mp-7.0 foo.tab.c -Wunreachable-code
foo.tab.c:1302:5: warning: code will never be executed [-Wunreachable-code]
    goto yyerrorlab;
foo.tab.c:1301:8: note: silence by adding parentheses to mark code as
explicitly dead
  if ((0))
       /* DISABLES CODE */ ( )
1 warning generated.

I have this problem with all the versions of Clang I can run:

$ clang-mp-3.9 --version | sed 1q
clang version 3.9.1 (tags/RELEASE_391/final)
$ clang-mp-4.0 --version | sed 1q
clang version 4.0.1 (tags/RELEASE_401/final)
$ clang-mp-5.0 --version | sed 1q
clang version 5.0.2 (tags/RELEASE_502/final)
$ clang-mp-7.0 --version | sed 1q
clang version 7.0.0 (tags/RELEASE_700/final)
$ clang-mp-devel --version | sed 1q
clang version 8.0.0 (trunk 340138)

I attached the generated output.  The input file is below.


  int yylex (void)
    return 0;

  void yyerror (char const *s)
int main (void)
  return yyparse ();

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181121/d883c2e5/attachment-0001.html>

More information about the llvm-bugs mailing list