blob: 85138bfaf5e04884ff332e2d65b14dfd7e0f3354 [file] [log] [blame]
Nuno Lopes060ddb02012-05-09 21:21:49 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
Eli Friedman06e863f2008-05-13 23:18:27 +00002
3int* a = &(int){1};
4struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
Eli Friedman58c65fc2011-12-22 00:04:00 +00005_Complex double * x = &(_Complex double){1.0f};
6typedef int v4i32 __attribute((vector_size(16)));
Eli Friedmandedb3622011-12-22 00:06:39 +00007v4i32 *y = &(v4i32){1,2,3,4};
Eli Friedman06e863f2008-05-13 23:18:27 +00008
Douglas Gregor673e98b2011-06-17 16:37:20 +00009void xxx() {
Eli Friedman06e863f2008-05-13 23:18:27 +000010int* a = &(int){1};
11struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
12_Complex double * x = &(_Complex double){1.0f};
Eli Friedman06e863f2008-05-13 23:18:27 +000013}
Douglas Gregor673e98b2011-06-17 16:37:20 +000014
Stephen Lin93ab6bf2013-08-15 06:47:53 +000015// CHECK-LABEL: define void @f()
Douglas Gregor673e98b2011-06-17 16:37:20 +000016void f() {
17 typedef struct S { int x,y; } S;
18 // CHECK: [[S:%[a-zA-Z0-9.]+]] = alloca [[STRUCT:%[a-zA-Z0-9.]+]],
19 struct S s;
20 // CHECK-NEXT: [[COMPOUNDLIT:%[a-zA-Z0-9.]+]] = alloca [[STRUCT]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070021 // CHECK-NEXT: [[CX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 0
22 // CHECK-NEXT: [[SY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], [[STRUCT]]* [[S]], i32 0, i32 1
23 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, i32* [[SY]]
Douglas Gregor673e98b2011-06-17 16:37:20 +000024 // CHECK-NEXT: store i32 [[TMP]], i32* [[CX]]
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070025 // CHECK-NEXT: [[CY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 1
26 // CHECK-NEXT: [[SX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]], [[STRUCT]]* [[S]], i32 0, i32 0
27 // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, i32* [[SX]]
Douglas Gregor673e98b2011-06-17 16:37:20 +000028 // CHECK-NEXT: store i32 [[TMP]], i32* [[CY]]
29 // CHECK-NEXT: [[SI8:%[a-zA-Z0-9.]+]] = bitcast [[STRUCT]]* [[S]] to i8*
30 // CHECK-NEXT: [[COMPOUNDLITI8:%[a-zA-Z0-9.]+]] = bitcast [[STRUCT]]* [[COMPOUNDLIT]] to i8*
Douglas Gregorebfbf9f2011-06-17 17:23:28 +000031 // CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* [[SI8]], i8* [[COMPOUNDLITI8]]
Douglas Gregor673e98b2011-06-17 16:37:20 +000032 s = (S){s.y,s.x};
33 // CHECK-NEXT: ret void
34}
John McCall1723f632013-03-07 21:36:54 +000035
Stephen Lin93ab6bf2013-08-15 06:47:53 +000036// CHECK-LABEL: define i48 @g(
John McCall1723f632013-03-07 21:36:54 +000037struct G { short x, y, z; };
38struct G g(int x, int y, int z) {
39 // CHECK: [[RESULT:%.*]] = alloca [[G:%.*]], align 2
40 // CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
41 // CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
42 // CHECK-NEXT: [[Z:%.*]] = alloca i32, align 4
43 // CHECK-NEXT: [[COERCE_TEMP:%.*]] = alloca i48
44 // CHECK-NEXT: store i32
45 // CHECK-NEXT: store i32
46 // CHECK-NEXT: store i32
47
48 // Evaluate the compound literal directly in the result value slot.
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070049 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 0
50 // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[X]], align 4
John McCall1723f632013-03-07 21:36:54 +000051 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
52 // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070053 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 1
54 // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[Y]], align 4
John McCall1723f632013-03-07 21:36:54 +000055 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
56 // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070057 // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 2
58 // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[Z]], align 4
John McCall1723f632013-03-07 21:36:54 +000059 // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
60 // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2
61 return (struct G) { x, y, z };
62
63 // CHECK-NEXT: [[T0:%.*]] = bitcast i48* [[COERCE_TEMP]] to i8*
64 // CHECK-NEXT: [[T1:%.*]] = bitcast [[G]]* [[RESULT]] to i8*
65 // CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* [[T0]], i8* [[T1]], i64 6
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070066 // CHECK-NEXT: [[T0:%.*]] = load i48, i48* [[COERCE_TEMP]]
John McCall1723f632013-03-07 21:36:54 +000067 // CHECK-NEXT: ret i48 [[T0]]
68}