public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/32324]  New: unsigned long long operator << and integer literals
@ 2007-06-13 16:48 gcc at axel-naumann dot de
  2007-06-13 16:50 ` [Bug c/32324] " gcc at axel-naumann dot de
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: gcc at axel-naumann dot de @ 2007-06-13 16:48 UTC (permalink / raw)
  To: gcc-bugs

The result of the division of 18446744065119617024llu by the result of (1<<31)
is wrong on a 32bit platform.

Reproduce:  gcc s.c && ./a.out
should have exit code 0 but doesn't.

Expected:   gcc -DEXPECTED s.c && ./a.out
has exit code 0 as expected.


gcc -v
Reading specs from /usr/lib/gcc/i386-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-java-awt=gtk --host=i386-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-8)
[lxbuild021] /afs/cern.ch/user/a/axel/tmp/gccconv >
/afs/cern.ch/sw/lcg/contrib/gcc/4.1.2/slc4_ia32_gcc34/bin/gcc -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /build/LCG/gcc-4.1.2/configure
--prefix=/afs/cern.ch/sw/lcg/contrib/gcc/4.1.2/slc4_ia32_gcc34
Thread model: posix
gcc version 4.1.2


uname -a
Linux lxbuild021.cern.ch 2.6.9-42.0.10.EL.cernsmp #1 SMP Thu Mar 1 15:11:46 CET
2007 i686 i686 i386 GNU/Linux


I'll give the .c instead of .i because it shows the expected result and has no
#includes:

int main (){
   unsigned long long a = 18446744065119617024llu;
   /* results expected to be identical */
#ifdef EXPECTED
   int b = ((int)(1<<31));
   a = a / b;
#else
   a = a / ((int)(1<<31));
#endif
   return a;
}


-- 
           Summary: unsigned long long operator << and integer literals
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: gcc at axel-naumann dot de
 GCC build triplet: i386-redhat-linux
  GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux


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


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

* [Bug c/32324] unsigned long long operator << and integer literals
  2007-06-13 16:48 [Bug c/32324] New: unsigned long long operator << and integer literals gcc at axel-naumann dot de
@ 2007-06-13 16:50 ` gcc at axel-naumann dot de
  2007-06-13 18:00 ` andrew dot stubbs at st dot com
  2007-06-14  9:45 ` schwab at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: gcc at axel-naumann dot de @ 2007-06-13 16:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from gcc at axel-naumann dot de  2007-06-13 16:50 -------
Created an attachment (id=13699)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13699&action=view)
Test case as stated in the report.


-- 


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


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

* [Bug c/32324] unsigned long long operator << and integer literals
  2007-06-13 16:48 [Bug c/32324] New: unsigned long long operator << and integer literals gcc at axel-naumann dot de
  2007-06-13 16:50 ` [Bug c/32324] " gcc at axel-naumann dot de
@ 2007-06-13 18:00 ` andrew dot stubbs at st dot com
  2007-06-14  9:45 ` schwab at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: andrew dot stubbs at st dot com @ 2007-06-13 18:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from andrew dot stubbs at st dot com  2007-06-13 18:00 -------
As it happens, I encountered your real problem quite recently. :)

"(int)(1<<31)" is undefined (C99 standard 6.5.7/4).

This modified version gives the same result both ways:

int main (){
   unsigned long long a = 18446744065119617024llu;
   /* results expected to be identical */
#ifdef EXPECTED
   unsigned int b = ((unsigned int)(1<<31));
   a = a / b;
#else
   a = a / ((unsigned int)(1<<31));
#endif

   return a;
}


-- 


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


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

* [Bug c/32324] unsigned long long operator << and integer literals
  2007-06-13 16:48 [Bug c/32324] New: unsigned long long operator << and integer literals gcc at axel-naumann dot de
  2007-06-13 16:50 ` [Bug c/32324] " gcc at axel-naumann dot de
  2007-06-13 18:00 ` andrew dot stubbs at st dot com
@ 2007-06-14  9:45 ` schwab at suse dot de
  2 siblings, 0 replies; 4+ messages in thread
From: schwab at suse dot de @ 2007-06-14  9:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from schwab at suse dot de  2007-06-14 09:45 -------
This is still undefined.  Use 1U<<31 instead.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-06-14  9:45 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-13 16:48 [Bug c/32324] New: unsigned long long operator << and integer literals gcc at axel-naumann dot de
2007-06-13 16:50 ` [Bug c/32324] " gcc at axel-naumann dot de
2007-06-13 18:00 ` andrew dot stubbs at st dot com
2007-06-14  9:45 ` schwab at suse dot de

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