[PATCH] D36550: [mips] Notify user that `-mabicalls` is ignored on non-PIC N64 ABI

Simon Atanasyan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 9 14:07:13 PDT 2017


atanasyan created this revision.
atanasyan added a project: clang.
Herald added a subscriber: arichardson.

The `-mabicalls` option does not have a sense in case of non position independent code on N64 ABI. After this change driver starts to show a warning that `-mabicalls` is ignored in that case.


Repository:
  rL LLVM

https://reviews.llvm.org/D36550

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  lib/Driver/ToolChains/Arch/Mips.cpp
  test/Driver/mips-abicalls-warning.c
  test/Driver/mips-features.c


Index: test/Driver/mips-features.c
===================================================================
--- test/Driver/mips-features.c
+++ test/Driver/mips-features.c
@@ -10,6 +10,11 @@
 // RUN:   | FileCheck --check-prefix=CHECK-MNOABICALLS %s
 // CHECK-MNOABICALLS: "-target-feature" "+noabicalls"
 //
+// -mno-abicalls non-PIC N64
+// RUN: %clang -target mips64-linux-gnu -### -c -fno-PIC %s 2>&1 \
+// RUN:   | FileCheck --check-prefix=CHECK-MNOABICALLS-N64NPIC %s
+// CHECK-MNOABICALLS-N64NPIC: "-target-feature" "+noabicalls"
+//
 // -mgpopt
 // RUN: %clang -target mips-linux-gnu -### -c %s -mno-gpopt -mgpopt -Wno-unsupported-gpopt 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-MGPOPT-DEF-ABICALLS %s
Index: test/Driver/mips-abicalls-warning.c
===================================================================
--- /dev/null
+++ test/Driver/mips-abicalls-warning.c
@@ -0,0 +1,3 @@
+// REQUIRES: mips-registered-target
+// RUN: %clang -### -c -target mips64-mti-elf -fno-PIC -mabicalls %s 2>&1 | FileCheck %s
+// CHECK: warning: ignoring '-mabicalls' option as it cannot be used with non position-independent code and N64 ABI
Index: lib/Driver/ToolChains/Arch/Mips.cpp
===================================================================
--- lib/Driver/ToolChains/Arch/Mips.cpp
+++ lib/Driver/ToolChains/Arch/Mips.cpp
@@ -227,11 +227,30 @@
          O.matches(options::OPT_fno_PIE) || O.matches(options::OPT_fno_pie));
   }
 
-  if (IsN64 && NonPIC)
+  bool DefNoAbiCalls = IsN64 && NonPIC;
+  bool NeedNoAbiCalls = false;
+
+  Arg *ABICallsArg =
+      Args.getLastArg(options::OPT_mabicalls, options::OPT_mno_abicalls);
+  if (!ABICallsArg)
+    NeedNoAbiCalls = DefNoAbiCalls;
+  else {
+    if (ABICallsArg->getOption().matches(options::OPT_mno_abicalls))
+      NeedNoAbiCalls = true;
+    else {
+      if (DefNoAbiCalls) {
+        D.Diag(diag::warn_drv_unsupported_abicalls);
+        NeedNoAbiCalls = true;
+      } else {
+        NeedNoAbiCalls = false;
+      }
+    }
+  }
+
+  if (NeedNoAbiCalls)
     Features.push_back("+noabicalls");
   else
-    AddTargetFeature(Args, Features, options::OPT_mno_abicalls,
-                     options::OPT_mabicalls, "noabicalls");
+    Features.push_back("-noabicalls");
 
   mips::FloatABI FloatABI = mips::getMipsFloatABI(D, Args);
   if (FloatABI == mips::FloatABI::Soft) {
Index: include/clang/Basic/DiagnosticDriverKinds.td
===================================================================
--- include/clang/Basic/DiagnosticDriverKinds.td
+++ include/clang/Basic/DiagnosticDriverKinds.td
@@ -292,6 +292,10 @@
   "ignoring '-mgpopt' option as it cannot be used with %select{|the implicit"
   " usage of }0-mabicalls">,
   InGroup<UnsupportedGPOpt>;
+def warn_drv_unsupported_abicalls : Warning<
+  "ignoring '-mabicalls' option as it cannot be used with "
+  "non position-independent code and N64 ABI">,
+  InGroup<OptionIgnored>;
 
 def warn_drv_unable_to_find_directory_expected : Warning<
   "unable to find %0 directory, expected to be in '%1'">,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36550.110477.patch
Type: text/x-patch
Size: 3024 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170809/1e754ac6/attachment.bin>


More information about the cfe-commits mailing list