diff options
| author | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2015-04-14 12:49:08 +0000 |
|---|---|---|
| committer | Petar Jovanovic <petar.jovanovic@imgtec.com> | 2015-04-14 12:49:08 +0000 |
| commit | 1dbc317736ce52ce7239d6a1099456e8eac7bcd8 (patch) | |
| tree | 61848f9e4893fe6b8723d7606aa41649f56b572d | |
| parent | 879d1be643e1b38381b85003498cf81c4039583f (diff) | |
| download | bcm5719-llvm-1dbc317736ce52ce7239d6a1099456e8eac7bcd8.tar.gz bcm5719-llvm-1dbc317736ce52ce7239d6a1099456e8eac7bcd8.zip | |
[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
llvm-svn: 234882
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticDriverKinds.td | 7 | ||||
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticGroups.td | 1 | ||||
| -rw-r--r-- | clang/lib/Driver/Tools.cpp | 40 | ||||
| -rw-r--r-- | clang/lib/Driver/Tools.h | 5 | ||||
| -rw-r--r-- | clang/test/CodeGen/mips-unsupported-nan.c | 25 | ||||
| -rw-r--r-- | clang/test/Driver/mips-features.c | 4 | ||||
| -rw-r--r-- | clang/test/Driver/mips-integrated-as.s | 2 | ||||
| -rw-r--r-- | clang/test/Preprocessor/init.c | 7 |
8 files changed, 82 insertions, 9 deletions
diff --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td b/clang/include/clang/Basic/DiagnosticDriverKinds.td index 9a055b8ec41..7c0696a1b92 100644 --- a/clang/include/clang/Basic/DiagnosticDriverKinds.td +++ b/clang/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<Fallback>; + +def warn_target_unsupported_nan2008 : Warning< + "ignoring '-mnan=2008' option because the '%0' architecture does not support it">, + InGroup<UnsupportedNan>; +def warn_target_unsupported_nanlegacy : Warning< + "ignoring '-mnan=legacy' option because the '%0' architecture does not support it">, + InGroup<UnsupportedNan>; } diff --git a/clang/include/clang/Basic/DiagnosticGroups.td b/clang/include/clang/Basic/DiagnosticGroups.td index 02d9c0cf26d..5e4d7efa982 100644 --- a/clang/include/clang/Basic/DiagnosticGroups.td +++ b/clang/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/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp index 4d0ca576593..1e34d7f403a 100644 --- a/clang/lib/Driver/Tools.cpp +++ b/clang/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<int>(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/clang/lib/Driver/Tools.h b/clang/lib/Driver/Tools.h index e8edaebbace..33fadd17004 100644 --- a/clang/lib/Driver/Tools.h +++ b/clang/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/clang/test/CodeGen/mips-unsupported-nan.c b/clang/test/CodeGen/mips-unsupported-nan.c new file mode 100644 index 00000000000..14a36fc0294 --- /dev/null +++ b/clang/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/clang/test/Driver/mips-features.c b/clang/test/Driver/mips-features.c index f7022306fc1..5094f2b09b7 100644 --- a/clang/test/Driver/mips-features.c +++ b/clang/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/clang/test/Driver/mips-integrated-as.s b/clang/test/Driver/mips-integrated-as.s index 08adb204cb2..2c298e75528 100644 --- a/clang/test/Driver/mips-integrated-as.s +++ b/clang/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/clang/test/Preprocessor/init.c b/clang/test/Preprocessor/init.c index 9bda63a1cf8..91ec4d77b5c 100644 --- a/clang/test/Preprocessor/init.c +++ b/clang/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 |

