[RISCV] Diagnose -mtune CPU with a : and no features as requiring -mexperimental-mtune-syntax. - #215855
Merged
Conversation
…xperimental-mtune-syntax. Without -mexperimental-mtune-syntax -mtune=sifive-x280: was considering sifive-x280: as the full CPU name. With this patch we now diagnose any use of the : even if there's nothing after it.
|
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Craig Topper (topperc) ChangesWithout -mexperimental-mtune-syntax -mtune=sifive-x280: was considering Full diff: https://github.com/llvm/llvm-project/pull/215855.diff 2 Files Affected:
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 | \
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
lenary
approved these changes
Aug 12, 2026
topperc
enabled auto-merge (squash)
August 12, 2026 20:27
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.