From patchwork Sat Jul 1 08:22:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Pinski X-Patchwork-Id: 115012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp10903909vqr; Sat, 1 Jul 2023 01:23:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJjd8Jx3UiBskMI7T99mlqXcTCtSL1VPeHUrVr0x0IVNt8cuUsZTjrgzWQNTUOF4k17Qfo X-Received: by 2002:aa7:d819:0:b0:51e:234:cb69 with SMTP id v25-20020aa7d819000000b0051e0234cb69mr476257edq.15.1688199805413; Sat, 01 Jul 2023 01:23:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688199805; cv=none; d=google.com; s=arc-20160816; b=hEUdHpSjhAqorBsN3CKFU1PWsLrLNU0kmxdYqFD4laR2aXvijSTSGa9i5E715HVW0U O+RrgCPo/oVCbRM476bicz8BP/7woznOj/Vt8zLhAZ4orRqX6j29PrgF3XLd0MBGFEtY uUUu836PNOBIYi9DtaYo0xl9cU7bfCmTkoFKbmF9z1nCmv7cmFvVi7a24LXZ2PKP3TA4 f4dI9krOrJ+nzX5cZ2OQLuyArZzdHlp3NnNnXOrJjR3wEcpf3NAyvSZiINsFEjYSS9D/ OyEaNCXeSkv4Id9ux0MLX7HcCbR6yTgotbM8nNeXtZzE25RgvwAmhRLKcMbn8oHTA1nM OOEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=S5dIyz416YPDjUoAAkEGDxWKavamG9+nkmeId2FMFY4=; fh=XbcmRug6/SzczusyoNU1I7Lu5oY0AN2u0mWDzKoxdSs=; b=qqKbN2uZoS4UJARKGWnGAgpm4rXkJDjaGj1/Shs+/nRUuQYFSF3jvWGyrkWd6KkTQq kAFd6Wz0/lwvRECdz0pMNPDPFGdRgvbPZr+0X+gH5P/xThmc2FnkptM5//XQJ2uelQ2u Wn3kLjP1th03NCvsYOgm93vGZMUEADZ/XOrW/SzL7XAAqSscHrzT8NQJ3ehcTep6uAzg liRnAx/AZsLpdqG8lmOmAhUUZ/uc0h8ChU1vW3s8dHj/lDXKD2etODCdQ9R3O26l5h6b xy/9bv2qjhBHPrpK3Atnb5NWTdc21x4OWT/YHraqZLS1zD01ZEtus7xH2B0blCay9fAL EUJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b67q62pb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id v12-20020aa7cd4c000000b0051d80279e56si305939edw.70.2023.07.01.01.23.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Jul 2023 01:23:25 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=b67q62pb; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3F05E3858418 for ; Sat, 1 Jul 2023 08:23:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3F05E3858418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1688199801; bh=S5dIyz416YPDjUoAAkEGDxWKavamG9+nkmeId2FMFY4=; h=To:CC:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=b67q62pbBk89luxEZ40AIiipL/2fSmcjfP0aWSwsz7OvwqgsxQXm/OYf9pfiyNx6A vTJmq6z6NTA6VHWV3wcbmyzcyy0iHqpX36cdVuse0s4kAEjjsfD6pzN9WT0DtW5LBW rwe66YS2j0h4actG/9WuWOBC+nfPKwbHlGiuAGLo= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 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 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) 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 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Andrew Pinski via Gcc-patches From: Andrew Pinski Reply-To: Andrew Pinski Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1770205798659016528?= X-GMAIL-MSGID: =?utf-8?q?1770205798659016528?= 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; } ) + ) + ) + ) + ) + ) ) ) )