Index: cfe/trunk/lib/Driver/ToolChains/Clang.h =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.h +++ cfe/trunk/lib/Driver/ToolChains/Clang.h @@ -119,6 +119,8 @@ llvm::opt::ArgStringList &CmdArgs) const; void AddX86TargetArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const; + void AddRISCVTargetArgs(const llvm::opt::ArgList &Args, + llvm::opt::ArgStringList &CmdArgs) const; bool hasGoodDiagnostics() const override { return true; } bool hasIntegratedAssembler() const override { return false; } bool hasIntegratedCPP() const override { return false; } Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -5931,6 +5931,15 @@ } } +void ClangAs::AddRISCVTargetArgs(const ArgList &Args, + ArgStringList &CmdArgs) const { + const llvm::Triple &Triple = getToolChain().getTriple(); + StringRef ABIName = riscv::getRISCVABI(Args, Triple); + + CmdArgs.push_back("-target-abi"); + CmdArgs.push_back(ABIName.data()); +} + void ClangAs::ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const ArgList &Args, @@ -6100,6 +6109,11 @@ CmdArgs.push_back("-arm-add-build-attributes"); } break; + + case llvm::Triple::riscv32: + case llvm::Triple::riscv64: + AddRISCVTargetArgs(Args, CmdArgs); + break; } // Consume all the warning flags. Usually this would be handled more Index: cfe/trunk/test/Driver/riscv-abi.c =================================================================== --- cfe/trunk/test/Driver/riscv-abi.c +++ cfe/trunk/test/Driver/riscv-abi.c @@ -2,6 +2,10 @@ // RUN: | FileCheck -check-prefix=CHECK-ILP32 %s // RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -mabi=ilp32 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ILP32 %s +// RUN: %clang -target riscv32-unknown-elf -x assembler %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32 %s +// RUN: %clang -target riscv32-unknown-elf -x assembler %s -### -o %t.o \ +// RUN: -mabi=ilp32 2>&1 | FileCheck -check-prefix=CHECK-ILP32 %s // CHECK-ILP32: "-target-abi" "ilp32" @@ -26,6 +30,10 @@ // RUN: | FileCheck -check-prefix=CHECK-LP64 %s // RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -mabi=lp64 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LP64 %s +// RUN: %clang -target riscv64-unknown-elf -x assembler %s -### -o %t.o 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LP64 %s +// RUN: %clang -target riscv64-unknown-elf -x assembler %s -### -o %t.o \ +// RUN: -mabi=lp64 2>&1 | FileCheck -check-prefix=CHECK-LP64 %s // CHECK-LP64: "-target-abi" "lp64" Index: cfe/trunk/tools/driver/cc1as_main.cpp =================================================================== --- cfe/trunk/tools/driver/cc1as_main.cpp +++ cfe/trunk/tools/driver/cc1as_main.cpp @@ -137,6 +137,10 @@ /// The name of the relocation model to use. std::string RelocationModel; + /// The ABI targeted by the backend. Specified using -target-abi. Empty + /// otherwise. + std::string TargetABI; + /// @} public: @@ -282,6 +286,7 @@ Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack); Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings); Opts.RelocationModel = Args.getLastArgValue(OPT_mrelocation_model, "pic"); + Opts.TargetABI = Args.getLastArgValue(OPT_target_abi); Opts.IncrementalLinkerCompatible = Args.hasArg(OPT_mincremental_linker_compatible); Opts.SymbolDefs = Args.getAllArgValues(OPT_defsym); @@ -426,6 +431,9 @@ raw_pwrite_stream *Out = FDOS.get(); std::unique_ptr BOS; + MCTargetOptions MCOptions; + MCOptions.ABIName = Opts.TargetABI; + // FIXME: There is a bit of code duplication with addPassesToEmitFile. if (Opts.OutputType == AssemblerInvocation::FT_Asm) { MCInstPrinter *IP = TheTarget->createMCInstPrinter( @@ -434,7 +442,6 @@ std::unique_ptr CE; if (Opts.ShowEncoding) CE.reset(TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); - MCTargetOptions MCOptions; std::unique_ptr MAB( TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); @@ -455,7 +462,6 @@ std::unique_ptr CE( TheTarget->createMCCodeEmitter(*MCII, *MRI, Ctx)); - MCTargetOptions MCOptions; std::unique_ptr MAB( TheTarget->createMCAsmBackend(*STI, *MRI, MCOptions)); std::unique_ptr OW = @@ -489,9 +495,8 @@ createMCAsmParser(SrcMgr, Ctx, *Str.get(), *MAI)); // FIXME: init MCTargetOptions from sanitizer flags here. - MCTargetOptions Options; std::unique_ptr TAP( - TheTarget->createMCAsmParser(*STI, *Parser, *MCII, Options)); + TheTarget->createMCAsmParser(*STI, *Parser, *MCII, MCOptions)); if (!TAP) Failed = Diags.Report(diag::err_target_unknown_triple) << Opts.Triple;