void check_VLA_extent() {
  int x = 3;
  int vla1[x];
  clang_analyzer_eval(clang_analyzer_getExtent(&vla1) == x * sizeof(int));
  int vla2[x][2];
  clang_analyzer_eval(clang_analyzer_getExtent(&vla2) == x * 2 * sizeof(int));
  int vla2m[2][x];
  clang_analyzer_eval(clang_analyzer_getExtent(&vla2m) == 2 * x * sizeof(int));
  int vla3m[2][x][4];
  clang_analyzer_eval(clang_analyzer_getExtent(&vla3m) ==
                      2 * x * 4 * sizeof(int));
}


x86 assembly (clang, -O0):
<check_VLA_extent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x3,-0x4(%rbp)
mov    -0x4(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x10(%rbp)
lea    0xf(,%rax,4),%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x18(%rbp)
xor    %eax,%eax
mov    %al,-0x31(%rbp)
call   1030 <clang_analyzer_getExtent@plt>
mov    %eax,%ecx
mov    -0x31(%rbp),%al
movslq %ecx,%rcx
movslq -0x4(%rbp),%rdx
shl    $0x2,%rdx
sub    %rdx,%rcx
sete   %cl
movzbl %cl,%edi
call   1040 <clang_analyzer_eval@plt>
mov    -0x31(%rbp),%al
mov    -0x4(%rbp),%ecx
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,%rsp
mov    %rcx,-0x20(%rbp)
call   1030 <clang_analyzer_getExtent@plt>
mov    %eax,%ecx
mov    -0x31(%rbp),%al
movslq %ecx,%rcx
mov    -0x4(%rbp),%edx
add    %edx,%edx
movslq %edx,%rdx
shl    $0x2,%rdx
sub    %rdx,%rcx
sete   %cl
movzbl %cl,%edi
call   1040 <clang_analyzer_eval@plt>
mov    -0x31(%rbp),%al
mov    -0x4(%rbp),%ecx
lea    0xf(,%rcx,8),%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rdi
sub    %rdx,%rdi
mov    %rdi,%rsp
mov    %rcx,-0x28(%rbp)
call   1030 <clang_analyzer_getExtent@plt>
mov    %eax,%ecx
mov    -0x31(%rbp),%al
movslq %ecx,%rcx
mov    -0x4(%rbp),%edx
add    %edx,%edx
movslq %edx,%rdx
shl    $0x2,%rdx
sub    %rdx,%rcx
sete   %cl
movzbl %cl,%edi
call   1040 <clang_analyzer_eval@plt>
mov    -0x4(%rbp),%eax
mov    %rax,%rcx
shl    $0x5,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,%rsp
mov    %rax,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clang_analyzer_getExtent@plt>
cltq
mov    -0x4(%rbp),%ecx
shl    $0x1,%ecx
shl    $0x2,%ecx
movslq %ecx,%rcx
shl    $0x2,%rcx
cmp    %rcx,%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
mov    $0x0,%al
call   1040 <clang_analyzer_eval@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_VLA_extent>:
sub    $0xb8,%rsp
mov    %rsp,%rdi
xor    %eax,%eax
call   1030 <clang_analyzer_getExtent@plt>
xor    %edi,%edi
cmp    $0xc,%eax
sete   %dil
xor    %eax,%eax
call   1040 <clang_analyzer_eval@plt>
lea    0x30(%rsp),%rdi
xor    %eax,%eax
call   1030 <clang_analyzer_getExtent@plt>
xor    %edi,%edi
cmp    $0x18,%eax
sete   %dil
xor    %eax,%eax
call   1040 <clang_analyzer_eval@plt>
lea    0x10(%rsp),%rdi
xor    %eax,%eax
call   1030 <clang_analyzer_getExtent@plt>
xor    %edi,%edi
cmp    $0x18,%eax
sete   %dil
xor    %eax,%eax
call   1040 <clang_analyzer_eval@plt>
lea    0x50(%rsp),%rdi
xor    %eax,%eax
call   1030 <clang_analyzer_getExtent@plt>
xor    %edi,%edi
cmp    $0x60,%eax
sete   %dil
xor    %eax,%eax
call   1040 <clang_analyzer_eval@plt>
add    $0xb8,%rsp
ret

LLVM IR (-O0):
define void @check_VLA_extent() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i64
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store i32 3, i32* %1
%7 = load i32, i32* %1
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %2
%10 = alloca i32, i64 %8
store i64 %8, i64* %3
%11 = call i32 (i32*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 (i32*, ...)*)(i32* %10)
%12 = sext i32 %11 to i64
%13 = load i32, i32* %1
%14 = sext i32 %13 to i64
%15 = mul i64 %14, 4
%16 = icmp eq i64 %12, %15
%17 = zext i1 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %17)
%19 = load i32, i32* %1
%20 = zext i32 %19 to i64
%21 = alloca [2 x i32], i64 %20
store i64 %20, i64* %4
%22 = call i32 ([2 x i32]*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 ([2 x i32]*, ...)*)([2 x i32]* %21)
%23 = sext i32 %22 to i64
%24 = load i32, i32* %1
%25 = mul nsw i32 %24, 2
%26 = sext i32 %25 to i64
%27 = mul i64 %26, 4
%28 = icmp eq i64 %23, %27
%29 = zext i1 %28 to i32
%30 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %29)
%31 = load i32, i32* %1
%32 = zext i32 %31 to i64
%33 = mul nuw i64 2, %32
%34 = alloca i32, i64 %33
store i64 %32, i64* %5
%35 = call i32 (i32*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 (i32*, ...)*)(i32* %34)
%36 = sext i32 %35 to i64
%37 = load i32, i32* %1
%38 = mul nsw i32 2, %37
%39 = sext i32 %38 to i64
%40 = mul i64 %39, 4
%41 = icmp eq i64 %36, %40
%42 = zext i1 %41 to i32
%43 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %42)
%44 = load i32, i32* %1
%45 = zext i32 %44 to i64
%46 = mul nuw i64 2, %45
%47 = alloca [4 x i32], i64 %46
store i64 %45, i64* %6
%48 = call i32 ([4 x i32]*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 ([4 x i32]*, ...)*)([4 x i32]* %47)
%49 = sext i32 %48 to i64
%50 = load i32, i32* %1
%51 = mul nsw i32 2, %50
%52 = mul nsw i32 %51, 4
%53 = sext i32 %52 to i64
%54 = mul i64 %53, 4
%55 = icmp eq i64 %49, %54
%56 = zext i1 %55 to i32
%57 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %56)
%58 = load i8*, i8** %2
ret void
}

LLVM IR (-O2):
define void @check_VLA_extent() {
%1 = alloca [3 x i32]
%2 = getelementptr inbounds [3 x i32], [3 x i32]* %1, i64 0, i64 0
%3 = call i32 (i32*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 (i32*, ...)*)(i32* %2)
%4 = icmp eq i32 %3, 12
%5 = zext i1 %4 to i32
%6 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %5)
%7 = alloca [3 x [2 x i32]]
%8 = getelementptr inbounds [3 x [2 x i32]], [3 x [2 x i32]]* %7, i64 0, i64 0
%9 = call i32 ([2 x i32]*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 ([2 x i32]*, ...)*)([2 x i32]* %8)
%10 = icmp eq i32 %9, 24
%11 = zext i1 %10 to i32
%12 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %11)
%13 = alloca [6 x i32]
%14 = getelementptr inbounds [6 x i32], [6 x i32]* %13, i64 0, i64 0
%15 = call i32 (i32*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 (i32*, ...)*)(i32* %14)
%16 = icmp eq i32 %15, 24
%17 = zext i1 %16 to i32
%18 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %17)
%19 = alloca [6 x [4 x i32]]
%20 = getelementptr inbounds [6 x [4 x i32]], [6 x [4 x i32]]* %19, i64 0, i64 0
%21 = call i32 ([4 x i32]*, ...) bitcast (i32 (...)* @clang_analyzer_getExtent to i32 ([4 x i32]*, ...)*)([4 x i32]* %20)
%22 = icmp eq i32 %21, 96
%23 = zext i1 %22 to i32
%24 = call i32 (i32, ...) bitcast (i32 (...)* @clang_analyzer_eval to i32 (i32, ...)*)(i32 %23)
ret void
}