From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 82570384D982; Sat, 19 Nov 2022 01:27:02 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82570384D982 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668821222; bh=XjC8ItNCTSzLDUXaCc8D9LqwO5J+IDVG8IuZ2V2O/go=; h=From:To:Subject:Date:From; b=KQOvE8gdQByIf19HNjMdwmcXVbxg9OtGheDYAFcNU5NW8YdHTDWQaIEPZ+E50+BY6 etwMag407hYAjJ+ADVs8UaYZ/6+2meVLGzwVGc3Lif6TJNHZi5gXd5mdlzEBw1AMfg MFFUCPRfO+5fsJA7sotiPXPwet0pPy8XvpFlK30w= From: "pokechu022+gccbugzilla at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107755] New: ICE: in fold_convert_loc, at fold-const.c:2435, with -Wlogical-op, implicit user-defined conversion operator, template function, logical operator, and conditional operator Date: Sat, 19 Nov 2022 01:27:01 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 10.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: pokechu022+gccbugzilla at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107755 Bug ID: 107755 Summary: ICE: in fold_convert_loc, at fold-const.c:2435, with -Wlogical-op, implicit user-defined conversion operator, template function, logical operator, and conditional operator Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: pokechu022+gccbugzilla at gmail dot com Target Milestone: --- Created attachment 53928 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D53928&action=3Dedit failing code using (!false && (false ? a : b)) A combination of -Wlogical-op, a template function, an implicit user-defined conversion operator, a logical AND or OR operator, and a ternary conditional operator results in an ICE. ``` $ gcc-10 -Wlogical-op -save-temps test.cpp test.cpp: In function =E2=80=98bool Bar()=E2=80=99: test.cpp:12:35: internal compiler error: in fold_convert_loc, at fold-const.c:2435 12 | return (!false && (false ? a : b)); | ^ 0x7f08a2bf4082 __libc_start_main ../csu/libc-start.c:308 Please submit a full bug report, with preprocessed source if appropriate. Please include the complete backtrace with any bug report. See for instructions. $ gcc-10 -v Using built-in specs. COLLECT_GCC=3Dgcc-10 COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/10/lto-wrapper OFFLOAD_TARGET_NAMES=3Dnvptx-none:amdgcn-amdhsa:hsa OFFLOAD_TARGET_DEFAULT=3D1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 10.3.0-1ubuntu1~20.04' --with-bugurl=3Dfile:///usr/share/doc/gcc-10/README.= Bugs --enable-languages=3Dc,ada,c++,go,brig,d,fortran,objc,obj-c++,m2 --prefix= =3D/usr --with-gcc-major-version-only --program-suffix=3D-10 --program-prefix=3Dx86_64-linux-gnu- --enable-shared --enable-linker-build-= id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --libdir=3D/usr/lib --enable-nls --enable-bootstrap --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --with-default-libstdcxx-abi=3Dnew --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-= zlib --enable-libphobos-checking=3Drelease --with-target-system-zlib=3Dauto --enable-objc-gc=3Dauto --enable-multiarch --disable-werror --with-arch-32= =3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-offload-targets=3Dnvptx-none=3D/build/gcc-10-S4I5Pr/gcc-10-10.3.0/= debian/tmp-nvptx/usr,amdgcn-amdhsa=3D/build/gcc-10-S4I5Pr/gcc-10-10.3.0/deb= ian/tmp-gcn/usr,hsa --without-cuda-driver --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu --with-build-config=3Dbootstrap-lto-lean --enable-link-mutex Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 10.3.0 (Ubuntu 10.3.0-1ubuntu1~20.04) ``` I tested at https://godbolt.org/z/574Wq1Ws5 and found that this issue was n= ot present in 4.7.4 and is present in 4.8.1, 12.2, and trunk. Here's the outpu= t on trunk from compiler explorer, for convenience: ``` Using built-in specs. COLLECT_GCC=3D/opt/compiler-explorer/gcc-snapshot/bin/g++ Target: x86_64-linux-gnu Configured with: ../gcc-trunk-20221118/configure --prefix=3D/opt/compiler-explorer/gcc-build/staging --build=3Dx86_64-linux-= gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu --disable-bootstrap --enable-multiarch --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --enable-clocale=3Dgnu --enable-languages=3Dc,c++,fortran,ada,objc,obj-c++,d --enable-ld=3Dyes --enable-gold=3Dyes --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --enable-linker-build-id --enable-lto --enable-plugins --enable-threads=3Dp= osix --with-pkgversion=3DCompiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d32= 2d8a793f411dd-binutils-2.38 --enable-libstdcxx-backtrace=3Dyes Thread model: posix Supported LTO compression algorithms: zlib gcc version 13.0.0 20221117 (experimental) (Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binut= ils-2.38)=20 COLLECT_GCC_OPTIONS=3D'-fdiagnostics-color=3Dalways' '-g' '-o' '/app/output= .s' '-masm=3Dintel' '-S' '-Wlogical-op' '-v' '-shared-libgcc' '-mtune=3Dgeneric' '-march=3Dx86-64' '-dumpdir' '/app/' /opt/compiler-explorer/gcc-trunk-20221118/bin/../libexec/gcc/x86_64-linux-g= nu/13.0.0/cc1plus -quiet -v -imultiarch x86_64-linux-gnu -iprefix /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/ -D_GNU_SOURCE -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase= -ext .cpp -masm=3Dintel -mtune=3Dgeneric -march=3Dx86-64 -g -Wlogical-op -version -fdiagnostics-color=3Dalways -o /app/output.s GNU C++17 (Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binut= ils-2.38) version 13.0.0 20221117 (experimental) (x86_64-linux-gnu) compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 4.= 1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=3D30 --param ggc-min-heapsize=3D4096 ignoring nonexistent directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/= 13.0.0/../../../../x86_64-linux-gnu/include" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/../../../../include/c++/13.0.0" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/x86_64-linux-gnu" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/../../../../include/c++/13.0.0/backward" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/include" ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/include-fixed/x86_64-linux-gnu" ignoring duplicate directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/include-fixed" ignoring nonexistent directory "/opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../lib/gcc/x86= _64-linux-gnu/13.0.0/../../../../x86_64-linux-gnu/include" #include "..." search starts here: #include <...> search starts here: /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/../../../../include/c++/13.0.0 /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/../../../../include/c++/13.0.0/x86_64-linux-gnu /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/../../../../include/c++/13.0.0/backward /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/include /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/include-fixed/x86_64-linux-gnu /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/x86_64-linux-gnu/1= 3.0.0/include-fixed /usr/local/include /opt/compiler-explorer/gcc-trunk-20221118/bin/../lib/gcc/../../include /usr/include/x86_64-linux-gnu /usr/include End of search list. GNU C++17 (Compiler-Explorer-Build-gcc-7b3b2f50953c5143d4b14b59d322d8a793f411dd-binut= ils-2.38) version 13.0.0 20221117 (experimental) (x86_64-linux-gnu) compiled by GNU C version 9.4.0, GMP version 6.2.1, MPFR version 4.= 1.0, MPC version 1.2.1, isl version isl-0.24-GMP GGC heuristics: --param ggc-min-expand=3D30 --param ggc-min-heapsize=3D4096 Compiler executable checksum: d17bd4a13b030ab0955e667094fe2b0e : In function 'bool Bar()': :12:35: internal compiler error: in fold_convert_loc, at fold-const.cc:2495 12 | return (!false && (false ? a : b)); | ^ 0x23ac0ce internal_error(char const*, ...) ???:0 0xaaf7fc fancy_abort(char const*, int, char const*) ???:0 0xfb89a1 fold_binary_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ???:0 0xfc093d fold_build2_loc(unsigned int, tree_code, tree_node*, tree_node*, tree_node*) ???:0 0xfcc891 build_range_check(unsigned int, tree_node*, tree_node*, int, tree_node*, tree_node*) ???:0 0xfcc857 build_range_check(unsigned int, tree_node*, tree_node*, int, tree_node*, tree_node*) ???:0 0xdfe839 warn_logical_operator(unsigned int, tree_code, tree_node*, tree_co= de, tree_node*, tree_code, tree_node*) ???:0 0xae1b92 build_new_op(op_location_t const&, tree_code, int, tree_node*, tree_node*, tree_node*, tree_node*, tree_node**, int) ???:0 0xd42852 build_x_binary_op(op_location_t const&, tree_code, tree_node*, tree_code, tree_node*, tree_code, tree_node*, tree_node**, int) ???:0 0xc8e277 c_parse_file() ???:0 0xdd7a09 c_common_parse_file() ???:0 Please submit a full bug report, with preprocessed source (by using -freport-bug). Please include the complete backtrace with any bug report. See for instructions. Compiler returned: 1 ``` A few variants that also trigger the same ICE. The first operand to the ter= nary operator can be anything (false, true, a bool parameter, etc.). The logical operator can be either || or &&, and the ternary operator can be on either = side of it. The other operand of the logical operator can be a bool parameter or !false or !true (but using false or true without a NOT avoids the ICE, prob= ably due to a separate optimisation). The function containing the ternary operat= or must be a template, even if the template parameters are not used. The second and third operands to the ternary operator must be of different types and must use an implicit user-defined conversion operator. In my exam= ple, I compared a bool to a type implicitly convertible to bool, but this also happens with int + implicit conversion to bool, int + implicit conversion to int, two distinct types implicitly convertible to bool, two types implicitly convertible to int, etc. It does not happen if the same type (including template parameters) is used for both operands, nor if no user-defined conversion operator is involved (e.g. int + bool). This issue was originally found at https://github.com/dolphin-emu/dolphin/pull/11289.=