]> granicus.if.org Git - clang/commitdiff
Fix up handling of ARM options for controlling strict alignment.
authorBob Wilson <bob.wilson@apple.com>
Tue, 29 Jul 2014 00:23:18 +0000 (00:23 +0000)
committerBob Wilson <bob.wilson@apple.com>
Tue, 29 Jul 2014 00:23:18 +0000 (00:23 +0000)
The -mstrict-align option was originally added in r167619 as a target-
independent option. It was then changed in r167623 to be implemented with an
ARM-specific backend option, even though the code remained in the
target-independent Clang::ConstructJob function. This means that if you used
the -mstrict-align option with a non-ARM target, you would still get the
-arm-strict-align option getting passed to the backend, which was harmless
but gross. The driver option was then replaced by the GCC-compatible
-m[no-]unaligned-access option (r189175) and modified to work with AArch64
(r208075). However, in the process, the help text for -mstrict-align was
incorrectly changed to show it as only being supported for AArch64. Even worse,
the logic for handling these options together with -mkernel was wrong for
AArch64, where -mkernel does not currently imply strict alignment.

This patch fixes up all of those things. Besides the obvious change to the
option help text, it moves the logic into the ARM and AArch64-specific parts
of the driver, so that the option will be correctly ignored for non-ARM
targets. <rdar://problem/17823697>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@214148 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
lib/Driver/Tools.cpp
test/Driver/arm-alignment.c

index 61e463c5e6d00a4a7ec9ca901886d502a4bd8905..7a68761f323b6e776172600110e8b15dca6f2629 100644 (file)
@@ -1113,7 +1113,7 @@ def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_arm_Features_G
 def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_arm_Features_Group>,
   HelpText<"Force all memory accesses to be aligned (AArch32/AArch64 only)">;
 def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>, Flags<[CC1Option,HelpHidden]>,
-  HelpText<"Force all memory accesses to be aligned (AArch64 only, same as mno-unaligned-access)">;
+  HelpText<"Force all memory accesses to be aligned (same as mno-unaligned-access)">;
 def mno_thumb : Flag<["-"], "mno-thumb">, Group<m_arm_Features_Group>;
 def mrestrict_it: Flag<["-"], "mrestrict-it">, Group<m_arm_Features_Group>,
   HelpText<"Disallow generation of deprecated IT blocks for ARMv8. It is on by default for ARMv8 Thumb mode.">;
index adbe09448914feea484735209abb3944ca134b59..b607f2f26d883287c82a258ae62bb2a45afbc866 100644 (file)
@@ -799,6 +799,18 @@ void Clang::AddARMTargetArgs(const ArgList &Args,
     CmdArgs.push_back("-arm-use-movt=0");
   }
 
+  // -mkernel implies -mstrict-align; don't add the redundant option.
+  if (!KernelOrKext) {
+    if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
+                                 options::OPT_munaligned_access)) {
+      CmdArgs.push_back("-backend-option");
+      if (A->getOption().matches(options::OPT_mno_unaligned_access))
+        CmdArgs.push_back("-arm-strict-align");
+      else
+        CmdArgs.push_back("-arm-no-strict-align");
+    }
+  }
+
   // Setting -mno-global-merge disables the codegen global merge pass. Setting 
   // -mglobal-merge has no effect as the pass is enabled by default.
   if (Arg *A = Args.getLastArg(options::OPT_mglobal_merge,
@@ -873,9 +885,13 @@ void Clang::AddAArch64TargetArgs(const ArgList &Args,
   CmdArgs.push_back("-target-abi");
   CmdArgs.push_back(ABIName);
 
-  if (Args.hasArg(options::OPT_mstrict_align)) {
+  if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
+                               options::OPT_munaligned_access)) {
     CmdArgs.push_back("-backend-option");
-    CmdArgs.push_back("-aarch64-strict-align");
+    if (A->getOption().matches(options::OPT_mno_unaligned_access))
+      CmdArgs.push_back("-aarch64-strict-align");
+    else
+      CmdArgs.push_back("-aarch64-no-strict-align");
   }
 
   // Setting -mno-global-merge disables the codegen global merge pass. Setting
@@ -3673,27 +3689,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     StringRef alignment = Args.getLastArgValue(options::OPT_mstack_alignment);
     CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment));
   }
-  // -mkernel implies -mstrict-align; don't add the redundant option.
-  if (!KernelOrKext) {
-    if (Arg *A = Args.getLastArg(options::OPT_mno_unaligned_access,
-                                 options::OPT_munaligned_access)) {
-      if (A->getOption().matches(options::OPT_mno_unaligned_access)) {
-        CmdArgs.push_back("-backend-option");
-        if (getToolChain().getTriple().getArch() == llvm::Triple::aarch64 ||
-            getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be)
-          CmdArgs.push_back("-aarch64-strict-align");
-        else
-          CmdArgs.push_back("-arm-strict-align");
-      } else {
-        CmdArgs.push_back("-backend-option");
-        if (getToolChain().getTriple().getArch() == llvm::Triple::aarch64 ||
-            getToolChain().getTriple().getArch() == llvm::Triple::aarch64_be)
-          CmdArgs.push_back("-aarch64-no-strict-align");
-        else
-          CmdArgs.push_back("-arm-no-strict-align");
-      }
-    }
-  }
 
   if (Arg *A = Args.getLastArg(options::OPT_mrestrict_it,
                                options::OPT_mno_restrict_it)) {
index 98046d7edf1d36f4533bfb36117376e9b484d186..e7b7ac34874d3211bb18dab34e477ba3675a0d63 100644 (file)
@@ -44,5 +44,8 @@
 // RUN: %clang -target aarch64-none-gnueabi -munaligned-access -mstrict-align -### %s 2> %t
 // RUN: FileCheck --check-prefix=CHECK-ALIGNED-AARCH64 < %t %s
 
+// RUN: %clang -target aarch64-none-gnueabi -mkernel -mno-unaligned-access -### %s 2> %t
+// RUN: FileCheck --check-prefix=CHECK-ALIGNED-AARCH64 < %t %s
+
 // CHECK-ALIGNED-ARM: "-backend-option" "-arm-strict-align"
 // CHECK-ALIGNED-AARCH64: "-backend-option" "-aarch64-strict-align"