[swift-dev] PointerIntPair alignment

Chris Lattner clattner at apple.com
Thu Jan 28 22:42:26 CST 2016


> On Jan 28, 2016, at 7:10 PM, William Dillon via swift-dev <swift-dev at swift.org> wrote:
> 
> 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) {
>    assert(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)?

Hi William,

Does it help to add an alignment to the ProtocolConformance type, change:

class ProtocolConformance {

to:

class alignas(1 << DeclAlignInBits) ProtocolConformance {


?

-Chris


More information about the swift-dev mailing list