http://llvm.org/bugs/show_bug.cgi?id=15891

            Bug ID: 15891
           Summary: False positives
           Product: clang
           Version: unspecified
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: Static Analyzer
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected]
    Classification: Unclassified

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";
}

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to