http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53802

             Bug #: 53802
           Summary: Spurious 'may be used uninitialized' related to shifts
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: lukeocam...@gmail.com


Trivial changes in the following program suppress the warning:

inline void foo(const unsigned char* mem_, unsigned int* value_)
{
  unsigned int value = *mem_;
  value <<= 8;
  value |= *++mem_;
  value <<= 8;
  value |= *++mem_;
  value <<= 8;
  value |= *++mem_;
  value <<= 8;
  value |= *++mem_;
  *value_ = value;
}

inline void bar(unsigned char* dest_, unsigned int value_)
{
  if (!value_)
    return;
  dest_[0] = 0;
  dest_[1] = value_ >> 24;
  dest_[2] = value_ >> 16;
  dest_[3] = value_ >> 8;
  dest_[4] = value_;
}

int main()
{
  for (unsigned int number = 0xFFFFFFFF; number; number >>= 1)
  {
    unsigned char buf[5];
    bar(buf, number);
    unsigned int val;
    foo(buf, &val);
    if (number != val)
      return 0;
  }
}

$ gcc main.cpp -O -Wall
main.cpp: In function 'int main()':
main.cpp:6:19: warning: '*((void*)& buf +1)' may be used uninitialized in this
function [-Wmaybe-uninitialized]
main.cpp:31:19: note: '*((void*)& buf +1)' was declared here
main.cpp:12:19: warning: '*((void*)& buf +4)' may be used uninitialized in this
function [-Wmaybe-uninitialized]
main.cpp:31:19: note: '*((void*)& buf +4)' was declared here
main.cpp:10:19: warning: '*((void*)& buf +3)' may be used uninitialized in this
function [-Wmaybe-uninitialized]
main.cpp:31:19: note: '*((void*)& buf +3)' was declared here
main.cpp:8:19: warning: '*((void*)& buf +2)' may be used uninitialized in this
function [-Wmaybe-uninitialized]
main.cpp:31:19: note: '*((void*)& buf +2)' was declared here

Reply via email to