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

Bug#501404: g++-4.3: Optimization changes output



Package: g++-4.3
Version: 4.3.2-1
Severity: important



Compile the following code with g++:

===

#include <cmath>
#include <iostream>

struct TimeStruct
{
    int millisecond;
    int second;
};


void fillTimeStruct(double time, TimeStruct& gt)
{

    gt.millisecond = std::fmod(time, 1000.0);

    time /= 1000.0;
    
    // This is a safe cast.
    int remainder = static_cast<int>(std::fmod(time, 86400.0));
   
    gt.second = remainder % 60;
}

int main()
{
	double d = 3.0935415006117e+23;
	TimeStruct gt;
	fillTimeStruct(d, gt);
	std::cout << gt.millisecond << std::endl;
	std::cout << gt.second << std::endl;
}

===

With -O2 the output is:
584
52

With -O0 the output is (correct):
584
0

Other Debian g++ versions (e.g. 4.0 and 4.1) don't have this problem, 
neither do other distros.


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

Kernel: Linux 2.6.26-1-486
Locale: LANG=de_DE.UTF-8, LC_CTYPE=de_DE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages g++-4.3 depends on:
ii  gcc-4.3                   4.3.2-1        The GNU C compiler
ii  gcc-4.3-base              4.3.2-1        The GNU Compiler Collection (base 
ii  libc6                     2.7-13         GNU C Library: Shared libraries
ii  libgmp3c2                 2:4.2.2+dfsg-3 Multiprecision arithmetic library
ii  libmpfr1ldbl              2.3.1.dfsg.1-2 multiple precision floating-point 
ii  libstdc++6-4.3-dev        4.3.2-1        The GNU Standard C++ Library v3 (d

g++-4.3 recommends no packages.

Versions of packages g++-4.3 suggests:
pn  g++-4.3-multilib              <none>     (no description available)
pn  gcc-4.3-doc                   <none>     (no description available)
pn  libstdc++6-4.3-dbg            <none>     (no description available)

-- no debconf information



Reply to: