From patchwork Fri Nov 5 22:34:54 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 1551590 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=JavPOPrP; dkim-atps=neutral Authentication-Results: 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=) Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HmFh86LTzz9sPf for ; Sat, 6 Nov 2021 09:35:19 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3717F3858435 for ; Fri, 5 Nov 2021 22:35:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3717F3858435 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636151717; bh=ixn2e4PbDH3yEDsHxdjURRNzY1ytXDKvopWXk6Hvtjo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=JavPOPrPwA+HCs7l3ojz51IIEiSjzPiHNKGykXp0Hcj6t/Kip6EpEN0fzJ7papxui sNeiNUT8tladPsJDn4FfKRLxfqZXkd9ZKuN/6Xdobu42FDtj4ik+n16YHtk316THb0 ZE55vTqQmN/8bK5JyM8qs32AebRyIMIEBrSmAiKs= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from nikam.ms.mff.cuni.cz (nikam.ms.mff.cuni.cz [195.113.20.16]) by sourceware.org (Postfix) with ESMTPS id F405D3858414 for ; Fri, 5 Nov 2021 22:34:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org F405D3858414 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id C52E22809B4; Fri, 5 Nov 2021 23:34:54 +0100 (CET) Date: Fri, 5 Nov 2021 23:34:54 +0100 To: gcc-patches@gcc.gnu.org Subject: Fix ICE in insert_access Message-ID: <20211105223454.GF4548@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP 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-Patchwork-Original-From: Jan Hubicka via Gcc-patches From: Jan Hubicka Reply-To: Jan Hubicka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Hi, this patch makes insert_access to ignore accesses that are paradoxical (i.e. their max_size is smaller than size) which can happen for example when VRP proves that the access happens past the end of array bounds. It also checks for zero sized accesses and verifies that max_size is never negative. Bootstrapped/regtested x86_64-linux, comitted. gcc/ChangeLog: PR ipa/103073 * ipa-modref-tree.h (modref_tree::insert): Do nothing for paradoxical and zero sized accesses. gcc/testsuite/ChangeLog: PR ipa/103073 * g++.dg/torture/pr103073.C: New test. * gcc.dg/tree-ssa/modref-11.c: New test. diff --git a/gcc/ipa-modref-tree.h b/gcc/ipa-modref-tree.h index bc428d193d2..54ae9e1df4e 100644 --- a/gcc/ipa-modref-tree.h +++ b/gcc/ipa-modref-tree.h @@ -818,6 +818,36 @@ struct GTY((user)) modref_tree bool changed = false; + /* We may end up with max_size being less than size for accesses past the + end of array. Those are undefined and safe to ignore. */ + if (a.range_info_useful_p () + && known_size_p (a.size) && known_size_p (a.max_size) + && known_lt (a.max_size, a.size)) + { + if (dump_file) + fprintf (dump_file, + " - Paradoxical range. Ignoring\n"); + return false; + } + if (known_size_p (a.size) + && known_eq (a.size, 0)) + { + if (dump_file) + fprintf (dump_file, + " - Zero size. Ignoring\n"); + return false; + } + if (known_size_p (a.max_size) + && known_eq (a.max_size, 0)) + { + if (dump_file) + fprintf (dump_file, + " - Zero max_size. Ignoring\n"); + return false; + } + gcc_checking_assert (!known_size_p (a.max_size) + || !known_le (a.max_size, 0)); + /* No useful information tracked; collapse everything. */ if (!base && !ref && !a.useful_p ()) { diff --git a/gcc/testsuite/g++.dg/torture/pr103073.C b/gcc/testsuite/g++.dg/torture/pr103073.C new file mode 100644 index 00000000000..02b1eee064a --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr103073.C @@ -0,0 +1,8 @@ +// { dg-do compile } +int a; +void b(bool c[], char d[], bool g[][55][21]) { + for (signed e = 0; e < 11; e += 3) + for (unsigned f = c[0] + 1; f < d[0]; f += 3) + a = g[0][e][f + 2]; +} + diff --git a/gcc/testsuite/gcc.dg/tree-ssa/modref-11.c b/gcc/testsuite/gcc.dg/tree-ssa/modref-11.c new file mode 100644 index 00000000000..de9ad16879f --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/modref-11.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-modref1" } */ +struct linkedlist { + struct linkedlist *next; +}; +struct linkedlist * +find_last (struct linkedlist *l) +{ + while (l->next) + l = l->next; + return l; +} +/* { dg-final { scan-tree-dump "noclobber noescape nodirectescape" "modref1"} } */