From patchwork Sun Jan 3 18:26:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 1421905 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (768-bit key; unprotected) header.d=tromey.com header.i=@tromey.com header.a=rsa-sha256 header.s=default header.b=vNqrgJnS; dkim-atps=neutral Received: from sourceware.org (unknown [8.43.85.97]) (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 ozlabs.org (Postfix) with ESMTPS id 4D86fx5WjTz9sSs for ; Mon, 4 Jan 2021 05:27:05 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5127B3870849; Sun, 3 Jan 2021 18:26:39 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from gateway33.websitewelcome.com (gateway33.websitewelcome.com [192.185.146.97]) by sourceware.org (Postfix) with ESMTPS id 1D702386F824 for ; Sun, 3 Jan 2021 18:26:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1D702386F824 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tom@tromey.com Received: from cm17.websitewelcome.com (cm17.websitewelcome.com [100.42.49.20]) by gateway33.websitewelcome.com (Postfix) with ESMTP id AD8F14EDD1 for ; Sun, 3 Jan 2021 12:26:34 -0600 (CST) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id w85KkOsqyDT64w85KkVz9D; Sun, 03 Jan 2021 12:26:34 -0600 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=oL2tdLAC2jPaNgvkF6H7qd+6yLKeV1gfRg/DwgmGkeE=; b=vNqrgJnSIoB3U+CQmgJxaU7usg L6EIAh97yCT+juZO4eipscg6qBWfWSZdYbsT+iErZyKGAPASW5QpShaBtOxBArEXsYtC/qlNkSStv x8ZikvuC0rc50sVGjHEja2wwr; Received: from 97-122-81-39.hlrn.qwest.net ([97.122.81.39]:39392 helo=localhost.localdomain) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.93) (envelope-from ) id 1kw85K-00234L-Fy; Sun, 03 Jan 2021 11:26:34 -0700 From: Tom Tromey To: gcc-patches@gcc.gnu.org Subject: [PATCH 07/10] libcc1: use std::vector when building function types Date: Sun, 3 Jan 2021 11:26:28 -0700 Message-Id: <20210103182631.2316205-8-tom@tromey.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210103182631.2316205-1-tom@tromey.com> References: <20210103182631.2316205-1-tom@tromey.com> MIME-Version: 1.0 X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - gcc.gnu.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 97.122.81.39 X-Source-L: No X-Exim-ID: 1kw85K-00234L-Fy X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 97-122-81-39.hlrn.qwest.net (localhost.localdomain) [97.122.81.39]:39392 X-Source-Auth: tom+tromey.com X-Email-Count: 8 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3032.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_ABUSEAT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , Cc: Tom Tromey Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This changes libcc1 to use std::vector in the code that builds function types. This avoids some explicit memory management. libcc1/ChangeLog 2021-01-03 Tom Tromey * libcp1plugin.cc (plugin_build_function_type): Use std::vector. * libcc1plugin.cc (plugin_build_function_type): Use std::vector. --- libcc1/ChangeLog | 5 +++++ libcc1/libcc1plugin.cc | 11 +++++------ libcc1/libcp1plugin.cc | 11 +++++------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/libcc1/libcc1plugin.cc b/libcc1/libcc1plugin.cc index a0fb61f2e46..aa07e6dbaef 100644 --- a/libcc1/libcc1plugin.cc +++ b/libcc1/libcc1plugin.cc @@ -67,6 +67,8 @@ #include "rpc.hh" #include "gcc-c-interface.h" +#include + #ifdef __GNUC__ #pragma GCC visibility push(default) #endif @@ -672,24 +674,21 @@ plugin_build_function_type (cc1_plugin::connection *self, const struct gcc_type_array *argument_types_in, int is_varargs) { - tree *argument_types; tree return_type = convert_in (return_type_in); tree result; - argument_types = new tree[argument_types_in->n_elements]; + std::vector argument_types (argument_types_in->n_elements); for (int i = 0; i < argument_types_in->n_elements; ++i) argument_types[i] = convert_in (argument_types_in->elements[i]); if (is_varargs) result = build_varargs_function_type_array (return_type, argument_types_in->n_elements, - argument_types); + argument_types.data ()); else result = build_function_type_array (return_type, argument_types_in->n_elements, - argument_types); - - delete[] argument_types; + argument_types.data ()); plugin_context *ctx = static_cast (self); return convert_out (ctx->preserve (result)); diff --git a/libcc1/libcp1plugin.cc b/libcc1/libcp1plugin.cc index 648368353cb..d2700e24152 100644 --- a/libcc1/libcp1plugin.cc +++ b/libcc1/libcp1plugin.cc @@ -70,6 +70,8 @@ #include "marshall-cp.hh" #include "rpc.hh" +#include + #ifdef __GNUC__ #pragma GCC visibility push(default) #endif @@ -1980,24 +1982,21 @@ plugin_build_function_type (cc1_plugin::connection *self, const struct gcc_type_array *argument_types_in, int is_varargs) { - tree *argument_types; tree return_type = convert_in (return_type_in); tree result; - argument_types = new tree[argument_types_in->n_elements]; + std::vector argument_types (argument_types_in->n_elements); for (int i = 0; i < argument_types_in->n_elements; ++i) argument_types[i] = convert_in (argument_types_in->elements[i]); if (is_varargs) result = build_varargs_function_type_array (return_type, argument_types_in->n_elements, - argument_types); + argument_types.data ()); else result = build_function_type_array (return_type, argument_types_in->n_elements, - argument_types); - - delete[] argument_types; + argument_types.data ()); plugin_context *ctx = static_cast (self); return convert_out (ctx->preserve (result));