summaryrefslogtreecommitdiff
path: root/clang/test/CodeGen/ms-anonymous-struct.c
blob: b41caab0309ef16dc49b40519600b6652734197b (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// RUN: %clang_cc1 -fms-extensions -emit-llvm -o - %s | FileCheck %s

// CHECK: %struct.test = type { i32, %struct.nested2, i32 }
// CHECK: %struct.nested2 = type { i32, %struct.nested1, i32 }
// CHECK: %struct.nested1 = type { i32, i32 }
typedef struct nested1 {
    int a1;
    int b1;
} NESTED1;

struct nested2 {
    int a;
    NESTED1; 
    int b;
};

struct test {
    int    x;
    struct nested2; 
    int    y;
};


void foo()
{
  // CHECK: %var = alloca %struct.test, align 4
  struct test var;

  // CHECK: getelementptr inbounds %struct.test* %var, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.a;

  // CHECK-NEXT: getelementptr inbounds %struct.test* %var, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 2
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.b;

  // CHECK-NEXT: getelementptr inbounds %struct.test* %var, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested1* %{{.*}}, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.a1;

  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}var, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested1* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.b1;

  // CHECK-NEXT: getelementptr inbounds %struct.test* %var, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.x;

  // CHECK-NEXT: getelementptr inbounds %struct.test* %var, i32 0, i32 2
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var.y;
}

void foo2(struct test* var)
{
  // CHECK: alloca %struct.test*, align
  // CHECK-NEXT: store %struct.test* %var, %struct.test** %{{.*}}, align
  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->a;

  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 2
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->b;

  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested1* %{{.*}}, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->a1;

  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested2* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: getelementptr inbounds %struct.nested1* %{{.*}}, i32 0, i32 1
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->b1;

  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 0
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->x;

  // CHECK-NEXT: load %struct.test** %{{.*}}, align
  // CHECK-NEXT: getelementptr inbounds %struct.test* %{{.*}}, i32 0, i32 2
  // CHECK-NEXT: load i32* %{{.*}}, align 4
  var->y;
}