xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGen/tbaa-struct.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - -O1 %s | FileCheck %s
2f4a2713aSLionel Sambuc //
3f4a2713aSLionel Sambuc // Check that we generate !tbaa.struct metadata for struct copies.
4f4a2713aSLionel Sambuc struct A {
5f4a2713aSLionel Sambuc   short s;
6f4a2713aSLionel Sambuc   int i;
7f4a2713aSLionel Sambuc   char c;
8f4a2713aSLionel Sambuc   int j;
9f4a2713aSLionel Sambuc };
10f4a2713aSLionel Sambuc 
copy(struct A * a,struct A * b)11f4a2713aSLionel Sambuc void copy(struct A *a, struct A *b) {
12f4a2713aSLionel Sambuc   *a = *b;
13f4a2713aSLionel Sambuc }
14f4a2713aSLionel Sambuc 
15*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 16, i32 4, i1 false), !tbaa.struct [[TS:!.*]]
16f4a2713aSLionel Sambuc 
17f4a2713aSLionel Sambuc struct B {
18f4a2713aSLionel Sambuc   char c1;
19f4a2713aSLionel Sambuc   struct A a;
20f4a2713aSLionel Sambuc   int ii;
21f4a2713aSLionel Sambuc };
22f4a2713aSLionel Sambuc 
copy2(struct B * a,struct B * b)23f4a2713aSLionel Sambuc void copy2(struct B *a, struct B *b) {
24f4a2713aSLionel Sambuc   *a = *b;
25f4a2713aSLionel Sambuc }
26f4a2713aSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 24, i32 4, i1 false), !tbaa.struct [[TS2:!.*]]
28f4a2713aSLionel Sambuc 
29f4a2713aSLionel Sambuc typedef _Complex int T2;
30f4a2713aSLionel Sambuc typedef _Complex char T5;
31f4a2713aSLionel Sambuc typedef _Complex int T7;
32f4a2713aSLionel Sambuc typedef struct T4 { T5 field0; T7 field1; } T4;
33f4a2713aSLionel Sambuc typedef union T1 { T2 field0; T4 field1; } T1;
34f4a2713aSLionel Sambuc 
copy3(T1 * a,T1 * b)35f4a2713aSLionel Sambuc void copy3 (T1 *a, T1 *b) {
36f4a2713aSLionel Sambuc   *a = *b;
37f4a2713aSLionel Sambuc }
38f4a2713aSLionel Sambuc 
39*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 12, i32 4, i1 false), !tbaa.struct [[TS3:!.*]]
40f4a2713aSLionel Sambuc 
41f4a2713aSLionel Sambuc // Make sure that zero-length bitfield works.
42f4a2713aSLionel Sambuc #define ATTR __attribute__ ((ms_struct))
43f4a2713aSLionel Sambuc struct five {
44f4a2713aSLionel Sambuc   char a;
45f4a2713aSLionel Sambuc   int :0;        /* ignored; prior field is not a bitfield. */
46f4a2713aSLionel Sambuc   char b;
47f4a2713aSLionel Sambuc   char c;
48f4a2713aSLionel Sambuc } ATTR;
copy4(struct five * a,struct five * b)49f4a2713aSLionel Sambuc void copy4(struct five *a, struct five *b) {
50f4a2713aSLionel Sambuc   *a = *b;
51f4a2713aSLionel Sambuc }
52*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 3, i32 1, i1 false), !tbaa.struct [[TS4:!.*]]
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc struct six {
55f4a2713aSLionel Sambuc   char a;
56f4a2713aSLionel Sambuc   int :0;
57f4a2713aSLionel Sambuc   char b;
58f4a2713aSLionel Sambuc   char c;
59f4a2713aSLionel Sambuc };
copy5(struct six * a,struct six * b)60f4a2713aSLionel Sambuc void copy5(struct six *a, struct six *b) {
61f4a2713aSLionel Sambuc   *a = *b;
62f4a2713aSLionel Sambuc }
63*0a6a1f1dSLionel Sambuc // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 6, i32 1, i1 false), !tbaa.struct [[TS5:!.*]]
64f4a2713aSLionel Sambuc 
65*0a6a1f1dSLionel Sambuc // CHECK: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}}
66*0a6a1f1dSLionel Sambuc // CHECK: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}}
67*0a6a1f1dSLionel Sambuc // CHECK: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0}
68*0a6a1f1dSLionel Sambuc // CHECK: [[INT]] = !{!"int", [[CHAR]]
69*0a6a1f1dSLionel Sambuc // CHECK: [[TAG_CHAR:!.*]] = !{[[CHAR]], [[CHAR]], i64 0}
70f4a2713aSLionel Sambuc // (offset, size) = (0,1) char; (4,2) short; (8,4) int; (12,1) char; (16,4) int; (20,4) int
71*0a6a1f1dSLionel Sambuc // CHECK: [[TS2]] = !{i64 0, i64 1, !{{.*}}, i64 4, i64 2, !{{.*}}, i64 8, i64 4, !{{.*}}, i64 12, i64 1, !{{.*}}, i64 16, i64 4, {{.*}}, i64 20, i64 4, {{.*}}}
72f4a2713aSLionel Sambuc // (offset, size) = (0,8) char; (0,2) char; (4,8) char
73*0a6a1f1dSLionel Sambuc // CHECK: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}}
74*0a6a1f1dSLionel Sambuc // CHECK: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 4, [[TAG_INT]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]}
75*0a6a1f1dSLionel Sambuc // CHECK: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 4, [[TAG_INT]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]}
76