<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 --- - False positives"
   href="http://llvm.org/bugs/show_bug.cgi?id=15891">15891</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positives
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </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>Static Analyzer
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>kremenek@apple.com
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>avitzur@gmail.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>I'm not sure which version of clang is in Xcode 4.6.2. It generates two false
positives in the following:

#include <iostream>

int Test1(unsigned int x);
void Test2(int x, int y);

int main(int argc, const char * argv[])
{

   Test2(0,100);

   return Test1(51);
}

int Test1(unsigned int x)
{
   int a;

   switch (x & 0x3)
      {
         case 0: a = 1; break;
         case 1: a = 2; break;
         case 2: a = 3; break;
         case 3: a = 4; break;
      }

   std::cout << "Test 1";

   return a; 
// False positive Undefined or garbage value returned to caller, but x&0x3 can
be only 0,1,2, or 3. Making case 3 default: eliminates the false positive.
}

void Test2(int x, int y)
{
   int n = 10;
   int a[100];

   for (int i = 0; i < y; i++)
      a[i] = 0;

   for (int i = 0; i < 50; i++) {
      int w = i;
      if (w > a[x?0:(i / n)]) a[x?0:(i / n)]    = w; 
// The right operand of '>' is a garbage value
// moving the array index into a local or moving y into a local eliminates the
false positive.
      }

   std::cout << "Test 2\n";
}</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>