From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by sourceware.org (Postfix) with ESMTPS id 0A8003858415 for ; Wed, 9 Mar 2022 14:55:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0A8003858415 Received: by mail-ej1-x632.google.com with SMTP id bg10so5638156ejb.4 for ; Wed, 09 Mar 2022 06:55:24 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=3VNOymb8LLuhvkdIlb7D5ktuB/0wbSW3PrOsKKX4C3s=; b=SWA+8fBQZrEAAhB2AEzySr3N1I3m/05fnZv+xVzDvsdEqGphEXJguz9Hz3wQXlw9L2 8lFCSqoHgHHvEtRATR9gIrvqGiA7EMl8TTYB5AEKzYByEZFmSt0ttEi/TnbVL62yXURn 9kO/roRWTdkCE3JYC2wdKceLMxiER9eleaLgHBOu4oyqAsTRrE9Xxn8miR3fQ1T1PLBC ONp3xdaJKVJBBdMSCvG7qOmpTcvNAgWH1l/nVVCks5mWVZTyR0M6MSsaMfonzwGQGZNr VgWB9kevTEHhLV2JFnMlTLXlSAq6yjLiAIPSBkqC3MYxLV/9euQAspoTFAIwPf4C3Z2T AEnQ== X-Gm-Message-State: AOAM533lFBWBYsmb2jdFUlI3CGu6QFdBTJeygEos8veilnlrToD+lnk7 zqYB3X5WhdvYvcbO/J58bh179tQTzsYPv6JMz78= X-Google-Smtp-Source: ABdhPJwZvtmfQTLteM2VgDiT3vi40iNfe2CAvrgib6QE7ltyt+vDFC+UvPrIgJD9qAeihdBhjHrRWcVeXmgIa8fupHo= X-Received: by 2002:a17:907:2da1:b0:6da:8e01:8313 with SMTP id gt33-20020a1709072da100b006da8e018313mr131821ejc.32.1646837723922; Wed, 09 Mar 2022 06:55:23 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Richard Biener Date: Wed, 9 Mar 2022 15:55:13 +0100 Message-ID: Subject: Re: [PATCH] cse: avoid signed overflow in compute_const_anchors [PR 104843] To: Xi Ruoyao Cc: GCC Patches , Richard Sandiford , Jeff Law Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.8 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Wed, 09 Mar 2022 14:55:26 -0000 On Wed, Mar 9, 2022 at 12:20 PM Xi Ruoyao via Gcc-patches wrote: > > Bootstrapped and tested on mips64el-linux-gnuabi64, and MIPS is the only > port with a non-zero targetm.const_anchor. Ok for trunk? > > -- >8 -- > > With a non-zero const_anchor, the behavior of this function relied on > signed overflow. > > gcc/ > > PR rtl-optimization/104843 > * cse.cc (compute_const_anchors): Cast to unsigned HOST_WIDE_INT > to perform overflow arithmetics safely. > --- > gcc/cse.cc | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > > diff --git a/gcc/cse.cc b/gcc/cse.cc > index a18b599d324..7c39a009449 100644 > --- a/gcc/cse.cc > +++ b/gcc/cse.cc > @@ -1169,10 +1169,10 @@ compute_const_anchors (rtx cst, > HOST_WIDE_INT *lower_base, HOST_WIDE_INT *lower_offs, > HOST_WIDE_INT *upper_base, HOST_WIDE_INT *upper_offs) > { > - HOST_WIDE_INT n = INTVAL (cst); > + unsigned HOST_WIDE_INT n = INTVAL (cst); UINTVAL (cst)? > > *lower_base = n & ~(targetm.const_anchor - 1); isn't it better to make targetm.const_anchor unsigned? The & and ~ are not subject to overflow rules. > - if (*lower_base == n) > + if (*lower_base == INTVAL (cst)) duplicating this here is definitely ugly. > return false; > > *upper_base = > -- > 2.35.1 > >