Skip to content

[RISCV] Diagnose -mtune CPU with a : and no features as requiring -mexperimental-mtune-syntax. - #215855

Merged
topperc merged 2 commits into
llvm:mainfrom
topperc:pr/mtune-colon
Aug 12, 2026
Merged

[RISCV] Diagnose -mtune CPU with a : and no features as requiring -mexperimental-mtune-syntax.#215855
topperc merged 2 commits into
llvm:mainfrom
topperc:pr/mtune-colon

Conversation

@topperc

@topperc topperc commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

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.

…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.
@topperc
topperc requested review from lenary and mshockwave August 12, 2026 17:58
@llvmorg-github-actions llvmorg-github-actions Bot added clang Clang issues not falling into any other category backend:RISC-V clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' labels Aug 12, 2026
@llvmorg-github-actions

llvmorg-github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Craig Topper (topperc)

Changes

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 --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 | \

@github-actions

github-actions Bot commented Aug 12, 2026

Copy link
Copy Markdown

✅ With the latest revision this PR passed the C/C++ code formatter.

@topperc
topperc enabled auto-merge (squash) August 12, 2026 20:27
@topperc
topperc merged commit 574fcf1 into llvm:main Aug 12, 2026
11 of 12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:RISC-V clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants