From 9cbad60fe56426efa4d90f7856485ff14f081855 Mon Sep 17 00:00:00 2001 From: Petar Jovanovic Date: Tue, 14 Apr 2015 12:49:08 +0000 Subject: [PATCH] [Mips] Generate warning for invalid '-mnan' and '-march' combinations This patch generates a warning for invalid combination of '-mnan' and '-march' options, it properly sets NaN encoding for a given '-march', and it passes a proper NaN encoding to the assembler. Patch by Vladimir Radosavljevic. Differential Revision: http://reviews.llvm.org/D8170 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@234882 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/Basic/DiagnosticDriverKinds.td | 7 ++++ include/clang/Basic/DiagnosticGroups.td | 1 + lib/Driver/Tools.cpp | 40 +++++++++++++++++--- lib/Driver/Tools.h | 5 +++ test/CodeGen/mips-unsupported-nan.c | 25 ++++++++++++ test/Driver/mips-features.c | 4 +- test/Driver/mips-integrated-as.s | 2 +- test/Preprocessor/init.c | 7 +++- 8 files changed, 82 insertions(+), 9 deletions(-) create mode 100644 test/CodeGen/mips-unsupported-nan.c diff --git a/include/clang/Basic/DiagnosticDriverKinds.td b/include/clang/Basic/DiagnosticDriverKinds.td index 9a055b8ec4..7c0696a1b9 100644 --- a/include/clang/Basic/DiagnosticDriverKinds.td +++ b/include/clang/Basic/DiagnosticDriverKinds.td @@ -187,4 +187,11 @@ def err_drv_modules_validate_once_requires_timestamp : Error< def warn_drv_invoking_fallback : Warning<"falling back to %0">, InGroup; + +def warn_target_unsupported_nan2008 : Warning< + "ignoring '-mnan=2008' option because the '%0' architecture does not support it">, + InGroup; +def warn_target_unsupported_nanlegacy : Warning< + "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">, + InGroup; } diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 02d9c0cf26..5e4d7efa98 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -45,6 +45,7 @@ def IntConversion : DiagGroup<"int-conversion">; def EnumConversion : DiagGroup<"enum-conversion">; def FloatConversion : DiagGroup<"float-conversion">; def EnumTooLarge : DiagGroup<"enum-too-large">; +def UnsupportedNan : DiagGroup<"unsupported-nan">; def NonLiteralNullConversion : DiagGroup<"non-literal-null-conversion">; def NullConversion : DiagGroup<"null-conversion">; def ImplicitConversionFloatingPointToBool : diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp index 4d0ca57659..1e34d7f403 100644 --- a/lib/Driver/Tools.cpp +++ b/lib/Driver/Tools.cpp @@ -1118,11 +1118,21 @@ static void getMIPSTargetFeatures(const Driver &D, const llvm::Triple &Triple, if (Arg *A = Args.getLastArg(options::OPT_mnan_EQ)) { StringRef Val = StringRef(A->getValue()); - if (Val == "2008") - Features.push_back("+nan2008"); - else if (Val == "legacy") - Features.push_back("-nan2008"); - else + if (Val == "2008") { + if (mips::getSupportedNanEncoding(CPUName) & mips::Nan2008) + Features.push_back("+nan2008"); + else { + Features.push_back("-nan2008"); + D.Diag(diag::warn_target_unsupported_nan2008) << CPUName; + } + } else if (Val == "legacy") { + if (mips::getSupportedNanEncoding(CPUName) & mips::NanLegacy) + Features.push_back("-nan2008"); + else { + Features.push_back("+nan2008"); + D.Diag(diag::warn_target_unsupported_nanlegacy) << CPUName; + } + } else D.Diag(diag::err_drv_unsupported_option_argument) << A->getOption().getName() << Val; } @@ -5637,6 +5647,26 @@ void arm::appendEBLinkFlags(const ArgList &Args, ArgStringList &CmdArgs, const l CmdArgs.push_back(LinkFlag); } +mips::NanEncoding mips::getSupportedNanEncoding(StringRef &CPU) { + return (NanEncoding)llvm::StringSwitch(CPU) + .Case("mips1", NanLegacy) + .Case("mips2", NanLegacy) + .Case("mips3", NanLegacy) + .Case("mips4", NanLegacy) + .Case("mips5", NanLegacy) + .Case("mips32", NanLegacy) + .Case("mips32r2", NanLegacy) + .Case("mips32r3", NanLegacy | Nan2008) + .Case("mips32r5", NanLegacy | Nan2008) + .Case("mips32r6", Nan2008) + .Case("mips64", NanLegacy) + .Case("mips64r2", NanLegacy) + .Case("mips64r3", NanLegacy | Nan2008) + .Case("mips64r5", NanLegacy | Nan2008) + .Case("mips64r6", Nan2008) + .Default(NanLegacy); +} + bool mips::hasMipsAbiArg(const ArgList &Args, const char *Value) { Arg *A = Args.getLastArg(options::OPT_mabi_EQ); return A && (A->getValue() == StringRef(Value)); diff --git a/lib/Driver/Tools.h b/lib/Driver/Tools.h index e8edaebbac..33fadd1700 100644 --- a/lib/Driver/Tools.h +++ b/lib/Driver/Tools.h @@ -234,6 +234,11 @@ namespace arm { } namespace mips { + typedef enum { + NanLegacy = 1, + Nan2008 = 2 + } NanEncoding; + NanEncoding getSupportedNanEncoding(StringRef &CPU); void getMipsCPUAndABI(const llvm::opt::ArgList &Args, const llvm::Triple &Triple, StringRef &CPUName, StringRef &ABIName); diff --git a/test/CodeGen/mips-unsupported-nan.c b/test/CodeGen/mips-unsupported-nan.c new file mode 100644 index 0000000000..14a36fc029 --- /dev/null +++ b/test/CodeGen/mips-unsupported-nan.c @@ -0,0 +1,25 @@ +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS2 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips3 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS3 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips4 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS4 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R2 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mipsel-unknown-linux -mnan=2008 -march=mips32r3 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-NOT-MIPS32R3 -check-prefix=CHECK-NAN2008 %s +// RUN: %clang -target mipsel-unknown-linux -mnan=legacy -march=mips32r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS32R6 -check-prefix=CHECK-NAN2008 %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=2008 -march=mips64r2 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R2 -check-prefix=CHECK-NANLEGACY %s +// RUN: %clang -target mips64el-unknown-linux -mnan=legacy -march=mips64r6 -emit-llvm -S %s -o - 2>&1 | FileCheck -check-prefix=CHECK-MIPS64R6 -check-prefix=CHECK-NAN2008 %s + +// CHECK-MIPS2: warning: ignoring '-mnan=2008' option because the 'mips2' architecture does not support it +// CHECK-MIPS3: warning: ignoring '-mnan=2008' option because the 'mips3' architecture does not support it +// CHECK-MIPS4: warning: ignoring '-mnan=2008' option because the 'mips4' architecture does not support it +// CHECK-MIPS32: warning: ignoring '-mnan=2008' option because the 'mips32' architecture does not support it +// CHECK-MIPS32R2: warning: ignoring '-mnan=2008' option because the 'mips32r2' architecture does not support it +// CHECK-MIPS32R3: warning: ignoring '-mnan=2008' option because the 'mips32r3' architecture does not support it +// CHECK-MIPS32R6: warning: ignoring '-mnan=legacy' option because the 'mips32r6' architecture does not support it +// CHECK-MIPS64: warning: ignoring '-mnan=2008' option because the 'mips64' architecture does not support it +// CHECK-MIPS64R2: warning: ignoring '-mnan=2008' option because the 'mips64r2' architecture does not support it +// CHECK-MIPS64R6: warning: ignoring '-mnan=legacy' option because the 'mips64r6' architecture does not support it +// CHECK-NANLEGACY: float 0x7FF4000000000000 +// CHECK-NAN2008: float 0x7FF8000000000000 + +float f = __builtin_nan(""); diff --git a/test/Driver/mips-features.c b/test/Driver/mips-features.c index f7022306fc..5094f2b09b 100644 --- a/test/Driver/mips-features.c +++ b/test/Driver/mips-features.c @@ -105,13 +105,13 @@ // CHECK-NOMFP64: "-target-feature" "-fp64" // // -mnan=2008 -// RUN: %clang -target mips-linux-gnu -### -c %s \ +// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \ // RUN: -mnan=legacy -mnan=2008 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NAN2008 %s // CHECK-NAN2008: "-target-feature" "+nan2008" // // -mnan=legacy -// RUN: %clang -target mips-linux-gnu -### -c %s \ +// RUN: %clang -target mips-linux-gnu -march=mips32r3 -### -c %s \ // RUN: -mnan=2008 -mnan=legacy 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-NANLEGACY %s // CHECK-NANLEGACY: "-target-feature" "-nan2008" diff --git a/test/Driver/mips-integrated-as.s b/test/Driver/mips-integrated-as.s index 08adb204cb..2c298e7552 100644 --- a/test/Driver/mips-integrated-as.s +++ b/test/Driver/mips-integrated-as.s @@ -62,7 +62,7 @@ // NAN-LEGACY: -cc1as // NAN-LEGACY: "-target-feature" "-nan2008" -// RUN: %clang -target mips-linux-gnu -### -fintegrated-as -c %s -mnan=2008 2>&1 | \ +// RUN: %clang -target mips-linux-gnu -march=mips32r6 -### -fintegrated-as -c %s -mnan=2008 2>&1 | \ // RUN: FileCheck -check-prefix=NAN-2008 %s // NAN-2008: -cc1as // NAN-2008: "-target-feature" "+nan2008" diff --git a/test/Preprocessor/init.c b/test/Preprocessor/init.c index 9bda63a1cf..91ec4d77b5 100644 --- a/test/Preprocessor/init.c +++ b/test/Preprocessor/init.c @@ -4416,11 +4416,16 @@ // RUN: | FileCheck -check-prefix MIPS-MSA %s // MIPS-MSA:#define __mips_msa 1 // -// RUN: %clang_cc1 -target-feature +nan2008 \ +// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature +nan2008 \ // RUN: -E -dM -triple=mips-none-none < /dev/null \ // RUN: | FileCheck -check-prefix MIPS-NAN2008 %s // MIPS-NAN2008:#define __mips_nan2008 1 // +// RUN: %clang_cc1 -target-cpu mips32r3 -target-feature -nan2008 \ +// RUN: -E -dM -triple=mips-none-none < /dev/null \ +// RUN: | FileCheck -check-prefix NOMIPS-NAN2008 %s +// NOMIPS-NAN2008-NOT:#define __mips_nan2008 1 +// // RUN: %clang_cc1 -target-feature -fp64 \ // RUN: -E -dM -triple=mips-none-none < /dev/null \ // RUN: | FileCheck -check-prefix MIPS32-MFP32 %s -- 2.40.0