[clang] [RISCV] Diagnose -mtune CPU with a : and no features as requiring -mexperimental-mtune-syntax. (PR #215855)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 10:59:43 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-driver
Author: Craig Topper (topperc)
<details>
<summary>Changes</summary>
Without -mexperimental-mtune-syntax -mtune=sifive-x280: was considering
sifive-x280: as the full CPU name and give an invalid CPU error. With this
patch we now diagnose any use of the : even if there's nothing after it.
---
Full diff: https://github.com/llvm/llvm-project/pull/215855.diff
2 Files Affected:
- (modified) clang/lib/Driver/ToolChains/Arch/RISCV.cpp (+10-7)
- (modified) clang/test/Driver/riscv-mtune-tune-features.c (+5)
``````````diff
diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index c90d771e87a23..a1bf62f80589c 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -404,22 +404,25 @@ riscv::getRISCVTuneCPU(const Driver &D, const llvm::opt::ArgList &Args,
if (!MTuneArg)
return "";
- StringRef MTune = MTuneArg->getValue();
- // Split the CPU name part from the tune features string.
- auto [TuneCPU, TFString] = MTune.split(':');
- if (!Args.hasFlag(options::OPT_mexperimental_mtune_syntax,
+ StringRef TuneCPU = MTuneArg->getValue();
+ StringRef TFString;
+
+ auto Idx = TuneCPU.find(':');
+ if (Idx != StringRef::npos) {
+ if (!Args.hasFlag(options::OPT_mexperimental_mtune_syntax,
options::OPT_mno_experimental_mtune_syntax, false)) {
- if (!TFString.empty()) {
// Only print this diagnostics if it's used for retrieving tune features
// to avoid printing the same error message multiple times.
if (TuneFeatures)
D.Diag(diag::err_drv_invalid_riscv_mtune_string)
- << 0 << MTune
+ << 0 << TuneCPU
<< "require '-mexperimental-mtune-syntax' to use with tune feature "
"string";
return std::nullopt;
}
- return MTune;
+
+ TFString = TuneCPU.substr(Idx + 1);
+ TuneCPU = TuneCPU.slice(0, Idx);
}
if (!TuneFeatures || TFString.empty())
diff --git a/clang/test/Driver/riscv-mtune-tune-features.c b/clang/test/Driver/riscv-mtune-tune-features.c
index e31500cf9d20a..bb55443b51c8e 100644
--- a/clang/test/Driver/riscv-mtune-tune-features.c
+++ b/clang/test/Driver/riscv-mtune-tune-features.c
@@ -19,6 +19,11 @@
// RUN: FileCheck --check-prefix=NO-EXPERIMENTAL %s
// NO-EXPERIMENTAL: invalid -mtune string 'sifive-x390:full-vec-fp64':
// NO-EXPERIMENTAL-SAME: require '-mexperimental-mtune-syntax' to use with tune feature string
+//
+// RUN: not %clang --target=riscv64 -mtune=sifive-x390: -c %s 2>&1 | \
+// RUN: FileCheck --check-prefix=NO-EXPERIMENTAL2 %s
+// NO-EXPERIMENTAL2: invalid -mtune string 'sifive-x390:':
+// NO-EXPERIMENTAL2-SAME: require '-mexperimental-mtune-syntax' to use with tune feature string
// RUN: not %clang --target=riscv64 -mexperimental-mtune-syntax \
// RUN: -mtune=sifive-p470:full-vec-fp64 -c %s 2>&1 | \
``````````
</details>
https://github.com/llvm/llvm-project/pull/215855
More information about the cfe-commits
mailing list