[Bug c++/47964] New: logical || returns false result, optimization level 02 or 03

2011-03-03 Thread rob.bob.301 at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

   Summary: logical || returns false result, optimization level 02
or 03
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: critical
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: rob.bob@hotmail.com


A very simple expression 
return a < C || ~a < C;
 produces incorrect result if compiled with optimization level O2 or O3.
"a" is an unsigned, "C" is const unsigned,
gcc (SUSE Linux) 4.5.0 20100604 [gcc-4_5-branch revision 160292].
Optimization levels O1 and O0 work fine.

Note that all works fine if compiled with O2 or O3 and gcc version
gcc (SUSE Linux) 4.3.2 [gcc-4_3-branch revision 141291]

Valgrind reports no errors. Please read the few lines of code below.
Please read cout statements, and the printout. They demonstrate the
problem. t_mdb_id is unsigned (typedef).
You will see that the same logical || in cout also produces incorrect
results.
The function is in anonymous namespace.
When I copy the function to a simple
project the problem disappears. 
Note that removing "inline" changes the result to the correct 
value if cout statements stay as they are, but does not change the 
result if complied with cout statements commented out.


inline bool is_valid( t_mdb_id a0 )
{
std::cout << " a0: " << a0 << " ~a0: " << (~a0) << " cv: " <<
exampler::CONST_VOID << std::endl;
std::cout << " l: " << (a0 < exampler::CONST_VOID) << std::endl;
std::cout << " r: " << (~a0 < exampler::CONST_VOID) << std::endl;
std::cout << " is: " << ((a0 < exampler::CONST_VOID) || (~a0 <
exampler::CONST_VOID)) << std::endl;
  return a0 < exampler::CONST_VOID || ~a0 < exampler::CONST_VOID;
}


---
 a0: 1 ~a0: 4294967294 cv: 101
 l: 1
 r: 0
 is: 0
---


[Bug c++/47964] logical || returns false result, optimization level 02 or 03

2011-03-03 Thread rob.bob.301 at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

--- Comment #4 from rob.bob.301 at hotmail dot com 2011-03-03 18:26:00 UTC ---
(In reply to comment #1)
> You need to provide self-contained testcase, this is not self-contained.

Thank you for running your simple experiment. Unfortunately, all my attempts to
create a simple self-contained test have failed. Of course, during this
process, I did play with exactly the same code you did. 
I have been aware of this problem for several months. I decided to file a bug
without a test because the problem appears to be critical and I hope somebody
who knows the optimization code might spot the issue.
All I can add is that my project is about 110k lines of code, the function in
question is in a .cpp file of about 560 lines. But I doubt it helps very much.

S.


[Bug c++/47964] logical || returns false result, optimization level 02 or 03

2011-03-05 Thread rob.bob.301 at hotmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

--- Comment #6 from rob.bob.301 at hotmail dot com 2011-03-05 21:28:26 UTC ---
This bug is not present in 
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]