Alignment in a struct

I do have some problems with the alignment within structs for my target. On my target everything is aligned to 64 bits, no matter how many bits the value has in size.

For the struct:

typedef struct {
  short4* p[3];
} short4Array_t;

only memory for 2 pointers instead of 3 is allocated. For the simplified but equivalent type

typedef short4* short4Array_t[3];

memory for all 3 pointers is allocated. This tells me that the array is not the problem.

Debugging showed me, that the array knows its correct size, but it is not used. Instead the function call chain ItaniumRecordLayoutBuilder::LayoutFieldASTContext::getTypeInfoInCharsgetConstantArrayInfoInChars (re-)computes the size of the array as #Elements * sizeof(Element). In general this would be correct, but I have to align each element:

  unsigned Align = EltInfo.Align.getQuantity();
  uint64_t Width = llvm::alignTo(EltInfo.Width.getQuantity(), Align) * Size;

Now, everything is complied as expected. But I have two questions:

  1. Could this change raise a problem in other situations?
  2. Might such a change be needed for an array of MVT::f80, 128 bits aligned on a X86?

C ABI rules don’t really allow a type to have ABI alignment greater than its size as computed by sizeof(). If you have such types, weird things will happen with array/pointer arithmetic. (See ⚙ D133711 [Sema] Reject array element types whose sizes aren't a multiple of their alignments .)

sizeof(long double) on 64-bit x86 is 16 bytes to account for the necessary padding.