[Bug c++/20184] New: assignment error in inline function
// Postet by [EMAIL PROTECTED] // Compiler Error found: // gcc (GCC) 3.3.4 (pre 3.3.5 20040809) // under SuSE Linux kernel 2.6.8-24.10-default (i386) // // If this littel programm is compiled with the option -O2 // the assignment in the inline function data::data() is wrong. // If I remove the 'inline' the result is correct. // // Compiled with: g++ -Wall error.cpp // -> OK, printout = : // // Compiled with: g++ -Wall -O2 error.cpp // -> ERROR, printout = :b408 // // Compiled with: g++ -Wall -O2 error.cpp,, but without 'inline' // -> OK, printout = : // #include #include typedef unsigned int uint32; typedef unsigned long long uint64; class data { public: uint32 lo; uint32 hi; data ( uint32 num ); }; inline data::data ( uint32 num ) { *(uint64*)this = num; } int main() { printf("sizeof(uint32)=%d\n",sizeof(uint32)); printf("sizeof(uint64)=%d\n",sizeof(uint64)); printf("sizeof(data) =%d\n", sizeof(data)); uint32 tab[] = { 0,0,0,0,0 }; uint32 *p = tab; data D = data(*p++); printf("%08x:%08x\n",D.hi,D.lo); } -- Summary: assignment error in inline function Product: gcc Version: 3.3.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dirk at cle-mens dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20184
[Bug c++/20185] New: assignment error in inline function
// Postet by [EMAIL PROTECTED] // Compiler Error found: // gcc (GCC) 3.3.4 (pre 3.3.5 20040809) // under SuSE Linux kernel 2.6.8-24.10-default (i386) // // This Bug is a little bit different in relation to bug #20184 // // If this littel programm is compiled with the option -O2 // the assignment in the inline function was wrong. // If I remove the 'inline' the result is correct. // // Compiled with: g++ -Wall error.cpp // -> OK, printout = // // Compiled with: g++ -Wall -O2 error.cpp // -> ERROR, printout = 0804836d // // Compiled with: g++ -Wall -O2 error.cpp,, // but without 'inline' for func data::data() // -> OK, printout = // #include #include typedef unsigned int uint32; typedef unsigned long long uint64; class data { public: uint32 lo; uint32 hi; data ( uint32 num ); operator uint64 () const; }; inline data::data ( uint32 num ) { lo = num; hi = -(num<0); } inline data::operator uint64 () const { return *(uint64*)this; } int main() { printf("sizeof(uint32)=%d\n",sizeof(uint32)); printf("sizeof(uint64)=%d\n",sizeof(uint64)); printf("sizeof(data) =%d\n", sizeof(data)); uint32 tab[] = { 0,0,0,0,0 }; uint32 *p = tab; uint64 u64 = data(*p++); printf("%016llx\n",u64); } -- Summary: assignment error in inline function Product: gcc Version: 3.3.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dirk at cle-mens dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20185
[Bug c++/20184] assignment error in inline function
--- Additional Comments From dirk at cle-mens dot de 2005-02-24 10:35 --- The cast is, perhaps, illegal. But after the cast there is an assignment from uint32 to uin64. And that assignment does not work. -- What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20184
[Bug c++/20184] assignment error in inline function
--- Additional Comments From dirk at cle-mens dot de 2005-02-24 10:38 --- The reinterpret_cast solves the problem with this old code. inline data::data ( uint32 num ) { *reinterpret_cast(this) = num; } -- What|Removed |Added Status|UNCONFIRMED |RESOLVED Resolution||INVALID http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20184
[Bug c++/20185] assignment error in inline function
--- Additional Comments From dirk at cle-mens dot de 2005-02-24 12:21 --- (In reply to comment #1) > Invalid for the same reason as PR 20184... > I get the same failure if I use (little endian system) inline data::operator uint64 () const { return *reinterpret_cast(this); } or inline data::operator uint64 () const { return *reinterpret_cast(&lo); } or inline data::operator uint64 () const { return *(uint64*)&lo; } It looks like an optimation failure. The function has to copy 64 bits, but it only copies the low 32 bits into the result. For verifying this, I have changed the values of table 'tab[]' into {1,1,1,1,1} Let's have a lokk into the assembler listing movl$1, -48(%ebp) movl$0, -44(%ebp) // this is data::data(1) -> u64 pushl %edx// the hi-32-bits of u64, but edx was not set movl-48(%ebp), %eax // the low-32-bit of u64 pushl %eax pushl $.LC3 callprintf And again: This failure appears only with the combination of inline and the option -O2. --- Another question: I marked this bug 'reopen' while I'm posting this. Is this the correct way? -- What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20185
[Bug c/20189] New: assignment error in inline function
This error was similar to bug #20185, but now it is a C-Programm and not C++ // Postet by [EMAIL PROTECTED] // Compiler Error found: // gcc (GCC) 3.3.4 (pre 3.3.5 20040809) // under SuSE Linux kernel 2.6.8-24.10-default (i386) // // This Bug is a little bit different in relation to bug #20184 // // If this littel programm is compiled with the option -O2 // the assignment in the inline function was wrong. // If I remove the 'inline' of any of both functions the result is correct. // // Compiled with: gcc -Wall error.cpp // -> OK, last line of printout: 0001 // // Compiled with: gcc -Wall -O2 error.cpp // -> ERROR, last line of printout: 080482c50001 // // Compiled with: gcc -Wall -O2 error.cpp // but without 'inline' for GenData() and/or GetData() // -> OK, last line of printout: 0001 // #include #include typedef unsigned int uint32; typedef unsigned long long uint64; struct data { uint32 lo; uint32 hi; }; inline struct data * GenData ( struct data * d, uint32 num ) { d->lo = num; d->hi = -(num<0); return d; } inline uint64 GetData ( const struct data * d ) { return *(uint64*)&d->lo; } int main ( int argc, char ** argv ) { printf("sizeof(uint32)=%d\n",sizeof(uint32)); printf("sizeof(uint64)=%d\n",sizeof(uint64)); printf("sizeof(data)= %d\n",sizeof(struct data)); uint32 tab[] = { 1,1,1,1,1 }; uint32 *p = tab; struct data D; printf("D=%p lo=%p hi=%p\n",&D,&D.lo,&D.hi); uint64 u64 = GetData(GenData(&D,*p++)); printf("%016llx\n",u64); return 0; } -- Summary: assignment error in inline function Product: gcc Version: 3.3.4 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dirk at cle-mens dot de CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20189
[Bug c++/20185] assignment error in inline function
--- Additional Comments From dirk at cle-mens dot de 2005-02-24 13:56 --- (In reply to comment #3) > (In reply to comment #2) > > (In reply to comment #1) > > You are accessing an object of type "class data" through an lvalue of type > "uint64". The type "uint64" here matches none of the mentioned cases; But if you take this line: inline data::operator uint64 () const { return *(uint64*)&lo; } ... we have no class data. And please see bug #20189: same error with a C example. --- Another question again: I marked this bug 'reopen' while I'm posting this. Is this the correct way? -- What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20185
[Bug c/20189] assignment error in inline function
--- Additional Comments From dirk at cle-mens dot de 2005-02-26 10:35 --- (In reply to comment #1) > Invalid you are violating C90/C99 aliasing rules. Ok. But where is the compiler warning? The dokumentation of gcc says: (man gcc) -Wstrict-aliasing This option is only active when -fstrict-aliasing is active. It warns about code which might break the strict aliasing rules that the compiler is using for optimization. The warning does not catch all cases, but does attempt to catch the more common pit‐ falls. It is included in -Wall. But the compiler don't give any warning! And this is a compiler error in category warnings. P.S.: I have minimized the Programm that shows this error: #include #include typedef unsigned int uint32; typedef unsigned long long uint64; struct data { uint32 lo; uint32 hi; }; inline uint64 GetData ( const struct data * d ) { const uint64 *p = (uint64*)d; // <<<<<<<<<<<<<<<<<<<< return *p; } int main( int argc, char ** argv ) { struct data D = {1,2}; uint64 u64 = GetData(&D); printf("%016llx\n",u64); return 0; } -- What|Removed |Added Status|RESOLVED|UNCONFIRMED Resolution|INVALID | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20189