1 // RUN: %clang_cc1 -triple x86_64-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK64
2 // RUN: %clang_cc1 -triple x86_64-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK64
3 // RUN: %clang_cc1 -triple i386-gnu-linux -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,LIN32
4 // RUN: %clang_cc1 -triple i386-windows-pc -O3 -disable-llvm-passes -emit-llvm -o - %s | FileCheck %s --check-prefixes=CHECK,WIN32
5 
6 void GenericTest(_ExtInt(3) a, unsigned _ExtInt(3) b, _ExtInt(4) c) {
7   // CHECK: define {{.*}}void @GenericTest
8   int which = _Generic(a, _ExtInt(3): 1, unsigned _ExtInt(3) : 2, _ExtInt(4) : 3);
9   // CHECK: store i32 1
10   int which2 = _Generic(b, _ExtInt(3): 1, unsigned _ExtInt(3) : 2, _ExtInt(4) : 3);
11   // CHECK: store i32 2
12   int which3 = _Generic(c, _ExtInt(3): 1, unsigned _ExtInt(3) : 2, _ExtInt(4) : 3);
13   // CHECK: store i32 3
14 }
15 
16 void VLATest(_ExtInt(3) A, _ExtInt(99) B, _ExtInt(123456) C) {
17   // CHECK: define {{.*}}void @VLATest
18   int AR1[A];
19   // CHECK: %[[A:.+]] = zext i3 %{{.+}} to i[[INDXSIZE:[0-9]+]]
20   // CHECK: %[[VLA1:.+]] = alloca i32, i[[INDXSIZE]] %[[A]]
21   int AR2[B];
22   // CHECK: %[[B:.+]] = trunc i99 %{{.+}} to i[[INDXSIZE]]
23   // CHECK: %[[VLA2:.+]] = alloca i32, i[[INDXSIZE]] %[[B]]
24   int AR3[C];
25   // CHECK: %[[C:.+]] = trunc i123456 %{{.+}} to i[[INDXSIZE]]
26   // CHECK: %[[VLA3:.+]] = alloca i32, i[[INDXSIZE]] %[[C]]
27 }
28 
29 struct S {
30   _ExtInt(17) A;
31   _ExtInt(16777200) B;
32   _ExtInt(17) C;
33 };
34 
OffsetOfTest()35 void OffsetOfTest() {
36   // CHECK: define {{.*}}void @OffsetOfTest
37   int A = __builtin_offsetof(struct S,A);
38   // CHECK: store i32 0, i32* %{{.+}}
39   int B = __builtin_offsetof(struct S,B);
40   // CHECK64: store i32 8, i32* %{{.+}}
41   // LIN32: store i32 4, i32* %{{.+}}
42   // WINCHECK32: store i32 8, i32* %{{.+}}
43   int C = __builtin_offsetof(struct S,C);
44   // CHECK64: store i32 2097160, i32* %{{.+}}
45   // LIN32: store i32 2097156, i32* %{{.+}}
46   // WIN32: store i32 2097160, i32* %{{.+}}
47 }
48