public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/96369] New: Wrong evaluation order of || operator
@ 2020-07-29 14:14 frank_yzg at outlook dot com
  2020-07-29 15:41 ` [Bug tree-optimization/96369] " glisse at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: frank_yzg at outlook dot com @ 2020-07-29 14:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96369

            Bug ID: 96369
           Summary: Wrong evaluation order of || operator
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frank_yzg at outlook dot com
  Target Milestone: ---

The following code snippet:

#include <stdio.h> 
int main(void)
{
    const long ONE = 1L;
    long y = 0L;
    long x = ((long) (ONE || (y = 1L)) % 8L);
    printf("x = %ld, y = %ld\n", x, y);    // with -O1/-O2/-O3 flag, gcc prints
x = 1, y = 1 where clang prints x = 1, y = 0
}

> $ /usr/gcc-trunk/bin/gcc -O2 -Wall -Wextra bug.c -o a.out
> $ ./a.out
> x = 1, y = 1

If the first operand of a logical-OR operation has a nonzero value, the second
operand is not evaluated. Therefore (y = 1L) should not be evaluated. It should
print y = 0 instead of y = 1.

This bug appears in GCC-4.8, GCC-6.4.0, GCC-7.5.0, GCC-8.4.0, GCC-9.3.0,
GCC-10.2.0 and GCC-11.0.0 20200501.

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

end of thread, other threads:[~2021-03-17 11:15 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-29 14:14 [Bug c/96369] New: Wrong evaluation order of || operator frank_yzg at outlook dot com
2020-07-29 15:41 ` [Bug tree-optimization/96369] " glisse at gcc dot gnu.org
2020-07-30  5:57 ` [Bug c/96369] " rguenth at gcc dot gnu.org
2020-07-31  0:21 ` [Bug tree-optimization/96369] [8/9/10/11 Regression] " jsm28 at gcc dot gnu.org
2020-07-31  6:39 ` rguenth at gcc dot gnu.org
2020-07-31 10:12 ` cvs-commit at gcc dot gnu.org
2020-07-31 10:12 ` [Bug tree-optimization/96369] [8/9/10 " rguenth at gcc dot gnu.org
2020-07-31 10:12 ` rguenth at gcc dot gnu.org
2020-09-11 12:11 ` cvs-commit at gcc dot gnu.org
2020-12-02 13:23 ` [Bug tree-optimization/96369] [8/9 " cvs-commit at gcc dot gnu.org
2021-03-17 11:14 ` [Bug tree-optimization/96369] [8 " cvs-commit at gcc dot gnu.org
2021-03-17 11:15 ` rguenth at gcc dot gnu.org

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