From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by sourceware.org (Postfix) with ESMTPS id 488BB3858D28 for ; Mon, 3 Jul 2023 07:53:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 488BB3858D28 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-x22f.google.com with SMTP id 38308e7fff4ca-2b6a152a933so62174301fa.1 for ; Mon, 03 Jul 2023 00:53:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688370807; x=1690962807; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=zFYwfzTT864moaxSc2Ca85SVxX+Jxou2ypDwAR/nPeE=; b=Cv8HOQZk++AZHaQt50L2MPyA7Q2SZhzAOUxYOUCBJanwTO0o3oJ7O4hXp4bdEn7h03 QpsiVhbogLVGBzRQhYGy2vBlg7DJuX5WR0ZxwVEUq4FnfHk8RkmoDDgnSxnFMkOPfQRB fxcL/hqqAggusRf/VymPc4MHbQG4cYp7GJJGL75cxbxFY9D5/Rh/2y2hoMtsyVDBt8PE MX6eZtd40o7owZ4Zlh2jVgF77AS5hSbfWU1bV4JPA1295XUBkVAr0clvkNJmechUeJ0l Jne2G7ueHNIwWiflsybASuEJn2ugcroWA7XHv8EEdM4dqYCFiSvMk2kNERxQ8LYWai2D MMug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688370807; x=1690962807; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zFYwfzTT864moaxSc2Ca85SVxX+Jxou2ypDwAR/nPeE=; b=FwwPlPagcXCr6udOPy7NelRnxBVmlvuLrhFCtXZpe6aFJlT9/HkSLzKvzyD740e6se WXSwbYwc2tzy9lPWpXBT0vy1P7vh86j74+z1p0lcKwuH4FPTfuHJTgg6srufGnNPA32V smdxbtapIR8jbX7DC+wBtsGlWLWDGjD//AcdR33kAEqT3ref+6vplgxJl57iKYlHI/DP FR1vhj7E90LhkRPui+6cIqvj0NK8lTayTBj6Xlbm0kLNIvysTu6hgSzkVSFysD2/fwDd /T8NIylcR9P1Pczdn+S4fkXTSDiBNBRWli5SCL4KqIqFo6KZitrSr5Xy6hTdLwfIEG0v 2jWg== X-Gm-Message-State: ABy/qLaVUAeJensFpE7DtoypFWzG0DvqMKzmwTgv9yiewLy+Xh4puWFo rEhRZT2LxjyoRozteH63+ljwtbAXDkrK8QV11Rw= X-Google-Smtp-Source: APBJJlEpLAyroyq9PPMSXss5lUygmiAiw8sZdgSk4Z3/6UdHv3XSYiddp2RXO4c0LiYdWA27QiuXJc/mIKP76aoVpmY= X-Received: by 2002:a2e:95d9:0:b0:2b5:8153:deb3 with SMTP id y25-20020a2e95d9000000b002b58153deb3mr6628992ljh.4.1688370806474; Mon, 03 Jul 2023 00:53:26 -0700 (PDT) MIME-Version: 1.0 References: <20230701082216.299104-1-apinski@marvell.com> In-Reply-To: <20230701082216.299104-1-apinski@marvell.com> From: Richard Biener Date: Mon, 3 Jul 2023 09:50:12 +0200 Message-ID: Subject: Re: [PATCH 1/2] Fix PR 110487: invalid signed boolean value To: Andrew Pinski Cc: gcc-patches@gcc.gnu.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,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: On Sat, Jul 1, 2023 at 10:23=E2=80=AFAM Andrew Pinski via Gcc-patches wrote: > > 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. OK. Richard. > 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 correctl= y. */ > (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@1)) > - (negate (convert (convert:boolean_type_node @0)))))) > + (with { > + auto prec =3D TYPE_PRECISION (type); > + auto unsign =3D TYPE_UNSIGNED (type); > + tree inttype =3D build_nonstandard_integer_type (prec, unsign); > + } > + (convert (negate (convert:inttype (convert:boolean_type_node @0)))= ))))) > (if (integer_zerop (@1)) > (with { > tree booltrue =3D 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 be= ing 1 > here as the powerof2cst case above will handle that case correctl= y. */ > (if (INTEGRAL_TYPE_P (type) && integer_all_onesp (@2)) > - (negate (convert (bit_xor (convert:boolean_type_node @0) { booltru= e; } )))) > + (with { > + auto prec =3D TYPE_PRECISION (type); > + auto unsign =3D TYPE_UNSIGNED (type); > + tree inttype =3D build_nonstandard_integer_type (prec, unsign); > + } > + (convert > + (negate > + (convert:inttype > + (bit_xor (convert:boolean_type_node @0) { booltrue; } ) > + ) > + ) > + ) > + ) > + ) > ) > ) > ) > -- > 2.31.1 >