diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index 8e9502a610b0..a171257aaf8e 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -151,6 +151,8 @@ def m_wasm_Features_Group : OptionGroup<"">, Group, DocName<"WebAssembly">; def m_x86_Features_Group : OptionGroup<"">, Group, Flags<[CoreOption]>, DocName<"X86">; +def m_riscv_Features_Group : OptionGroup<"">, + Group, DocName<"RISCV">; def m_libc_Group : OptionGroup<"">, Group, Flags<[HelpHidden]>; @@ -1947,6 +1949,11 @@ def mno_rtd: Flag<["-"], "mno-rtd">, Group; def mno_soft_float : Flag<["-"], "mno-soft-float">, Group; def mno_stackrealign : Flag<["-"], "mno-stackrealign">, Group; +def mrelax : Flag<["-"], "mrelax">, Group, + HelpText<"Enable linker relaxation">; +def mno_relax : Flag<["-"], "mno-relax">, Group, + HelpText<"Disable linker relaxation">; + def munaligned_access : Flag<["-"], "munaligned-access">, Group, HelpText<"Allow memory accesses to be unaligned (AArch32/AArch64 only)">; def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group, diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp index 9e675bd0cab9..11ce8a1fd769 100644 --- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -15,6 +15,7 @@ #include "llvm/Option/ArgList.h" #include "llvm/Support/TargetParser.h" #include "llvm/Support/raw_ostream.h" +#include "ToolChains/CommonArgs.h" using namespace clang::driver; using namespace clang::driver::tools; @@ -363,6 +364,10 @@ void riscv::getRISCVTargetFeatures(const Driver &D, const ArgList &Args, // Handle all other types of extensions. getExtensionFeatures(D, Args, Features, MArch, OtherExts); } + + // Now add any that the user explicitly requested on the command line, + // which may override the defaults. + handleTargetFeaturesGroup(Args, Features, options::OPT_m_riscv_Features_Group); } StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) { diff --git a/clang/test/Driver/riscv-features.c b/clang/test/Driver/riscv-features.c index 565596cdd3a8..95f84f31c611 100644 --- a/clang/test/Driver/riscv-features.c +++ b/clang/test/Driver/riscv-features.c @@ -2,3 +2,12 @@ // RUN: %clang -target riscv64-unknown-elf -### %s -fsyntax-only 2>&1 | FileCheck %s // CHECK: fno-signed-char + +// RUN: %clang -target riscv32-unknown-elf -### %s -mrelax 2>&1 | FileCheck %s -check-prefix=RELAX +// RUN: %clang -target riscv32-unknown-elf -### %s -mno-relax 2>&1 | FileCheck %s -check-prefix=NO-RELAX +// RUN: %clang -target riscv32-unknown-elf -### %s 2>&1 | FileCheck %s -check-prefix=DEFAULT + +// RELAX: "-target-feature" "+relax" +// NO-RELAX: "-target-feature" "-relax" +// DEFAULT-NOT: "-target-feature" "+relax" +// DEFAULT-NOT: "-target-feature" "-relax"