[clang] [llvm] [RISCV] Make parseArchString only accept [a-z0-9_]. (PR #90879)
via llvm-commits
llvm-commits at lists.llvm.org
Thu May 2 10:19:49 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Similar change was recently made to parseNormalizedArchString.
---
Full diff: https://github.com/llvm/llvm-project/pull/90879.diff
3 Files Affected:
- (modified) clang/test/Driver/riscv-arch.c (+1-1)
- (modified) llvm/lib/TargetParser/RISCVISAInfo.cpp (+4-3)
- (modified) llvm/unittests/TargetParser/RISCVISAInfoTest.cpp (+2-2)
``````````diff
diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c
index 8c701a736fc7e0..ddf617bbb62372 100644
--- a/clang/test/Driver/riscv-arch.c
+++ b/clang/test/Driver/riscv-arch.c
@@ -199,7 +199,7 @@
// RUN: not %clang --target=riscv32-unknown-elf -march=rv32imC -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-LOWER %s
// RV32-LOWER: error: invalid arch name 'rv32imC',
-// RV32-LOWER: string must be lowercase
+// RV32-LOWER: string may only contain [a-z0-9_]
// RUN: not %clang --target=riscv32-unknown-elf -march=unknown -### %s \
// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-STR %s
diff --git a/llvm/lib/TargetParser/RISCVISAInfo.cpp b/llvm/lib/TargetParser/RISCVISAInfo.cpp
index e4ff4bcfe25a5c..7bb17b50bb57b7 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -590,10 +590,11 @@ llvm::Expected<std::unique_ptr<RISCVISAInfo>>
RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
bool ExperimentalExtensionVersionCheck,
bool IgnoreUnknown) {
- // RISC-V ISA strings must be lowercase.
- if (llvm::any_of(Arch, isupper))
+ // RISC-V ISA strings must be [a-z0-9_]
+ if (!llvm::all_of(
+ Arch, [](char C) { return isDigit(C) || isLower(C) || C == '_'; }))
return createStringError(errc::invalid_argument,
- "string must be lowercase");
+ "string may only contain [a-z0-9_]");
// ISA string must begin with rv32, rv64, or a profile.
unsigned XLen = 0;
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index facaa75ad912a0..c512c9bdf9af17 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -109,10 +109,10 @@ TEST(ParseNormalizedArchString, UpdatesFLenMinVLenMaxELen) {
EXPECT_EQ(Info.getMaxELen(), 64U);
}
-TEST(ParseArchString, RejectsUpperCase) {
+TEST(ParseArchString, RejectsInvalidChars) {
for (StringRef Input : {"RV32", "rV64", "rv32i2P0", "rv64i2p0_A2p0"}) {
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
- "string must be lowercase");
+ "string may only contain [a-z0-9_]");
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/90879
More information about the llvm-commits
mailing list