]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
aarch64: Suggest an -mcpu option when user passes CPU name to -march
authorKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 5 Sep 2022 13:31:32 +0000 (14:31 +0100)
committerKyrylo Tkachov <kyrylo.tkachov@arm.com>
Mon, 5 Sep 2022 13:37:13 +0000 (14:37 +0100)
This small patch helps users who confuse -march and -mcpu on AArch64.
Sometimes users pass -march with a CPU name, where they most likely wanted to
use -mcpu, which would select the right architecture features *and* tune for
their desired CPU. Currently we'll just error out with an unkown architecture
message and list the valid architecture options.
With this patch we check if their string matches a known CPU and suggest they
use an -mcpu option instead.

So compiling with -march=neoverse-n1 will now give the error:
cc1: error: unknown value 'neoverse-n1' for '-march'
cc1: note: valid arguments are: armv8-a armv8.1-a armv8.2-a armv8.3-a armv8.4-a armv8.5-a armv8.6-a armv8.7-a armv8.8-a armv8-r armv9-a
cc1: note: did you mean '-mcpu=neoverse-n1'?

Bootstrapped and tested on aarch64-none-linux-gnu.

gcc/ChangeLog:

* config/aarch64/aarch64.cc (aarch64_validate_march): Check if invalid arch
string is a valid -mcpu string and emit hint.

gcc/testsuite/ChangeLog:

* gcc.target/aarch64/spellcheck_10.c: New test.

gcc/config/aarch64/aarch64.cc
gcc/testsuite/gcc.target/aarch64/spellcheck_10.c [new file with mode: 0644]

index 2311ad0e2b83f8c9ce110dd06b12f7699740f213..566763ce50c42f61fe1b9c80f7d5392c52dc1db9 100644 (file)
@@ -18019,6 +18019,11 @@ aarch64_validate_march (const char *str, const struct processor **res,
       case AARCH64_PARSE_INVALID_ARG:
        error ("unknown value %qs for %<-march%>", str);
        aarch64_print_hint_for_arch (str);
+       /* A common user error is confusing -march and -mcpu.
+          If the -march string matches a known CPU suggest -mcpu.  */
+       parse_res = aarch64_parse_cpu (str, res, isa_flags, &invalid_extension);
+       if (parse_res == AARCH64_PARSE_OK)
+         inform (input_location, "did you mean %<-mcpu=%s%>?", str);
        break;
       case AARCH64_PARSE_INVALID_FEATURE:
        error ("invalid feature modifier %qs in %<-march=%s%>",
diff --git a/gcc/testsuite/gcc.target/aarch64/spellcheck_10.c b/gcc/testsuite/gcc.target/aarch64/spellcheck_10.c
new file mode 100644 (file)
index 0000000..08540c9
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-skip-if "" { *-*-* } { "-march=*" } { "" } } */
+/* { dg-skip-if "" { *-*-* } { "-mcpu=*" } { "" } } */
+/* { dg-options "-march=neoverse-n1" } */
+
+void
+foo ()
+{
+}
+
+/* { dg-error "unknown value .neoverse-n1. for .-march."  "" { target *-*-* } 0 } */
+/* { dg-message "valid arguments are: \[^\n\r]*"  "" { target *-*-* } 0 } */
+/* { dg-message "did you mean .-mcpu=neoverse-n1.?"  "" { target *-*-* } 0 } */