<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 positive testing enum value of particular size"
   href="http://llvm.org/bugs/show_bug.cgi?id=15905">15905</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>False positive testing enum value of particular size
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>3.1
          </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>jbrooks@kcptech.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>Clang reports a comparison with an uninitialized value in the below code.  This
is a simplification of code compiled both for iOS and on Mac OS 32 bit.  The
bug only occurs if the enumeration values are defined as starting at 0x8000. 
The comparison is against an unsigned short.  If it was signed, there could be
a potential problem with the sign bit being set, but as it stands, it looks
like it's a bug.

Contents of main.c:
#define false 0
#define true 1
typedef int bool;

typedef enum {
    value1 =  0x8000, /*If value1 is initialized at < 0x8000, the bug doesn't
occur*/
    value2,
    value3,
    value4,
    value5,
    value6
}myEnum;

static bool test_UTIL(bool aBool, unsigned short iCaseValue)
{
    bool canMatch = true;
    unsigned short myValue; /*not initialized*/

    if (aBool)
        myValue = 1;  /*myValue set only in this path */
    else
        canMatch = ((value1 == iCaseValue)
            || (value2 == iCaseValue)
            || (value3 == iCaseValue)
            || (value4 == iCaseValue)
            || (value5 == iCaseValue)
            || (value6 == iCaseValue));

    if (canMatch)
    {
        switch (iCaseValue) 
        {
            case value1:
            case value2:
            case value3:
            case value4:
            case value5:
            case value6:
                break;

            default:
                /*This triggers a clang warning, claiming myValue is
undefined*/
                canMatch = (iCaseValue == myValue);
                break;
        }
    }

    return canMatch;
}

/* Main() is written this way just to prevent compiler optimizations, and can
be ignored. */
int main(int argc, const char * argv[])
{
    unsigned short i;
    int j = 0;

    for( i = 0; i < 0x8888; i++)
    {
        bool ret = test_UTIL(i & 1, i);
        if( ret )
            j++;
    }


    return j;
}</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>