use the last passed -munaligned-access / -mno-unaligned-access

Passing inconsistent munaligned-access / mno-unaligned-access
flags, intentionally resulted in a warning and the flag
no-unaligned-access being used.

Gcc does, at least in practice, use the last flag in such a
case. This patch updates clang behaviour accordingly; use the
last flag or base alignment behaviour on the target (which
llvm will do if no flag is explicitly passed)

Patch by Jeroen Hofstee.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@189542 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Tools.cpp b/lib/Driver/Tools.cpp
index 6862e76..9633d6b 100644
--- a/lib/Driver/Tools.cpp
+++ b/lib/Driver/Tools.cpp
@@ -2944,12 +2944,15 @@
   }
   // -mkernel implies -mstrict-align; don't add the redundant option.
   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");
+    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");
+        CmdArgs.push_back("-arm-strict-align");
+      } else {
+        CmdArgs.push_back("-backend-option");
+        CmdArgs.push_back("-arm-no-strict-align");
+      }
     }
   }