[PATCH] D147986: [RISCV] Print a better error message when a rv32 CPU is used on rv64 and vice versa.
Craig Topper via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 10 19:14:42 PDT 2023
craig.topper created this revision.
craig.topper added reviewers: asb, reames, luismarques, kito-cheng.
Herald added subscribers: jobnoorman, luke, VincentWu, vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, arichardson.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added subscribers: pcwang-thead, eopXD, MaskRay.
Herald added a project: clang.
Instead of rejecting the CPU out right with no information, try
to diagnose that it doesn't match the triple.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D147986
Files:
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/Driver/ToolChains/Arch/RISCV.cpp
clang/test/Driver/riscv-cpus.c
Index: clang/test/Driver/riscv-cpus.c
===================================================================
--- clang/test/Driver/riscv-cpus.c
+++ clang/test/Driver/riscv-cpus.c
@@ -173,7 +173,7 @@
// FAIL-MCPU-NAME: error: unsupported argument 'generic-rv321' to option '-mcpu='
// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv32 -march=rv64i | FileCheck -check-prefix=MISMATCH-ARCH %s
-// MISMATCH-ARCH: error: unsupported argument 'generic-rv32' to option '-mcpu='
+// MISMATCH-ARCH: cpu 'generic-rv32' does not support rv64
// RUN: %clang --target=riscv32 -### -c %s 2>&1 -mcpu=generic-rv64 | FileCheck -check-prefix=MISMATCH-MCPU %s
-// MISMATCH-MCPU: error: unsupported argument 'generic-rv64' to option '-mcpu='
+// MISMATCH-MCPU: error: cpu 'generic-rv64' does not support rv32
Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -49,14 +49,20 @@
}
// Get features except standard extension feature
-static void getRISCFeaturesFromMcpu(const Driver &D, const llvm::Triple &Triple,
+static void getRISCFeaturesFromMcpu(const Driver &D, const Arg *A,
+ const llvm::Triple &Triple,
StringRef Mcpu,
std::vector<StringRef> &Features) {
bool Is64Bit = Triple.isRISCV64();
llvm::RISCV::CPUKind CPUKind = llvm::RISCV::parseCPUKind(Mcpu);
- if (!llvm::RISCV::checkCPUKind(CPUKind, Is64Bit))
- D.Diag(clang::diag::err_drv_unsupported_option_argument)
- << A->getSpelling() << CPU;
+ if (!llvm::RISCV::checkCPUKind(CPUKind, Is64Bit)) {
+ // Try inverting Is64Bit in case the CPU is valid, but for the wrong target.
+ if (llvm::RISCV::checkCPUKind(CPUKind, !Is64Bit))
+ D.Diag(clang::diag::err_drv_invalid_riscv_cpu_name_for_target) << Mcpu << Is64Bit;
+ else
+ D.Diag(clang::diag::err_drv_unsupported_option_argument)
+ << A->getSpelling() << Mcpu;
+ }
}
void riscv::getRISCVTargetFeatures(const Driver &D, const llvm::Triple &Triple,
@@ -74,7 +80,7 @@
if (CPU == "native")
CPU = llvm::sys::getHostCPUName();
- getRISCFeaturesFromMcpu(D, Triple, CPU, Features);
+ getRISCFeaturesFromMcpu(D, A, Triple, CPU, Features);
}
// Handle features corresponding to "-ffixed-X" options
Index: clang/include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -29,6 +29,8 @@
"invalid arch name '%0'">;
def err_drv_invalid_riscv_arch_name : Error<
"invalid arch name '%0', %1">;
+def err_drv_invalid_riscv_cpu_name_for_target : Error<
+ "cpu '%0' does not support rv%select{32|64}1">;
def warn_drv_invalid_arch_name_with_suggestion : Warning<
"ignoring invalid /arch: argument '%0'; for %select{64|32}1-bit expected one of %2">,
InGroup<UnusedCommandLineArgument>;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147986.512311.patch
Type: text/x-patch
Size: 3107 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230411/d3741244/attachment.bin>
More information about the cfe-commits
mailing list