Bug 80548 - -Wmaybe-uninitialized false positive when an assignment is added
Summary: -Wmaybe-uninitialized false positive when an assignment is added
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 6.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: diagnostic
Depends on:
Reported: 2017-04-27 15:36 UTC by Vincent Lefèvre
Modified: 2017-04-28 09:23 UTC (History)
0 users

See Also:
Known to work:
Known to fail: 4.8.5, 5.4.1, 6.3.1, 7.0.1
Last reconfirmed: 2017-04-28 00:00:00


Note You need to log in before you can comment on or make changes to this bug.
Description Vincent Lefèvre 2017-04-27 15:36:24 UTC

int g (void);
void h (int, int);

void f (int b)
  int x, y;

  if (b)
      x = g ();
      y = g ();

  while (g ())
    if (b)
        h (x, y);
        y = g ();

Compiling this program with "-O -Wmaybe-uninitialized -c" yields:

tst.c: In function ‘f’:
tst.c:17:9: warning: ‘y’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         h (x, y);

Note that x and y play a symmetric role here, except that y has an additional assignment, and this assignment makes GCC think that y may be used uninitialized! Indeed, if one removes this assignment, the warning disappear.
Comment 1 Richard Biener 2017-04-28 09:23:55 UTC
Confirmed (also with -O2).  Older compilers need -Wuninitialized to trigger it.

[WORKLIST]: add to initial list: x_22 = PHI <x_6(D)(11), x_10(3)>
[WORKLIST]: add to initial list: y_21 = PHI <y_7(D)(11), y_12(3)>
[CHECK]: examining phi: y_21 = PHI <y_7(D)(11), y_12(3)>
[CHECK]: Found unguarded use: y_18 = PHI <y_21(4), y_16(6)>
[WORKLIST]: Update worklist with phi: y_18 = PHI <y_21(4), y_16(6)>
[CHECK]: examining phi: y_18 = PHI <y_21(4), y_16(6)>

[CHECK] Found def edge 1 in y_21 = PHI <y_7(D)(11), y_12(3)>

[CHECK] Found def edge 1 in y_18 = PHI <y_21(4), y_16(6)>
[CHECK]: Found unguarded use: h (x_22, y_18);
[CHECK]: examining phi: x_22 = PHI <x_6(D)(11), x_10(3)>

it's confused by the CFG structure it seems.