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

Bug#350636: gcc-4.0: compiles wrong code with -O2



Package: gcc-4.0
Version: 4.0.2-8
Severity: normal

i am reading from a stream in c++. The read values differ depending on
compiler optimization level.

Note that i have a little endian machine (x86)!

take this code

inline uint32_t read_u32(istream& in) {
    uint32_t i;
    in.read((char*)&i, 4);
    return i;
}

and elsewhere it is called
...
uint32_t a = read_u32(in);
uint32_t b = read_u32(in);
uint32_t c = read_u32(in);

when i use the values later they're wrong. If i printf() them directly
after the read calls, they are ok later, same when i call a pseudo
function with each value, that justs assigns it to a global variable.
This happens only with -O2, not with -O0 or -O1.
I compared the assembler code of both versions, but could not find
relevant differences, except the call and some stack operations. Maybe
the inlining makes the difference.
Note that the bug does not occour in a simple example source, but the
code is user in a bigger context. I'm afraid this description won't help
much, though...
Note that gcc-3.4 compiles the code without problems and the results are ok.


-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Shell:  /bin/sh linked to /bin/bash
Kernel: Linux 2.6.15
Locale: LANG=de_DE, LC_CTYPE=de_DE (charmap=ISO-8859-1)

Versions of packages gcc-4.0 depends on:
ii  binutils             2.16.1cvs20060117-1 The GNU assembler, linker
and bina
ii  cpp-4.0              4.0.2-8             The GNU C preprocessor
ii  gcc-4.0-base         4.0.2-8             The GNU Compiler Collection
(base
ii  libc6                2.3.5-12            GNU C Library: Shared
libraries an
ii  libgcc1              1:4.0.2-8           GCC support library

Versions of packages gcc-4.0 recommends:
ii  libc6-dev                     2.3.5-12   GNU C Library: Development
Librari
ii  libmudflap0-dev               4.0.2-8    GCC mudflap support
libraries (dev

-- no debconf information




Reply to: