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: 1740869 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=qkAsxL4o; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PDQsG4xN2z23hX for ; Sat, 11 Feb 2023 20:53:21 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 27E0E385840D for ; Sat, 11 Feb 2023 09:53:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27E0E385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676109198; bh=C1FoelqatuXDlFOxJQa828E8a0XZmiCIRcXLEJmyy5k=; h=Date:To:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=qkAsxL4oxERpRlnw7LOKGfec6lRJUsu2xXZ0GmonAhXRK6vHaM5xsEFRa2v18nkov /P6de8CP4//9qX49QZbObvb+1IEzEaoBdRGLW1/jRipsawKXu+ToL9ZBlE6v+g31BR lbS5+cGNclJDMqZhfxDu4urWSl5Oh3CQh8akeOKI= 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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); +}