From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2119) id 4989D3858D28; Sat, 17 Jun 2023 20:38:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4989D3858D28 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1687034319; bh=w/2LYWt9pSaqekYWznwup6qXxG8kaancs8etxGTbBdM=; h=From:To:Subject:Date:From; b=UM6IOfNKp3SCkqmO/VNPYcy4N+nnrV0T4Zh0NmOT+oh/eVsDqah3cZ4nVDopzu24P uD5V5nswNf39T/TEonPZJ8++Gb0aC5PnAhCJxMEZKWBgW3/bKfuyl16MoUQInVBfjD uV15oI3JKE7M4vDfHQ0nYPTbJb8eb22ESXZ10VlY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jeff Law To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-1901] gcc-ar: Remove code duplication. X-Act-Checkin: gcc X-Git-Author: Costas Argyris X-Git-Refname: refs/heads/master X-Git-Oldrev: f10a4ce044a62c92ff3787895f5bae11f5375a59 X-Git-Newrev: c2b1cbb5f177c5f2f39592dd30c21f0fd03899ad Message-Id: <20230617203839.4989D3858D28@sourceware.org> Date: Sat, 17 Jun 2023 20:38:39 +0000 (GMT) List-Id: https://gcc.gnu.org/g:c2b1cbb5f177c5f2f39592dd30c21f0fd03899ad commit r14-1901-gc2b1cbb5f177c5f2f39592dd30c21f0fd03899ad Author: Costas Argyris Date: Sat Jun 17 14:37:01 2023 -0600 gcc-ar: Remove code duplication. From c3f3b2fd53291805b5d0be19df6d1a348c5889ec Mon Sep 17 00:00:00 2001 From: Costas Argyris Date: Thu, 15 Jun 2023 12:37:35 +0100 Subject: [PATCH] gcc-ar: Remove code duplication. Preparatory refactoring that simplifies by eliminating some duplicated code, before trying to fix 77576. I believe this stands on its own regardless of the PR. It also saves a nargv element when we have a plugin and three when not. gcc/ * gcc-ar.cc (main): Refactor to slightly reduce code duplication. Avoid unnecessary elements in nargv. Diff: --- gcc/gcc-ar.cc | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/gcc/gcc-ar.cc b/gcc/gcc-ar.cc index 5e5b63e1988..4e4c525927d 100644 --- a/gcc/gcc-ar.cc +++ b/gcc/gcc-ar.cc @@ -128,6 +128,9 @@ main (int ac, char **av) const char *exe_name; #if HAVE_LTO_PLUGIN > 0 char *plugin; + const int j = 2; /* Two extra args, --plugin */ +#else + const int j = 0; /* No extra args. */ #endif int k, status, err; const char *err_msg; @@ -206,25 +209,21 @@ main (int ac, char **av) } } + /* Prepend - if necessary. */ + if (is_ar && av[1] && av[1][0] != '-') + av[1] = concat ("-", av[1], NULL); + /* Create new command line with plugin - if we have one, otherwise just copy the command through. */ - nargv = XCNEWVEC (const char *, ac + 4); + nargv = XCNEWVEC (const char *, ac + j + 1); /* +j plugin args +1 for NULL. */ nargv[0] = exe_name; #if HAVE_LTO_PLUGIN > 0 nargv[1] = "--plugin"; nargv[2] = plugin; - if (is_ar && av[1] && av[1][0] != '-') - av[1] = concat ("-", av[1], NULL); - for (k = 1; k < ac; k++) - nargv[2 + k] = av[k]; - nargv[2 + k] = NULL; -#else - if (is_ar && av[1] && av[1][0] != '-') - av[1] = concat ("-", av[1], NULL); - for (k = 1; k < ac; k++) - nargv[k] = av[k]; - nargv[k] = NULL; #endif + for (k = 1; k < ac; k++) + nargv[j + k] = av[k]; + nargv[j + k] = NULL; /* Run utility */ /* ??? the const is misplaced in pex_one's argv? */