Skip to content

Commit 61e9198

Browse files
committed
[RISCV] Add errors for mixing Zcmp with C/Zcd and D.
We already had an error for Zcmt though it appears to be untested Add similar one for Zcmp along with tests for both. Factor the code to share the strings as much as possible. Reviewed By: VincentWu Differential Revision: https://reviews.llvm.org/D153159
1 parent 2268459 commit 61e9198

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

llvm/lib/Support/RISCVISAInfo.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -860,13 +860,11 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
860860

861861
Error RISCVISAInfo::checkDependency() {
862862
bool HasC = Exts.count("c") != 0;
863-
bool HasD = Exts.count("d") != 0;
864863
bool HasF = Exts.count("f") != 0;
865864
bool HasZfinx = Exts.count("zfinx") != 0;
866865
bool HasVector = Exts.count("zve32x") != 0;
867866
bool HasZvl = MinVLen != 0;
868867
bool HasZcmt = Exts.count("zcmt") != 0;
869-
bool HasZcd = Exts.count("zcd") != 0;
870868

871869
if (HasF && HasZfinx)
872870
return createStringError(errc::invalid_argument,
@@ -899,15 +897,13 @@ Error RISCVISAInfo::checkDependency() {
899897
errc::invalid_argument,
900898
"'zvknhb' requires 'v' or 'zve64*' extension to also be specified");
901899

902-
if (HasZcmt && HasD && HasC)
900+
if ((HasZcmt || Exts.count("zcmp")) && Exts.count("d") &&
901+
(HasC || Exts.count("zcd")))
903902
return createStringError(
904903
errc::invalid_argument,
905-
"'zcmt' is incompatible with 'c' extension when 'd' extension is set");
906-
907-
if (HasZcmt && HasD && HasZcd)
908-
return createStringError(errc::invalid_argument,
909-
"'zcmt' is incompatible with 'zcd' extension when "
910-
"'d' extension is set");
904+
Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
905+
"' extension is incompatible with '" + (HasC ? "c" : "zcd") +
906+
"' extension when 'd' extension is enabled");
911907

912908
// Additional dependency checks.
913909
// TODO: The 'q' extension requires rv64.

llvm/unittests/Support/RISCVISAInfoTest.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,30 @@ TEST(ParseArchString, RejectsConflictingExtensions) {
447447
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
448448
"'f' and 'zfinx' extensions are incompatible");
449449
}
450+
451+
for (StringRef Input : {"rv32idc_zcmp1p0", "rv64idc_zcmp1p0"}) {
452+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
453+
"'zcmp' extension is incompatible with 'c' extension when 'd' "
454+
"extension is enabled");
455+
}
456+
457+
for (StringRef Input : {"rv32id_zcd1p0_zcmp1p0", "rv64id_zcd1p0_zcmp1p0"}) {
458+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
459+
"'zcmp' extension is incompatible with 'zcd' extension when 'd' "
460+
"extension is enabled");
461+
}
462+
463+
for (StringRef Input : {"rv32idc_zcmt1p0", "rv64idc_zcmt1p0"}) {
464+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
465+
"'zcmt' extension is incompatible with 'c' extension when 'd' "
466+
"extension is enabled");
467+
}
468+
469+
for (StringRef Input : {"rv32id_zcd1p0_zcmt1p0", "rv64id_zcd1p0_zcmt1p0"}) {
470+
EXPECT_EQ(toString(RISCVISAInfo::parseArchString(Input, true).takeError()),
471+
"'zcmt' extension is incompatible with 'zcd' extension when 'd' "
472+
"extension is enabled");
473+
}
450474
}
451475

452476
TEST(ToFeatureVector, IIsDroppedAndExperimentalExtensionsArePrefixed) {

0 commit comments

Comments
 (0)