[LLVMbugs] [Bug 11572] New: Right shift of a bit field strips the "unsigned" type property from a bitfield

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Wed Dec 14 11:25:59 PST 2011


             Bug #: 11572
           Summary: Right shift of a bit field strips the "unsigned" type
                    property from a bitfield
           Product: clang
           Version: 3.0
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: Kevin.Harris at unisys.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 7730
  --> http://llvm.org/bugs/attachment.cgi?id=7730
source file for the bug

With the following test source:

class Example {
    unsigned int lock : 26;
    unsigned int v1    :  3;
    unsigned int v2    :  3;

inline    unsigned int getPermission(unsigned int key)
        if( key != 0 ){
            if( ( key >> 24 ) < ( lock >> 24 ) )
                return (unsigned int)( v1 );
                return (unsigned int)( v2 );
        return 7;

I get a warning on the compare when -Wsign-compare is in effect.

va-sa.cpp:10:31: warning: comparison of integers of different signs:
      'unsigned int' and 'int' [-Wsign-compare]
            if( ( key >> 24 ) < ( lock >> 24 ) )
                  ~~~~~~~~~   ^   ~~~~~~~~~~

What seems to have happened is that the >> operator strips the "unsigned"
property when the left operand is a bit field.  Both the use of a bit field
and the use of the >> operator are needed to trigger the warning.  

g++ 4.5.3 doesn't give a warning for this.

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list