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

            Bug ID: 91445
           Summary: After memset, logical && operator produces false
                    result, optimization level >=O1
           Product: gcc
           Version: 9.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: frishy at gmail dot com
  Target Milestone: ---

Produces expected result in 8.3.0.  Appears to be a regression in 9.2.0. 
Running on CentOS 7.6.1810.  Commands we use to build gcc are below:

mkdir gcc-build; cd gcc-build
../../downloads/gcc-${GCC_VERSION}/configure --prefix=${OUTPUT_DIR}
--disable-multilib
make -j32
make install

Two examples show similar behavior.  In test1.cpp, you can see (_boolVal ==
rhs._boolVal) evaluates to true.  (_intVal == rhs._intVal) evaluates to true. 
However, ((_intVal == rhs._intVal) && (_boolVal == rhs._boolVal)) evaluates to
false when compiling with O1 optimization.  The last expression evaluates to
true, as expected, with O0.  Also, it evaluates to true with O1 optimization in
gcc 8.3.0

In test2.cpp, there are two functions, IsEqual1() and IsEqual2().  In it the
order of the expressions are different, but the expressions are exactly the
same otherwise.  With optimization level O0, they both produce the same,
expected result, true.  With optimization level O1, they produce different
results (one true and one false).  In 8.3.0, they both produce the same result,
regardless of the optimization level.

Compile and runtime outputs for test1.cpp and test2.cpp are below:

[root@5fa926449e49 tmp]# /opt/blackedge/vendor/bin/g++ --version
g++ (GCC) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

[root@5fa926449e49 tmp]# /opt/blackedge/vendor/bin/g++ test1.cpp -Wall -Wextra
-O1 -o test1.o

[root@5fa926449e49 tmp]# ./test1.o
1
1
0
0

[root@5fa926449e49 tmp]# /opt/blackedge/vendor/bin/g++ test2.cpp -Wall -Wextra
-O1 -o test2.o

[root@5fa926449e49 tmp]# ./test2.o
0
1


Expected output for both test1.cpp and test2.cpp are below (compiled using O0
in this case, though using gcc 8.3.0 with any optimization level produces the
expected output as well):

[root@5fa926449e49 tmp]# /opt/blackedge/vendor/bin/g++ test1.cpp -Wall -Wextra
-O0 -o test1.o
[root@5fa926449e49 tmp]# ./test1.o
1
1
1
1
[root@5fa926449e49 tmp]# /opt/blackedge/vendor/bin/g++ test2.cpp -Wall -Wextra
-O0 -o test2.o
[root@5fa926449e49 tmp]# ./test2.o
1
1

Reply via email to