From patchwork Tue Feb 11 23:01:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Sebor X-Patchwork-Id: 1236561 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519370-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=RQeZsh/3; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=iW7ggkds; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48HJDr2013z9sP7 for ; Wed, 12 Feb 2020 10:01:46 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=N9oqheEbLa736aRWaQm5QNgjAzrJ9LXY3f1kzvPXuBid7mlxu3 XlKBaUJExPFCuXJ5X1HB+jlpmRrwLxoDGkP5sjwFcrbzVWc7jn1mVwrTaK8dxwAE JTCuuuRnt5Y5Fma22zm6CVb1E+2C1ycu32pk16gmnfkx0DcvyYSylfWGw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=szTpnsI6XrCd2q3rxJyMHLXsmSg=; b=RQeZsh/3ykJGCOSRdGpw ydk1+ttQNUzq8vuOKoRbE8tixW08Nppcfkm44wl4jV+/NmJEiqkQj2um5iJa6smV fnBHpM5zfZ/l3Gx5XMZcl6pzcJyfZMI8/E2aMWpDJJiag03acRXpuA23V4aHwkzy Ae0T4wgodo1G+PIo7G2Nb7o= Received: (qmail 106405 invoked by alias); 11 Feb 2020 23:01:38 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 106369 invoked by uid 89); 11 Feb 2020 23:01:33 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.4 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mail-qk1-f173.google.com Received: from mail-qk1-f173.google.com (HELO mail-qk1-f173.google.com) (209.85.222.173) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 11 Feb 2020 23:01:31 +0000 Received: by mail-qk1-f173.google.com with SMTP id z19so225589qkj.5 for ; Tue, 11 Feb 2020 15:01:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=vqg7fRvNg5PL5DaHT27AMQ0yo1AU2BE27Y9CZYCZiI8=; b=iW7ggkdsVpMIEK3kGxjM+waafs4LoaQaOx7fTMCGAO0h3aDbVf5DGv1VA0GZNdvmL9 tFvvhNlz1JHEXPsYp/bTLmRSNTqzyfugVqcksRumzC5lLj50e/yCNE/LEFeWbq7v9eyY Izy4gRo3Q+GL8Lqk7wvi9Mbpdt1vk2XwLC0t7YxSf05Byj8bNQRrpMvdaiOMNnVyHHb0 r68/43tehEIBd+ucrM8+EaEX6bJiMG1TYF7jNlV+vHyuR4Hb76yhw1dlycaoP75oDKf3 /5tm99Qv0R+Kzml3py9i4U1Zhm2dxyeuI489+aFMAWK9+eEhPvG4fwY8Aih9zjcNkkrQ 5PHg== Received: from [192.168.0.41] (174-16-112-158.hlrn.qwest.net. [174.16.112.158]) by smtp.gmail.com with ESMTPSA id m54sm3031331qtf.67.2020.02.11.15.01.29 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 11 Feb 2020 15:01:29 -0800 (PST) To: gcc-patches , Jeff Law From: Martin Sebor Subject: [PATCH] avoid assuming calloc return value is used (PR 93683) Message-ID: <2ff077c9-e41e-16ae-c551-b8798c23c2d0@gmail.com> Date: Tue, 11 Feb 2020 16:01:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 X-IsSubscribed: yes Along with some special handling of calloc calls, r272717 introduced the assumption into stmt_kills_ref_p that the value returned from the call is used. The code triggers an ICE when invoked during DCE in an attempt to determine whether a calloc call can be eliminated. To avoid the ICE the attached patch avoids using the return value if it's not set. Tested on x86_64-linux. Martin PR tree-optimization/93683 - ICE on calloc with unused return value in ao_ref_init_from_ptr_and_size gcc/testsuite/ChangeLog: PR tree-optimization/93683 * gcc.dg/tree-ssa/ssa-dse-39.c: New test. gcc/ChangeLog: PR tree-optimization/93683 * tree-ssa-alias.c (stmt_kills_ref_p): Avoid using LHS when not set. diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-39.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-39.c new file mode 100644 index 00000000000..29b1a480ecd --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-39.c @@ -0,0 +1,18 @@ +/* PR tree-optimization/93683 - ICE on calloc with unused return value + in ao_ref_init_from_ptr_and_size + { dg-do compile } + { dg-options "-O2 -Wall -Wno-unused-result -fdump-tree-cddce1" } */ + +void f0 (int *a) +{ + *a = 0; + __builtin_calloc (1, 1); +} + +void f1 (int *a, unsigned n) +{ + *a = n; + __builtin_calloc (n, n); +} + +/* { dg-final { scan-tree-dump-not "calloc" "cddce1" } } */ diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index c7e6679f990..fd781050668 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -3265,6 +3265,8 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref) return false; dest = gimple_call_lhs (stmt); + if (!dest) + return false; len = fold_build2 (MULT_EXPR, TREE_TYPE (arg0), arg0, arg1); } else