public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/53802] New: Spurious 'may be used uninitialized' related to shifts
@ 2012-06-29  9:02 lukeocamden at gmail dot com
  2012-06-29  9:57 ` [Bug tree-optimization/53802] " rguenth at gcc dot gnu.org
  2014-02-03 18:31 ` lukeocamden at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: lukeocamden at gmail dot com @ 2012-06-29  9:02 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: lukeocamden@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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-02-03 18:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-29  9:02 [Bug tree-optimization/53802] New: Spurious 'may be used uninitialized' related to shifts lukeocamden at gmail dot com
2012-06-29  9:57 ` [Bug tree-optimization/53802] " rguenth at gcc dot gnu.org
2014-02-03 18:31 ` lukeocamden at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).