alignment of local variables

Is it possible to set a maximum alignment for local variables, either by passing a command line option or using target-specific hooks?
For example, in the code shown below, if the maximum alignment is 8, the alignment attribute in the source code (aligned(16)) will be ignored, and local variable a will be aligned on an 8-byte boundary.

align2.c

#define N 16

int main1 (int n, int *a);

int main (void)
{
int a[N+1] attribute ((aligned(16)));

main1 (N, a+1);

return 0;
}

.ll

clang -O3 -S -o - -emit-llvm align2.c

; ModuleID = ‘align2.c’
target datalayout = “e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32”
target triple = “i386-pc-linux-gnu”

define i32 @main() nounwind {
entry:
%a = alloca [17 x i32], align 16;
%add.ptr = getelementptr inbounds [17 x i32]* %a, i32 0, i32 1
%call = call i32 @main1(i32 16, i32* %add.ptr) nounwind
ret i32 0
}

declare i32 @main1(i32, i32*)

No, and why would you want to do this?

-eric

I just wanted to know if it is absolutely necessary to implement dynamic stack realignment in the backend. If the maximum alignment is no larger than the default alignment of the run-time stack, you won’t have to adjust the stack pointer at run-time.

You'll run into other problems where people have requested an alignment and then depend upon it.

-eric

I understand it is probably not right to ignore alignment attributes in the source code, but I just wanted to know if it is an option, because some gcc backends (e.g. mips) seem to do that.

I understand it is probably not right to ignore alignment attributes in the source code, but I just wanted to know if it is an option, because some gcc backends (e.g. mips) seem to do that.

We don’t currently have a way to do this, but we could add it. We’d just add a “MaxStackAlignment” setting to target info (the default being “none”) and targets could specify their limits this way.

-Chris