Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s
      2 
      3 int* a = &(int){1};
      4 struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};
      5 _Complex double * x = &(_Complex double){1.0f};
      6 typedef int v4i32 __attribute((vector_size(16)));
      7 v4i32 *y = &(v4i32){1,2,3,4};
      8 
      9 void xxx() {
     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};
     13 }
     14 
     15 // CHECK: define void @f()
     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]]
     21   // CHECK-NEXT: [[CX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 0
     22   // CHECK-NEXT: [[SY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[S]], i32 0, i32 1
     23   // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32* [[SY]]
     24   // CHECK-NEXT: store i32 [[TMP]], i32* [[CX]]
     25   // CHECK-NEXT: [[CY:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[COMPOUNDLIT]], i32 0, i32 1
     26   // CHECK-NEXT: [[SX:%[a-zA-Z0-9.]+]] = getelementptr inbounds [[STRUCT]]* [[S]], i32 0, i32 0
     27   // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32* [[SX]]
     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*
     31   // CHECK-NEXT: call void @llvm.memcpy{{.*}}(i8* [[SI8]], i8* [[COMPOUNDLITI8]]
     32   s = (S){s.y,s.x};
     33   // CHECK-NEXT: ret void
     34 }
     35 
     36 // CHECK: define i48 @g(
     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.
     49   // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]]* [[RESULT]], i32 0, i32 0
     50   // CHECK-NEXT: [[T1:%.*]] = load i32* [[X]], align 4
     51   // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
     52   // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2
     53   // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]]* [[RESULT]], i32 0, i32 1
     54   // CHECK-NEXT: [[T1:%.*]] = load i32* [[Y]], align 4
     55   // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i16
     56   // CHECK-NEXT: store i16 [[T2]], i16* [[T0]], align 2
     57   // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[G]]* [[RESULT]], i32 0, i32 2
     58   // CHECK-NEXT: [[T1:%.*]] = load i32* [[Z]], align 4
     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
     66   // CHECK-NEXT: [[T0:%.*]] = load i48* [[COERCE_TEMP]]
     67   // CHECK-NEXT: ret i48 [[T0]]
     68 }
     69