Comment 3 for bug 1791425

Revision history for this message
In , Remi-ducceschi (remi-ducceschi) wrote :

Created attachment 44538
preprocessed file of a small test case for the constexpr crash

Hello,

I've created a small test case that produces a compiler crash. You can find attached the preprocessed file (main.ii) made by running the following command, with `G++ 7.3.1 20180303 (Red Hat 7.3.1-5)` on a CentOS 7 (with the devtoolset-7 installed), but it seems to exist on the last version too (see https://wandbox.org/permlink/zGZWdHIrRNJKfh5Z):

g++ -O3 -Wall -Wextra -o main -save-temps -v main.cpp

I give at the end of the mail the output of the command.

You can find a run on the last G++ version (9) here: https://wandbox.org/permlink/zGZWdHIrRNJKfh5Z

-----------------------
Here is the code:

#include <iostream>
struct Bugged {
    double x; bool isfreex; bool isfreey;
    constexpr bool operator==(const Bugged& other) const noexcept {
        return (x == other.x) && (isfreex == other.isfreex) && (isfreey == other.isfreey);
    }
};
int main () {
    std::cout << std::boolalpha << (Bugged{} == Bugged{}) << std::endl;
    return 0;
}
-----------------------

The bug only appears if I enable optimization (-02 or -O3), I guess constexpr optimization is not done otherwise.

The problem occurs on the operator==(). The compiler crashes because it can't compute the result of the constexpr. Note that if I change the struct so it doesn't hold booleans, but double instead, or if I remove any of the parentheses term in the operator== function, it doesn't crash.

Note that this code compiles on MSVC 2017 and on clang 6 (though it doesn't mean anything).

I search for a similar bug report but didn't find anything, sorry if this is a duplicate.

-----------------------
Below the output of the command:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-7/root/usr --mandir=/opt/rh/devtoolset-7/root/usr/share/man --infodir=/opt/rh/devtoolset-7/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --enable-plugin --with-linker-hash-style=gnu --enable-initfini-array --with-default-libstdcxx-abi=gcc4-compatible --with-isl=/builddir/build/BUILD/gcc-7.3.1-20180303/obj-x86_64-redhat-linux/isl-install --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 7.3.1 20180303 (Red Hat 7.3.1-5) (GCC)
COLLECT_GCC_OPTIONS='-O3' '-Wall' '-Wextra' '-o' 'main' '-save-temps' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -E -quiet -v -D_GNU_SOURCE main.cpp -mtune=generic -march=x86-64 -Wall -Wextra -O3 -fpch-preprocess -o main.ii
ignoring nonexistent directory "/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/include-fixed"
ignoring nonexistent directory "/opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../x86_64-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7
 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/x86_64-redhat-linux
 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/../../../../include/c++/7/backward
 /opt/rh/devtoolset-7/root/usr/lib/gcc/x86_64-redhat-linux/7/include
 /usr/local/include
 /opt/rh/devtoolset-7/root/usr/include
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-O3' '-Wall' '-Wextra' '-o' 'main' '-save-temps' '-v' '-shared-libgcc' '-mtune=generic' '-march=x86-64'
 /opt/rh/devtoolset-7/root/usr/libexec/gcc/x86_64-redhat-linux/7/cc1plus -fpreprocessed main.ii -quiet -dumpbase main.cpp -mtune=generic -march=x86-64 -auxbase main -O3 -Wall -Wextra -version -o main.s
GNU C++14 (GCC) version 7.3.1 20180303 (Red Hat 7.3.1-5) (x86_64-redhat-linux)
 compiled by GNU C version 7.3.1 20180303 (Red Hat 7.3.1-5), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++14 (GCC) version 7.3.1 20180303 (Red Hat 7.3.1-5) (x86_64-redhat-linux)
 compiled by GNU C version 7.3.1 20180303 (Red Hat 7.3.1-5), GMP version 6.0.0, MPFR version 3.1.1, MPC version 1.0.1, isl version isl-0.16.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: d120f4d100e8519a845aa191e71919b8
main.cpp: In function ‘int main()’:
main.cpp:23:43: in constexpr expansion of ‘Bugged{}.Bugged::operator==(Bugged{})’
main.cpp:23:54: internal compiler error: in cxx_eval_bit_field_ref, at cp/constexpr.c:2565
  std::cout << std::boolalpha << (Bugged{} == Bugged{}) << std::endl;
                                                      ^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccVplEXc.out file, please attach this to your bugreport.