How to change alignment of long long

In clang-3.8, I'm trying to have some data types aligned on 8-bit
boundaries, which works for everything except long long.

In my target, I've used:

IntAlign = 8;
LongAlign = 8;
LongLongAlign = 8;
FloatAlign = 8;
DataLayoutString =
"E-p:16:8:8-i1:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-a:8:8";

If I compile this test.c

int i;
long l;
long long ll;
float f;

I get the following test.ll:

; ModuleID = 'test.c'
target datalayout =
"E-p:16:8:8-i1:8:8-i8:8:8-i16:8:8-i32:8:8-i64:8:8-f32:8:8-a:8:8"
target triple = "sdcc-stm8"

@i = common global i16 0, align 1
@l = common global i32 0, align 1
@ll = common global i64 0, align 8
@f = common global float 0.000000e+00, align 1

!llvm.ident = !{!0}

!0 = !{!"clang version 3.8.1 "}

So the alignment is wrong for long long only.

It seems someone else had such a problem in January
(http://lists.llvm.org/pipermail/llvm-dev/2016-January/094000.html), but
I don't see a solution there.

Philipp

Found another one that encountered this problem:

http://lists.llvm.org/pipermail/cfe-dev/2013-October/032554.html

Again no solution there.

Is anyone sucessfully using clang (preferably 3.8) with an alignment for
long long or double that is not 64 bits?

Philipp

To all the other encountering this issue: I was able to track down the
issue.

In general, alignment handling in clang is a mess.

Yes, there are some values in the Target for alignment, but they dont't
always do what one might think. They seem to be fine for char, int, long
and float. For short, there is none, as short alignment is hardcoded to
16 bits. For long long and double there are alignment values, but they
are not used. Instead the width is used as alignment: In
ASTContext::getPreferredTypeAlign, unless the target is xcore, for
double, long long and unsigned long long, the alignment of the type is
replaced by the width.
So, to make alignment for long long and double work, you need add a
special case for your target in ASTContext::getPreferredTypeAlign like
there already is for xcore. And to make alignment work for short, you
need to make getShortAlign() virtual in TargetInfo and override it in
your Target.

Philipp

P.S.: I am using clang 3.8, the above might or might not apply to other
versions.