[clang] [llvm] [llvm][RISC-V] Improve error message for invalid extension letters (PR #90468)
David Spickett via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 29 06:17:08 PDT 2024
https://github.com/DavidSpickett created https://github.com/llvm/llvm-project/pull/90468
Previously you got:
clang: error: invalid arch name 'rv64v', first letter should be 'e', 'i' or 'g'
Which to me, unfamiliar with riscv, reads as if I should have used "[eig]rv64v". Which is not what clang means.
Include the first bit in the error message to make this clearer:
clang: error: invalid arch name 'rv64v', first letter after 'rv64' should be 'e', 'i' or 'g'
>From d9fb96ea3e7279d8f975d0c29eed25ec9f686a07 Mon Sep 17 00:00:00 2001
From: David Spickett <david.spickett at linaro.org>
Date: Mon, 29 Apr 2024 13:13:39 +0000
Subject: [PATCH] [llvm][RISC-V] Improve error message for invalid extension
letters
Previously you got:
clang: error: invalid arch name 'rv64v', first letter should be 'e', 'i' or 'g'
Which to me, unfamiliar with riscv, reads as if I should have used
"[eig]rv64v". Which is not what clang means.
Include the first bit in the error message to make this clearer:
clang: error: invalid arch name 'rv64v', first letter after 'rv64' should be 'e', 'i' or 'g'
---
clang/test/Driver/riscv-arch.c | 6 +++---
llvm/lib/TargetParser/RISCVISAInfo.cpp | 3 ++-
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 10 +++++++---
3 files changed, 12 insertions(+), 7 deletions(-)
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 8399b4e97f86d5..abbe8612b3780a 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -209,7 +209,7 @@
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32q -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-LETTER %s
// RV32-LETTER: error: invalid arch name 'rv32q',
-// RV32-LETTER: first letter should be 'e', 'i' or 'g'
+// RV32-LETTER: first letter after 'rv32' should be 'e', 'i' or 'g'
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imcq -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-ORDER %s
@@ -239,12 +239,12 @@
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32xabc -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X %s
// RV32X: error: invalid arch name 'rv32xabc',
-// RV32X: first letter should be 'e', 'i' or 'g'
+// RV32X: first letter after 'rv32' should be 'e', 'i' or 'g'
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32sabc -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32S %s
// RV32S: error: invalid arch name 'rv32sabc',
-// RV32S: first letter should be 'e', 'i' or 'g'
+// RV32S: first letter after 'rv32' should be 'e', 'i' or 'g'
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32ix -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32X-NAME %s
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index 494dc76a18521c..20182fb06037c2 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -639,7 +639,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
switch (Baseline) {
default:
return createStringError(errc::invalid_argument,
- "first letter should be 'e', 'i' or 'g'");
+ "first letter after \'" + Arch.slice(0, 4) +
+ "\' should be 'e', 'i' or 'g'");
case 'e':
case 'i':
break;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index c945c4fbcf6352..9f23000d733d06 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -120,10 +120,14 @@ TEST(ParseArchString, RejectsInvalidBaseISA) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
"string must begin with rv32{i,e,g} or rv64{i,e,g}");
}
- for (StringRef Input : {"rv32j", "rv64k", "rv32_i"}) {
+
+ for (StringRef Input : {"rv32j", "rv32_i"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
- "first letter should be 'e', 'i' or 'g'");
+ "first letter after 'rv32' should be 'e', 'i' or 'g'");
}
+
+ EXPECT_EQ(toString(RISCVISAInfo::parseArchString("rv64k", true).takeError()),
+ "first letter after 'rv64' should be 'e', 'i' or 'g'");
}
TEST(ParseArchString, RejectsUnsupportedBaseISA) {
@@ -395,7 +399,7 @@ TEST(ParseArchString, AcceptsAmbiguousFromRelaxExtensions) {
TEST(ParseArchString, RejectsRelaxExtensionsNotStartWithEorIorG) {
EXPECT_EQ(
toString(RISCVISAInfo::parseArchString("rv32zba_im", true).takeError()),
- "first letter should be 'e', 'i' or 'g'");
+ "first letter after 'rv32' should be 'e', 'i' or 'g'");
}
TEST(ParseArchString,
More information about the cfe-commits
mailing list