From: Simon Cook Date: Mon, 18 Nov 2019 10:44:13 +0000 (+0000) Subject: [RISCV] Set triple based on -march flag X-Git-Tag: llvmorg-11-init~4063 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c00e5cf29d49e51701b00382a3f41a4dfe1c0c0f;p=platform%2Fupstream%2Fllvm.git [RISCV] Set triple based on -march flag For RISC-V the value provided to -march should determine whether to compile for 32- or 64-bit RISC-V irrespective of the target provided to the Clang driver. This adds a test for this flag for RISC-V and sets the Target architecture correctly in these cases. Differential Revision: https://reviews.llvm.org/D54214 --- diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index aa0d88db1c9f..5c8f3bd13d5a 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -112,7 +112,8 @@ future versions of Clang. Modified Compiler Flags ----------------------- -- ... +- RISC-V now sets the architecture (riscv32/riscv64) based on the value provided + to the ``-march`` flag, overriding the target provided by ``-triple``. New Pragmas in Clang -------------------- diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 3fb38a79051c..cdf4a579f431 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -541,6 +541,17 @@ static llvm::Triple computeTargetTriple(const Driver &D, } } + // If target is RISC-V adjust the target triple according to + // provided architecture name + A = Args.getLastArg(options::OPT_march_EQ); + if (A && Target.isRISCV()) { + StringRef ArchName = A->getValue(); + if (ArchName.startswith_lower("rv32")) + Target.setArch(llvm::Triple::riscv32); + else if (ArchName.startswith_lower("rv64")) + Target.setArch(llvm::Triple::riscv64); + } + return Target; } diff --git a/clang/test/Driver/riscv-arch.c b/clang/test/Driver/riscv-arch.c index 5329fe87aac7..3e1be9a011bf 100644 --- a/clang/test/Driver/riscv-arch.c +++ b/clang/test/Driver/riscv-arch.c @@ -315,3 +315,15 @@ // RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-X-S-SX-INVAL %s // RV32-X-S-SX-INVAL: error: invalid arch name 'rv32ixabc_sdef_sxghi', // RV32-X-S-SX-INVAL: unsupported non-standard user-level extension 'xabc' + +// RUN: %clang -target riscv32-unknown-elf -march=rv32i -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s +// RUN: %clang -target riscv64-unknown-elf -march=rv32i -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s +// RV32-TARGET: "-triple" "riscv32-unknown-unknown-elf" + +// RUN: %clang -target riscv32-unknown-elf -march=rv64i -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s +// RUN: %clang -target riscv64-unknown-elf -march=rv64i -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s +// RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf"