Index: clang/lib/Driver/ToolChains/Arch/RISCV.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/RISCV.cpp +++ clang/lib/Driver/ToolChains/Arch/RISCV.cpp @@ -605,8 +605,10 @@ // // rv32g | rv32*d -> ilp32d // rv32e -> ilp32e + // rv32*f (excluding zbf/d, including zfh) -> ilp32f // rv32* -> ilp32 // rv64g | rv64*d -> lp64d + // rv64*f (excluding zbf/d, including zfh) -> lp64f // rv64* -> lp64 StringRef MArch = getRISCVArch(Args, Triple); @@ -616,12 +618,20 @@ return "ilp32d"; else if (MArch.startswith_lower("rv32e")) return "ilp32e"; + else if (MArch.substr(4).contains_lower("f") && + !MArch.substr(4).contains_lower("d") && + !MArch.substr(4).contains_lower("zbf")) + return "ilp32f"; else return "ilp32"; } else if (MArch.startswith_lower("rv64")) { // FIXME: parse `March` to find `D` extension properly if (MArch.substr(4).contains_lower("d") || MArch.startswith_lower("rv64g")) return "lp64d"; + else if (MArch.substr(4).contains_lower("f") && + !MArch.substr(4).contains_lower("d") && + !MArch.substr(4).contains_lower("zbf")) + return "lp64f"; else return "lp64"; } Index: clang/test/Driver/riscv-abi.c =================================================================== --- clang/test/Driver/riscv-abi.c +++ clang/test/Driver/riscv-abi.c @@ -2,6 +2,8 @@ // 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 %s -### -o %t.o -march=rv32imac 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 \ @@ -9,13 +11,26 @@ // CHECK-ILP32: "-target-abi" "ilp32" +// RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -mabi=ilp32e 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32E %s +// RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32e 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32E %s + +// CHECK-ILP32E: "-target-abi" "ilp32e" + // RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32if -mabi=ilp32f 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ILP32F %s +// RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32if 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32F %s // CHECK-ILP32F: "-target-abi" "ilp32f" // RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32ifd -mabi=ilp32d 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ILP32D %s +// RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32ifd 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32D %s +// RUN: %clang -target riscv32-unknown-elf %s -### -o %t.o -march=rv32gc 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-ILP32D %s // RUN: %clang -target riscv32-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-ILP32D %s // RUN: %clang -target riscv32-unknown-linux-gnu -x assembler %s -### -o %t.o 2>&1 \ @@ -32,6 +47,8 @@ // 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 %s -### -o %t.o -march=rv64m 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 \ @@ -41,11 +58,17 @@ // RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64f -mabi=lp64f 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LP64F %s +// RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64f 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LP64F %s // CHECK-LP64F: "-target-abi" "lp64f" // RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64d -mabi=lp64d 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LP64D %s +// RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64d 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LP64D %s +// RUN: %clang -target riscv64-unknown-elf %s -### -o %t.o -march=rv64g 2>&1 \ +// RUN: | FileCheck -check-prefix=CHECK-LP64D %s // RUN: %clang -target riscv64-unknown-linux-gnu %s -### -o %t.o 2>&1 \ // RUN: | FileCheck -check-prefix=CHECK-LP64D %s // RUN: %clang -target riscv64-unknown-linux-gnu -x assembler %s -### -o %t.o 2>&1 \ Index: clang/test/Driver/riscv-cpus.c =================================================================== --- clang/test/Driver/riscv-cpus.c +++ clang/test/Driver/riscv-cpus.c @@ -64,7 +64,7 @@ // MCPU-SIFIVE-E76: "-nostdsysteminc" "-target-cpu" "sifive-e76" // MCPU-SIFIVE-E76: "-target-feature" "+m" "-target-feature" "+a" "-target-feature" "+f" // MCPU-SIFIVE-E76: "-target-feature" "+c" -// MCPU-SIFIVE-E76: "-target-abi" "ilp32" +// MCPU-SIFIVE-E76: "-target-abi" "ilp32f" // mcpu with mabi option // RUN: %clang -target riscv64 -### -c %s 2>&1 -mcpu=sifive-u74 -mabi=lp64 | FileCheck -check-prefix=MCPU-ABI-SIFIVE-U74 %s