From patchwork Tue Jul 9 12:47:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christoph_M=C3=BCllner?= X-Patchwork-Id: 1958409 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=vrull.eu header.i=@vrull.eu header.a=rsa-sha256 header.s=google header.b=Cd6UDl+0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WJLRm0dhsz1xpd for ; Tue, 9 Jul 2024 22:49:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 32626386D61D for ; Tue, 9 Jul 2024 12:49:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id A4CD2386D623 for ; Tue, 9 Jul 2024 12:48:12 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A4CD2386D623 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=vrull.eu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=vrull.eu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A4CD2386D623 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::62c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720529303; cv=none; b=etnlR+ATkFM/VIVNIzYlr7GMqi3nBdgUp2HSQbT6Kmbntv2vhnt9hxDimp76WXPnJANTwO1jM4VJFSnk6slh/ozv66rFHCiOD7lNBI4ge6q3zqvqLGzPgDwAYEI4esHoj+BCfPErvm7khBfhCKdu1NFrid1JrHmkwGjmxzDslOE= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720529303; c=relaxed/simple; bh=F1/GvnxDQgkw+5h/bGjX7motdC+1PkpdfdjeyYJzc3Y=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=PZqmlrmYAc5NHSopKm9Xe8dt/AjxSfqJagpwuKgUehPYGYK1jnK6atOk8nEVc0sFwnuyQsisiAqsIlAgh+Dha1bT5CHjvhCYQjXVqSprTLLflhmWM3h8pPgSuyeY0B/hw/sUR6bl6q7J8P1X35AwFqTriGm/7R2MUEtJAYqTlC4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-ej1-x62c.google.com with SMTP id a640c23a62f3a-a77b60cafecso595554966b.1 for ; Tue, 09 Jul 2024 05:48:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vrull.eu; s=google; t=1720529290; x=1721134090; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JC19Y5xOk+jM4C2Pr3u9/whGF+BT18eB8pbwPdiRPHo=; b=Cd6UDl+0fC1nJRTWzvJfX9a7G+YhG+G0E/tH/KQwlvEAf0AgFLbovpUe9I/y0+mJ4k hFkUSHiU04PmWb7OnPNmitGgSpFC4Dw+4JLJXTihrq8mjGMtLvMtjDvJFCbCExriN6Wk 0vUL3Si+a+DHVsCnLnJQCkcyNJJq1woZIGqAlYQL2pJaAAHSwxpD/7dlqJe4IaIldXZ4 ReKlsiThmZGg61TiLRvWZUDnvIPjmYW7VQ9JKfrl2gAoCixl4LjeAUaqWJnLsBPcEKge z566StUCJDE9ZLu4O7BJqhSTZ/7BKcoafZn8Xe2Vr/C/OcNVxB95TTszyMboVuL8AiqH ED4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720529290; x=1721134090; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JC19Y5xOk+jM4C2Pr3u9/whGF+BT18eB8pbwPdiRPHo=; b=mvye7P/8ocoJ2+1+HV3T4Mp6ISJTZfDvPUugH6rxvjpQQtYqcTaOwGUNYdnnstWUJx jgyvGSu8y4Gf48TnmjqDKWSHCavoepMAr9lELNH5VDB9r86uU3iuUgG+SY11I5AaWm+U JxqHTPY1cg9t+d79LqHK0lKZNddrZ9bf0+SsAdgQAcP3iuSRrvVTCOZNoVnG6/W6jY2w PuRPwYAworlgm3JfXLqrPsEvT7RJ7yKvT1IVCWonIKgtGJQ9YxTzjz7EyRa4g+OKk6CC nqfqTKbr8tKf2X6GiUeKLgvBCz8VoRXCutZ1GjkIUZO/j/6FeJsF20+8ZLUZMTmgi/4V j3ng== X-Gm-Message-State: AOJu0YxfCoYTsivi1b6JqmwSyTJX2auP32ho+iO2fWkOPB8It/5pupX+ dleS5nfvLZmImqIyhDzpnkDXsU3FAeNxfeT6yt78U3kxxijaFQjSOqJwAwIMnqZiJVjZHkfyjNt zeZ4= X-Google-Smtp-Source: AGHT+IFFu8CArcRHgLaeaGSCVaN3uiCDFoBpxAKuYrc8bPdy7ZQSBqjESNUU3w/6jiNsK147itqicw== X-Received: by 2002:a17:906:4715:b0:a77:c525:5c70 with SMTP id a640c23a62f3a-a780b6b1901mr175340866b.32.1720529290418; Tue, 09 Jul 2024 05:48:10 -0700 (PDT) Received: from antares.fritz.box (62-178-148-172.cable.dynamic.surfer.at. [62.178.148.172]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a780a6dc721sm74268466b.53.2024.07.09.05.48.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Jul 2024 05:48:09 -0700 (PDT) From: =?utf-8?q?Christoph_M=C3=BCllner?= To: gcc-patches@gcc.gnu.org, Kito Cheng , Jim Wilson , Palmer Dabbelt , Andrew Waterman , Philipp Tomsich , Jeff Law , Vineet Gupta , Pan Li , Patrick O'Neill Cc: =?utf-8?q?Christoph_M=C3=BCllner?= Subject: [PATCH 3/6] RISC-V: Attribute parser: Use alloca() instead of new + std::unique_ptr Date: Tue, 9 Jul 2024 14:47:54 +0200 Message-ID: <20240709124757.1405749-4-christoph.muellner@vrull.eu> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240709124757.1405749-1-christoph.muellner@vrull.eu> References: <20240709124757.1405749-1-christoph.muellner@vrull.eu> MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Allocating an object on the heap with new, wrapping it in a std::unique_ptr and finally getting the buffer via buf.get() is a correct way to allocate a buffer that is automatically freed on return. However, a simple invocation of alloca() does the same with less overhead. gcc/ChangeLog: * config/riscv/riscv-target-attr.cc (riscv_target_attr_parser::parse_arch): Replace new + std::unique_ptr by alloca(). (riscv_process_one_target_attr): Likewise. (riscv_process_target_attr): Likewise. Signed-off-by: Christoph Müllner --- gcc/config/riscv/riscv-target-attr.cc | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/gcc/config/riscv/riscv-target-attr.cc b/gcc/config/riscv/riscv-target-attr.cc index 19eb7b06d548..e59cc53f23c6 100644 --- a/gcc/config/riscv/riscv-target-attr.cc +++ b/gcc/config/riscv/riscv-target-attr.cc @@ -109,8 +109,7 @@ riscv_target_attr_parser::parse_arch (const char *str) { /* Parsing the extension list like "+[,+]*". */ size_t len = strlen (str); - std::unique_ptr buf (new char[len+1]); - char *str_to_check = buf.get (); + char *str_to_check = (char *) alloca (len + 1); strcpy (str_to_check, str); const char *token = strtok_r (str_to_check, ",", &str_to_check); m_subset_list = riscv_cmdline_subset_list ()->clone (); @@ -247,8 +246,7 @@ riscv_process_one_target_attr (char *arg_str, return false; } - std::unique_ptr buf (new char[len+1]); - char *str_to_check = buf.get(); + char *str_to_check = (char *) alloca (len + 1); strcpy (str_to_check, arg_str); char *arg = strchr (str_to_check, '='); @@ -334,8 +332,7 @@ riscv_process_target_attr (tree fndecl, tree args, location_t loc, return false; } - std::unique_ptr buf (new char[len+1]); - char *str_to_check = buf.get (); + char *str_to_check = (char *) alloca (len + 1); strcpy (str_to_check, TREE_STRING_POINTER (args)); /* Used to catch empty spaces between commas i.e.