public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/26630]  New: Incorrect result when subtracting, casting to short and back to int, adding and multiplying
@ 2006-03-10 12:50 cyp561 at gmail dot com
  2006-03-10 12:57 ` [Bug middle-end/26630] [4.0 Regression] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: cyp561 at gmail dot com @ 2006-03-10 12:50 UTC (permalink / raw)
  To: gcc-bugs

As far as I can tell, c1 should be equal to 80000, not -51072, or at least
equal to c2.

Sorry if I'm mistaken, but I can't see how c1 and c2 can be different. The
result is the same using gcc 3.3.6, gcc 3.4.4 and gcc 4.0.2.

Program (error.c):
---------
#include <stdio.h>

int main()
{
    int a1 = 40000;
#define b1   ((int)(short)(a1-10000))
    int c1 = ( b1 +10000)*2;

    int a2 = 40000;
    int b2 = ((int)(short)(a2-10000));
    int c2 = ( b2 +10000)*2;

    printf("sizeof(int) = %d, sizeof(short) = %d\na1 = %d, b1 = %d, c1 = %d\na2
= %d, b2 = %d, c2 = %d (c1 and c2 should both be 80000)\n",
            sizeof(int),      sizeof(short),      a1,      b1,      c1,     
a2,      b2,      c2);

    if( c1!=80000 || c2!=80000 )
    {
        printf("Error!\n");
        return 1;
    }

    return 0;
}
----------
Output:

j@gentoo ~/tmp $ cat /proc/version
Linux version 2.6.15-gentoo-r1 (root@gentoo) (gcc version 3.3.6 (Gentoo 3.3.6,
ssp-3.3.6-1.0, pie-8.7.8)) #1 PREEMPT Wed Jan 25 11:58:26 CET 2006
j@gentoo ~/tmp $ gcc-3.3.6 -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/specs
Configured with: /var/tmp/portage/gcc-3.3.6/work/gcc-3.3.6/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3.6
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3.6
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3.6/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3.6/info
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.6/include/g++-v3
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --disable-libunwind-exceptions --disable-multilib
--disable-libgcj --enable-languages=c,c++,f77 --enable-shared
--enable-threads=posix --enable-__cxa_atexit --enable-clocale=gnu
Thread model: posix
gcc version 3.3.6 (Gentoo 3.3.6, ssp-3.3.6-1.0, pie-8.7.8)
j@gentoo ~/tmp $ gcc-3.3.6 -o error error.c -Wall
j@gentoo ~/tmp $ ./error
sizeof(int) = 4, sizeof(short) = 2
a1 = 40000, b1 = 30000, c1 = -51072
a2 = 40000, b2 = 30000, c2 = 80000 (c1 and c2 should both be 80000)
Error!
j@gentoo ~/tmp $ gcc-3.4.4 -v
Reading specs from /usr/lib/gcc/i686-pc-linux-gnu/3.4.4/specs
Configured with: /var/tmp/portage/gcc-3.4.4-r1/work/gcc-3.4.4/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.4.4
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.4.4/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/3.4.4/include/g++-v3
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --disable-libunwind-exceptions --disable-multilib
--disable-libmudflap --disable-libgcj --enable-languages=c,c++,f77
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu
Thread model: posix
gcc version 3.4.4 (Gentoo 3.4.4-r1, ssp-3.4.4-1.0, pie-8.7.8)
j@gentoo ~/tmp $ gcc-3.4.4 -o error error.c -Wall
j@gentoo ~/tmp $ ./error
sizeof(int) = 4, sizeof(short) = 2
a1 = 40000, b1 = 30000, c1 = -51072
a2 = 40000, b2 = 30000, c2 = 80000 (c1 and c2 should both be 80000)
Error!
j@gentoo ~/tmp $ gcc-4.0.2 -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /var/tmp/portage/gcc-4.0.2-r3/work/gcc-4.0.2/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/4.0.2
--includedir=/usr/lib/gcc/i686-pc-linux-gnu/4.0.2/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/4.0.2/info
--with-gxx-include-dir=/usr/lib/gcc/i686-pc-linux-gnu/4.0.2/include/g++-v4
--host=i686-pc-linux-gnu --build=i686-pc-linux-gnu --disable-altivec
--enable-nls --without-included-gettext --with-system-zlib --disable-checking
--disable-werror --disable-libunwind-exceptions --disable-multilib
--disable-libmudflap --disable-libgcj --enable-languages=c,c++,f95
--enable-shared --enable-threads=posix --enable-__cxa_atexit
--enable-clocale=gnu
Thread model: posix
gcc version 4.0.2 (Gentoo 4.0.2-r3, pie-8.7.8)
j@gentoo ~/tmp $ gcc-4.0.2 -o error error.c -Wall
j@gentoo ~/tmp $ ./error
sizeof(int) = 4, sizeof(short) = 2
a1 = 40000, b1 = 30000, c1 = -51072
a2 = 40000, b2 = 30000, c2 = 80000 (c1 and c2 should both be 80000)
Error!
j@gentoo ~/tmp $


-- 
           Summary: Incorrect result when subtracting, casting to short and
                    back to int, adding and multiplying
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: cyp561 at gmail dot com
 GCC build triplet: i686-pc-linux-gnu-gcc-3.3.6
  GCC host triplet: i686-pc-linux-gnu-gcc-3.3.6
GCC target triplet: i686-pc-linux-gnu-gcc-3.3.6


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


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

end of thread, other threads:[~2007-02-03 16:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-03-10 12:50 [Bug c/26630] New: Incorrect result when subtracting, casting to short and back to int, adding and multiplying cyp561 at gmail dot com
2006-03-10 12:57 ` [Bug middle-end/26630] [4.0 Regression] " pinskia at gcc dot gnu dot org
2006-03-10 13:52 ` rguenth at gcc dot gnu dot org
2006-03-10 13:53 ` rguenth at gcc dot gnu dot org
2006-03-10 14:31 ` rguenth at gcc dot gnu dot org
2006-03-10 16:17 ` rguenth at gcc dot gnu dot org
2006-03-10 16:25 ` patchapp at dberlin dot org
2006-03-13  9:02 ` rguenth at gcc dot gnu dot org
2006-03-13  9:09 ` rguenth at gcc dot gnu dot org
2006-06-09 10:35 ` rguenth at gcc dot gnu dot org
2007-02-03 16:23 ` gdr 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).