From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by sourceware.org (Postfix) with ESMTPS id B58FC3858D35 for ; Sat, 1 Jul 2023 08:22:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B58FC3858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=marvell.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=marvell.com Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36180RHK023157 for ; Sat, 1 Jul 2023 01:22:27 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=S5dIyz416YPDjUoAAkEGDxWKavamG9+nkmeId2FMFY4=; b=if189H4NFymWvhLgN02pRjhA4nhBur8015QI3OfQxTLL3XYReiiYMWYAJU98h4nxPOS7 Ru35oq3csXC0kp0oqbucr2mhzmEC4C79/+ghSrVyTqeQBKYorvRnLMA5BxBZxNWwW1/x KAy+Ljvfq8B6rUi/B63klhCtn+G254p0ZsxD1+vBF1mVTAbxi7EZaao5KPXqlqpXx+ji +/Tckc/iJXkqLvIwv97TF2TaUSchmqwyNXFuldX5as9dLgBmvdtyOWs1/MvnesVunPpz EjP8YFdG4BfeiLqtreSauvsvHY1XIoHSp/EA+yuD3hylnLONk5hJ/ewhDPWRE+whzUaT gw== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3rhp2emw7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT) for ; Sat, 01 Jul 2023 01:22:27 -0700 Received: from DC5-EXCH01.marvell.com (10.69.176.38) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.48; Sat, 1 Jul 2023 01:22:25 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server id 15.0.1497.48 via Frontend Transport; Sat, 1 Jul 2023 01:22:25 -0700 Received: from vpnclient.wrightpinski.org.com (unknown [10.69.242.187]) by maili.marvell.com (Postfix) with ESMTP id 4B2B03F707B; Sat, 1 Jul 2023 01:22:25 -0700 (PDT) From: Andrew Pinski To: CC: Andrew Pinski Subject: [PATCH 1/2] Fix PR 110487: invalid signed boolean value Date: Sat, 1 Jul 2023 01:22:15 -0700 Message-ID: <20230701082216.299104-1-apinski@marvell.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: oyOsBbzEJaBXO-RL3hv0JN7B8kP6FEzn X-Proofpoint-GUID: oyOsBbzEJaBXO-RL3hv0JN7B8kP6FEzn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-01_06,2023-06-30_01,2023-05-22_02 X-Spam-Status: No, score=-14.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: This fixes the first part of this bug where `a ? -1 : 0` would cause a value of 1 into the signed boolean value. It fixes the problem by casting to an integer type of the same size/signedness before doing the negative and then casting to the type of expression. OK? Bootstrapped and tested on x86_64. gcc/ChangeLog: * match.pd (a?-1:0): Cast type an integer type rather the type before the negative. (a?0:-1): Likewise. --- gcc/match.pd | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 45c72e733a5..a0d114f6a16 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -4703,7 +4703,12 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* a ? -1 : 0 -> -a. No need to check the TYPE_PRECISION not being 1 here as the powerof2cst case above will handle that case correctly. */ (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) - (negate (convert (convert:boolean_type_node @0)))))) + (with { + auto prec = TYPE_PRECISION (type); + auto unsign = TYPE_UNSIGNED (type); + tree inttype = build_nonstandard_integer_type (prec, unsign); + } + (convert (negate (convert:inttype (convert:boolean_type_node @0)))))))) (if (integer_zerop (@1)) (with { tree booltrue = constant_boolean_node (true, boolean_type_node); @@ -4722,7 +4727,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* a ? -1 : 0 -> -(!a). No need to check the TYPE_PRECISION not being 1 here as the powerof2cst case above will handle that case correctly. */ (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) - (negate (convert (bit_xor (convert:boolean_type_node @0) { booltrue; } )))) + (with { + auto prec = TYPE_PRECISION (type); + auto unsign = TYPE_UNSIGNED (type); + tree inttype = build_nonstandard_integer_type (prec, unsign); + } + (convert + (negate + (convert:inttype + (bit_xor (convert:boolean_type_node @0) { booltrue; } ) + ) + ) + ) + ) + ) ) ) ) -- 2.31.1