From patchwork Sun Nov 14 13:15:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 1554824 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=uPgmnPAi; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4HsXrJ49qdz9s0r for ; Mon, 15 Nov 2021 00:15:42 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 570BE3858403 for ; Sun, 14 Nov 2021 13:15:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 570BE3858403 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1636895740; bh=wYWs/vb/WlaCXIHQN+POUdo8sB4NMOy59OXiSQpkW1U=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=uPgmnPAiNToV3a69oo1fEwX3POuRdurNVyranuEa9kVYmxkWq8hVBciBbAjRQval4 e/stKijX55Kxb/oOz55KVjYqdbMpizXOjrBV62mf/FMNS0LfkcF9Ydk8C2soxwGen0 AXvlbp3YLiHfyjpj7ZJd7LolA2Y9icfWGEDAn/Bo= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 0AA793858403 for ; Sun, 14 Nov 2021 13:15:14 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0AA793858403 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-548-mqd7bJCFNO23PTRfntSitA-1; Sun, 14 Nov 2021 08:15:09 -0500 X-MC-Unique: mqd7bJCFNO23PTRfntSitA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C5C559F92B; Sun, 14 Nov 2021 13:15:08 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.192.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5A2A61346F; Sun, 14 Nov 2021 13:15:08 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.16.1/8.15.2) with ESMTPS id 1AEDF5lP1091240 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 14 Nov 2021 14:15:06 +0100 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.16.1/8.16.1/Submit) id 1AEDF4fY1091239; Sun, 14 Nov 2021 14:15:04 +0100 To: GCC patches Subject: [COMMITTED] Do not pass NULL to memset in ssa_global_cache. Date: Sun, 14 Nov 2021 14:15:00 +0100 Message-Id: <20211114131500.1091155-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, 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: Aldy Hernandez via Gcc-patches From: Aldy Hernandez Reply-To: Aldy Hernandez Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The code computing ranges in PHIs in the path solver reuses the temporary ssa_global_cache by calling its clear method. Calling it on an empty cache causes us to call memset with NULL. [The testcase doesn't fail without the patch. I suppose it needs some usbsan magic, or to live somewhere else?] Tested on x86-64 Linux. gcc/ChangeLog: PR tree-optimization/103229 * gimple-range-cache.cc (ssa_global_cache::clear): Do not pass null value to memset. gcc/testsuite/ChangeLog: * gcc.dg/pr103229.c: New test. --- gcc/gimple-range-cache.cc | 3 ++- gcc/testsuite/gcc.dg/pr103229.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.dg/pr103229.c diff --git a/gcc/gimple-range-cache.cc b/gcc/gimple-range-cache.cc index a63e20e7e49..b347edeb474 100644 --- a/gcc/gimple-range-cache.cc +++ b/gcc/gimple-range-cache.cc @@ -651,7 +651,8 @@ ssa_global_cache::clear_global_range (tree name) void ssa_global_cache::clear () { - memset (m_tab.address(), 0, m_tab.length () * sizeof (irange *)); + if (m_tab.address ()) + memset (m_tab.address(), 0, m_tab.length () * sizeof (irange *)); } // Dump the contents of the global cache to F. diff --git a/gcc/testsuite/gcc.dg/pr103229.c b/gcc/testsuite/gcc.dg/pr103229.c new file mode 100644 index 00000000000..96ef9aff67c --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr103229.c @@ -0,0 +1,10 @@ +// { dg-do compile } +// { dg-options "-O -w" } + +int main() { + int i; + for (; i;) + ; + + return 0; +}