From patchwork Sat Nov 11 08:35: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: 164104 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp117555vqg; Sat, 11 Nov 2023 00:36:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IFmHq8cTzX3igIA9Y0jPQ8dSWuG5v+/z7k6WOnw3eBhB7yWljxl7cdIK/Ef8rTxv7F9YNM8 X-Received: by 2002:a05:622a:182:b0:41c:bcd4:19b7 with SMTP id s2-20020a05622a018200b0041cbcd419b7mr1771428qtw.15.1699691816281; Sat, 11 Nov 2023 00:36:56 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699691816; cv=pass; d=google.com; s=arc-20160816; b=Q9Oa6/emVOZk1Jv2J593IJCmSC3k3quB3qa5m7Ofsf4mDej/mqzskuFSKidLr06EnG M/LKR/MbEtlzrDG77g7yW1LEnzGhVKlTauXM0Zbg65fIwMaQjOM+58OsZVuc6EbT5C5/ IddfC8FRoIXavDXQypFsY7MBXLWyut1VAXj93tp5CQuFyyITM7G6jE0PYwiiNHRJieNY HSY+EeJ5ZDXTEIFTASZck2I0wYkKwFGw965UcqXMHMgITPKAxS6totF1yX1ai4rZ6Ihl 2Pf6Yg8EC6/V6l4as2FIg2aV1ayIHwZdKJAJ0UUusiQVjiCAeN4//lH8c4HC1S5HvRNv GaWA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:reply-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=UzHUY+zVmWWzoDvkR+XEWl69LiiRd4o0js3V45XJfL0=; fh=ZLMzTYOm8A3n2M1qmTcIxjDCr3NAKXQX2EUZq5w01Fo=; b=Kb04c5ovAimt2o0A7uSlo1MPUWOFqOXeu1dmSFeF2ywcJwCpi3tXB5VBLhC2CNKI+H DGuats9VSV6MAVvJof+E0VltEq8/Qt3x5yawBM8ipOYNcIP7emFxBkahmfuvJ4IMBVHn 3h7ih+euPwl4GpJ7Aw1MoFnwuhLnRSBK8gE5rMAISmGpEcgf6FKKWfRfKgxqPfboh8A/ ZqrXKc9S6wWXke7WH46bDjiX/wIkpyyucguXIpj5FydwWHAwXxBPucMaYAX9nSswmC98 6r2/2mxLMTemmkZdN3Vc0FSqkg4zfFtRiKoPW3RcxzBxITIKLMEVZ1yxs+lxGs6U2lRs +sLQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=fKqSwXp+; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id b22-20020a05622a021600b0041951be6b60si1078565qtx.39.2023.11.11.00.36.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Nov 2023 00:36:56 -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=@redhat.com header.s=mimecast20190719 header.b=fKqSwXp+; arc=pass (i=1); 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=redhat.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 120463858C33 for ; Sat, 11 Nov 2023 08:36:56 +0000 (GMT) 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 02FAF3858D32 for ; Sat, 11 Nov 2023 08:35:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 02FAF3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 02FAF3858D32 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699691756; cv=none; b=EZOf7yXm/ZTnb0keM01tnWXZPhoqZm74ETuKNOUAbDRvOb0z9Ls24vL749ppZ5fPHsYC2604GK9Nm8ovJXmytevchiT5UeYe+hAosYf5Gs0/ACPdBeuXApNki1EyFLlMOEvek47pX3i3Z7N5kbLwOlf1dyv6ZvEm8HF5dMfbHtM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699691756; c=relaxed/simple; bh=f8ZFAJQhciDNxMnlYg8fERlGGyO0t8kW4w1LZYH7Rbs=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=hhE4nsq8Nypb85UZU9tofZUe+ZCfyO/MP1JLmVJZ3O7gLcQUzrQ78IAiiaKdJD70y1z88CWTOPG2oxGoMQNW/PrpdpMMqRrHOf+AVoZWEzG61riJocF3cmUaFyzb6Rn4bvIz4Gj8i9h1iuPdcHjAjMkgRo+X1NT5+MgNnfbihvY= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1699691753; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=UzHUY+zVmWWzoDvkR+XEWl69LiiRd4o0js3V45XJfL0=; b=fKqSwXp+NhwpqTYWEcbtzNIUgKxSB7dv79SfkZ95tty9CGUW92y2Ut4sQMs/a0lB/dfKs4 /ISU7QAPbW04GFZqTVYPDxLKBg+81FNqKd+Mrwmoaigrt0o3QgjXUjStUMzkk8dwyHsmX3 3oyDdr2RMSoNXOnQsSdTBm7uquXtszY= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-623-B6xKwP89NXeglv2zGl4n9g-1; Sat, 11 Nov 2023 03:35:51 -0500 X-MC-Unique: B6xKwP89NXeglv2zGl4n9g-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 44742101A52D for ; Sat, 11 Nov 2023 08:35:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 06FF7492BFA; Sat, 11 Nov 2023 08:35:50 +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 3AB8ZmE13773584 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sat, 11 Nov 2023 09:35:49 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3AB8Zm4b3773583; Sat, 11 Nov 2023 09:35:48 +0100 Date: Sat, 11 Nov 2023 09:35:48 +0100 From: Jakub Jelinek To: Andrew MacLeod Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] gimple-range-cache: Fix ICEs when dumping details [PR111967] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-3.4 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_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782256045812688632 X-GMAIL-MSGID: 1782256045812688632 Hi! The following testcase ICEs when dumping details. When m_ssa_ranges vector is created, it is safe_grow_cleared (num_ssa_names), but when when some new SSA_NAME is added, we strangely grow it to num_ssa_names + 1 instead and later on the 3 argument dump method iterates from 1 to m_ssa_ranges.length () - 1 and uses ssa_name (x) on each; but because set_bb_range grew it one too much, ssa_name (m_ssa_ranges.length () - 1) might be after the end of the ssanames vector and ICE. The fix grows the vector consistently only to num_ssa_names, doesn't waste time checking m_ssa_ranges[0] because there is no ssa_names (0), it is always NULL, before using ssa_name (x) checks if we'll need it at all (we check later if m_ssa_ranges[x] is non-NULL, so we might check it earlier as well) and also in the last loop iterates until m_ssa_ranges.length () rather than num_ssa_names, I don't see a reason for the inconsistency and in theory some SSA_NAME could be added without set_bb_range called for it and the vector could be shorter than the ssanames vector. To actually fix the ICE, either the first hunk or the last 2 hunks would be enough, but I think it doesn't hurt to change all the spots. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2023-11-11 Jakub Jelinek PR tree-optimization/111967 * gimple-range-cache.cc (block_range_cache::set_bb_range): Grow m_ssa_ranges to num_ssa_names rather than num_ssa_names + 1. (block_range_cache::dump): Iterate from 1 rather than 0. Don't use ssa_name (x) unless m_ssa_ranges[x] is non-NULL. Iterate to m_ssa_ranges.length () rather than num_ssa_names. * gcc.dg/tree-ssa/pr111967.c: New test. Jakub --- gcc/gimple-range-cache.cc.jj 2023-10-10 11:56:05.819220320 +0200 +++ gcc/gimple-range-cache.cc 2023-11-10 17:06:52.482867324 +0100 @@ -390,7 +390,7 @@ block_range_cache::set_bb_range (tree na { unsigned v = SSA_NAME_VERSION (name); if (v >= m_ssa_ranges.length ()) - m_ssa_ranges.safe_grow_cleared (num_ssa_names + 1); + m_ssa_ranges.safe_grow_cleared (num_ssa_names); if (!m_ssa_ranges[v]) { @@ -465,7 +465,7 @@ void block_range_cache::dump (FILE *f) { unsigned x; - for (x = 0; x < m_ssa_ranges.length (); ++x) + for (x = 1; x < m_ssa_ranges.length (); ++x) { if (m_ssa_ranges[x]) { @@ -487,11 +487,14 @@ block_range_cache::dump (FILE *f, basic_ bool summarize_varying = false; for (x = 1; x < m_ssa_ranges.length (); ++x) { + if (!m_ssa_ranges[x]) + continue; + if (!gimple_range_ssa_p (ssa_name (x))) continue; Value_Range r (TREE_TYPE (ssa_name (x))); - if (m_ssa_ranges[x] && m_ssa_ranges[x]->get_bb_range (r, bb)) + if (m_ssa_ranges[x]->get_bb_range (r, bb)) { if (!print_varying && r.varying_p ()) { @@ -508,13 +511,16 @@ block_range_cache::dump (FILE *f, basic_ if (summarize_varying) { fprintf (f, "VARYING_P on entry : "); - for (x = 1; x < num_ssa_names; ++x) + for (x = 1; x < m_ssa_ranges.length (); ++x) { + if (!m_ssa_ranges[x]) + continue; + if (!gimple_range_ssa_p (ssa_name (x))) continue; Value_Range r (TREE_TYPE (ssa_name (x))); - if (m_ssa_ranges[x] && m_ssa_ranges[x]->get_bb_range (r, bb)) + if (m_ssa_ranges[x]->get_bb_range (r, bb)) { if (r.varying_p ()) { --- gcc/testsuite/gcc.dg/tree-ssa/pr111967.c.jj 2023-11-10 16:45:54.006085324 +0100 +++ gcc/testsuite/gcc.dg/tree-ssa/pr111967.c 2023-11-10 17:03:17.257844360 +0100 @@ -0,0 +1,15 @@ +/* PR tree-optimization/111967 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-forwprop -fdump-tree-evrp-all" } */ + +void bar (char *); +int a; +char *b; + +void +foo (void) +{ + long c = a & 3; + if (c) + bar (b + c); +}