[Bug c/93744] New: Different results between gcc-9 and gcc-7

k.even-mendoza at imperial dot ac.uk gcc-bugzilla@gcc.gnu.org
Fri Feb 14 18:04:00 GMT 2020


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

            Bug ID: 93744
           Summary: Different results between gcc-9 and gcc-7
           Product: gcc
           Version: 9.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: k.even-mendoza at imperial dot ac.uk
  Target Milestone: ---

Seen on: 18.04.3 LTS (Bionic Beaver)
kar@kar-VirtualBox:~/example1$ gcc-9 ex1.c -o ex
kar@kar-VirtualBox:~/example1$ ./ex
0
kar@kar-VirtualBox:~/example1$ gcc-7 ex1.c -o ex
kar@kar-VirtualBox:~/example1$ ./ex
2
kar@kar-VirtualBox:~/example1$ more ex1.c
#include <stdio.h>

typedef int int32_t;

int main() {
   int a = 0;
   int32_t b = 0;
   (a > 0) * (b |= 2);
   printf("%d\n", b);
}
===
1. Output shall be 2 instead of 0.
2. GCC-8 and GCC-9 produce 0.
        gcc-9 (Ubuntu 9.2.1-17ubuntu1~18.04.1) 9.2.1 20191102
        gcc-8 (Ubuntu 8.3.0-6ubuntu1~18.04.1) 8.3.0
        gcc-7 (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
        compiled: gcc-9 ex1.c -o ex
3. Explanation:
(a > 0) * (b |= 2); ==> b here shall be set to 2, but since (a > 0) is 0, the
side effect of evaluating b is skipped.
As a result printf("%d\n", b); prints to the screen 0 instead of 2.
4. GCC-7 and LLVM (for example) produce 2. Note: You can try to compile the
code with GCC-7 or llvm to observe the behaviour where the output is 2.


More information about the Gcc-bugs mailing list