xen0n created this revision. xen0n added reviewers: SixWeining, wangleiat, hev, xry111, MaskRay. Herald added a subscriber: tpr. Herald added a project: All. xen0n requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits.
This kind of CLI flags duplication can sometimes be convenient for build systems that may have to tinker with these. For example, in the Linux kernel we almost always want to ensure no FP instruction is emitted, so `-msoft-float` is present by default; but sometimes we do want to allow FPU usage (e.g. certain parts of amdgpu DC code), in which case we want the `-msoft-float` stripped and `-mfpu=64` added. Here we face a dilemma without this change: - Either `-mabi` is not supplied by `arch/loongarch` Makefile, in which case the correct ABI has to be supplied by the driver Makefile, potentially duplicating logic; - Or `-mabi` is still supplied by `arch/loongarch` Makefile, and the build immediately errors out because `-Werror,-Wunused-command-line-argument` is unconditionally set for Clang builds. To solve this, simply make sure to check `-mabi` and `-mfpu` (and gain some useful diagnostics in case of conflicting settings) when `-m*-float` is successfully parsed. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153707 Files: clang/include/clang/Basic/DiagnosticDriverKinds.td clang/lib/Driver/ToolChains/Arch/LoongArch.cpp clang/test/Driver/loongarch-mdouble-float.c clang/test/Driver/loongarch-msingle-float.c clang/test/Driver/loongarch-msoft-float.c
Index: clang/test/Driver/loongarch-msoft-float.c =================================================================== --- clang/test/Driver/loongarch-msoft-float.c +++ clang/test/Driver/loongarch-msoft-float.c @@ -1,12 +1,16 @@ // RUN: %clang --target=loongarch64 -msoft-float -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1 +// RUN: %clang --target=loongarch64 -msoft-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \ +// RUN: FileCheck %s --check-prefixes=CC1,NOWARN // RUN: %clang --target=loongarch64 -msoft-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefixes=CC1,WARN // RUN: %clang --target=loongarch64 -msoft-float -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR -// WARN: warning: argument unused during compilation: '-mfpu=64' -// WARN: warning: argument unused during compilation: '-mabi=lp64d' +// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=0' +// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64s' +// WARN: warning: the -mabi setting 'lp64d' conflicts with that implied by -m*-float (lp64s); using lp64s +// WARN: warning: the -mfpu setting '64' conflicts with that implied by -m*-float (0); using 0 // CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d" // CC1: "-target-abi" "lp64s" Index: clang/test/Driver/loongarch-msingle-float.c =================================================================== --- clang/test/Driver/loongarch-msingle-float.c +++ clang/test/Driver/loongarch-msingle-float.c @@ -1,12 +1,16 @@ // RUN: %clang --target=loongarch64 -msingle-float -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1 +// RUN: %clang --target=loongarch64 -msingle-float -mfpu=32 -mabi=lp64f -fsyntax-only %s -### 2>&1 | \ +// RUN: FileCheck %s --check-prefixes=CC1,NOWARN // RUN: %clang --target=loongarch64 -msingle-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefixes=CC1,WARN // RUN: %clang --target=loongarch64 -msingle-float -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR -// WARN: warning: argument unused during compilation: '-mfpu=0' -// WARN: warning: argument unused during compilation: '-mabi=lp64s' +// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=32' +// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64f' +// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64f); using lp64f +// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (32); using 32 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "-d" // CC1: "-target-abi" "lp64f" Index: clang/test/Driver/loongarch-mdouble-float.c =================================================================== --- clang/test/Driver/loongarch-mdouble-float.c +++ clang/test/Driver/loongarch-mdouble-float.c @@ -1,12 +1,16 @@ // RUN: %clang --target=loongarch64 -mdouble-float -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefix=CC1 +// RUN: %clang --target=loongarch64 -mdouble-float -mfpu=64 -mabi=lp64d -fsyntax-only %s -### 2>&1 | \ +// RUN: FileCheck %s --check-prefixes=CC1,NOWARN // RUN: %clang --target=loongarch64 -mdouble-float -mfpu=0 -mabi=lp64s -fsyntax-only %s -### 2>&1 | \ // RUN: FileCheck %s --check-prefixes=CC1,WARN // RUN: %clang --target=loongarch64 -mdouble-float -S -emit-llvm %s -o - | \ // RUN: FileCheck %s --check-prefix=IR -// WARN: warning: argument unused during compilation: '-mfpu=0' -// WARN: warning: argument unused during compilation: '-mabi=lp64s' +// NOWARN-NOT: warning: argument unused during compilation: '-mfpu=64' +// NOWARN-NOT: warning: argument unused during compilation: '-mabi=lp64d' +// WARN: warning: the -mabi setting 'lp64s' conflicts with that implied by -m*-float (lp64d); using lp64d +// WARN: warning: the -mfpu setting '0' conflicts with that implied by -m*-float (64); using 64 // CC1: "-target-feature" "+f"{{.*}} "-target-feature" "+d" // CC1: "-target-abi" "lp64d" Index: clang/lib/Driver/ToolChains/Arch/LoongArch.cpp =================================================================== --- clang/lib/Driver/ToolChains/Arch/LoongArch.cpp +++ clang/lib/Driver/ToolChains/Arch/LoongArch.cpp @@ -26,16 +26,54 @@ "Unexpected triple"); bool IsLA32 = Triple.getArch() == llvm::Triple::loongarch32; + // Parse -mfpu value for later use. + int FPU = -1; + if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) { + StringRef V = A->getValue(); + if (V == "64") + FPU = 64; + if (V == "32") + FPU = 32; + if (V == "0" || V == "none") + FPU = 0; + D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << V; + } + // Check -m*-float firstly since they have highest priority. if (const Arg *A = Args.getLastArg(options::OPT_mdouble_float, options::OPT_msingle_float, options::OPT_msoft_float)) { - if (A->getOption().matches(options::OPT_mdouble_float)) - return IsLA32 ? "ilp32d" : "lp64d"; - if (A->getOption().matches(options::OPT_msingle_float)) - return IsLA32 ? "ilp32f" : "lp64f"; - if (A->getOption().matches(options::OPT_msoft_float)) - return IsLA32 ? "ilp32s" : "lp64s"; + StringRef ImpliedABI; + int ImpliedFPU = -1; + if (A->getOption().matches(options::OPT_mdouble_float)) { + ImpliedABI = IsLA32 ? "ilp32d" : "lp64d"; + ImpliedFPU = 64; + } + if (A->getOption().matches(options::OPT_msingle_float)) { + ImpliedABI = IsLA32 ? "ilp32f" : "lp64f"; + ImpliedFPU = 32; + } + if (A->getOption().matches(options::OPT_msoft_float)) { + ImpliedABI = IsLA32 ? "ilp32s" : "lp64s"; + ImpliedFPU = 0; + } + + // Still consume `-mabi=` and `-mfpu=` arguments and report if the settings + // conflicts with the higher-priority settings implied by -m*-float. + if (!ImpliedABI.empty()) { + if (const Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) { + StringRef MABIValue = A->getValue(); + if (ImpliedABI != MABIValue) + D.Diag(diag::warn_drv_loongarch_conflicting_mabi) + << MABIValue << ImpliedABI; + } + + // -mfpu= has already been parsed at this point. + if (FPU != -1 && ImpliedFPU != FPU) + D.Diag(diag::warn_drv_loongarch_conflicting_mfpu) << FPU << ImpliedFPU; + + return ImpliedABI; + } } // If `-mabi=` is specified, use it. @@ -43,15 +81,13 @@ return A->getValue(); // Select abi based on -mfpu=xx. - if (const Arg *A = Args.getLastArg(options::OPT_mfpu_EQ)) { - StringRef FPU = A->getValue(); - if (FPU == "64") - return IsLA32 ? "ilp32d" : "lp64d"; - if (FPU == "32") - return IsLA32 ? "ilp32f" : "lp64f"; - if (FPU == "0" || FPU == "none") - return IsLA32 ? "ilp32s" : "lp64s"; - D.Diag(diag::err_drv_loongarch_invalid_mfpu_EQ) << FPU; + switch (FPU) { + case 64: + return IsLA32 ? "ilp32d" : "lp64d"; + case 32: + return IsLA32 ? "ilp32f" : "lp64f"; + case 0: + return IsLA32 ? "ilp32s" : "lp64s"; } // Choose a default based on the triple. Index: clang/include/clang/Basic/DiagnosticDriverKinds.td =================================================================== --- clang/include/clang/Basic/DiagnosticDriverKinds.td +++ clang/include/clang/Basic/DiagnosticDriverKinds.td @@ -728,6 +728,12 @@ def err_drv_riscv_unsupported_with_linker_relaxation : Error< "%0 is unsupported with RISC-V linker relaxation (-mrelax)">; +def warn_drv_loongarch_conflicting_mabi : Warning< + "the -mabi setting '%0' conflicts with that implied by -m*-float (%1); using %1">, + InGroup<OptionIgnored>; +def warn_drv_loongarch_conflicting_mfpu : Warning< + "the -mfpu setting '%0' conflicts with that implied by -m*-float (%1); using %1">, + InGroup<OptionIgnored>; def err_drv_loongarch_invalid_mfpu_EQ : Error< "invalid argument '%0' to -mfpu=; must be one of: 64, 32, none, 0 (alias for none)">;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits