Home | History | Annotate | Download | only in CodeGen
      1 // RUN: %clang_cc1 -triple i386-unknown-unknown -emit-llvm %s -o - | FileCheck %s
      2 
      3 struct I { int k[3]; };
      4 struct M { struct I o[2]; };
      5 struct M v1[1] = { [0].o[0 ... 1].k[0 ... 1] = 4, 5 };
      6 unsigned v2[2][3] = {[0 ... 1][0 ... 1] = 2222, 3333};
      7 
      8 // CHECK-DAG: %struct.M = type { [2 x %struct.I] }
      9 // CHECK-DAG: %struct.I = type { [3 x i32] }
     10 
     11 // CHECK: [1 x %struct.M] [%struct.M { [2 x %struct.I] [%struct.I { [3 x i32] [i32 4, i32 4, i32 0] }, %struct.I { [3 x i32] [i32 4, i32 4, i32 5] }] }],
     12 // CHECK: [2 x [3 x i32]] {{[[][[]}}3 x i32] [i32 2222, i32 2222, i32 0], [3 x i32] [i32 2222, i32 2222, i32 3333]],
     13 
     14 void f1() {
     15   // Scalars in braces.
     16   int a = { 1 };
     17 }
     18 
     19 void f2() {
     20   int a[2][2] = { { 1, 2 }, { 3, 4 } };
     21   int b[3][3] = { { 1, 2 }, { 3, 4 } };
     22   int *c[2] = { &a[1][1], &b[2][2] };
     23   int *d[2][2] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
     24   int *e[3][3] = { {&a[1][1], &b[2][2]}, {&a[0][0], &b[1][1]} };
     25   char ext[3][3] = {".Y",".U",".V"};
     26 }
     27 
     28 typedef void (* F)(void);
     29 extern void foo(void);
     30 struct S { F f; };
     31 void f3() {
     32   struct S a[1] = { { foo } };
     33 }
     34 
     35 // Constants
     36 // CHECK: @g3 = constant i32 10
     37 // CHECK: @f4.g4 = internal constant i32 12
     38 const int g3 = 10;
     39 int f4() {
     40   static const int g4 = 12;
     41   return g4;
     42 }
     43 
     44 // PR6537
     45 typedef union vec3 {
     46   struct { double x, y, z; };
     47   double component[3];
     48 } vec3;
     49 vec3 f5(vec3 value) {
     50   return (vec3) {{
     51     .x = value.x
     52   }};
     53 }
     54 
     55 // rdar://problem/8154689
     56 void f6() {
     57   int x;
     58   long ids[] = { (long) &x };
     59 }
     60 
     61 
     62 
     63 
     64 // CHECK: @test7 = global{{.*}}{ i32 0, [4 x i8] c"bar\00" }
     65 // PR8217
     66 struct a7 {
     67   int  b;
     68   char v[];
     69 };
     70 
     71 struct a7 test7 = { .b = 0, .v = "bar" };
     72 
     73 
     74 // PR279 comment #3
     75 char test8(int X) {
     76   char str[100000] = "abc"; // tail should be memset.
     77   return str[X];
     78 // CHECK: @test8(
     79 // CHECK: call void @llvm.memset
     80 // CHECK: store i8 97
     81 // CHECK: store i8 98
     82 // CHECK: store i8 99
     83 // CHECK-NOT: getelementptr
     84 // CHECK: load
     85 }
     86 
     87 void bar(void*);
     88 
     89 // PR279
     90 int test9(int X) {
     91   int Arr[100] = { X };     // Should use memset
     92   bar(Arr);
     93 // CHECK: @test9
     94 // CHECK: call void @llvm.memset
     95 // CHECK-NOT: store i32 0
     96 // CHECK: call void @bar
     97 }
     98 
     99 struct a {
    100   int a, b, c, d, e, f, g, h, i, j, k, *p;
    101 };
    102 
    103 struct b {
    104   struct a a,b,c,d,e,f,g;
    105 };
    106 
    107 int test10(int X) {
    108   struct b S = { .a.a = X, .d.e = X, .f.e = 0, .f.f = 0, .f.p = 0 };
    109   bar(&S);
    110 
    111   // CHECK: @test10
    112   // CHECK: call void @llvm.memset
    113   // CHECK-NOT: store i32 0
    114   // CHECK: call void @bar
    115 }
    116 
    117 
    118 // PR9257
    119 struct test11S {
    120   int A[10];
    121 };
    122 void test11(struct test11S *P) {
    123   *P = (struct test11S) { .A = { [0 ... 3] = 4 } };
    124   // CHECK: @test11
    125   // CHECK: store i32 4
    126   // CHECK: store i32 4
    127   // CHECK: store i32 4
    128   // CHECK: store i32 4
    129   // CHECK: ret void
    130 }
    131 
    132 
    133 // Verify that we can convert a recursive struct with a memory that returns
    134 // an instance of the struct we're converting.
    135 struct test12 {
    136   struct test12 (*p)(void);
    137 } test12g;
    138 
    139 
    140 void test13(int x) {
    141   struct X { int a; int b : 10; int c; };
    142   struct X y = {.c = x};
    143   // CHECK: @test13
    144   // CHECK: and i16 {{.*}}, -1024
    145 }
    146 
    147 // CHECK-LABEL: @PR20473
    148 void PR20473() {
    149   // CHECK: memcpy{{.*}}getelementptr inbounds ([2 x i8], [2 x i8]* @
    150   bar((char[2]) {""});
    151   // CHECK: memcpy{{.*}}getelementptr inbounds ([3 x i8], [3 x i8]* @
    152   bar((char[3]) {""});
    153 }
    154