public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/43645]  New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly
@ 2010-04-05 10:17 alangcarter at gmail dot com
  2010-04-05 10:18 ` [Bug c++/43645] " alangcarter at gmail dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: alangcarter at gmail dot com @ 2010-04-05 10:17 UTC (permalink / raw)
  To: gcc-bugs

A 32 bit pointer with highest bit set ( >= 0x80000000) is incorrectly cast to
unsigned long long. The top 32 bits of the unsigned long long are all set 1,
not 0. The problem does not occur if the pointer is less than 0x80000000 or if
it is first cast to unsigned long and that is then cast to unsigned long long. 

Obviously the highest bit would indicate a negative value in a signed int of
the same size. It looks like some signed logic is being invoked inappropriately

Details provided from 4.3.3 on Ubuntu, also seen on 4.4.1 on Ubuntu and 4.1.2
on NetBSD. Exact same behaviour also seen with Microsoft Visual C++ 2008, but
not on Apple's version of 4.0.1.

Here is a small test program which demonstrates the problem, I'll attach the
.ii and gcc output:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;

template<typename T> void dump(string legend, T* data)
{
   // Display the bytes of the supplied type and its cout operator << rendition
   unsigned char* puc = (unsigned char*)data;

   cout << legend << ":" << endl;
   for(unsigned int i = 0; i < sizeof(T); i++)
      cout << hex << setw(2) << setfill('0') << (unsigned int)(puc[i]) << " ";
   cout << endl << hex << setw(16) << setfill('0') << *data << endl << endl;
}

int main(int argc, char **argv)
{
   void* pv1 = (void*)0x12345678;
   void* pv2 = (void*)0x87654321;
   unsigned long long int ulli;

   dump("small void*", &pv1);

   ulli = (unsigned long long int)pv1;
   dump("small void* cast to unsigned long long", &ulli);

   ulli = (unsigned long long int)(unsigned long int)pv1;
   dump("small void* cast to unsigned long cast to unsigned long long", &ulli);

   dump("large void*", &pv2);

   ulli = (unsigned long long int)pv2;
   dump("large void* cast to unsigned long long", &ulli);

   ulli = (unsigned long long int)(unsigned long int)pv2;
   dump("large void* cast to unsigned long cast to unsigned long long", &ulli);
}


-- 
           Summary: 32 bit pointer in top half of VM casts to unsigned long
                    long incorrectly
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alangcarter at gmail dot com


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


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

* [Bug c++/43645] 32 bit pointer in top half of VM casts to unsigned long long incorrectly
  2010-04-05 10:17 [Bug c++/43645] New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly alangcarter at gmail dot com
@ 2010-04-05 10:18 ` alangcarter at gmail dot com
  2010-04-05 10:20 ` alangcarter at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: alangcarter at gmail dot com @ 2010-04-05 10:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from alangcarter at gmail dot com  2010-04-05 10:18 -------
Created an attachment (id=20307)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20307&action=view)
Source code of demo program


-- 


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


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

* [Bug c++/43645] 32 bit pointer in top half of VM casts to unsigned long long incorrectly
  2010-04-05 10:17 [Bug c++/43645] New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly alangcarter at gmail dot com
  2010-04-05 10:18 ` [Bug c++/43645] " alangcarter at gmail dot com
@ 2010-04-05 10:20 ` alangcarter at gmail dot com
  2010-04-05 10:20 ` alangcarter at gmail dot com
  2010-04-05 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: alangcarter at gmail dot com @ 2010-04-05 10:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from alangcarter at gmail dot com  2010-04-05 10:19 -------
Created an attachment (id=20308)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20308&action=view)
.ii file from compiling test program


-- 


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


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

* [Bug c++/43645] 32 bit pointer in top half of VM casts to unsigned long long incorrectly
  2010-04-05 10:17 [Bug c++/43645] New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly alangcarter at gmail dot com
  2010-04-05 10:18 ` [Bug c++/43645] " alangcarter at gmail dot com
  2010-04-05 10:20 ` alangcarter at gmail dot com
@ 2010-04-05 10:20 ` alangcarter at gmail dot com
  2010-04-05 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: alangcarter at gmail dot com @ 2010-04-05 10:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from alangcarter at gmail dot com  2010-04-05 10:20 -------
Created an attachment (id=20309)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=20309&action=view)
g++ command and console output


-- 


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


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

* [Bug c++/43645] 32 bit pointer in top half of VM casts to unsigned long long incorrectly
  2010-04-05 10:17 [Bug c++/43645] New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly alangcarter at gmail dot com
                   ` (2 preceding siblings ...)
  2010-04-05 10:20 ` alangcarter at gmail dot com
@ 2010-04-05 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2010-04-05 10:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2010-04-05 10:27 -------
This is implementation-defined.  See
http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Arrays-and-pointers-implementation.html#Arrays-and-pointers-implementation


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID
            Summary|32 bit pointer in top half  |32 bit pointer in top half
                   |of VM casts to unsigned long|of VM casts to unsigned long
                   |long incorrectly            |long incorrectly


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


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

end of thread, other threads:[~2010-04-05 10:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-04-05 10:17 [Bug c++/43645] New: 32 bit pointer in top half of VM casts to unsigned long long incorrectly alangcarter at gmail dot com
2010-04-05 10:18 ` [Bug c++/43645] " alangcarter at gmail dot com
2010-04-05 10:20 ` alangcarter at gmail dot com
2010-04-05 10:20 ` alangcarter at gmail dot com
2010-04-05 10:27 ` rguenth at gcc dot gnu dot org

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).