[swift-dev] PointerIntPair alignment

William Dillon william at housedillon.com
Thu Jan 28 21:10:11 CST 2016

Hi everyone,

I’ve been working on rebasing my Arm patch with the latest apple/master.  There is an assertion thrown by the swift compiler that the pointer in PointerIntPair is insufficiently aligned (using ProtocolConformance *).  I’ve found where the allocator used for these objects, the specified alignment, and the definition of the NumLowBitsAvailable for ProtocolConformance is.  The problem is that on these systems (I’m not sure whether it’s an ARM problem or a 32-bit problem) the alignment specified in the allocator is insufficient for the stated NumLowBitsAvailable.

For convince, the allocator is in ProtocolConformance.h:

  // Only allow allocation of protocol conformances using the allocator in
  // ASTContext or by doing a placement new.
  void *operator new(size_t bytes, ASTContext &context,
                     AllocationArena arena,
                     unsigned alignment = alignof(ProtocolConformance)); // (4-byte aligned)
  void *operator new(size_t bytes, void *mem) {
    return mem;

and the definition of NumLowBitsAvailable is in TypeAlignments.h:

constexpr size_t DeclAlignInBits = 3;
LLVM_DECLARE_TYPE_ALIGNMENT(swift::ProtocolConformance, swift::DeclAlignInBits)

So, my question is this:  There are tons of ways to solve the problem, but I think all but one are a hack.  What method of solving the problem best matches the coding conventions and the overall architecture (which I readily admit that I don’t fully understand)?

- Will

More information about the swift-dev mailing list