ahatanak created this revision.
ahatanak added a reviewer: vsk.
ahatanak added a subscriber: cfe-commits.
Herald added subscribers: rengolin, aemerson.

This patch corrects http://reviews.llvm.org/D12155, which didn't take into 
account the fact that aapcs ABI can be selected on darwin platforms. The new 
patch errors out only when the ABI is APCS and the float-abi is hard.

http://reviews.llvm.org/D12344

Files:
  lib/Driver/Tools.cpp
  test/Driver/arm-float-abi.c

Index: test/Driver/arm-float-abi.c
===================================================================
--- /dev/null
+++ test/Driver/arm-float-abi.c
@@ -0,0 +1,6 @@
+// RUN: not %clang %s -target armv7-apple-ios -mfloat-abi=hard 2>&1 | 
FileCheck -check-prefix=ARMV7-ERROR %s
+// RUN: %clang %s -target armv7-apple-ios -mfloat-abi=softfp -### 2>&1 | 
FileCheck -check-prefix=NOERROR %s
+// RUN: %clang %s -arch armv7 -target thumbv7-apple-darwin-eabi 
-mfloat-abi=hard -### 2>&1 | FileCheck -check-prefix=NOERROR %s
+
+// ARMV7-ERROR: unsupported option '-mfloat-abi=hard' for target 'thumbv7'
+// NOERROR-NOT: unsupported option
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -563,6 +563,13 @@
     D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
+static bool useAAPCSForMachO(const llvm::Triple &T) {
+  // The backend is hardwired to assume AAPCS for M-class processors, ensure
+  // the frontend matches that.
+  return T.getEnvironment() == llvm::Triple::EABI ||
+         T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
+}
+
 // Select the float ABI as determined by -msoft-float, -mhard-float, and
 // -mfloat-abi=.
 StringRef tools::arm::getARMFloatABI(const Driver &D, const ArgList &Args,
@@ -582,6 +589,13 @@
         FloatABI = "soft";
       }
     }
+
+    // It is incorrect to select hard float ABI on MachO platforms if the ABI 
is
+    // "apcs-gnu".
+    if (Triple.isOSBinFormatMachO() && !useAAPCSForMachO(Triple) &&
+        FloatABI == "hard")
+      D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args)
+                                                       << Triple.getArchName();
   }
 
   // If unspecified, choose the default based on the platform.
@@ -856,10 +870,7 @@
   if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
     ABIName = A->getValue();
   } else if (Triple.isOSBinFormatMachO()) {
-    // The backend is hardwired to assume AAPCS for M-class processors, ensure
-    // the frontend matches that.
-    if (Triple.getEnvironment() == llvm::Triple::EABI ||
-        Triple.getOS() == llvm::Triple::UnknownOS || isARMMProfile(Triple)) {
+    if (useAAPCSForMachO(Triple)) {
       ABIName = "aapcs";
     } else {
       ABIName = "apcs-gnu";


Index: test/Driver/arm-float-abi.c
===================================================================
--- /dev/null
+++ test/Driver/arm-float-abi.c
@@ -0,0 +1,6 @@
+// RUN: not %clang %s -target armv7-apple-ios -mfloat-abi=hard 2>&1 | FileCheck -check-prefix=ARMV7-ERROR %s
+// RUN: %clang %s -target armv7-apple-ios -mfloat-abi=softfp -### 2>&1 | FileCheck -check-prefix=NOERROR %s
+// RUN: %clang %s -arch armv7 -target thumbv7-apple-darwin-eabi -mfloat-abi=hard -### 2>&1 | FileCheck -check-prefix=NOERROR %s
+
+// ARMV7-ERROR: unsupported option '-mfloat-abi=hard' for target 'thumbv7'
+// NOERROR-NOT: unsupported option
Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -563,6 +563,13 @@
     D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);
 }
 
+static bool useAAPCSForMachO(const llvm::Triple &T) {
+  // The backend is hardwired to assume AAPCS for M-class processors, ensure
+  // the frontend matches that.
+  return T.getEnvironment() == llvm::Triple::EABI ||
+         T.getOS() == llvm::Triple::UnknownOS || isARMMProfile(T);
+}
+
 // Select the float ABI as determined by -msoft-float, -mhard-float, and
 // -mfloat-abi=.
 StringRef tools::arm::getARMFloatABI(const Driver &D, const ArgList &Args,
@@ -582,6 +589,13 @@
         FloatABI = "soft";
       }
     }
+
+    // It is incorrect to select hard float ABI on MachO platforms if the ABI is
+    // "apcs-gnu".
+    if (Triple.isOSBinFormatMachO() && !useAAPCSForMachO(Triple) &&
+        FloatABI == "hard")
+      D.Diag(diag::err_drv_unsupported_opt_for_target) << A->getAsString(Args)
+                                                       << Triple.getArchName();
   }
 
   // If unspecified, choose the default based on the platform.
@@ -856,10 +870,7 @@
   if (Arg *A = Args.getLastArg(options::OPT_mabi_EQ)) {
     ABIName = A->getValue();
   } else if (Triple.isOSBinFormatMachO()) {
-    // The backend is hardwired to assume AAPCS for M-class processors, ensure
-    // the frontend matches that.
-    if (Triple.getEnvironment() == llvm::Triple::EABI ||
-        Triple.getOS() == llvm::Triple::UnknownOS || isARMMProfile(Triple)) {
+    if (useAAPCSForMachO(Triple)) {
       ABIName = "aapcs";
     } else {
       ABIName = "apcs-gnu";
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to