simoncook created this revision. simoncook added a reviewer: asb. Herald added subscribers: cfe-commits, jocewei, PkmX, rkruppe, the_o, brucehoult, MartinMosbeck, rogfer01, mgrang, edward-jones, zzheng, jrtc27, shiva0217, kito-cheng, niosHD, sabuasal, apazos, johnrusso, rbar.
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. Repository: rC Clang https://reviews.llvm.org/D54214 Files: lib/Driver/Driver.cpp test/Driver/riscv-arch.c Index: test/Driver/riscv-arch.c =================================================================== --- test/Driver/riscv-arch.c +++ 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" Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -506,6 +506,17 @@ } } + // 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; }
Index: test/Driver/riscv-arch.c =================================================================== --- test/Driver/riscv-arch.c +++ 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" Index: lib/Driver/Driver.cpp =================================================================== --- lib/Driver/Driver.cpp +++ lib/Driver/Driver.cpp @@ -506,6 +506,17 @@ } } + // 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; }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits