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

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2018-02-20
                 CC|                            |egallager at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Eric Gallager <egallager at gcc dot gnu.org> ---
(In reply to Paul Eggert from comment #0)
> I found this problem when compiling GNU Emacs with GCC 7.1.0 and with Clang
> 3.9.1.  GCC missed an uninitialized-variable bug that Clang correctly warned
> about. To reproduce the problem with GCC 7.1.0 x86-64, compile the following
> stripped-down test case:
> 
>   _Bool
>   xg_update_scrollbar_pos (int a, int b)
>   {
>     _Bool hidden;
>     if (a < b)
>       hidden = 1;
>     return !hidden;
>   }
> 
> using the command:
> 
>   gcc -O2 -Wall -S u.i
> 
> GCC does not warn, even though 'hidden' is a possibly-uninitialized
> variable. With the same options, Clang warns about the bug.

Confirmed, the clang output is:

$ /opt/local/bin/clang -c -O2 -Wall -S 80787.i
80787.i:5:7: warning: variable 'hidden' is used uninitialized whenever 'if'
condition is false [-Wsometimes-uninitialized]
  if (a < b)
      ^~~~~
80787.i:7:11: note: uninitialized use occurs here
  return !hidden;
          ^~~~~~
80787.i:5:3: note: remove the 'if' if its condition is always true
  if (a < b)
  ^~~~~~~~~~
80787.i:4:15: note: initialize the variable 'hidden' to silence this warning
  _Bool hidden;
              ^
               = 0
1 warning generated.
$

Reply via email to