[cfe-dev] How to change default alignment in Clang

Joan Lluch via cfe-dev cfe-dev at lists.llvm.org
Sat May 18 11:48:56 PDT 2019


For my 16 bit based target implementation, I need objects larger than 1 byte to get always aligned to 2 bytes.

For simple types, this is easily made by setting alignments in the MyTarget.h file (for example IntWidth=16; IntAlign=16; and so on)
For arrays, I have set LargeArrayMinWidth = 8; LargeArrayAlign = 16;  so that all of them get an alignment of 2 bytes.

However, I am lost at what to do with Structs. The desired behaviour is obtained when I explicitly give the __attribute__( (aligned) ) in the source C code, such as this

struct AA
{
  char n;
  char m;
  char j;
} __attribute__( (aligned) );

but I would want CLang to set that attribute by default to all aggregate types.

Setting MinGlobalAlign is not an option because I still want single bytes to be 1 byte aligned, also, this does not work for objects initialised on the stack.

So, what’s the code hook to instruct Clang to always emit aligned code (as if the __attribute__( (aligned) ) was specified) ?

John Lluch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20190518/b51d4aae/attachment.html>


More information about the cfe-dev mailing list