From: Kito Cheng Date: Mon, 28 Jul 2025 12:49:39 +0000 (+0800) Subject: RISC-V: Support -march=unset X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aa1ae5284da3377190c7dd1e0dbd865bb41c46e6;p=thirdparty%2Fgcc.git RISC-V: Support -march=unset This patch introduces a new `-march=unset` option for RISC-V GCC that allows users to explicitly ignore previous `-march` options and derive the architecture string from the `-mcpu` option instead. This feature is particularly useful for build systems and toolchain configurations where you want to ensure the architecture is always derived from the CPU specification rather than relying on potentially conflicting `-march` options. gcc/ChangeLog: * common/config/riscv/riscv-common.cc (riscv_expand_arch): Ignore `unset`. * config/riscv/riscv.h (OPTION_DEFAULT_SPECS): Handle `-march=unset`. (ARCH_UNSET_CLEANUP_SPECS): New. (DRIVER_SELF_SPECS): Handle -march=unset. * doc/invoke.texi (RISC-V Options): Update documentation for `-march=unset`. gcc/testsuite/ChangeLog: * gcc.target/riscv/arch-unset-1.c: New test. * gcc.target/riscv/arch-unset-2.c: New test. * gcc.target/riscv/arch-unset-3.c: New test. * gcc.target/riscv/arch-unset-4.c: New test. * gcc.target/riscv/arch-unset-5.c: New test. --- diff --git a/gcc/common/config/riscv/riscv-common.cc b/gcc/common/config/riscv/riscv-common.cc index da3cb9f788d..f2ede074ac5 100644 --- a/gcc/common/config/riscv/riscv-common.cc +++ b/gcc/common/config/riscv/riscv-common.cc @@ -1758,6 +1758,11 @@ riscv_expand_arch (int argc, { gcc_assert (argc == 1); location_t loc = UNKNOWN_LOCATION; + + /* Filter out -march=unset, it will expand from -mcpu later. */ + if (strcmp (argv[0], "unset") == 0) + return ""; + /* Try to interpret the arch as CPU first. */ const char *arch_str = riscv_expand_arch_from_cpu (argc, argv); if (!strlen (arch_str)) diff --git a/gcc/config/riscv/riscv.h b/gcc/config/riscv/riscv.h index 45fa521f219..29342d8a64c 100644 --- a/gcc/config/riscv/riscv.h +++ b/gcc/config/riscv/riscv.h @@ -71,7 +71,7 @@ extern const char *riscv_arch_help (int argc, const char **argv); {"tune", "%{!mtune=*:" \ " %{!mcpu=*:-mtune=%(VALUE)}" \ " %{mcpu=*:-mtune=%:riscv_default_mtune(%* %(VALUE))}}" }, \ - {"arch", "%{!march=*:" \ + {"arch", "%{!march=*|march=unset:" \ " %{!mcpu=*:-march=%(VALUE)}" \ " %{mcpu=*:%:riscv_expand_arch_from_cpu(%* %(VALUE))}}" }, \ {"abi", "%{!mabi=*:-mabi=%(VALUE)}" }, \ @@ -111,13 +111,19 @@ extern const char *riscv_arch_help (int argc, const char **argv); %(subtarget_asm_spec)" \ ASM_MISA_SPEC +/* Drop all -march=* options before -march=unset. */ +#define ARCH_UNSET_CLEANUP_SPECS \ + "%{march=unset:%