From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f172.google.com (mail-pl1-f172.google.com [209.85.214.172]) by sourceware.org (Postfix) with ESMTPS id EB8023858C78 for ; Mon, 18 Dec 2023 22:59:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EB8023858C78 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EB8023858C78 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=209.85.214.172 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702940374; cv=none; b=OD4R0T8jWSAvz+CT8Jwn6zDN6cR0Gph+d79qjLV8QpX84823M4JzeWhOFqSxJJVG3ufP8EDyAw9qvlyvYBoL6mOCRryIWLfAnK/X83VAFg01yXHs57Nva0ho/0+ifhSvHVzvHz3vGIqusAjVixzlMQRd9NjU6tBRE6FT/kjOCLM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702940374; c=relaxed/simple; bh=5iha3g3i0RLBQ3SmyD7659UIMtg/zUkCJ7vh9Q9yDbs=; h=MIME-Version:From:Date:Message-ID:Subject:To; b=RTa0gzeVE5SX/FS8RXrKkE63lTQOWqXo0Tjfh0HdqWaWDfhI6CK1z+GsYTOt5JrOXbA9Ntjin1olwbWw3fStfTAAPmcu3GoUluAObA1BUQSW8Lh1ZH2SngwqACY/NFiXO+8c5VohijXZcD01v3rm4B7tDyt+eftDjTrMnFZEjUM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-f172.google.com with SMTP id d9443c01a7336-1d075392ff6so26541255ad.1 for ; Mon, 18 Dec 2023 14:59:32 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1702940371; x=1703545171; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=QN9+CZXhSBn+3MMw8Wty5HL/Z7FlqkX7dCZdKWAn978=; b=Hmwzx+NifZkGNhPFWoTdIJx76L09FG0oGhYRiC7OTjDQuFIA2YLSElwlG4s8vX/SSR f3R1AvdCdoVvIqdsvSvvEwEjaVk4G3vELDJiMRQXbRm8m+IRh1NuxtQILVYqlyFNQKyT uGY7QN7/GUVCI3atfiiu0ATC0kAFPrcmDnwLbwOQiUP/NF40TEMJcs6d6vCjhTkpe6On tX5vPtvsVmxUeXz7vNAZ3miRBEZ6WUaMRw7NTUbwh1V/+6ce/6dXNuLsp1ujg+PMnMrf MemWfCyfNdje/nnG3wxRwlOd/VJeW/bNOJXYbOy+/8ismzVeNSBYqZD0UmGIzgxsBGVb 1A+w== X-Gm-Message-State: AOJu0YyRW31/UbvxYxDCP/UZZypPnyEpWDLDNcWdh9nsiDO30N1kky5V UVzJtdEjAtn9Hor0xq399zqeSoenTr8bkCpi X-Google-Smtp-Source: AGHT+IGzQutnzzjI4WWvWrnfMNQVg/mz2iInE7QjKRlWg+jm7v07iW+ZlRodh8YRYv12SiBgE+lyJQ== X-Received: by 2002:a17:903:234e:b0:1d3:415f:ae9a with SMTP id c14-20020a170903234e00b001d3415fae9amr210269plh.6.1702940371381; Mon, 18 Dec 2023 14:59:31 -0800 (PST) Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com. [209.85.214.176]) by smtp.gmail.com with ESMTPSA id t18-20020a170902d21200b001d3ad367fb4sm3180040ply.155.2023.12.18.14.59.31 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 18 Dec 2023 14:59:31 -0800 (PST) Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-1d075392ff6so26541215ad.1 for ; Mon, 18 Dec 2023 14:59:31 -0800 (PST) X-Received: by 2002:a17:902:ee84:b0:1d3:d645:e05e with SMTP id a4-20020a170902ee8400b001d3d645e05emr142464pld.25.1702940371032; Mon, 18 Dec 2023 14:59:31 -0800 (PST) MIME-Version: 1.0 References: <20231218034422.2668628-1-syq@gcc.gnu.org> In-Reply-To: From: YunQiang Su Date: Tue, 19 Dec 2023 06:59:20 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 1/2] MIPS: host_detect_local_cpu, init ret with concat [PR112759] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org, ian@airs.com, pinskia@gmail.com, matoro_mailinglist_gcc-patches@matoro.tk Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,BODY_8BITS,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,GIT_PATCH_0,HEADER_FROM_DIFFERENT_DOMAINS,KAM_DMARC_STATUS,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Jakub Jelinek =E4=BA=8E2023=E5=B9=B412=E6=9C=8818=E6=97= =A5=E5=91=A8=E4=B8=80 16:10=E5=86=99=E9=81=93=EF=BC=9A > > On Mon, Dec 18, 2023 at 11:44:21AM +0800, YunQiang Su wrote: > > The function `reconcat` cannot append string(s) to NULL, > > as the concat process will stop at the first NULL. > > > > Let's initialize `ret` with `concat (" ", NULL)`, then > > it can be used by reconcat. > > > > gcc/ > > > > PR target/112759 > > * config/mips/driver-native.cc (host_detect_local_cpu): > > initialize ret with concat, so that it can be used by > > reconcat later. > > --- > > gcc/config/mips/driver-native.cc | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/gcc/config/mips/driver-native.cc b/gcc/config/mips/driver-= native.cc > > index afc276f5278..471d1925eff 100644 > > --- a/gcc/config/mips/driver-native.cc > > +++ b/gcc/config/mips/driver-native.cc > > @@ -44,7 +44,7 @@ const char * > > host_detect_local_cpu (int argc, const char **argv) > > { > > const char *cpu =3D NULL; > > - char *ret =3D NULL; > > + char *ret =3D concat(" ", NULL); > > char buf[128]; > > FILE *f; > > bool arch; > > -- > > 2.39.2 > > The formatting is wrong (no space after concat), but more importantly, I will fix the format. > I don't think you want to return " " rather than NULL if there isn't > anything known and it is unnecessary to prefix everything with a space > when > gnu-user.h: " %{march=3Dnative:% gnu-user.h: " %{mtune=3Dnative:% space is already present. Given the simple thing the function does, > I think much better would be to avoid any reconcat calls and just do one > concat, i.e. > --- gcc/config/mips/driver-native.cc 2023-01-02 09:32:58.422764590 +01= 00 > +++ gcc/config/mips/driver-native.cc 2023-12-18 09:08:39.547609739 +01= 00 > @@ -44,6 +44,7 @@ const char * > host_detect_local_cpu (int argc, const char **argv) > { > const char *cpu =3D NULL; > + const char *nan2008 =3D ""; > char *ret =3D NULL; > char buf[128]; > FILE *f; > @@ -90,7 +91,7 @@ host_detect_local_cpu (int argc, const c > > fallback_cpu: > #if defined (__mips_nan2008) > - ret =3D reconcat (ret, " -mnan=3D2008 ", NULL); > + nan2008 =3D "-mnan=3D2008 "; > #endif > > #ifdef HAVE_GETAUXVAL > @@ -104,7 +105,9 @@ fallback_cpu: > #endif > > if (cpu) > - ret =3D reconcat (ret, ret, "-m", argv[0], "=3D", cpu, NULL); > + ret =3D concat (nan2008, "-m", argv[0], "=3D", cpu, NULL); > + else if (nan2008) > + ret =3D concat (nan2008, NULL); > > return ret; > } > > > Or, if you really want to use reconcat, drop that space from > before -mnan=3D2008 and use > ret =3D reconcat (ret, ret ? ret : "", "-m", argv[0], "=3D", cpu, NUL= L); > Good idea. Maybe that we can use ret =3D reconcat (ret, "-m", argv[0], "=3D", cpu, ret, NULL); Then won't worry about ret is NULL here. One reason I want to use reconcat is that I try to avoid something wrong in future, if somebody else add some new detect conditions. With reconcat, the person will need only copy/paste ;) It will reduce the possibility for doing something wrong in future. And let's add a comment here. > Jakub >