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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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 ` jakub at gcc dot gnu.org
  2011-03-03 10:13 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-03-03  9:11 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-03-03 09:11:43 UTC ---
You need to provide self-contained testcase, this is not self-contained.


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-03-03 10:13 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2011.03.03 10:13:18
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-03-03 10:13:18 UTC ---
Self-contained as in, compilable and runnable and showing the failure.


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2011-03-03 10:17 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2011-03-03 10:17:45 UTC ---
bool foo (unsigned int a0)
{
  return a0 < 1000001U || ~a0 < 1000001U;
}

int
main ()
{
  __builtin_printf ("%d\n", (int) foo (1));
}

certainly prints one, not 0.


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (2 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rob.bob.301 at hotmail dot com @ 2011-03-03 18:26 UTC (permalink / raw)
  To: gcc-bugs

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.


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (3 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: manu at gcc dot gnu.org @ 2011-03-03 19:04 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org

--- Comment #5 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-03-03 19:03:47 UTC ---
(In reply to comment #4)
> Unfortunately, all my attempts to
> create a simple self-contained test have failed. Of course, during this

The advice here may help you:

http://gcc.gnu.org/bugs/minimize.html


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (4 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: rob.bob.301 at hotmail dot com @ 2011-03-05 21:28 UTC (permalink / raw)
  To: gcc-bugs

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]


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (5 preceding siblings ...)
  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
  7 siblings, 0 replies; 9+ messages in thread
From: redi at gcc dot gnu.org @ 2011-03-29 17:00 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

--- Comment #7 from Jonathan Wakely <redi at gcc dot gnu.org> 2011-03-29 16:51:47 UTC ---
Is this still present on the 4.5 branch, or later releases?

(In reply to comment #4)
> (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.

It doesn't necessarily have to be simple (although that's preferable) but
without a testcase of some kind this will not get looked at.


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

* [Bug c++/47964] logical || returns false result, optimization level 02 or 03
  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
                   ` (6 preceding siblings ...)
  2011-03-29 17:00 ` redi at gcc dot gnu.org
@ 2011-09-23 21:33 ` paolo.carlini at oracle dot com
  7 siblings, 0 replies; 9+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-09-23 21:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47964

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |RESOLVED
         Resolution|                            |INVALID

--- Comment #8 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-09-23 21:31:24 UTC ---
Feedback not forthcoming.


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