Clang-Cl - max type alignment not effecting arrays?

Hello Clang-Deves,

I’m currently playing around with Clang-Cl and use it to generate LLVM assembly files. In one of my files I create a double array like this:

double planschiArray[3] = {1.0, 1.1, 1.2};

Clang will generate the following LLVM assembly for it:

@"?planschiArray@@3PANA" = dso_local local_unnamed_addr global [3 x double] [double 1.000000e+00, double 1.100000e+00, double 1.200000e+00], align 16

As far as I understand, the array was aligned to 16 byte - however for an generic address calculation done by us I need an 8byte aligment even though this might effect the SIMD instructions. So I added “-Xclang -fmax-type-align=8” to the compile command but it didn’t effected the array. The full command is:

“D:\Program Files\LLVM10\bin\clang-cl” /c -Xclang -emit-llvm -Xclang -fmax-type-align=8 -m64 -ferror-limit=3000 /FAcs /GS- /MT /EHsc /W4 /O2 /Ob2 /Oi /Ot -Wno-unused-command-line-argument -Wno-microsoft-cast -Wno-writable-strings -Wno-microsoft-enum-forward-reference -Wno-invalid-token-paste -Wno-microsoft-include “%(FullPath)” /Fo"x64\Release\ObjectFile.obj"

Is there a way to force the 8byte alignment via the command line? Using

alignas(sizeof(double)) double planschiArray[3] = {1.0, 1.1, 1.2};

does work however, but I hoped “-Xclang -fmax-type-align=8” would take care of this automatically.

Does anyone know what I’m doing wrong?

Kind greetings

Björn

Hello Clang-Deves,

I’m currently playing around with Clang-Cl and use it to generate LLVM assembly files. In one of my files I create a double array like this:
double planschiArray[3] = {1.0, 1.1, 1.2};

Clang will generate the following LLVM assembly for it:
@"?planschiArray@@3PANA" = dso_local local_unnamed_addr global [3 x double] [double 1.000000e+00, double 1.100000e+00, double 1.200000e+00], align 16

As far as I understand, the array was aligned to 16 byte - however for an generic address calculation done by us I need an 8byte aligment even though this might effect the SIMD instructions. So I added “-Xclang -fmax-type-align=8” to the compile command but it didn’t effected the array. The full command is:

“D:\Program Files\LLVM10\bin\clang-cl” /c -Xclang -emit-llvm -Xclang -fmax-type-align=8 -m64 -ferror-limit=3000 /FAcs /GS- /MT /EHsc /W4 /O2 /Ob2 /Oi /Ot -Wno-unused-command-line-argument -Wno-microsoft-cast -Wno-writable-strings -Wno-microsoft-enum-forward-reference -Wno-invalid-token-paste -Wno-microsoft-include “%(FullPath)” /Fo"x64\Release\ObjectFile.obj"

Is there a way to force the 8byte alignment via the command line? Using
alignas(sizeof(double)) double planschiArray[3] = {1.0, 1.1, 1.2};

does work however, but I hoped “-Xclang -fmax-type-align=8” would take care of this automatically.

Despite the name, -fmax-type-align is specifically just about controlling implicit alignment assumptions and doesn’t actually change the alignment of anything. If it capped alignments in general, it would be ABI-breaking.

John.

That makes sense to me! Thank you for the explanation. So using “alignas” is the only way to force an 8byte alignment for that array?

That makes sense to me! Thank you for the explanation. So using “alignas” is the only way to force an 8byte alignment for that array?

I believe so, yes. You may be able to request lower alignment en masse with a pragma, but you’d have to be careful about what you sweep in under it because, again, that pragma could be ABI-breaking.

John.

Thank you John!
This cleared things for me :3