brintos

brintos / llvm-project-archived public Read only

0
0
Text · 4.3 KiB · 5fe9594 Raw
97 lines · c
1// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm %s -o - | FileCheck %s2// RUN: %clang_cc1 -triple x86_64-apple-darwin -fexperimental-new-constant-interpreter -emit-llvm %s -o - | FileCheck %s3 4// Capture the type and name so matching later is cleaner.5struct CompoundTy { int a; };6// CHECK: @MyCLH ={{.*}} constant [[MY_CLH:[^,]+]]7const struct CompoundTy *const MyCLH = &(struct CompoundTy){3};8 9int* a = &(int){1};10struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};11_Complex double * x = &(_Complex double){1.0f};12typedef int v4i32 __attribute((vector_size(16)));13v4i32 *y = &(v4i32){1,2,3,4};14 15// Check generated code for GNU constant array init from compound literal,16// for a global variable.17// CHECK: @compound_array ={{.*}} global [8 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5, i32 6, i32 7, i32 8]18int compound_array[] = __extension__(__builtin_choose_expr(0, 0, _Generic(1, int: (int[]){1, 2, 3, 4, 5, 6, 7, 8})));19 20void xxx(void) {21int* a = &(int){1};22struct s {int a, b, c;} * b = &(struct s) {1, 2, 3};23_Complex double * x = &(_Complex double){1.0f};24}25 26// CHECK-LABEL: define{{.*}} void @f()27void f(void) {28  typedef struct S { int x,y; } S;29  // CHECK: [[S:%[a-zA-Z0-9.]+]] = alloca [[STRUCT:%[a-zA-Z0-9.]+]],30  struct S s;31  // CHECK-NEXT: [[COMPOUNDLIT:%[a-zA-Z0-9.]+]] = alloca [[STRUCT]]32  // CHECK-NEXT: [[CX:%[a-zA-Z0-9.]+]] = getelementptr inbounds nuw [[STRUCT]], ptr [[COMPOUNDLIT]], i32 0, i32 033  // CHECK-NEXT: [[SY:%[a-zA-Z0-9.]+]] = getelementptr inbounds nuw [[STRUCT]], ptr [[S]], i32 0, i32 134  // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, ptr [[SY]]35  // CHECK-NEXT: store i32 [[TMP]], ptr [[CX]]36  // CHECK-NEXT: [[CY:%[a-zA-Z0-9.]+]] = getelementptr inbounds nuw [[STRUCT]], ptr [[COMPOUNDLIT]], i32 0, i32 137  // CHECK-NEXT: [[SX:%[a-zA-Z0-9.]+]] = getelementptr inbounds nuw [[STRUCT]], ptr [[S]], i32 0, i32 038  // CHECK-NEXT: [[TMP:%[a-zA-Z0-9.]+]] = load i32, ptr [[SX]]39  // CHECK-NEXT: store i32 [[TMP]], ptr [[CY]]40  // CHECK-NEXT: call void @llvm.memcpy{{.*}}(ptr align {{[0-9]+}} [[S]], ptr align {{[0-9]+}} [[COMPOUNDLIT]]41  s = (S){s.y,s.x};42  // CHECK-NEXT: ret void43}44 45// CHECK-LABEL: define{{.*}} i48 @g(46struct G { short x, y, z; };47struct G g(int x, int y, int z) {48  // CHECK:      [[RESULT:%.*]] = alloca [[G:%.*]], align 249  // CHECK-NEXT: [[X:%.*]] = alloca i32, align 450  // CHECK-NEXT: [[Y:%.*]] = alloca i32, align 451  // CHECK-NEXT: [[Z:%.*]] = alloca i32, align 452  // CHECK-NEXT: [[COERCE_TEMP:%.*]] = alloca i4853  // CHECK-NEXT: store i3254  // CHECK-NEXT: store i3255  // CHECK-NEXT: store i3256 57  // Evaluate the compound literal directly in the result value slot.58  // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw [[G]], ptr [[RESULT]], i32 0, i32 059  // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[X]], align 460  // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i1661  // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 262  // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw [[G]], ptr [[RESULT]], i32 0, i32 163  // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[Y]], align 464  // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i1665  // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 266  // CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds nuw [[G]], ptr [[RESULT]], i32 0, i32 267  // CHECK-NEXT: [[T1:%.*]] = load i32, ptr [[Z]], align 468  // CHECK-NEXT: [[T2:%.*]] = trunc i32 [[T1]] to i1669  // CHECK-NEXT: store i16 [[T2]], ptr [[T0]], align 270  return (struct G) { x, y, z };71 72  // CHECK-NEXT: call void @llvm.memcpy.p0.p0.i64(ptr align {{[0-9]+}} [[COERCE_TEMP]], ptr align {{[0-9]+}} [[RESULT]], i64 673  // CHECK-NEXT: [[T0:%.*]] = load i48, ptr [[COERCE_TEMP]]74  // CHECK-NEXT: ret i48 [[T0]]75}76 77// We had a bug where we'd emit a new GlobalVariable for each time we used a78// const pointer to a variable initialized by a compound literal.79// CHECK-LABEL: define{{.*}} i32 @compareMyCLH() #080int compareMyCLH(void) {81  // CHECK: store [[MY_CLH]]82  const void *a = MyCLH;83  // CHECK: store [[MY_CLH]]84  const void *b = MyCLH;85  return a == b;86}87 88// Check generated code for GNU constant array init from compound literal,89// for a local variable.90// CHECK-LABEL: define{{.*}} i32 @compound_array_fn()91// CHECK: [[COMPOUND_ARRAY:%.*]] = alloca [8 x i32]92// CHECK: call void @llvm.memcpy.p0.p0.i64({{.*}}, i64 32, i1 false)93int compound_array_fn(void) {94  int compound_array[] = (int[]){1,2,3,4,5,6,7,8};95  return compound_array[0];96}97