<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - -Wconditional-uninitialized false positive when usage is correctly constrained by other variable"
   href="http://llvm.org/bugs/show_bug.cgi?id=17526">17526</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>-Wconditional-uninitialized false positive when usage is correctly constrained by other variable
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>new-bugs
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Macintosh
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>MacOS X
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>new bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sean@rogue-research.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider this C99:

-------------------------
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

typedef enum
{
  kDog,
  kCat,
} MyEnum;

int main (void)
{
  bool isValid = false;
  MyEnum animal;  // NB: UNINITIALIZED!

  int random = rand();
  if (random == 420)
  {
    animal = kDog;
    isValid = true;
  }

  if (isValid)
  {
    printf("animal is %u", animal);
  }

  return 0;
}
-------------------------

$ clang --version
clang version 3.4 (192323)

$ clang -Weverything -fsyntax-only ~/Desktop/test.c
/Users/sean/Desktop/test.c:25:26: warning: variable 'animal' may be
uninitialized when used here [-Wconditional-uninitialized]
                printf("animal is %u", animal);
                                       ^~~~~~
/Users/sean/Desktop/test.c:14:2: note: variable 'animal' is declared here
        MyEnum animal;  // NB: UNINITIALIZED!
        ^
1 warning generated.


It's easy for a human to see that "animal" is only used if "isValid" is true
and that everywhere "isValid" is set to true, "animal" is also set to
something.  The bug is that clang can't also see this.  :)

This is a reduced test case of something similar but with many more if-else
branches.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>