This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/34459] New: incorrect code when compiled with optimization (-O1)
- From: "noblige at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 14 Dec 2007 06:29:22 -0000
- Subject: [Bug c++/34459] New: incorrect code when compiled with optimization (-O1)
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The G++ produces invalid code for snippet bellow when compiled with -O1.
Using built-in specs.
Target: i486-linux
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-checking=release i486-linux
Thread model: posix
gcc version 4.1.2 20060613 (prerelease) (Debian 4.1.1-5)
Program output:
a=content: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
f=content: 14 90 90 1 30 0 74 9 10 0 80 9 10 0 1 0 0 0 c0 2d e 90 f0 2 30
Expected behavior would be to have both variables initialized to zeroes - this
is OK in non-optimized build (-O0).
Here's the source snippet:
#include <iostream>
#include <sstream>
using std::string;
struct ip_addr {
string to_string() const {
std::stringstream os;
os << "content: ";
for (size_t i = 0; i < sizeof(addr_); ++i) {
os << std::hex
<< (short(addr_[i]) & 0xff) << " ";
}
return os.str();
}
ip_addr() {
memset(&addr_, 0, sizeof(addr_));
}
private:
char addr_[25];
};
struct foo {
foo(ip_addr const & a) : remote_(a) {
rebind(remote_);
}
void rebind(ip_addr const & to) {
remote_ = to;
}
ip_addr remote_;
};
int main()
{
ip_addr a;
std::cout << "a=" << a.to_string() << std::endl;
foo f(a);
std::cout << "f=" << f.remote_.to_string() << std::endl;
}
--
Summary: incorrect code when compiled with optimization (-O1)
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: noblige at gmail dot com
GCC build triplet: gcc version 4.1.2 20060613 (prerelease) (Debian 4.1.1-5)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34459