Index: clang/lib/Driver/Driver.cpp =================================================================== --- clang/lib/Driver/Driver.cpp +++ clang/lib/Driver/Driver.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "clang/Driver/Driver.h" +#include "ToolChains/Arch/RISCV.h" #include "ToolChains/AIX.h" #include "ToolChains/AMDGPU.h" #include "ToolChains/AMDGPUOpenMP.h" @@ -650,13 +651,16 @@ } // 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_insensitive("rv32")) + // provided architecture relative info such as -march/-mcpu/-mabi. + if (Target.isRISCV()) { + StringRef ArchName = tools::riscv::getRISCVArch(Args, Target); + llvm::Triple::ArchType RVArch = Target.getArch(); + + if (RVArch == llvm::Triple::riscv64 && + ArchName.startswith_insensitive("rv32")) Target.setArch(llvm::Triple::riscv32); - else if (ArchName.startswith_insensitive("rv64")) + else if (RVArch == llvm::Triple::riscv32 && + ArchName.startswith_insensitive("rv64")) Target.setArch(llvm::Triple::riscv64); } Index: clang/test/Driver/riscv-abi.c =================================================================== --- clang/test/Driver/riscv-abi.c +++ clang/test/Driver/riscv-abi.c @@ -40,11 +40,6 @@ // CHECK-ILP32D: "-target-abi" "ilp32d" -// RUN: not %clang --target=riscv32-unknown-elf %s -o %t.o -mabi=lp64 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-RV32-LP64 %s - -// CHECK-RV32-LP64: error: unknown target ABI 'lp64' - // RUN: %clang --target=riscv64-unknown-elf %s -### 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LP64 %s // RUN: %clang --target=riscv64-unknown-elf %s -### -mabi=lp64 2>&1 \ @@ -77,8 +72,3 @@ // RUN: | FileCheck -check-prefix=CHECK-LP64D %s // CHECK-LP64D: "-target-abi" "lp64d" - -// RUN: not %clang --target=riscv64-unknown-elf %s -o %t.o -mabi=ilp32 2>&1 \ -// RUN: | FileCheck -check-prefix=CHECK-RV64-ILP32 %s - -// CHECK-RV64-ILP32: error: unknown target ABI 'ilp32' Index: clang/test/Driver/riscv-arch.c =================================================================== --- clang/test/Driver/riscv-arch.c +++ clang/test/Driver/riscv-arch.c @@ -392,12 +392,29 @@ // 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 +// RUN: %clang --target=riscv32-unknown-elf -mcpu=sifive-e20 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s +// RUN: %clang --target=riscv64-unknown-elf -mcpu=sifive-e20 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s +// RUN: %clang --target=riscv32-unknown-elf -mabi=ilp32 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV32-TARGET %s +// RUN: %clang --target=riscv64-unknown-elf -mabi=ilp32 -### %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 +// RUN: %clang --target=riscv32-unknown-elf -mcpu=sifive-s21 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s +// RUN: %clang --target=riscv64-unknown-elf -mcpu=sifive-s21 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s +// RUN: %clang --target=riscv32-unknown-elf -mabi=lp64 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s +// RUN: %clang --target=riscv64-unknown-elf -mabi=lp64 -### %s \ +// RUN: -fsyntax-only 2>&1 | FileCheck -check-prefix=RV64-TARGET %s // RV64-TARGET: "-triple" "riscv64-unknown-unknown-elf" // RUN: %clang --target=riscv32-unknown-elf -march=rv32ifzfh01p0 -### %s \