Nuno Lopes | 060ddb0 | 2012-05-09 21:21:49 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 2 | |
| 3 | int* a = &(int){1}; |
| 4 | struct s {int a, b, c;} * b = &(struct s) {1, 2, 3}; |
Eli Friedman | 58c65fc | 2011-12-22 00:04:00 +0000 | [diff] [blame] | 5 | _Complex double * x = &(_Complex double){1.0f}; |
| 6 | typedef int v4i32 __attribute((vector_size(16))); |
Eli Friedman | dedb362 | 2011-12-22 00:06:39 +0000 | [diff] [blame] | 7 | v4i32 *y = &(v4i32){1,2,3,4}; |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 8 | |
Douglas Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 9 | void xxx() { |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 10 | int* a = &(int){1}; |
| 11 | struct s {int a, b, c;} * b = &(struct s) {1, 2, 3}; |
| 12 | _Complex double * x = &(_Complex double){1.0f}; |
Eli Friedman | 06e863f | 2008-05-13 23:18:27 +0000 | [diff] [blame] | 13 | } |
Douglas Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 14 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 15 | // CHECK-LABEL: define void @f() |
Douglas Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 16 | void 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 Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 21 | // 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 Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 24 | // CHECK-NEXT: store i32 [[TMP]], i32* [[CX]] |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 25 | // 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 Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 28 | // 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 Gregor | ebfbf9f | 2011-06-17 17:23:28 +0000 | [diff] [blame] | 31 | // CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* [[SI8]], i8* [[COMPOUNDLITI8]] |
Douglas Gregor | 673e98b | 2011-06-17 16:37:20 +0000 | [diff] [blame] | 32 | s = (S){s.y,s.x}; |
| 33 | // CHECK-NEXT: ret void |
| 34 | } |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 35 | |
Stephen Lin | 93ab6bf | 2013-08-15 06:47:53 +0000 | [diff] [blame] | 36 | // CHECK-LABEL: define i48 @g( |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 37 | struct G { short x, y, z; }; |
| 38 | struct 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 Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 49 | // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 0 |
| 50 | // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[X]], align 4 |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 51 | // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16 |
| 52 | // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2 |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 53 | // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 1 |
| 54 | // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[Y]], align 4 |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 55 | // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16 |
| 56 | // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2 |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 57 | // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]], [[G]]* [[RESULT]], i32 0, i32 2 |
| 58 | // CHECK-NEXT: [[T1:%.*]] = load i32, i32* [[Z]], align 4 |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 59 | // 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 Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 66 | // CHECK-NEXT: [[T0:%.*]] = load i48, i48* [[COERCE_TEMP]] |
John McCall | 1723f63 | 2013-03-07 21:36:54 +0000 | [diff] [blame] | 67 | // CHECK-NEXT: ret i48 [[T0]] |
| 68 | } |