Add gcc ARM flags -munaligned-access / -mno-unaligned-access

clang already had a mstrict-align which mentiones "Force all memory
accesses to be aligned (ARM only)". On gcc arm this is controlled by
-munaligned-access / -mno-unaligned-access. Add the gcc versions to
the frontend and make -mstrict-align and alias to -mno-unaligned-access
and only show it in clang -cc1 -help.

Since the default value for unaligned accesses / strict alignment
depends on the tripple, both the enable and disable flags are added.
If both are set, the no-unaligned-access is used.

Patch by Jeroen Hofstee.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189175 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index 24759ce..a9e2f53 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -942,8 +942,6 @@
   HelpText<"Force realign the stack at entry to every function">;
 def mstack_alignment : Joined<["-"], "mstack-alignment=">, Group<m_Group>, Flags<[CC1Option]>,
   HelpText<"Set the stack alignment">;
-def mstrict_align : Flag<["-"], "mstrict-align">, Group<m_Group>, Flags<[CC1Option]>,
-  HelpText<"Force all memory accesses to be aligned (ARM only)">;
 def mmmx : Flag<["-"], "mmmx">, Group<m_x86_Features_Group>;
 def mno_3dnowa : Flag<["-"], "mno-3dnowa">, Group<m_x86_Features_Group>;
 def mno_3dnow : Flag<["-"], "mno-3dnow">, Group<m_x86_Features_Group>;
@@ -987,6 +985,12 @@
 def mno_prfchw : Flag<["-"], "mno-prfchw">, Group<m_x86_Features_Group>;
 def mno_rdseed : Flag<["-"], "mno-rdseed">, Group<m_x86_Features_Group>;
 
+def munaligned_access : Flag<["-"], "munaligned-access">, Group<m_arm_Features_Group>,
+  HelpText<"Allow memory accesses to be unaligned (ARM only)">;
+def mno_unaligned_access : Flag<["-"], "mno-unaligned-access">, Group<m_arm_Features_Group>,
+  HelpText<"Force all memory accesses to be aligned (ARM only)">;
+def mstrict_align : Flag<["-"], "mstrict-align">, Alias<mno_unaligned_access>, Flags<[CC1Option,HelpHidden]>,
+  HelpText<"Force all memory accesses to be aligned (ARM only, same as mno-unaligned-access)">;
 def mno_thumb : Flag<["-"], "mno-thumb">, Group<m_arm_Features_Group>;
 def marm : Flag<["-"], "marm">, Alias<mno_thumb>;
 def ffixed_r9 : Flag<["-"], "ffixed-r9">, Group<m_arm_Features_Group>,
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 71cbcb2..1d5b18f 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2941,9 +2941,14 @@
     CmdArgs.push_back(Args.MakeArgString("-mstack-alignment=" + alignment));
   }
   // -mkernel implies -mstrict-align; don't add the redundant option.
-  if (Args.hasArg(options::OPT_mstrict_align) && !KernelOrKext) {
-    CmdArgs.push_back("-backend-option");
-    CmdArgs.push_back("-arm-strict-align");
+  if (!KernelOrKext) {
+    if (Args.hasArg(options::OPT_mno_unaligned_access)) {
+      CmdArgs.push_back("-backend-option");
+      CmdArgs.push_back("-arm-strict-align");
+    } else if (Args.hasArg(options::OPT_munaligned_access)) {
+      CmdArgs.push_back("-backend-option");
+      CmdArgs.push_back("-arm-no-strict-align");
+    }
   }
 
   // Forward -f options with positive and negative forms; we translate