From patchwork Sun Jul 28 14:57:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 1138021 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-505741-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="U+CqYOVM"; 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 45xQsf5Glnz9s4Y for ; Mon, 29 Jul 2019 00:57:40 +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:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=gqWgz3xrB6hMOvebF 4Pg08izqgxRQMLWuck/fwzwyYTYOs6+zGAJTRfda19JZT4xX/CPbZhy2lEeI7D/I RVSdIo3qFUWuwtOGU2zXSHYlTJj4fh9nFlh6HOKTza5c2v/tRxZIliUmnONpxhQe QJtK1RUSgsRXk6jVRHIh7rkteo= 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:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=PbtpNwjTk5Q0Nm7xjFhNyvd k8TY=; b=U+CqYOVMk2JpGan1hb/r7E7yUdWnc1O9ZSHyExyBzHwt10wvy1FXpKf v7tu2x0qVYkxqMH0W648E7MqcPbejZX1AKAUiPBxZKZsa87o/jLwafDhc0x69Z9Z VodScd2kWlwajMJlgdJnrMogZ4/ghwa2Pjcw5FHH2nsQmgntWM9Q= Received: (qmail 1096 invoked by alias); 28 Jul 2019 14:57:32 -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 1086 invoked by uid 89); 28 Jul 2019 14:57:32 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-17.3 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=H*f:sk:alpine., U*mliska, liska, Liska 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; Sun, 28 Jul 2019 14:57:30 +0000 Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id E8928ACC4; Sun, 28 Jul 2019 14:57:27 +0000 (UTC) Subject: [PATCH] Remove also 2nd argument for unused delete operator (PR tree-optimization/91270). From: =?utf-8?q?Martin_Li=C5=A1ka?= To: Marc Glisse Cc: Jason Merrill , Richard Biener , gcc-patches@gcc.gnu.org, David Malcolm , dominik.infuehr@theobroma-systems.com, Nathan Sidwell References: <8305B5F4-2A96-4698-8C2E-3255658B5C12@theobroma-systems.com> <0dd24714-1f35-6a80-c607-7c8a332e95b9@suse.cz> <9D090495-3C97-4873-B0DF-2610B478F621@gmail.com> <70688da3-caf4-53c1-d0ee-63d16cbaadd9@suse.cz> <12f00f76-31c1-d3ca-a71b-c14b85892ef5@suse.cz> <6b43a610-4a16-cd1a-b7fa-ef2da7a77729@redhat.com> <74ce7d0b-2610-8cb6-4c22-60f9ed2bfc23@suse.cz> <3a940ca7-b024-61d1-3b05-6d36d3e22f25@suse.cz> Message-ID: <6c25e7d2-81eb-fb59-bd44-839c70cdebcd@suse.cz> Date: Sun, 28 Jul 2019 16:57: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 Hi. And there's one more patch that deals with delete operator which has a second argument (size). That definition GIMPLE statement of the size must be also properly marked. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin From 3d69c779ad5de447cd5ddba2595d2b1586dc5d3c Mon Sep 17 00:00:00 2001 From: Martin Liska Date: Sun, 28 Jul 2019 13:04:28 +0200 Subject: [PATCH] Remove also 2nd argument for unused delete operator (PR tree-optimization/91270). gcc/ChangeLog: 2019-07-28 Martin Liska PR tree-optimization/91270 * tree-ssa-dce.c (eliminate_unnecessary_stmts): Delete also 2nd argument of a delete operator. gcc/testsuite/ChangeLog: 2019-07-28 Martin Liska PR tree-optimization/91270 * g++.dg/torture/pr91270.C: New test. --- gcc/testsuite/g++.dg/torture/pr91270.C | 10 ++++++++++ gcc/tree-ssa-dce.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 gcc/testsuite/g++.dg/torture/pr91270.C diff --git a/gcc/testsuite/g++.dg/torture/pr91270.C b/gcc/testsuite/g++.dg/torture/pr91270.C new file mode 100644 index 00000000000..60d766e9e9f --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr91270.C @@ -0,0 +1,10 @@ +/* { dg-do compile } */ + +struct S { + ~S(); +}; +int a = 123; +void fn1() { + S *s = new S[a]; + delete[] s; +} diff --git a/gcc/tree-ssa-dce.c b/gcc/tree-ssa-dce.c index cf507fa0453..e5a1a9b7aa3 100644 --- a/gcc/tree-ssa-dce.c +++ b/gcc/tree-ssa-dce.c @@ -1294,6 +1294,20 @@ eliminate_unnecessary_stmts (void) && !gimple_plf (def_stmt, STMT_NECESSARY)) gimple_set_plf (stmt, STMT_NECESSARY, false); } + + /* Some delete operators have 2 arguments, where + the second argument is size of the deallocated memory. */ + if (gimple_call_num_args (stmt) == 2) + { + tree ptr = gimple_call_arg (stmt, 1); + 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); + } + } } /* If GSI is not necessary then remove it. */ -- 2.22.0