From patchwork Fri Sep 1 13:04:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Boeckel X-Patchwork-Id: 137393 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c792:0:b0:3f2:4152:657d with SMTP id b18csp876967vqu; Fri, 1 Sep 2023 06:13:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEg887BR0R6egpdBvzlS10LC7XP0FiOa9eBYRZFvQE4flAw6PlY8z3obShavS0YVkZdEQgq X-Received: by 2002:aa7:d888:0:b0:522:b876:9ef5 with SMTP id u8-20020aa7d888000000b00522b8769ef5mr3429217edq.8.1693573981773; Fri, 01 Sep 2023 06:13:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693573981; cv=none; d=google.com; s=arc-20160816; b=K5ACc01+uRjifoneFpsvS9yGGPzWTLc4kKuJDm+DgwHeCBqM/QsY5ckyhT6JppsfPd 16ESarHPMYCnJm4pN3DL3YTKl9fbfTMTQ6HwgRAEG6FrVttdv8u+4ZVYPhLAu84lry9F 1j1ZojDwpXPlakjI9nCM1U3xRqrhqUPldPdR4f0SoicgpWo3LnrRO/LIbnTjF1piI852 5Zr7v8fDVXfTXCC0KKfyzQ9hDV07Lzo/htHfo/UaoJRqmb13F6TO7K67gqJhNENqPfyx qKCcZwygqCuLa5Kc4SpUMFDg/tTO24Ca+SyJ/DbV4r5IZCkcNG25d1Q0Yi5Fz3qymA2U H9cg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=lP3364Z6HzVU3Ekzueaq+vdqRp4slb3XDgcyWa7noNc=; fh=k/Ceyxcdi7bE5nnOFo1POLZehPadJc8HBydZ6eliaUc=; b=ybuTI7OfXnZPTFntpJxgfd8xhDNHAxe8rCwU9w5vpgQp/fZWaLfVIozImlBgvFkUOn GZBY6BWPmQjU3rHHLMzbrhfQc5TNBBjYtBXkw7HJTJ7FG3x9ZJMPLsm0fdCgp5oYR8YQ Z7lyZzjWQeAW+hzwxrIuJoEtzzU5pw5hY4+bQZxXJ2kdM1dN+8xbw/xTc3EpHgb9NVxd NW/a7voZATp2Jf8kboY1Uuqyic0Vs7YplEU1PSWCwzqCcuS1KqEBJ7d3iUnpH2wh/Gx4 v/Yz+dIv9z/jF5ylR4tmPYefhS6dbRTAjuuH04d0BHkiH/KFFklniylwc5R+KlOYHD6X Hh6A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GOJE5yi7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id e12-20020a50fb8c000000b0052bcdbe263csi2446262edq.149.2023.09.01.06.13.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:13:01 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=GOJE5yi7; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D06FC3959E4F for ; Fri, 1 Sep 2023 13:05:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D06FC3959E4F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1693573510; bh=lP3364Z6HzVU3Ekzueaq+vdqRp4slb3XDgcyWa7noNc=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=GOJE5yi7sY2mIVIDijO1S16sDh1wTDZE6JcwtqNlBqgjffxLr5aymL3ZBK2cqzEek RR38nH+C2fqarBi1bpr3dUS0T4vEEvoxgTuMyJz+3YAnVsSCjnR0x45mRwRaqXAJ4F MgG0C5sBmDNl2fL2EG5GHnYwVqwWdfJEarVK08+A= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72f.google.com (mail-qk1-x72f.google.com [IPv6:2607:f8b0:4864:20::72f]) by sourceware.org (Postfix) with ESMTPS id B24EF3853D0F for ; Fri, 1 Sep 2023 13:04:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B24EF3853D0F Received: by mail-qk1-x72f.google.com with SMTP id af79cd13be357-76d7224c5bcso114913985a.2 for ; Fri, 01 Sep 2023 06:04:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693573456; x=1694178256; 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=lP3364Z6HzVU3Ekzueaq+vdqRp4slb3XDgcyWa7noNc=; b=ar3yig4PoQ1cXeDjTJ3kIOlJQayl31c+WlPdTSzJK6Qnp+FzK2XXZNsxxQOq4GwRiw xohePXul4IBtdZYLD8nv4SRm54IxBRtNegMSYa1Ym4YQyPOy9rg/pDlA8sBFMQNkCuHd yhun7GoaOB0iQvIQLcBRnGWUSvqh53hOwwM1i7INZVQ0RJ2MWtW1jrBHyB89rjmm3eqY IYXDAiJDoyczrXVyvAwwequMpH3eRoQ1RabW1SDA2vgJ/YZrTwH/ZDN4eTmDjNJoyXDe xuuATlELNcfpBWszl1/1BuUvz1Gg3hfi5SNL80Q7JLIB5fAYYB1KP0G9mXaI6Eja2+B4 2L5A== X-Gm-Message-State: AOJu0Yx//Uls6cTOxVeTh+fqSxICbIRrstIJnDNFbASbvHG2PN8yTYq8 nNwzZZ6nRZAAKtRTZ1QzUWyymEjgcPAxP3ysTwWEAw== X-Received: by 2002:a05:620a:408a:b0:76c:e7b7:1d9d with SMTP id f10-20020a05620a408a00b0076ce7b71d9dmr2875530qko.27.1693573455890; Fri, 01 Sep 2023 06:04:15 -0700 (PDT) Received: from localhost (cpe-142-105-146-128.nycap.res.rr.com. [142.105.146.128]) by smtp.gmail.com with ESMTPSA id u7-20020ae9c007000000b0076cb0ed2d7asm1388835qkk.24.2023.09.01.06.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Sep 2023 06:04:15 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v8 1/4] spec: add a spec function to join arguments Date: Fri, 1 Sep 2023 09:04:01 -0400 Message-ID: <20230901130407.259768-2-ben.boeckel@kitware.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230901130407.259768-1-ben.boeckel@kitware.com> References: <20230901130407.259768-1-ben.boeckel@kitware.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: , X-Patchwork-Original-From: Ben Boeckel via Gcc-patches From: Ben Boeckel Reply-To: Ben Boeckel Cc: gcc@gcc.gnu.org, brad.king@kitware.com, fortran@gcc.gnu.org, Ben Boeckel , nathan@acm.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1775841031731543096 X-GMAIL-MSGID: 1775841031731543096 When passing `-o` flags to other options, the typical `-o foo` spelling leaves a leading whitespace when replacing elsewhere. This ends up creating flags spelled as `-some-option-with-arg= foo.ext` which doesn't parse properly. When attempting to make a spec function to just remove the leading whitespace, the argument splitting ends up masking the whitespace. However, the intended extension *also* ends up being its own argument. To perform the desired behavior, the arguments need to be concatenated together. gcc/: * gcc.cc (join_spec_func): Add a spec function to join all arguments. Signed-off-by: Ben Boeckel --- gcc/gcc.cc | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/gcc/gcc.cc b/gcc/gcc.cc index fdfac0b4fe4..4c4e81dee50 100644 --- a/gcc/gcc.cc +++ b/gcc/gcc.cc @@ -447,6 +447,7 @@ static const char *greater_than_spec_func (int, const char **); static const char *debug_level_greater_than_spec_func (int, const char **); static const char *dwarf_version_greater_than_spec_func (int, const char **); static const char *find_fortran_preinclude_file (int, const char **); +static const char *join_spec_func (int, const char **); static char *convert_white_space (char *); static char *quote_spec (char *); static char *quote_spec_arg (char *); @@ -1772,6 +1773,7 @@ static const struct spec_function static_spec_functions[] = { "debug-level-gt", debug_level_greater_than_spec_func }, { "dwarf-version-gt", dwarf_version_greater_than_spec_func }, { "fortran-preinclude-file", find_fortran_preinclude_file}, + { "join", join_spec_func}, #ifdef EXTRA_SPEC_FUNCTIONS EXTRA_SPEC_FUNCTIONS #endif @@ -10975,6 +10977,27 @@ find_fortran_preinclude_file (int argc, const char **argv) return result; } +/* The function takes any number of arguments and joins them together. + + This seems to be necessary to build "-fjoined=foo.b" from "-fseparate foo.a" + with a %{fseparate*:-fjoined=%.b$*} rule without adding undesired spaces: + when doing $* replacement we first replace $* with the rest of the switch + (in this case ""), and then add any arguments as arguments after the result, + resulting in "-fjoined= foo.b". Using this function with e.g. + %{fseparate*:-fjoined=%:join(%.b$*)} gets multiple words as separate argv + elements instead of separated by spaces, and we paste them together. */ + +static const char * +join_spec_func (int argc, const char **argv) +{ + if (argc == 1) + return argv[0]; + for (int i = 0; i < argc; ++i) + obstack_grow (&obstack, argv[i], strlen (argv[i])); + obstack_1grow (&obstack, '\0'); + return XOBFINISH (&obstack, const char *); +} + /* If any character in ORIG fits QUOTE_P (_, P), reallocate the string so as to precede every one of them with a backslash. Return the original string or the reallocated one. */