[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#547429: gcc: incorrect code with optimisation



Package: gcc
Version: 4:4.3.3-9
Severity: normal


The code below gives incorrect result for the subtraction when optimisation is used.

Without optimisation, the difference is 2.
With optimisation, the difference is 0.


#include <stdio.h>
#include <limits.h>

int main(void)
{
  int ii;
  float ftest;

  ii=INT_MAX-1;
  ftest=(float)ii;
  printf("%d %.11g %.11g\n",ii,ftest,ftest-ii);

  return 0;
}

Tested on both gcc 4.3 and 4.4, same error.



-- System Information:
Debian Release: squeeze/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)

Kernel: Linux 2.6.24
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages gcc depends on:
ii  cpp                           4:4.3.3-9  The GNU C preprocessor (cpp)
ii  gcc-4.3                       4.3.4-2    The GNU C compiler

Versions of packages gcc recommends:
ii  libc6-dev [libc-dev]          2.9-26     GNU C Library: Development Librari

Versions of packages gcc suggests:
ii  autoconf               2.64-2            automatic configure script builder
pn  automake1.9            <none>            (no description available)
ii  bison                  1:2.4.1.dfsg-3    A parser generator that is compati
ii  flex                   2.5.35-8          A fast lexical analyzer generator.
ii  gcc-doc                5:2               documentation for the GNU compiler
pn  gcc-multilib           <none>            (no description available)
ii  gdb                    6.8.50.20090628-4 The GNU Debugger
ii  libtool                2.2.6a-4          Generic library support script
ii  make                   3.81-6            An utility for Directing compilati
ii  manpages-dev           3.22-1            Manual pages about using GNU/Linux

-- no debconf information



Reply to: