If I compile the attached file with gcc 4.1.1 with -O1 it produces no output. With -ftree-vrp (or -O2 which implies this) added it prints "it broke". The check for "result == -result" (which is true for the most negative 2's complement long) gets optimized out. Unfortunately I do not know if this is something you're allowed to rely on or not, so if this code is broken please tell me so I can tell upstream (python). Portage 2.1.1_pre2-r4 (default-linux/x86/2006.0, gcc-4.1.1/vanilla, glibc-2.4-r3, 2.6.17-gentoo-r1-m2-radeonfb i686) ================================================================= System uname: 2.6.17-gentoo-r1-m2-radeonfb i686 AMD Athlon(tm) XP 2600+ Gentoo Base System version 1.12.1 app-admin/eselect-compiler: 2.0.0_rc2-r1 dev-lang/python: 2.3.5-r2, 2.4.3-r1, 2.5_beta2 dev-python/pycrypto: 2.0.1-r5 dev-util/ccache: [Not Present] dev-util/confcache: [Not Present] sys-apps/sandbox: 1.2.18.1 sys-devel/autoconf: 2.13, 2.60 sys-devel/automake: 1.4_p6, 1.5, 1.6.3, 1.7.9-r1, 1.8.5-r3, 1.9.6-r2 sys-devel/binutils: 2.17 sys-devel/gcc-config: [Not Present] sys-devel/libtool: 1.5.22 virtual/os-headers: 2.6.11-r5 ACCEPT_KEYWORDS="x86 ~x86" AUTOCLEAN="yes" CBUILD="i686-pc-linux-gnu" CFLAGS="-ggdb -O2 -march=athlon-xp -pipe" CHOST="i686-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/eselect/compiler /etc/gconf /etc/revdep-rebuild /etc/splash /etc/terminfo /etc/texmf/web2c" CXXFLAGS="-ggdb -O2 -march=athlon-xp -pipe -fvisibility-inlines-hidden" DISTDIR="/usr/portage/distfiles" FEATURES="autoconfig candy collision-protect cvs distlocks metadata-transfer sandbox sfperms sign splitdebug strict stricter test userpriv usersandbox verify-rdepend" GENTOO_MIRRORS="http://ftp.easynet.nl/mirror/gentoo/" LANG="en_US.UTF-8" PKGDIR="/var/chroot/var/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'" PORTAGE_TMPDIR="/var/tmp" PORTDIR="/var/cvsco/gentoo-x86" PORTDIR_OVERLAY="/usr/local/portage/twisted-divmod-overlay /usr/local/portage/python2.5-overlay /usr/local/portage/setuptools-overlay /usr/local/portage/mzbot-overlay /usr/local/portage/private /usr/local/portage/bzr-overlay /usr/local/portage/pyatlantic-overlay /usr/local/portage/xgl-overlay" SYNC="cvs://marienz@cvs.gentoo.org:/var/cvsroot" USE="x86 3dnow 3dnowex 3dnowext X a52 aac alsa ansi apache2 bonobo browserplugin bzip2 cairo canvas ccache cdr crypt dbus dri emacs faad fbcon firefox flac gif glibc-omitfp glitz glut gmp gnome gpgme gstreamer gstreamer010 gtk hal imap javascript jit jpeg kdeenablefinal kdehiddenvisibility kqemu libcaca libnotify mad maildir md5sum mmx mmx2 mmxext mng mozdevelop moznocompose moznoirc moznomail mozsvg mpeg nautilus ncurses nethack network new-login nfs nls nntp no-helpbrowser no-old-linux nonfsv4 nptl nptlonly nsplugin numeric offensive ogg oggvorbis opengl pam pdf png preview-latex python qemu-fast quicktime readline real rtc softmmu spell splash sqlite sse ssl startup-notification svg symlink tetex theora truetype truetype-fonts unicode userlocales vorbis win32codecs wxwindows xcomposite xinerama xml2 xorg xv zlib elibc_glibc input_devices_evdev kernel_linux userland_GNU video_cards_radeon" Unset: CTARGET, EMERGE_DEFAULT_OPTS, INSTALL_MASK, LC_ALL, LDFLAGS, LINGUAS, MAKEOPTS, PORTAGE_RSYNC_EXTRA_OPTS
Created attachment 91579 [details] code that behaves differently with -ftree-vrp
> If I compile the attached file with gcc 4.1.1 with -O1 it produces no output. > With -ftree-vrp (or -O2 which implies this) added it prints "it broke". The > check for "result == -result" (which is true for the most negative 2's > complement long) gets optimized out. Unfortunately I do not know if this is > something you're allowed to rely on or not, so if this code is broken please > tell me so I can tell upstream (python). I'm pretty sure it's broken. -LONG_MIN overflows when LONG_MIN < -LONG_MAX, and in standard C as well as "GNU C", behaviour after overflow on signed integer operations is undefined.
I have now filed this in python's bug tracker as http://sourceforge.net/tracker/index.php?func=detail&aid=1521947&group_id=5470&atid=105470
Python upstream stopped doing this, closing.