Bug 80787 - gcc -Wmaybe-uninitialized false negative when compiling Emacs
Summary: gcc -Wmaybe-uninitialized false negative when compiling Emacs
Status: RESOLVED DUPLICATE of bug 18501
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: Wuninitialized
  Show dependency treegraph
 
Reported: 2017-05-16 18:18 UTC by Paul Eggert
Modified: 2018-02-21 21:20 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-02-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Eggert 2017-05-16 18:18:37 UTC
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.
Comment 1 Marc Glisse 2017-05-16 18:27:50 UTC
This is a DUP of many other PRs, -fno-tree-ccp -fno-tree-vrp gives you the warning, but otherwise gcc optimises cond?value:undef to value.
Comment 2 Eric Gallager 2018-02-20 12:07:03 UTC
(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.
$
Comment 3 Manuel López-Ibáñez 2018-02-21 21:20:26 UTC
(In reply to Marc Glisse from comment #1)
> This is a DUP of many other PRs, -fno-tree-ccp -fno-tree-vrp gives you the
> warning, but otherwise gcc optimises cond?value:undef to value.

*** This bug has been marked as a duplicate of bug 18501 ***