[clang] [llvm] [RISCV] Make parseArchString only accept [a-z0-9_]. (PR #90879)
Craig Topper via cfe-commits
cfe-commits at lists.llvm.org
Thu May 2 10:19:18 PDT 2024
https://github.com/topperc created https://github.com/llvm/llvm-project/pull/90879
Similar change was recently made to parseNormalizedArchString.
>From c7688db16f777be740cd33a54431ae326d0b1c55 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 2 May 2024 10:17:48 -0700
Subject: [PATCH] [RISCV] Make parseArchString only accept [a-z0-9_].
Similar change was recently made to parseNormalizedArchString.
---
clang/test/Driver/riscv-arch.c | 2 +-
llvm/lib/TargetParser/RISCVISAInfo.cpp | 7 ++++---
llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 4 ++--
3 files changed, 7 insertions(+), 6 deletions(-)
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_]");
}
}
More information about the cfe-commits
mailing list