Skip to content

[RISCV] Add -march=unset to cancel and ignore a previous -march. #148321

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 9, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,9 @@ RISC-V Support

- Add support for the `__builtin_riscv_pause()` intrinsic from the `Zihintpause` extension.

- Add `-march=unset` to clear any previous `-march=` value. This ISA string will
be computed from `-mcpu` or the platform default.

CUDA/HIP Language Changes
^^^^^^^^^^^^^^^^^^^^^^^^^

Expand Down
11 changes: 7 additions & 4 deletions clang/lib/Driver/ToolChains/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,12 @@ std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,
// Clang does not yet support MULTILIB_REUSE, so we use `rv{XLEN}imafdc`
// instead of `rv{XLEN}gc` though they are (currently) equivalent.

// 1. If `-march=` is specified, use it.
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
return A->getValue();
// 1. If `-march=` is specified, use it unless the value is "unset".
if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
StringRef MArch = A->getValue();
if (MArch != "unset")
return MArch.str();
}

// 2. Get march (isa string) based on `-mcpu=`
if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
Expand All @@ -300,7 +303,7 @@ std::string riscv::getRISCVArch(const llvm::opt::ArgList &Args,

StringRef MArch = llvm::RISCV::getMArchFromMcpu(CPU);
// Bypass if target cpu's default march is empty.
if (MArch != "")
if (!MArch.empty())
return MArch.str();
}

Expand Down
5 changes: 5 additions & 0 deletions clang/test/Driver/riscv-cpus.c
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,11 @@
// MCPU-MARCH: "-nostdsysteminc" "-target-cpu" "sifive-e31" "-target-feature" "+m" "-target-feature" "+c"
// MCPU-MARCH: "-target-abi" "ilp32"

// march=unset erases previous march
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/// -march=unset erases previous -march.

Always include - when referring to a - option.

// RUN: %clang --target=riscv32 -### -c %s 2>&1 -march=rv32imc -march=unset -mcpu=sifive-e31 | FileCheck -check-prefix=MARCH-UNSET %s
// MARCH-UNSET: "-nostdsysteminc" "-target-cpu" "sifive-e31" "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+c"
// MARCH-UNSET: "-target-abi" "ilp32"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add -SAME if applicable.


// Check interaction between mcpu and mtune, mtune won't affect arch related
// target feature, but mcpu will.
//
Expand Down
Loading