public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47964] New: logical || returns false result, optimization level 02 or 03
@ 2011-03-03  8:40 rob.bob.301 at hotmail dot com
  2011-03-03  9:11 ` [Bug c++/47964] " jakub at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: rob.bob.301 at hotmail dot com @ 2011-03-03  8:40 UTC (permalink / raw)
  To: gcc-bugs

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: unassigned@gcc.gnu.org
        ReportedBy: rob.bob.301@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: 1000001
 l: 1
 r: 0
 is: 0
-----------------------


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

end of thread, other threads:[~2011-09-23 21:32 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-03  8:40 [Bug c++/47964] New: logical || returns false result, optimization level 02 or 03 rob.bob.301 at hotmail dot com
2011-03-03  9:11 ` [Bug c++/47964] " jakub at gcc dot gnu.org
2011-03-03 10:13 ` rguenth at gcc dot gnu.org
2011-03-03 10:17 ` jakub at gcc dot gnu.org
2011-03-03 18:26 ` rob.bob.301 at hotmail dot com
2011-03-03 19:04 ` manu at gcc dot gnu.org
2011-03-05 21:28 ` rob.bob.301 at hotmail dot com
2011-03-29 17:00 ` redi at gcc dot gnu.org
2011-09-23 21:33 ` paolo.carlini at oracle dot com

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).