From 364355da26053c321180fa31ecd731d36c4cffae Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 25 Apr 2014 16:00:38 -0700 Subject: Don't align member functions. Emscripten uses the ARM ABI for pointers to member functions and doesn't require that member functions are aligned. --- include/clang/Basic/TargetCXXABI.h | 18 ++++++++++++++++++ lib/CodeGen/CodeGenModule.cpp | 8 +++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/include/clang/Basic/TargetCXXABI.h b/include/clang/Basic/TargetCXXABI.h index 29e4e47076..abdf899f5d 100644 --- a/include/clang/Basic/TargetCXXABI.h +++ b/include/clang/Basic/TargetCXXABI.h @@ -134,6 +134,24 @@ public: llvm_unreachable("bad ABI kind"); } + /// \brief Are pointers to member functions differently aligned? + bool arePointersToMemberFunctionsAligned() const { + switch (getKind()) { + case Emscripten: + case GenericARM: + case GenericAArch64: + // ARM-style pointers to member functions put the discriminator in the + // this adjustment, so they don't require functions to have any special + // alignment. + return false; + case GenericItanium: + case iOS: + 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 15e4a50eaa..3fb7cba914 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -657,9 +657,11 @@ void CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D, if (alignment) F->setAlignment(alignment); - // C++ ABI requires 2-byte alignment for member functions. - if (F->getAlignment() < 2 && isa(D)) - F->setAlignment(2); + if (getTarget().getCXXABI().arePointersToMemberFunctionsAligned()) { + // C++ ABI requires 2-byte alignment for member functions. + if (F->getAlignment() < 2 && isa(D)) + F->setAlignment(2); + } } void CodeGenModule::SetCommonAttributes(const Decl *D, -- cgit v1.2.3-18-g5258