public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86
@ 2004-10-20 16:37 knutejunk at austin dot rr dot com
  2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: knutejunk at austin dot rr dot com @ 2004-10-20 16:37 UTC (permalink / raw)
  To: gcc-bugs

The problem...

The following program produces incorrect results on a Linux x86 system when 
compiled with gcc v3.4.2 (and 3.4.1) with full optimizations.  The program is 
supposed to print 0xFFFF, but instead produces random results (seems to be a 
stack corruption problem).

The source...

#include <inttypes.h>
#include <iostream>
#include <iomanip>


#define BUG

using namespace std;

class A
{
public:
   
   A () :
      valid_mask_(0x00000000FFFFFFFFull),
      size_(0x000000000000FFFFull)
   {}
      
   uint64_t calc(uint64_t value) const {
#ifdef BUG
      return valid_mask_ & (value | size_);
#else
      // This code will never expose the bug
      uint64_t tmp = valid_mask_ & (value | size_);
      return tmp;
#endif
   }

private:
   uint64_t valid_mask_;
   uint64_t size_;
   
};

uint32_t CheckStuff()
{
   A a;
   uint64_t value = a.calc(0);
#ifdef BUG
   // This code will expose the bug iff BUG is defined for calc()
   cout << "0x" << hex << setfill('0') << value << endl;
#else
   // This code will never expose the bug
   cout << "0x" << hex << value << endl;
#endif
   if(value == 0xffff) {
      return 0;
   }
   else {
      return 1;
   }
}


int main()
{
   return CheckStuff();
}

The build line...

   gcc-3.4.1 -v -W -Wall -O3 -g2 gcc_bug.cpp

The results (it's purely random, but here's an example)...

   0x8048978bfffbb68

What it should print...

   0xFFFF

Observations...

   - Take out the -O3 (-O0) and it works
   - This program works just fine on Solaris no matter how you compile it
   - This program works with gcc 3.3.X, gcc 3.2.X and (shudder) 2.95
   - Take out setfill('0') and it works
   - Keep setfill('0') in the cout statement and return a tmp for the inline 
calc() function and it works

Compiler/system info...

system type:

   Linux x86 (RedHat Enterprise 3) 

gcc -v output:

--enable-shared --with-ld=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-
linux2.4/bin/ld 

--with-as=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/as 

--with-nm=/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/nm 

--enable-languages=c,c++,java --disable-nls
Thread model: posix
gcc version 3.4.1
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/libexec/gcc/i686-pc-
linux-gnu/3.4

.1/cc1plus -quiet -v -D_GNU_SOURCE gcc_bug.cpp -quiet -dumpbase gcc_bug.cpp 

-mtune=pentiumpro -auxbase gcc_bug -g2 -O0 -W -Wall -version -o /tmp/cc82jgXc.s
ignoring nonexistent directory 

"/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/

../../../../i686-pc-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.

./../../../include/c++/3.4.1
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.

./../../../include/c++/3.4.1/i686-pc-linux-gnu
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/.

./../../../include/c++/3.4.1/backward
 /usr/local/include
 /<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/include
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/i

nclude
 /usr/include
End of search list.
GNU C++ version 3.4.1 (i686-pc-linux-gnu)
	compiled by GNU C version 3.4.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
 /<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/bin/as -V -Qy -o /tmp/
cc15JK08.o 

/tmp/cc82jgXc.s
GNU assembler version 2.13.2.1 (i686-pc-linux-gnu) using BFD version 2.13.2.1
 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/libexec/gcc/i686-pc-
linux-gnu/3.4

.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -rpath 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib /usr/lib/crt1.o 

/usr/lib/crti.o 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/c

rtbegin.o 

-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1 

-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1

/../../../../i686-pc-linux-gnu/lib 

-L/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-
linux-gnu/3.4.1

/../../.. /tmp/cc15JK08.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc 

/<blah>/gnu-gcc-3.4.1-binutils-2.13.2.1/i686-pc-linux2.4/lib/gcc/i686-pc-linux-
gnu/3.4.1/c

rtend.o /usr/lib/crtn.o

-- 
           Summary: setfill coupled with inline function: incorrect results
                    on Linux x86
           Product: gcc
           Version: 3.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: knutejunk at austin dot rr dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18084


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2004-10-31  1:57 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-20 16:37 [Bug c++/18084] New: setfill coupled with inline function: incorrect results on Linux x86 knutejunk at austin dot rr dot com
2004-10-20 17:09 ` [Bug rtl-optimization/18084] [3.4 only]setfill " pinskia at gcc dot gnu dot org
2004-10-20 18:00 ` bangerth at dealii dot org
2004-10-25 14:24 ` bangerth at dealii dot org
2004-10-25 14:57 ` [Bug rtl-optimization/18084] [3.4 regression]setfill " pinskia at gcc dot gnu dot org
2004-10-30 22:58 ` cvs-commit at gcc dot gnu dot org
2004-10-30 23:06 ` pinskia at gcc dot gnu dot org
2004-10-31  1:57 ` cvs-commit at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).