This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/16590] New: Incorrect execution when compiling with -O2
- From: "m dot galante at centrosistemi dot it" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 16 Jul 2004 14:56:35 -0000
- Subject: [Bug c++/16590] New: Incorrect execution when compiling with -O2
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
I have reduced the testcase to a small file that only includes <cassert> in
order to show where the execution fails. The assert in main() should never
fail, but it fails if you compile with:
g++ -O2 bug.cpp
The assert does not fail if you compile with one of the following:
g++ -O0 bug.cpp
g++ -O1 bug.cpp
g++ -O2 -DWORKAROUND bug.cpp
This happens with gcc 3.4.1 (mingw special) on Windows XP and gcc 3.4.0 on SCO
OPENSERVER 5.0.6, but NOT with gcc 3.4.0 on SUN Solaris; perhaps a bug in
generating code for INTEL X86?
Output of "gcc -v" for gcc 3.4.1/MinGW on Windows XP (assert FAILS):
Reading specs from c:/mingw/bin/../lib/gcc/mingw32/3.4.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --
host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --
enable-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-
shared --enable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-
x --enable-java-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-
hash-synchronization --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.1 (mingw special)
Output of "gcc -v" for gcc 3.4.0 on SCO OpenServer (assert FAILS):
Reading specs from /home/local/gcc-3.4.0/bin/../lib/gcc/i686-pc-
sco3.2v5.0.6/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --with-gnu-as --prefix=/usr/local/gcc-
3.4.0
Thread model: single
gcc version 3.4.0
Output of "gcc -v" for gcc 3.4.0 on SUN Solaris (assert does NOT FAIL):
Reading specs from /usr/local/gcc-3.4.0/lib/gcc/sparc-sun-
solaris2.8/3.4.0/specs
Configured with: ../gcc-3.4.0/configure --disable-shared --
prefix=/usr/local/gcc-3.4.0
Thread model: posix
gcc version 3.4.0
// -------------------- bug.cpp ------------------------
#include <cassert>
typedef char* iterator_type;
struct queue;
struct iterator
{
#ifdef WORKAROUND
iterator_type volatile pos_;
#else
iterator_type pos_;
#endif
queue const* queue_;
iterator(queue const* queue, iterator_type pos) : pos_(pos), queue_(queue) {}
iterator& operator--();
};
struct queue
{
iterator_type const first_, last_;
iterator_type put_, get_;
queue(iterator_type first, iterator_type last)
: first_(first), last_(last), put_(first), get_(first)
{}
iterator pbegin() const { return iterator(this, put_); }
iterator pend() const { iterator end(this, get_); return --end; }
};
inline iterator& iterator::operator--()
{
if(pos_ == queue_->first_) pos_ = queue_->last_;
--pos_;
return *this;
}
int main()
{
char mem[4+1];
queue buf(mem, mem+4+1);
assert(buf.pend().pos_ == buf.pbegin().pos_+4);
return 0;
}
--
Summary: Incorrect execution when compiling with -O2
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: m dot galante at centrosistemi dot it
CC: gcc-bugs at gcc dot gnu dot org
GCC host triplet: mingw32 / i686-pc-sco3.2v5.0.6
GCC target triplet: mingw32 / i686-pc-sco3.2v5.0.6
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16590