public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: YunQiang Su <syq@gcc.gnu.org>
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]
Date: Tue, 19 Dec 2023 09:40:40 +0100	[thread overview]
Message-ID: <ZYFXCB6b2FxoC+cb@tucnak> (raw)
In-Reply-To: <20231219013049.3165982-1-syq@gcc.gnu.org>

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


  reply	other threads:[~2023-12-19  8:40 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-19  1:30 YunQiang Su
2023-12-19  8:40 ` Jakub Jelinek [this message]
2023-12-23  8:25   ` YunQiang Su

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZYFXCB6b2FxoC+cb@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=ian@airs.com \
    --cc=matoro_mailinglist_gcc-patches@matoro.tk \
    --cc=pinskia@gmail.com \
    --cc=syq@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).