[clang][modules] Don't prevent translation of FW_Private includes when explicitly...
[llvm-project.git] / clang / test / CodeGen / compound-literal.c
blobecc2c73edfb1e6e22cfb29ed72fb8281a760e566
1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
3 // Capture the type and name so matching later is cleaner.
4 struct CompoundTy { int a; };
5 // CHECK: @MyCLH ={{.*}} constant [[MY_CLH:[^,]+]]
6 const struct CompoundTy *const MyCLH = &(struct CompoundTy){3};
8 int* a = &(int){1};
9 struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
10 _Complex double * x = &(_Complex double){1.0f};
11 typedef int v4i32 __attribute((vector_size(16)));
12 v4i32 *y = &(v4i32){1,2,3,4};
14 // Check generated code for GNU constant array init from compound literal,
15 // for a global variable.
16 // CHECK: @compound_array ={{.*}} global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]
17 int compound_array[] = __extension__(__builtin_choose_expr(0, 0, _Generic(1, int: (int[]){1, 2, 3, 4, 5, 6, 7, 8})));
19 void xxx(void) {
20 int* a = &(int){1};
21 struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
22 _Complex double * x = &(_Complex double){1.0f};
25 // CHECK-LABEL: define{{.*}} void @f()
26 void f(void) {
27 typedef struct S { int x,y; } S;
28 // CHECK: [[S:%[a-zA-Z0-9.]+]] = alloca [[STRUCT:%[a-zA-Z0-9.]+]],
29 struct S s;
30 // CHECK-NEXT: [[COMPOUNDLIT:%[a-zA-Z0-9.]+]] = alloca [[STRUCT]]
31 // CHECK-NEXT: [[CX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], ptr [[COMPOUNDLIT]], i32 0, i32 0
32 // CHECK-NEXT: [[SY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], ptr [[S]], i32 0, i32 1
33 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, ptr [[SY]]
34 // CHECK-NEXT: store i32 [[TMP]], ptr [[CX]]
35 // CHECK-NEXT: [[CY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], ptr [[COMPOUNDLIT]], i32 0, i32 1
36 // CHECK-NEXT: [[SX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], ptr [[S]], i32 0, i32 0
37 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, ptr [[SX]]
38 // CHECK-NEXT: store i32 [[TMP]], ptr [[CY]]
39 // CHECK-NEXT: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} [[S]], ptr align {{[0-9]+}} [[COMPOUNDLIT]]
40 s = (S){s.y,s.x};
41 // CHECK-NEXT: ret void
44 // CHECK-LABEL: define{{.*}} i48 @g(
45 struct G { short x, y, z; };
46 struct G g(int x, int y, int z) {
47 // CHECK: [[RESULT:%.*]] = alloca [[G:%.*]], align 2
48 // CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
49 // CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
50 // CHECK-NEXT: [[Z:%.*]] = alloca i32, align 4
51 // CHECK-NEXT: [[COERCE_TEMP:%.*]] = alloca i48
52 // CHECK-NEXT: store i32
53 // CHECK-NEXT: store i32
54 // CHECK-NEXT: store i32
56 // Evaluate the compound literal directly in the result value slot.
57 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], ptr [[RESULT]], i32 0, i32 0
58 // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[X]], align 4
59 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
60 // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 2
61 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], ptr [[RESULT]], i32 0, i32 1
62 // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[Y]], align 4
63 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
64 // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 2
65 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], ptr [[RESULT]], i32 0, i32 2
66 // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[Z]], align 4
67 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
68 // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 2
69 return (struct G) { x, y, z };
71 // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} [[COERCE_TEMP]], ptr align {{[0-9]+}} [[RESULT]], i64 6
72 // CHECK-NEXT: [[T0:%.*]] = load i48, ptr [[COERCE_TEMP]]
73 // CHECK-NEXT: ret i48 [[T0]]
76 // We had a bug where we'd emit a new GlobalVariable for each time we used a
77 // const pointer to a variable initialized by a compound literal.
78 // CHECK-LABEL: define{{.*}} i32 @compareMyCLH() #0
79 int compareMyCLH(void) {
80 // CHECK: store [[MY_CLH]]
81 const void *a = MyCLH;
82 // CHECK: store [[MY_CLH]]
83 const void *b = MyCLH;
84 return a == b;
87 // Check generated code for GNU constant array init from compound literal,
88 // for a local variable.
89 // CHECK-LABEL: define{{.*}} i32 @compound_array_fn()
90 // CHECK: [[COMPOUND_ARRAY:%.*]] = alloca [8 x i32]
91 // CHECK: call void @llvm.memcpy.p0.p0.i64({{.*}}, i64 32, i1 false)
92 int compound_array_fn(void) {
93 int compound_array[] = (int[]){1,2,3,4,5,6,7,8};
94 return compound_array[0];