llvm-capstone/clang/test/Driver/loongarch-msoft-float.c
WANG Xuerui f6932007ab [Clang][LoongArch] Consume and check -mabi and -mfpu even if -m*-float is present
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
  (otherwise the ABI will become double-float due to `-mfpu`), which is
  arguably not appropriate for a driver;
* Or `-mabi` is still supplied by `arch/loongarch` Makefile, and the
  build immediately errors out because
  `-Werror=unused-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.

Reviewed By: SixWeining, MaskRay

Differential Revision: https://reviews.llvm.org/D153707
2023-06-26 15:07:22 +08:00

22 lines
970 B
C

// 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
// NOWARN-NOT: warning:
// WARN: warning: ignoring '-mabi=lp64d' as it conflicts with that implied by '-msoft-float' (lp64s)
// WARN: warning: ignoring '-mfpu=64' as it conflicts with that implied by '-msoft-float' (0)
// CC1: "-target-feature" "-f"{{.*}} "-target-feature" "-d"
// CC1: "-target-abi" "lp64s"
// IR: attributes #[[#]] ={{.*}}"target-features"="{{(.*,)?}}-d,{{(.*,)?}}-f{{(,.*)?}}"
int foo(void) {
return 3;
}