From patchwork Mon Jan 13 18:11:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Jambor X-Patchwork-Id: 1222267 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-517294-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz 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=eY9T1b68; 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 47xM9C1nzfz9sR0 for ; Tue, 14 Jan 2020 05:11:25 +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:from :to:cc:subject:date:message-id:mime-version:content-type; q=dns; s=default; b=aMErMF+BRe+++8YJwWoQFDIcU2UzFSKvmmkZm4PfasRW82HaY2 4JeoGrdfnHX1OMDf1ApkA2h1Wg8McHubtTIkmyhFGHi69vZlxuGwuZi20pZJa+Nl egi5l+eE7fhQ/rMwMUqxpUQZkjJaVLPQEUCE3fPFd6zIDj9vJlem/Uuq8= 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:from :to:cc:subject:date:message-id:mime-version:content-type; s= default; bh=3/8Cp0IZVkLQSu5cH8MCvCuNo/8=; b=eY9T1b689v2xIMFN8Tse /7x8ZC12xJ1n/BHmwWSdCZjgS7QETn7M54McZnhYd2qBvsGmkV8GIQ39rV2qTLdc oPCkens4k+lSldrA/h2b5Y6Xzy3fRxQJ8hqvIyLkO1BP7G1X/MgIYwyPGMk0J7yj Xnj2N8ATFalb2sdVZuYC1sw= Received: (qmail 4672 invoked by alias); 13 Jan 2020 18:11:18 -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 4663 invoked by uid 89); 13 Jan 2020 18:11:18 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-20.9 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=avail, 93223, sk:ipa_fn_, IPA-CP X-HELO: mx2.suse.de Received: from mx2.suse.de (HELO mx2.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 13 Jan 2020 18:11:17 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id AA2CFAE61 for ; Mon, 13 Jan 2020 18:11:14 +0000 (UTC) From: Martin Jambor To: GCC Patches Cc: Subject: IPA: Avoid segfault in devirtualization_time_bonus (PR 93223) User-Agent: Notmuch/0.29.3 (https://notmuchmail.org) Emacs/26.3 (x86_64-suse-linux-gnu) Date: Mon, 13 Jan 2020 19:11:13 +0100 Message-ID: MIME-Version: 1.0 X-IsSubscribed: yes Hi, the following patch fixes a segfault happening when IPA-CP tried to evaluate benefits of inlining a function specifically compiled with -O0, which therefore does not have an inline summary. The fix is simply to add the check. Bootstrapped on x86_64-linux, Honza has just approved it offline and I will commit it momentarily. Thanks, Martin 2020-01-13 Martin Jambor PR ipa/93223 * ipa-cp.c (devirtualization_time_bonus): Check whether isummary is NULL. testsuite/ * g++.dg/ipa/pr93223.C: New test. --- gcc/ipa-cp.c | 2 +- gcc/testsuite/g++.dg/ipa/pr93223.C | 62 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr93223.C diff --git a/gcc/ipa-cp.c b/gcc/ipa-cp.c index 1c1103ca32b..1b8a5104a3d 100644 --- a/gcc/ipa-cp.c +++ b/gcc/ipa-cp.c @@ -3158,7 +3158,7 @@ devirtualization_time_bonus (struct cgraph_node *node, if (avail < AVAIL_AVAILABLE) continue; isummary = ipa_fn_summaries->get (callee); - if (!isummary->inlinable) + if (!isummary || !isummary->inlinable) continue; int size = ipa_size_summaries->get (callee)->size; diff --git a/gcc/testsuite/g++.dg/ipa/pr93223.C b/gcc/testsuite/g++.dg/ipa/pr93223.C new file mode 100644 index 00000000000..87f98b5e244 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr93223.C @@ -0,0 +1,62 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -std=gnu++14" } */ + +template +bool run(const int item_count, + Function && process_range, + const int max_parallelism, + int* progress = nullptr) +{ + if (max_parallelism <= 1) + { + if (progress == nullptr) + { + return process_range(0); + } + else + { + auto result = true; + for (int i = 0; i != item_count && result; ++i) + { + (*progress)++; + result = process_range(i); + } + return result; + } + } + + if (max_parallelism > 10) + { + if (progress == nullptr) + { + return process_range(0); + } + else + { + auto result = true; + for (int i = 0; i != item_count && result; ++i) + { + (*progress)++; + result = process_range(i); + } + return result; + } + } + return false; +} + +namespace +{ +__attribute__((optimize(0))) bool worker_fun(const int) +{ + return true; +} +} + +void demo(int n) +{ + for (int i = 0; i < n; ++i) + { + run(n, &worker_fun, n); + } +}