@@ -6,20 +6,72 @@ typedef union { yolo y; struct { int lifecnt; }; } yolm;
6
6
typedef union { yolo y; struct { int *lifecnt; int genpad; }; } yolm2;
7
7
typedef union { yolo y; struct { bool life; int genpad; }; } yolm3;
8
8
9
+ // CHECK-DAG: !ty_22U23A3ADummy22 = !cir.struct<struct "U2::Dummy" {!s16i, f32} #cir.recdecl.ast>
10
+ // CHECK-DAG: !ty_22anon221 = !cir.struct<struct "anon" {!cir.bool, !s32i} #cir.recdecl.ast>
11
+ // CHECK-DAG: !ty_22yolo22 = !cir.struct<struct "yolo" {!s32i} #cir.recdecl.ast>
12
+ // CHECK-DAG: !ty_22anon222 = !cir.struct<struct "anon" {!cir.ptr<!s32i>, !s32i} #cir.recdecl.ast>
13
+
14
+ // CHECK-DAG: !ty_22yolm22 = !cir.struct<union "yolm" {!ty_22yolo22, !ty_22anon22}>
15
+ // CHECK-DAG: !ty_22yolm322 = !cir.struct<union "yolm3" {!ty_22yolo22, !ty_22anon221}>
16
+ // CHECK-DAG: !ty_22yolm222 = !cir.struct<union "yolm2" {!ty_22yolo22, !ty_22anon222}>
17
+
18
+ // Should generate a union type with all members preserved.
19
+ union U {
20
+ bool b;
21
+ short s;
22
+ int i;
23
+ float f;
24
+ double d;
25
+ };
26
+ // CHECK-DAG: !ty_22U22 = !cir.struct<union "U" {!cir.bool, !s16i, !s32i, f32, f64}>
27
+
28
+ // Should generate unions with complex members.
29
+ union U2 {
30
+ bool b;
31
+ struct Dummy {
32
+ short s;
33
+ float f;
34
+ } s;
35
+ } u2;
36
+ // CHECK-DAG: !cir.struct<union "U2" {!cir.bool, !ty_22U23A3ADummy22} #cir.recdecl.ast>
37
+
38
+ // Should genereate unions without padding.
39
+ union U3 {
40
+ short b;
41
+ U u;
42
+ } u3;
43
+ // CHECK-DAG: !ty_22U322 = !cir.struct<union "U3" {!s16i, !ty_22U22} #cir.recdecl.ast>
44
+
9
45
void m () {
10
46
yolm q;
11
47
yolm2 q2;
12
48
yolm3 q3;
13
49
}
14
50
15
- // CHECK: !ty_22anon22 = !cir.struct<struct "anon" {!cir.bool, !s32i} #cir.recdecl.ast>
16
- // CHECK: !ty_22yolo22 = !cir.struct<struct "yolo" {!s32i} #cir.recdecl.ast>
17
- // CHECK: !ty_22anon221 = !cir.struct<struct "anon" {!cir.ptr<!s32i>, !s32i} #cir.recdecl.ast>
18
-
19
- // CHECK: !ty_22yolm22 = !cir.struct<union "yolm" {!ty_22yolo22}>
20
- // CHECK: !ty_22yolm222 = !cir.struct<union "yolm2" {!ty_22anon221}>
21
-
22
51
// CHECK: cir.func @_Z1mv()
23
52
// CHECK: cir.alloca !ty_22yolm22, cir.ptr <!ty_22yolm22>, ["q"] {alignment = 4 : i64}
24
53
// CHECK: cir.alloca !ty_22yolm222, cir.ptr <!ty_22yolm222>, ["q2"] {alignment = 8 : i64}
25
54
// CHECK: cir.alloca !ty_22yolm322, cir.ptr <!ty_22yolm322>, ["q3"] {alignment = 4 : i64}
55
+
56
+ void shouldGenerateUnionAccess (union U u) {
57
+ u.b = true ;
58
+ // CHECK: %[[#BASE:]] = cir.get_member %0[0] {name = "b"} : !cir.ptr<!ty_22U22> -> !cir.ptr<!cir.bool>
59
+ // CHECK: cir.store %{{.+}}, %[[#BASE]] : !cir.bool, cir.ptr <!cir.bool>
60
+ u.b ;
61
+ // CHECK: cir.get_member %0[0] {name = "b"} : !cir.ptr<!ty_22U22> -> !cir.ptr<!cir.bool>
62
+ u.i = 1 ;
63
+ // CHECK: %[[#BASE:]] = cir.get_member %0[2] {name = "i"} : !cir.ptr<!ty_22U22> -> !cir.ptr<!s32i>
64
+ // CHECK: cir.store %{{.+}}, %[[#BASE]] : !s32i, cir.ptr <!s32i>
65
+ u.i ;
66
+ // CHECK: %[[#BASE:]] = cir.get_member %0[2] {name = "i"} : !cir.ptr<!ty_22U22> -> !cir.ptr<!s32i>
67
+ u.f = 0 .1F ;
68
+ // CHECK: %[[#BASE:]] = cir.get_member %0[3] {name = "f"} : !cir.ptr<!ty_22U22> -> !cir.ptr<f32>
69
+ // CHECK: cir.store %{{.+}}, %[[#BASE]] : f32, cir.ptr <f32>
70
+ u.f ;
71
+ // CHECK: %[[#BASE:]] = cir.get_member %0[3] {name = "f"} : !cir.ptr<!ty_22U22> -> !cir.ptr<f32>
72
+ u.d = 0.1 ;
73
+ // CHECK: %[[#BASE:]] = cir.get_member %0[4] {name = "d"} : !cir.ptr<!ty_22U22> -> !cir.ptr<f64>
74
+ // CHECK: cir.store %{{.+}}, %[[#BASE]] : f64, cir.ptr <f64>
75
+ u.d ;
76
+ // CHECK: %[[#BASE:]] = cir.get_member %0[4] {name = "d"} : !cir.ptr<!ty_22U22> -> !cir.ptr<f64>
77
+ }
0 commit comments