public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rob.bob.301 at hotmail dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/47964] New: logical || returns false result, optimization level 02 or 03 Date: Thu, 03 Mar 2011 08:40:00 -0000 [thread overview] Message-ID: <bug-47964-4@http.gcc.gnu.org/bugzilla/> (raw) 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 -----------------------
next reply other threads:[~2011-03-03 8:40 UTC|newest] Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-03-03 8:40 rob.bob.301 at hotmail dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-47964-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).