From patchwork Sat Feb 11 09:52:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 55764 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1419365wrn; Sat, 11 Feb 2023 01:53:42 -0800 (PST) X-Google-Smtp-Source: AK7set8G2tTD7uQZrsvoipdFaWvyauE7rmigiIXY2NaGiZBOvMzc8MwnrJteoV8fPaYg3hO71bmO X-Received: by 2002:a50:8e57:0:b0:499:8849:5fac with SMTP id 23-20020a508e57000000b0049988495facmr18975899edx.40.1676109222906; Sat, 11 Feb 2023 01:53:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676109222; cv=none; d=google.com; s=arc-20160816; b=MKyWRw4dPGDBpUyLX2qENbpDUsX/zQCILt13Trb0Y6XnS8wPiA5Q5pxvdq56uyMy20 mDfj9xx/ufOjpWm8TJf8/tEkqNxvemsnlvwEEAbXKtVmHDdhwYblU4rPaF7cFyImW9hc iKq2IECOdL6Ysi+V2OxCNze49pNShCL8bGwVUxmN4kjE97qXjo1gSQZrSVZ5qXXcH0vN FHTteEPN0WuCfqAttX/y8jfTnfebOJBZkMOIHVTippooXgO7FcYR+gxed65owETdo+i2 /N8pDTA8a7Pj3EzOrWsfLicyEZGwR5ASyR0gc+GUxKsetcWQmpBshjyWX8dzwRcKc6JU O6Tg== 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-disposition:mime-version:message-id:subject:cc:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=C1FoelqatuXDlFOxJQa828E8a0XZmiCIRcXLEJmyy5k=; b=ds8FUEaPH7JC+a1wsuYqxfbVDEs6ZEcT3B2jHA1OC+5S26HOgQZPpQ7frYWU+FNGcC XiFY06Cr4I1Jh3DQJ2d6XlSPknGdlVoY9v9mT5S/7xmWt9DHTF1ARGvtkbaelOUC2MWj UrF9zrDcxWHMqEmKAUtSHfe1tNxpkDvQzsAh4lAr5EbuZ3034Poqjck0mQ0+AmjxTptq xb5EuqVPhZFvrkq+6qM8JTQ4lebQ21I4lsXOONBawillqUgPRcTLwE+s6XETWq3kPYPB pVpQ8XKa3JSrwGRt31wNigjHBEYMtQ9QAeKSg150a1h7zSJ79lGgdcBY8RrQgNKjjm1b o6cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NGibe1Fp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id d21-20020aa7d5d5000000b004ab1736d82csi7459870eds.354.2023.02.11.01.53.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Feb 2023 01:53:42 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=NGibe1Fp; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 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 F1B0D385840D for ; Sat, 11 Feb 2023 09:53:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F1B0D385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676109222; bh=C1FoelqatuXDlFOxJQa828E8a0XZmiCIRcXLEJmyy5k=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=NGibe1FppetiyQwNXJQubVoBNEDSvvEISh6G5b1vtRXBGDB9E1ru2nl084t+bL9Ig 8NE0mtKmHyschXEqZS2pZ63B61c8HrN5TPqw8ywIWeS5o/XU+fcqzhfcK9Wo9A1gx8 c+ptpPRv6fIZyCu9t0HuecY97qrkxmN/5RI00cXI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8085A3858D32 for ; Sat, 11 Feb 2023 09:52:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8085A3858D32 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-587-dhF94aciPQeOvKz37y8NSg-1; Sat, 11 Feb 2023 04:52:53 -0500 X-MC-Unique: dhF94aciPQeOvKz37y8NSg-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5C909185A78B; Sat, 11 Feb 2023 09:52:53 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 14282140EBF6; Sat, 11 Feb 2023 09:52:52 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 31B9qo0S3931231 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 11 Feb 2023 10:52:50 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 31B9qmE33931230; Sat, 11 Feb 2023 10:52:48 +0100 Date: Sat, 11 Feb 2023 10:52:48 +0100 To: Richard Biener , Martin Jambor Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] ipa-cp: Punt for too large offsets [PR108605] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek 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?1757527904009555375?= X-GMAIL-MSGID: =?utf-8?q?1757527904009555375?= Hi! Seems most of IPA uses unsigned type for byte offsets ipa-param-manipulation.h: unsigned unit_offset; ipa-param-manipulation.h: unsigned unit_offset; ipa-param-manipulation.h: void register_replacement (tree base, unsigned unit_offset, tree replacement); ipa-param-manipulation.h: tree lookup_replacement (tree base, unsigned unit_offset); ipa-param-manipulation.h: unsigned unit_offset); ipa-prop.h: unsigned unit_offset; ipa-prop.h: tree get_value (int index, unsigned unit_offset, bool by_ref) const; ipa-prop.h: tree get_value (int index, unsigned unit_offset) const; ipa-prop.h: const ipa_argagg_value *get_elt (int index, unsigned unit_offset) const; ipa-cp.cc:ipa_argagg_value_list::get_elt (int index, unsigned unit_offset) const ipa-cp.cc: unsigned prev_unit_offset = 0; ipa-cp.cc:ipa_argagg_value_list::get_value (int index, unsigned unit_offset) const ipa-cp.cc:ipa_argagg_value_list::get_value (int index, unsigned unit_offset, ipa-cp.cc: unsigned other_offset = other.m_elts[i].unit_offset; ipa-cp.cc: unsigned prev_unit_offset = 0; ipa-cp.cc: unsigned prev_unit_offset = 0; ipa-cp.cc: unsigned this_offset = elts[i].unit_offset; ipa-cp.cc: unsigned prev_unit_offset = 0; ipa-cp.cc: unsigned unit_offset = aglat->offset / BITS_PER_UNIT; ipa-cp.cc: unsigned prev_unit_offset = 0; ipa-param-manipulation.cc: unsigned unit_offset; ipa-param-manipulation.cc:isra_get_ref_base_and_offset (tree expr, tree *base_p, unsigned *unit_offset_p) ipa-param-manipulation.cc: unsigned unit_offset, ipa-param-manipulation.cc: unsigned unit_offset) ipa-param-manipulation.cc:ipa_param_body_adjustments::lookup_replacement (tree base, unsigned unit_offset) ipa-param-manipulation.cc: unsigned unit_offset; ipa-prop.cc: unsigned unit_offset = bit_offset / BITS_PER_UNIT; ipa-sra.cc: unsigned unit_offset; ipa-sra.cc: unsigned unit_offset; ipa-sra.cc: unsigned unit_offset, unsigned unit_size) ipa-sra.cc: unsigned offset = argacc->unit_offset + delta_offset; so before converting a HOST_WIDE_INT bit offset to unsigned byte offset we need to punt for too large offsets. Some places do that, e.g. isra_get_ref_base_and_offset has if (offset < 0 || (offset / BITS_PER_UNIT) > UINT_MAX) return false; but ipa_agg_value_from_jfunc doesn't. The following patch fixes that, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-02-11 Jakub Jelinek PR ipa/108605 * ipa-cp.cc (ipa_agg_value_from_jfunc): Return NULL_TREE also if item->offset bit position is too large to be representable as unsigned int byte position. * c-c++-common/pr108605.c: New test. Jakub --- gcc/ipa-cp.cc.jj 2023-01-02 09:32:34.699107365 +0100 +++ gcc/ipa-cp.cc 2023-02-10 19:10:21.565419411 +0100 @@ -1982,7 +1982,9 @@ ipa_agg_value_from_jfunc (ipa_node_param tree value = NULL_TREE; int src_idx; - if (item->offset < 0 || item->jftype == IPA_JF_UNKNOWN) + if (item->offset < 0 + || item->jftype == IPA_JF_UNKNOWN + || item->offset >= (HOST_WIDE_INT) UINT_MAX * BITS_PER_UNIT) return NULL_TREE; if (item->jftype == IPA_JF_CONST) --- gcc/testsuite/c-c++-common/pr108605.c.jj 2023-02-10 19:23:01.449592103 +0100 +++ gcc/testsuite/c-c++-common/pr108605.c 2023-02-10 19:22:43.773845986 +0100 @@ -0,0 +1,24 @@ +/* PR ipa/108605 */ +/* { dg-do compile { target { lp64 || llp64 } } } */ +/* { dg-options "-O2" } */ + +struct S { + char a, b, c; + int d[__INT_MAX__], e; +}; + +void +foo (struct S *s) +{ + if (s->b && s->c != 0) + __builtin_abort (); +} + +void +bar (void) +{ + struct S s[2]; + s[0].a = 0; + s[0].e = 0; + foo (s); +}