From patchwork Mon Aug 5 06:44:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1141995 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-506183-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.b="E+f8DlrV"; 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 4627Y05srrz9sNf for ; Mon, 5 Aug 2019 16:44:36 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=JAS8yci9oQgZDW4Vl 7UsVPKGz9tR5DJVq/+9KSZzSUTLPaeVvKe0XQKfyUYNjxZM9im2IdPCGjBcmxpeJ I7tu3GJndj4WOaAPqeSzy22Wc055z19YHLBBy6UBZqKB0cBFED177gTtiiBiTDES kM3HVDm0693KojGmd6YyCaxKKY= 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 :subject:to:cc:references:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=mf3Ddw7sgJEXbmDxWVLIFN1 J1ok=; b=E+f8DlrVoxl2H9wsm1t1iw3F/i244FCojCpUB/zijQIzY/8usB6Cfii gY4La6NEAMkuzyyHkjndgbVm7KciNnhfWNtBKuGA/Vc9LYUUjqNuAY1B5sMJeTdh EykZbypv9aSwVzhSMNwXsuQT22ur3vtB0equn8rPAGpjOu5wPz34= Received: (qmail 43026 invoked by alias); 5 Aug 2019 06:44:29 -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 43015 invoked by uid 89); 5 Aug 2019 06:44:29 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de Received: from mx2.suse.de (HELO mx1.suse.de) (195.135.220.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Aug 2019 06:44:27 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 95A75AEE1; Mon, 5 Aug 2019 06:44:25 +0000 (UTC) Subject: [PATCH] Handle new operators with no arguments in DCE. To: "H.J. Lu" Cc: Marc Glisse , David Malcolm , GCC Patches , Richard Biener , dominik.infuehr@theobroma-systems.com References: <8305B5F4-2A96-4698-8C2E-3255658B5C12@theobroma-systems.com> <20171122103742.GN14653@tucnak> <20171129083045.GX2353@tucnak> <1511972121.27881.39.camel@redhat.com> <0dd24714-1f35-6a80-c607-7c8a332e95b9@suse.cz> <993cd4f8-cc02-6934-b19b-5a313db0475c@suse.cz> From: =?utf-8?q?Martin_Li=C5=A1ka?= Message-ID: Date: Mon, 5 Aug 2019 08:44:26 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.8.0 MIME-Version: 1.0 In-Reply-To: X-IsSubscribed: yes On 8/2/19 11:34 PM, H.J. Lu wrote: > On Tue, Jul 2, 2019 at 4:50 AM Martin Liška wrote: >> >> Second part. >> >> Martin > > This caused: > > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91334 > Hi. I'm sending fix for the ICE. The issue is that we can end up with a ctor without an argument (when not being used). Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin From 76d215d59f32c5f6cbcb0a0ad4ecbfff8f181770 Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Mon, 5 Aug 2019 06:55:45 +0200 Subject: [PATCH] Handle new operators with no arguments in DCE. gcc/ChangeLog: 2019-08-05 Martin Liska PR c++/91334 * tree-ssa-dce.c (propagate_necessity): Handle new operators with not arguments. (eliminate_unnecessary_stmts): Likewise. gcc/testsuite/ChangeLog: 2019-08-05 Martin Liska PR c++/91334 * g++.dg/torture/pr91334.C: New test. --- gcc/testsuite/g++.dg/torture/pr91334.C | 14 ++++++++++++++ gcc/tree-ssa-dce.c | 22 ++++++++++++++++------ 2 files changed, 30 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/torture/pr91334.C diff --git a/gcc/testsuite/g++.dg/torture/pr91334.C b/gcc/testsuite/g++.dg/torture/pr91334.C new file mode 100644 index 00000000000..ba79d712b07 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr91334.C @@ -0,0 +1,14 @@ +/* PR c++/91334. */ +/* { dg-do compile } */ + +#include +#include + +struct A { + A() { throw 0; } + void* operator new(size_t size, double = 0.0) { return ::operator new(size);} + void operator delete(void* p, double) { exit(0); } + void operator delete(void* p) { abort(); } +}; + +int main() { try { new A; } catch(...) {} } diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index 80d5f5c30f7..afb7bd9dedc 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -810,6 +810,11 @@ propagate_necessity (bool aggressive) if (is_delete_operator || gimple_call_builtin_p (stmt, BUILT_IN_FREE)) { + /* It can happen that a user delete operator has the pointer + argument optimized out already. */ + if (gimple_call_num_args (stmt) == 0) + continue; + tree ptr = gimple_call_arg (stmt, 0); gimple *def_stmt; tree def_callee; @@ -1323,13 +1328,18 @@ eliminate_unnecessary_stmts (void) || (is_gimple_call (stmt) && gimple_call_operator_delete_p (as_a (stmt))))) { - tree ptr = gimple_call_arg (stmt, 0); - if (TREE_CODE (ptr) == SSA_NAME) + /* It can happen that a user delete operator has the pointer + argument optimized out already. */ + if (gimple_call_num_args (stmt) > 0) { - gimple *def_stmt = SSA_NAME_DEF_STMT (ptr); - if (!gimple_nop_p (def_stmt) - && !gimple_plf (def_stmt, STMT_NECESSARY)) - gimple_set_plf (stmt, STMT_NECESSARY, false); + tree ptr = gimple_call_arg (stmt, 0); + if (TREE_CODE (ptr) == SSA_NAME) + { + gimple *def_stmt = SSA_NAME_DEF_STMT (ptr); + if (!gimple_nop_p (def_stmt) + && !gimple_plf (def_stmt, STMT_NECESSARY)) + gimple_set_plf (stmt, STMT_NECESSARY, false); + } } } -- 2.22.0