Readd the C++ ABI alignment handling logic

This code was accidentally removed during Emscripten support removal.

R=stichnot@chromium.org

Review URL: https://codereview.chromium.org/1735523006 .
diff --git a/include/clang/Basic/TargetCXXABI.h b/include/clang/Basic/TargetCXXABI.h
index 42a976b..c0a72cd 100644
--- a/include/clang/Basic/TargetCXXABI.h
+++ b/include/clang/Basic/TargetCXXABI.h
@@ -146,6 +146,24 @@
     llvm_unreachable("bad ABI kind");
   }
 
+  /// \brief Are pointers to member functions differently aligned?
+  bool arePointersToMemberFunctionsAligned() const {
+    switch (getKind()) {
+    case GenericARM:
+    case GenericAArch64:
+      // TODO: ARM-style pointers to member functions put the discriminator in
+      //       the this adjustment, so they don't require functions to have any
+      //       special alignment and could therefore also return false.
+    case GenericItanium:
+    case GenericMIPS:
+    case iOS:
+    case iOS64:
+    case Microsoft:
+      return true;
+    }
+    llvm_unreachable("bad ABI kind");
+  }
+
   /// \brief Is the default C++ member function calling convention
   /// the same as the default calling convention?
   bool isMemberFunctionCCDefault() const {
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 9090ff2..9ba8396 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -793,6 +793,12 @@
   unsigned alignment = D->getMaxAlignment() / Context.getCharWidth();
   if (alignment)
     F->setAlignment(alignment);
+
+  if (getTarget().getCXXABI().arePointersToMemberFunctionsAligned()) {
+    // C++ ABI requires 2-byte alignment for member functions.
+    if (F->getAlignment() < 2 && isa<CXXMethodDecl>(D))
+      F->setAlignment(2);
+  }
 }
 
 void CodeGenModule::SetCommonAttributes(const Decl *D,