[LLVMbugs] [Bug 15891] New: False positives

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed May 1 14:36:38 PDT 2013


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: kremenek at apple.com
          Reporter: avitzur at gmail.com
                CC: llvmbugs at cs.uiuc.edu
    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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130501/d84fdcfe/attachment.html>


More information about the llvm-bugs mailing list