From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 79A883858298 for ; Tue, 19 Dec 2023 08:40:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 79A883858298 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 79A883858298 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702975250; cv=none; b=DbcKVuGZoO/oX48rbJbnThyIsdJPadG7asXgCpqSm+q0MGhO+6Heh45h6d7tQnbCquXm2NA5sHUFvjKEeZKEBpgVZWi56oBrDZr0y/zjAb81D0ovl9wDThzURJYhs4VVzhYeWI53dzUcgcttRC7js1te8DzP5LCwx0SuLMv1yKY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702975250; c=relaxed/simple; bh=VHYrqT1eDKEDNZXb+4R6NuTN0LUMnUiM95BbfIZzDlM=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=G3h9UFkvKMsX3mSV0MbRNTRq8+nisnT2jlL2Z5uFiKSov3BiA8z4zDWCxdeaY7/IGuXqViNjE8jbEjKEHTiMfXsvJtqN8nseFdLKqH1OYgzb+Sqz8M2VNgXno87OYXZH+MInbmmTCHnAQqQ1OtpLT1zF1iUmATAk5G7HgnxaOrI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1702975249; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=IM8rHeqq5lMtN/TEEpdcu8ryZLQkancXK47aFJ4Geoo=; b=XxW4MpsFrLxENunm5fX6gkU8eKttyyFUEG8a8kFUr1qpYcKRQ5V9F+f2ij7F45uLkIKw1L Wsperp7kVzbAa9oxEID3Imx3P0XY62OMRLQ8zVZC/a4HoU2pkAdKTYk85vVPKQ1Z9/5x2P LVjehLYCX6tXJWHMawyZm+sRmdWgh7I= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-280-vq8M_j0MOVGZlqH-2V5L8w-1; Tue, 19 Dec 2023 03:40:46 -0500 X-MC-Unique: vq8M_j0MOVGZlqH-2V5L8w-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A576E881EAA; Tue, 19 Dec 2023 08:40:45 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.92]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4ACEA2026D66; Tue, 19 Dec 2023 08:40:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 3BJ8eg874083830 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 19 Dec 2023 09:40:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 3BJ8eeBO4083829; Tue, 19 Dec 2023 09:40:40 +0100 Date: Tue, 19 Dec 2023 09:40:40 +0100 From: Jakub Jelinek To: YunQiang Su Cc: gcc-patches@gcc.gnu.org, ian@airs.com, pinskia@gmail.com, matoro_mailinglist_gcc-patches@matoro.tk Subject: Re: [PATCH v2] MIPS: Put the ret to the end of args of reconcat [PR112759] Message-ID: Reply-To: Jakub Jelinek References: <20231219013049.3165982-1-syq@gcc.gnu.org> MIME-Version: 1.0 In-Reply-To: <20231219013049.3165982-1-syq@gcc.gnu.org> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-9.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Tue, Dec 19, 2023 at 09:30:49AM +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 always put the `ret` to the end, as it may be NULL. > We keep use reconcat here, due to that reconcat can make it > easier if we add more hardware features detecting, for example > by hwcap. > > gcc/ > > PR target/112759 > * config/mips/driver-native.cc (host_detect_local_cpu): > Put the ret to the end of args of reconcat. > --- > gcc/config/mips/driver-native.cc | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/gcc/config/mips/driver-native.cc b/gcc/config/mips/driver-native.cc > index afc276f5278..9a224b3f401 100644 > --- a/gcc/config/mips/driver-native.cc > +++ b/gcc/config/mips/driver-native.cc > @@ -44,6 +44,8 @@ const char * > host_detect_local_cpu (int argc, const char **argv) > { > const char *cpu = NULL; > + /* Don't assigne any static string to ret. If you need to do so, > + use concat. */ > char *ret = NULL; > char buf[128]; > FILE *f; > @@ -90,7 +92,8 @@ host_detect_local_cpu (int argc, const char **argv) > > fallback_cpu: > #if defined (__mips_nan2008) > - ret = reconcat (ret, " -mnan=2008 ", NULL); > + /* Put the ret to the end of list, since it maybe NULL. */ > + ret = reconcat (ret, "-mnan=2008", ret, NULL); > #endif > > #ifdef HAVE_GETAUXVAL > @@ -104,7 +107,7 @@ fallback_cpu: > #endif > > if (cpu) > - ret = reconcat (ret, ret, "-m", argv[0], "=", cpu, NULL); > + ret = reconcat (ret, "-m", argv[0], "=", cpu, ret, NULL); I think if you don't put any spaces, the above could return -march=loongson3a-mnan=2008 which will not work. If you want to emit no spurious spaces around but emit them when needed, one way is to put there the space when needed, so ret = reconcat (ret, "-mnan=2008", ret ? " " : "", ret, NULL); or ret = reconcat (ret, "-m", argv[0], "=", cpu, ret ? " " : "", ret, NULL); would do it. I must say I'm also surprised by determining whether to use -mnan=2008 or not by how has the host compiler been configured, shouldn't that be querying properties of the hardware (say, perform some floating point operation that should result in a quiet NaN and see if it has the mantissa MSB set or clear)? And, do you really want to add that -mnan=2008 twice for -march=native -mtune=native, or just for one of those (I assume -mnan=2008 is an ABI option, so shouldn't be about tuning but about -march=). That said, don't really know anything about MIPS, so these are just random comments. Jakub