[clang] 0faf494 - [RISCV] Make parseArchString only accept [a-z0-9_]. (#90879)
via cfe-commits
cfe-commits at lists.llvm.org
Fri May 3 09:29:32 PDT 2024
Author: Craig Topper
Date: 2024-05-03T09:29:27-07:00
New Revision: 0faf494200860c307ba473114df6e50f7da1b52a
URL: https://github.com/llvm/llvm-project/commit/0faf494200860c307ba473114df6e50f7da1b52a
DIFF: https://github.com/llvm/llvm-project/commit/0faf494200860c307ba473114df6e50f7da1b52a.diff
LOG: [RISCV] Make parseArchString only accept [a-z0-9_]. (#90879)
Similar change was recently made to parseNormalizedArchString.
Added:
Modified:
clang/test/Driver/riscv-arch.c
llvm/lib/TargetParser/RISCVISAInfo.cpp
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
Removed:
################################################################################
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 d244326537faff..6ab5ee3508a672 100644
--- a/llvm/lib/TargetParser/RISCVISAInfo.cpp
+++ b/llvm/lib/TargetParser/RISCVISAInfo.cpp
@@ -599,10 +599,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 eb8eab73686931..d813a8d7185f61 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -125,10 +125,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_]");
}
}
More information about the cfe-commits
mailing list