From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 6F8FC3858294; Wed, 31 Jan 2024 01:25:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6F8FC3858294 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706664318; bh=ZsxdTm0jalw6rEBeXSdA8aW3PljDu8TN1tgjrRnXUQ4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jJitZ0xXotQLcGgG0kHSFnDNyr3nXwdVo/dh0UMkMy8LyeGQYvG6wb287Bdz8zR5Z 0iiDXMQRNJKGyCnNHeKBZ68kUqxJVrsnJ1PHD+w0FEutZqA1Uut3Yzy0odKtqBv27n M1E9bvyLp4wyNJt5H8XTP1Py2aoiXpBS3indL66k= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111911] [11/12/13/14 Regression] ICE with integer overflow converting to _Bool Date: Wed, 31 Jan 2024 01:25:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 14.0 X-Bugzilla-Keywords: ice-on-valid-code X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jsm28 at gcc dot gnu.org X-Bugzilla-Target-Milestone: 11.5 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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=3D111911 --- Comment #7 from GCC Commits --- The master branch has been updated by Joseph Myers : https://gcc.gnu.org/g:35de88e2ed0aa78f6e3306c8560cd6bb15ce0ffe commit r14-8641-g35de88e2ed0aa78f6e3306c8560cd6bb15ce0ffe Author: Joseph Myers Date: Wed Jan 31 01:24:21 2024 +0000 c: Fix ICEs casting expressions with integer constant operands to bool [PR111059, PR111911] C front-end bugs 111059 and 111911 both report ICEs with conversions to boolean of expressions with integer constant operands that can appear in an integer constant expression as long as they are not evaluated (such as division by zero). The issue is a nested C_MAYBE_CONST_EXPR, with the inner one generated in build_binary_op to indicate that a subexpression has been fully folded and should not be folded again, and the outer one in build_c_cast to indicate that the expression has integer constant operands. To avoid the inner one from build_binary_op, c_objc_common_truthvalue_conversion should be given an argument properly marked as having integer constant operands rather than that information having been removed by the caller - but because c_convert would then also wrap a C_MAYBE_CONST_EXPR with a NOP_EXPR converting to boolean, it seems most convenient to have c_objc_common_truthvalue_conversion produce the NE_EXPR directly in the desired type (boolean in this case), before generating any C_MAYBE_CONST_EXPR there, rather than it always producing a comparison in integer_type_node and doing a conversion to boolean in the caller. The same issue as in those PRs also applies for conversion to enums with a boolean fixed underlying type; that case is also fixed and tests added for it. Note that not all the tests added failed before the patch (in particular, the issue was specific to casts and did not apply for implicit conversions, but some tests of those are added as well). Bootstrapped with no regressions for x86_64-pc-linux-gnu. PR c/111059 PR c/111911 gcc/c/ * c-tree.h (c_objc_common_truthvalue_conversion): Add third argument. * c-convert.cc (c_convert): For conversions to boolean, pass th= ird argument to c_objc_common_truthvalue_conversion rather than converting here. * c-typeck.cc (build_c_cast): Ensure arguments with integer operands are marked as such for conversion to boolean. (c_objc_common_truthvalue_conversion): Add third argument TYPE. gcc/testsuite/ * gcc.c-torture/compile/pr111059-1.c, gcc.c-torture/compile/pr111059-2.c, gcc.c-torture/compile/pr111059-3.c, gcc.c-torture/compile/pr111059-4.c, gcc.c-torture/compile/pr111059-5.c, gcc.c-torture/compile/pr111059-6.c, gcc.c-torture/compile/pr111059-7.c, gcc.c-torture/compile/pr111059-8.c, gcc.c-torture/compile/pr111059-9.c, gcc.c-torture/compile/pr111059-10.c, gcc.c-torture/compile/pr111059-11.c, gcc.c-torture/compile/pr111059-12.c, gcc.c-torture/compile/pr111911-1.c, gcc.c-torture/compile/pr111911-2.c: New tests.=