https://bugs.llvm.org/show_bug.cgi?id=39736

            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: unassignedclangb...@nondot.org
          Reporter: akim.demai...@gmail.com
                CC: htmldevelo...@gmail.com, llvm-bugs@lists.llvm.org,
                    neeil...@live.com, richard-l...@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

yyerrorlab:
  /* 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.

Cheers!


%{
  int yylex (void)
  {
    return 0;
  }

  void yyerror (char const *s)
  {}
%}
%%
input:
%%
int main (void)
{
  return yyparse ();
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to