Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 175294 - gcc 64-bit: Adding a negative value multiplied by an unsigned int to a pointer always adds 0x100000000
Summary: gcc 64-bit: Adding a negative value multiplied by an unsigned int to a pointe...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Core system (show other bugs)
Hardware: AMD64 Linux
: High major (vote)
Assignee: Gentoo Linux bug wranglers
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-04-20 02:14 UTC by Gerry
Modified: 2007-04-20 03:12 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Gerry 2007-04-20 02:14:37 UTC
Tested gcc version 4.1.2, 64-bit.

Compile and run the following program:
--- 8< ---
#include <stdio.h>

int main (int argc, char *argv[])
{
        char *foo = (char*)1;
        unsigned int x = 1;

        printf("foo = %p\n", foo);
        foo += -1 * x;
        printf("foo = %p\n", foo);

        return 0;
}
--- 8< ---

When compiled in 32-bit mode, the output is (correctly):
--- 8< ---
foo = 0x1
foo = (nil)
--- 8< ---

However, when compiled in 64-bit mode, the output is:
--- 8< ---
foo = 0x1
foo = 0x100000000
--- 8< ---

This even happens if you add an unsigned integer multiplied by zero to the negative value (try changing 'foo += -1 * x' to 'foo += -1 + 0 * x').  Happens with or without optimization.  This can't be right ?

Workaround:  Casting x to int makes the output the same as for 32-bit.


Reproducible: Always




# emerge info
*** Deprecated use of action 'info', use '--info' instead
Portage 2.1.2.4 (default-linux/amd64/2006.1/desktop, gcc-4.1.2, glibc-2.5-r0, 2.6.19-gentoo-r5 x86_64)
=================================================================
System uname: 2.6.19-gentoo-r5 x86_64 AMD Athlon(tm) 64 X2 Dual Core Processor 4200+
Gentoo Base System release 1.12.9
Timestamp of tree: Thu, 19 Apr 2007 19:30:01 +0000
dev-java/java-config: 1.3.7, 2.0.31-r7
dev-lang/python:     2.3.5-r3, 2.4.3-r4
dev-python/pycrypto: 2.0.1-r5
sys-apps/sandbox:    1.2.17
sys-devel/autoconf:  2.13, 2.61
sys-devel/automake:  1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2, 1.10
sys-devel/binutils:  2.17
sys-devel/gcc-config: 1.3.15-r1
sys-devel/libtool:   1.5.22
virtual/os-headers:  2.6.17-r2
ACCEPT_KEYWORDS="amd64"
AUTOCLEAN="yes"
CBUILD="x86_64-pc-linux-gnu"
CFLAGS="-march=k8 -msse3 -O3 -pipe -fomit-frame-pointer"
CHOST="x86_64-pc-linux-gnu"
CONFIG_PROTECT="/etc /usr/kde/3.5/env /usr/kde/3.5/share/config /usr/kde/3.5/shutdown /usr/share/X11/xkb /usr/share/config"
CONFIG_PROTECT_MASK="/etc/env.d /etc/env.d/java/ /etc/gconf /etc/java-config/vms/ /etc/php/apache1-php5/ext-active/ /etc/php/apache2-php5/ext-active/ /etc/php/cgi-php5/ext-active/ /etc/php/cli-php5/ext-active/ /etc/revdep-rebuild /etc/terminfo"
CXXFLAGS="-march=k8 -msse3 -O3 -pipe -fomit-frame-pointer"
DISTDIR="/usr/portage/distfiles"
FEATURES="ccache distlocks metadata-transfer parallel-fetch sandbox sfperms strict userpriv usersandbox"
GENTOO_MIRRORS="ftp://trumpetti.atm.tut.fi/gentoo/ http://mirror.gentoo.no/"
LANG="nb_NO.UTF-8"
LC_ALL="nb_NO.UTF-8"
LDFLAGS=""
LINGUAS="no nb no_NO nb_NO"
MAKEOPTS="-j4"
PKGDIR="/usr/portage/packages"
PORTAGE_RSYNC_OPTS="--recursive --links --safe-links --perms --times --compress --force --whole-file --delete --delete-after --stats --timeout=180 --exclude=/distfiles --exclude=/local --exclude=/packages --filter=H_**/files/digest-*"
PORTAGE_TMPDIR="/var/tmp"
PORTDIR="/usr/portage"
PORTDIR_OVERLAY="/usr/local/portage"
SYNC="rsync://rsync.gentoo.org/gentoo-portage"
USE="16bit 7zip S3TC X Xaw3d a52 aac aalib acl acpi alsa amd64 ao aotuv apache2 applet artworkextra asf audiofile bash-completion berkdb bitmap-fonts browserplugin bzip2 cairo caps ccache cdparanoia cdr cli cracklib crypt css ctype cups curl cvs dbus dri dvd dvdr dvdread eds elf emboss emul-linux-x86 encode exif expat fam fame fat ffmpeg firefox flac flash fontconfig fortran gcj gd gdb gdbm gif gimp glitz glut glx gmp gnome gpm graphviz gstreamer gtk gtk2 gtkhtml guile gzip h323 hal icecast iconv idn ieee1394 imagemagick imap imlib imlib2 intl ipv6 jabber jack jack-tmpfs java javascript joystick jpeg json kde kdeenablefinal kdehiddenvisibility kqemu lame lcms ldap libcaca libg++ linuxthreads-tls logitech-mouse lua lzo mad matroska md5sum mhash midi mikmod ming mjpeg mmap mng mod modplug mono mozbranding mozilla moznocompose moznoirc moznomail moznoroaming mp3 mp4 mp4live mpeg mpeg2 mplayer mpm-prefork msn musepack music musicbrainz ncurses new-login nforce2 nls no nptl nptlonly nsplugin ntfs nvidia nvram objc ocaml ogg oggvorbis openal opengl openssh openssl oss pam paste64 pcre pdf perl php physfs png pnp povray ppds pppd python qemu-fast qt4 quicktime rar readline reflection rtc samba scanner sdk sdl sdl-sound session sharedext sharedmem sid slang smp sms sndfile speex spell spl sse-filters sse3 ssl startup-notification stencil-buffer subtitles subversion svg sysfs tcpd tga theora thesaurus threads tiff timidity transcode truetype truetype-fonts type1 type1-fonts unicode usb vcd videos vorbis wacom wma wma123 wxwindows x264 xanim xine xml xml2 xorg xpm xrandr xscreensaver xv xvid xvmc yv12 zip zlib" ALSA_CARDS="ali5451 als4000 atiixp atiixp-modem bt87x ca0106 cmipci emu10k1x ens1370 ens1371 es1938 es1968 fm801 hda-intel intel8x0 intel8x0m maestro3 trident usb-audio via82xx via82xx-modem ymfpci" ALSA_PCM_PLUGINS="adpcm alaw asym copy dmix dshare dsnoop empty extplug file hooks iec958 ioplug ladspa lfloat linear meter mulaw multi null plug rate route share shm softvol" ELIBC="glibc" INITNG_PLUGINS="also bash_launcher chdir chroot conflict cpout critical cron daemon dev dllaunch envparser find fstat history idleprobe initctl interactive iparser last limit logfile netprobe ngc4 pause pidfile reload renice rlparser simple_launcher stcmd stdout suid syncron syslog unneeded provide" INPUT_DEVICES="joystick keyboard mouse wacom" KERNEL="linux" LCD_DEVICES="bayrad cfontz cfontz633 glk hd44780 lb216 lcdm001 mtxorb ncurses text" LINGUAS="no nb no_NO nb_NO" USERLAND="GNU" VIDEO_CARDS="nv nvidia vesa fbdev"
Unset:  CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, PORTAGE_COMPRESS, PORTAGE_COMPRESS_FLAGS, PORTAGE_RSYNC_EXTRA_OPTS
Comment 1 Gerry 2007-04-20 03:12:05 UTC
Erm.  Now that I actually think about this, I see what happens:  The presence of the unsigned int converts the entire expression to unsigned.  Since the size of int and a pointer is different on 64-bit Linux, this results in the behavior above.  So, this isn't actually a bug.  I'll mark it as invalid.

Sorry for the noise.  I blame sleep deprivation =P