r218863 - [ARM] Handle conflicts between -mfpu and -mfloat-abi options.

Asiri Rathnayake asiri.rathnayake at arm.com
Thu Oct 2 02:56:08 PDT 2014


Author: asiri
Date: Thu Oct  2 04:56:07 2014
New Revision: 218863

URL: http://llvm.org/viewvc/llvm-project?rev=218863&view=rev
Log:
[ARM] Handle conflicts between -mfpu and -mfloat-abi options.

Summary: This patch implements warnings/downgradable errors for
invalid -mfpu, -mfloat-abi option combinations (e.g. -mfpu=none
-mfloat-abi=hard).

Change-Id: I94fa664e1bc0b5855ad835abd7a50a3e0395632d

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
    cfe/trunk/lib/Driver/Tools.cpp
    cfe/trunk/lib/Driver/Tools.h
    cfe/trunk/test/Driver/arm-mfpu.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=218863&r1=218862&r2=218863&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Oct  2 04:56:07 2014
@@ -146,6 +146,12 @@ def warn_drv_clang_unsupported : Warning
   "the clang compiler does not support '%0'">;
 def warn_drv_assuming_mfloat_abi_is : Warning<
   "unknown platform, assuming -mfloat-abi=%0">;
+def warn_drv_implied_soft_float_assumed : Warning<
+  "%0 implies soft-float, ignoring conflicting option '%1'">,
+  InGroup<DiagGroup<"implied-soft-float-assumed">>;
+def warn_drv_implied_soft_float_conflict : Warning<
+  "%0 implies soft-float, which conflicts with option '%1'">,
+  InGroup<DiagGroup<"implied-soft-float-conflict">>, DefaultError;
 def warn_ignoring_ftabstop_value : Warning<
   "ignoring invalid -ftabstop value '%0', using default value %1">;
 def warn_drv_overriding_flag_option : Warning<

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=218863&r1=218862&r2=218863&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Oct  2 04:56:07 2014
@@ -581,14 +581,24 @@ static void getARMFPUFeatures(const Driv
     D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
-// Select the float ABI as determined by -msoft-float, -mhard-float, and
-// -mfloat-abi=.
+// Select the float ABI as determined by -msoft-float, -mhard-float,
+// -mfpu=... and -mfloat-abi=...
 StringRef tools::arm::getARMFloatABI(const Driver &D, const ArgList &Args,
-                                     const llvm::Triple &Triple) {
+                                     const llvm::Triple &Triple,
+                                     bool *ExplicitNoFloat) {
+
+  // FIXME: -msoft-float and -mhard-float identify the nature of floating point
+  // ops, whereas -mfloat-abi=... identifies the floating point argument passing
+  // convention. But here we are mushing them together into FloatABI = soft/
+  // softfp/hard, which is a bit confusing. For example, this means -msoft-float
+  // and -mfloat-abi=soft are equivalent options to clang. But when we pass
+  // arguments to the backend (AddARMTargetArgs), these two options take their
+  // original interpretations.
   StringRef FloatABI;
-  if (Arg *A = Args.getLastArg(options::OPT_msoft_float,
-                               options::OPT_mhard_float,
-                               options::OPT_mfloat_abi_EQ)) {
+  const Arg *A = Args.getLastArg(options::OPT_msoft_float,
+                                 options::OPT_mhard_float,
+                                 options::OPT_mfloat_abi_EQ);
+  if (A) {
     if (A->getOption().matches(options::OPT_msoft_float))
       FloatABI = "soft";
     else if (A->getOption().matches(options::OPT_mhard_float))
@@ -603,6 +613,31 @@ StringRef tools::arm::getARMFloatABI(con
     }
   }
 
+  // Some -mfpu=... options are incompatible with some mfloat-abi=... options
+  if (Arg *B = Args.getLastArg(options::OPT_mfpu_EQ)) {
+    StringRef FPU = B->getValue();
+    if (FPU == "none") {
+      // Signal incompatible -mfloat-abi=... options
+      if (FloatABI == "hard")
+        D.Diag(diag::warn_drv_implied_soft_float_conflict)
+          << B->getAsString(Args) << A->getAsString(Args);
+      else if (FloatABI == "softfp")
+        D.Diag(diag::warn_drv_implied_soft_float_assumed)
+          << B->getAsString(Args) << A->getAsString(Args);
+      // Assume soft-float
+      FloatABI = "soft";
+    } else if (FloatABI.empty() || FloatABI == "soft") {
+      // Need -mhard-float for floating point ops
+      FloatABI = "softfp";
+    } 
+  }
+
+  // This allows us to differentiate between a user specified soft-float and
+  // an inferred soft-float. The latter may be overridden under other conditions
+  // but the former has higher priority.
+  if (FloatABI == "soft" && ExplicitNoFloat)
+    *ExplicitNoFloat = true;
+
   // If unspecified, choose the default based on the platform.
   if (FloatABI.empty()) {
     switch (Triple.getOS()) {
@@ -681,7 +716,8 @@ static void getARMTargetFeatures(const D
                                  const ArgList &Args,
                                  std::vector<const char *> &Features,
                                  bool ForAS) {
-  StringRef FloatABI = tools::arm::getARMFloatABI(D, Args, Triple);
+  bool ExplicitNoFloat = false;
+  StringRef FloatABI = tools::arm::getARMFloatABI(D, Args, Triple, &ExplicitNoFloat);
   if (!ForAS) {
     // FIXME: Note, this is a hack, the LLVM backend doesn't actually use these
     // yet (it uses the -mfloat-abi and -msoft-float options), and it is
@@ -716,6 +752,14 @@ static void getARMTargetFeatures(const D
     Features.push_back("-neon");
     // Also need to explicitly disable features which imply NEON.
     Features.push_back("-crypto");
+    // Disable remaining floating-point features if soft-float is explicitly
+    // requested.
+    if (ExplicitNoFloat) {
+      Features.push_back("-vfp2");
+      Features.push_back("-vfp3");
+      Features.push_back("-vfp4");
+      Features.push_back("-fp-armv8");
+    }
   }
 
   // En/disable crc

Modified: cfe/trunk/lib/Driver/Tools.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.h?rev=218863&r1=218862&r2=218863&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/Tools.h (original)
+++ cfe/trunk/lib/Driver/Tools.h Thu Oct  2 04:56:07 2014
@@ -614,7 +614,8 @@ namespace visualstudio {
 
 namespace arm {
   StringRef getARMFloatABI(const Driver &D, const llvm::opt::ArgList &Args,
-                         const llvm::Triple &Triple);
+                           const llvm::Triple &Triple,
+                           bool *ExplicitNoFloat = NULL);
 }
 namespace XCore {
   // For XCore, we do not need to instantiate tools for PreProcess, PreCompile and Compile.

Modified: cfe/trunk/test/Driver/arm-mfpu.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/arm-mfpu.c?rev=218863&r1=218862&r2=218863&view=diff
==============================================================================
--- cfe/trunk/test/Driver/arm-mfpu.c (original)
+++ cfe/trunk/test/Driver/arm-mfpu.c Thu Oct  2 04:56:07 2014
@@ -122,12 +122,12 @@
 
 // RUN: %clang -target armv8-linux-gnueabi -mfpu=none %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NO-FP %s
+// CHECK-NO-FP: "-target-feature" "-neon"
+// CHECK-NO-FP: "-target-feature" "-crypto"
 // CHECK-NO-FP: "-target-feature" "-vfp2"
 // CHECK-NO-FP: "-target-feature" "-vfp3"
 // CHECK-NO-FP: "-target-feature" "-vfp4"
 // CHECK-NO-FP: "-target-feature" "-fp-armv8"
-// CHECK-NO-FP: "-target-feature" "-crypto"
-// CHECK-NO-FP: "-target-feature" "-neon"
 
 // RUN: %clang -target arm-linux-gnueabihf %s -### 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-HF %s
@@ -136,3 +136,114 @@
 // RUN: %clang -target armv7-apple-darwin -x assembler %s -### -c 2>&1 \
 // RUN:   | FileCheck --check-prefix=ASM %s
 // ASM-NOT: -target-feature
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv7-linux-gnueabi -mfpu=none -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv6-linux-gnueabi -mfpu=none -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv5-linux-gnueabi -mfpu=none -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv4-linux-gnueabi -mfpu=none -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv7-linux-gnueabi -mfpu=none -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv6-linux-gnueabi -mfpu=none -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv5-linux-gnueabi -mfpu=none -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv4-linux-gnueabi -mfpu=none -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv8-linux-gnueabi -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv7-linux-gnueabi -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv6-linux-gnueabi -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv5-linux-gnueabi -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv4-linux-gnueabi -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv8-linux-gnueabi -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv7-linux-gnueabi -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv6-linux-gnueabi -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv5-linux-gnueabi -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv4-linux-gnueabi -msoft-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv7-linux-gnueabi -mfpu=none %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv6-linux-gnueabi -mfpu=none %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv5-linux-gnueabi -mfpu=none %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// RUN: %clang -target armv4-linux-gnueabi -mfpu=none %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI-FP %s
+// SOFT-ABI-FP-NOT: error:
+// SOFT-ABI-FP-NOT: warning:
+// SOFT-ABI-FP-NOT: "-target-feature" "+{{[^ ]*fp[^ ]*}}"
+// SOFT-ABI-FP: "-target-feature" "-neon"
+// SOFT-ABI-FP: "-target-feature" "-crypto"
+// SOFT-ABI-FP: "-target-feature" "-vfp2"
+// SOFT-ABI-FP: "-target-feature" "-vfp3"
+// SOFT-ABI-FP: "-target-feature" "-vfp4"
+// SOFT-ABI-FP: "-target-feature" "-fp-armv8"
+// SOFT-ABI-FP-NOT: "-target-feature" "+{{[^ ]*fp[^ ]*}}"
+// SOFT-ABI-FP: "-msoft-float"
+// SOFT-ABI-FP: "-mfloat-abi" "soft"
+// SOFT-ABI-FP-NOT: "-target-feature" "+{{[^ ]*fp[^ ]*}}"
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none -mfloat-abi=softfp %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ABI-IGNORE %s
+// ABI-IGNORE: warning: -mfpu=none implies soft-float, ignoring conflicting option '-mfloat-abi=softfp'
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none -mfloat-abi=hard %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=ABI-ERROR %s
+// ABI-ERROR: error: -mfpu=none implies soft-float, which conflicts with option '-mfloat-abi=hard'
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=none -mhard-float %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=FP-ERROR %s
+// FP-ERROR: error: -mfpu=none implies soft-float, which conflicts with option '-mhard-float'
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=vfp4 -mfloat-abi=soft %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI %s
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=vfp4 -mfloat-abi=softfp %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI %s
+// RUN: %clang -target armv8-freebsd-gnueabi -mfpu=vfp4 %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=SOFT-ABI %s
+// SOFT-ABI-NOT: error:
+// SOFT-ABI-NOT: warning:
+// SOFT-ABI-NOT: "-msoft-float"
+// SOFT-ABI: "-target-feature" "+vfp4"
+// SOFT-ABI-NOT: "-msoft-float"
+// SOFT-ABI: "-mfloat-abi" "soft"
+// SOFT-ABI-NOT: "-msoft-float"
+
+// Floating point features should be disabled only when explicitly requested,
+// otherwise we must respect target inferred defaults.
+//
+// RUN: %clang -target armv8-freebsd-gnueabi %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=DEFAULT-FP %s
+// DEAFULT-FP-NOT: error:
+// DEFAULT-FP-NOT: warning:
+// DEFAULT-FP-NOT: "-target-feature" "-{{[^ ]*fp[^ ]*}}"
+// DEFAULT-FP: "-msoft-float" "-mfloat-abi" "soft"
+// DEFAULT-FP-NOT: "-target-feature" "-{{[^ ]*fp[^ ]*}}"
+
+// RUN: %clang -target armv8-linux-gnueabi -mfpu=vfp4 -mfloat-abi=hard %s -### 2>&1 \
+// RUN:   | FileCheck --check-prefix=VFP-ABI %s
+// VFP-ABI-NOT: error:
+// VFP-ABI-NOT: warning:
+// VFP-ABI-NOT: "-msoft-float"
+// VFP-ABI: "-target-feature" "+vfp4"
+// VFP-ABI-NOT: "-msoft-float"
+// VFP-ABI: "-mfloat-abi" "hard"
+// VFP-ABI-NOT: "-msoft-float"





More information about the cfe-commits mailing list