1 // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - -O1 %s | \
2 // RUN: FileCheck -check-prefixes=CHECK,CHECK-OLD %s
3 // RUN: %clang_cc1 -triple x86_64-apple-darwin -new-struct-path-tbaa \
4 // RUN: -emit-llvm -o - -O1 %s | \
5 // RUN: FileCheck -check-prefixes=CHECK,CHECK-NEW %s
7 // Check that we generate TBAA metadata for struct copies correctly.
16 typedef A
__attribute__((may_alias
)) AA
;
18 void copy(A
*a1
, A
*a2
) {
19 // CHECK-LABEL: _Z4copyP1AS0_
20 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false)
21 // CHECK-OLD-SAME: !tbaa.struct [[TS:!.*]]
22 // CHECK-NEW-SAME: !tbaa [[TAG_A:![0-9]*]]
32 void copy2(B
*b1
, B
*b2
) {
33 // CHECK-LABEL: _Z5copy2P1BS0_
34 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(24) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(24) %{{.*}}, i64 24, i1 false)
35 // CHECK-OLD-SAME: !tbaa.struct [[TS2:!.*]]
36 // CHECK-NEW-SAME: !tbaa [[TAG_B:![0-9]*]]
50 void copy3(U
*u1
, U
*u2
) {
51 // CHECK-LABEL: _Z5copy3P1US0_
52 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(12) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(12) %{{.*}}, i64 12, i1 false)
53 // CHECK-OLD-SAME: !tbaa.struct [[TS3:!.*]]
54 // CHECK-NEW-SAME: !tbaa [[TAG_U:![0-9]*]]
58 // Make sure that zero-length bitfield works.
61 int : 0; // Shall not be ignored; see r185018.
64 } __attribute__((ms_struct
));
66 void copy4(C
*c1
, C
*c2
) {
67 // CHECK-LABEL: _Z5copy4P1CS0_
68 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(3) {{.*}}, ptr noundef nonnull align 1 dereferenceable(3) {{.*}}, i64 3, i1 false)
69 // CHECK-OLD-SAME: !tbaa.struct [[TS4:!.*]]
70 // CHECK-NEW-SAME: !tbaa [[TAG_C:![0-9]*]]
81 void copy5(D
*d1
, D
*d2
) {
82 // CHECK-LABEL: _Z5copy5P1DS0_
83 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 1 dereferenceable(6) {{.*}}, ptr noundef nonnull align 1 dereferenceable(6) {{.*}}, i64 6, i1 false)
84 // CHECK-OLD-SAME: !tbaa.struct [[TS5:!.*]]
85 // CHECK-NEW-SAME: !tbaa [[TAG_D:![0-9]*]]
89 void copy6(AA
*a1
, A
*a2
) {
90 // CHECK-LABEL: _Z5copy6P1AS0_
91 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false)
92 // CHECK-OLD-SAME: !tbaa.struct [[TS]]
93 // CHECK-NEW-SAME: !tbaa [[TAG_char:![0-9]*]]
97 void copy7(A
*a1
, AA
*a2
) {
98 // CHECK-LABEL: _Z5copy7P1AS0_
99 // CHECK: call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, ptr noundef nonnull align 4 dereferenceable(16) %{{.*}}, i64 16, i1 false)
100 // CHECK-OLD-SAME: !tbaa.struct [[TS]]
101 // CHECK-NEW-SAME: !tbaa [[TAG_char]]
105 // CHECK-OLD: [[TS]] = !{i64 0, i64 2, !{{.*}}, i64 4, i64 4, !{{.*}}, i64 8, i64 1, !{{.*}}, i64 12, i64 4, !{{.*}}}
106 // CHECK-OLD: [[CHAR:!.*]] = !{!"omnipotent char", !{{.*}}}
107 // CHECK-OLD: [[TAG_INT:!.*]] = !{[[INT:!.*]], [[INT]], i64 0}
108 // CHECK-OLD: [[INT]] = !{!"int", [[CHAR]]
109 // CHECK-OLD: [[TAG_CHAR:!.*]] = !{[[CHAR]], [[CHAR]], i64 0}
110 // (offset, size) = (0,1) char; (4,2) short; (8,4) int; (12,1) char; (16,4) int; (20,4) int
111 // CHECK-OLD: [[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, {{.*}}}
112 // (offset, size) = (0,8) char; (0,2) char; (4,8) char
113 // CHECK-OLD: [[TS3]] = !{i64 0, i64 8, !{{.*}}, i64 0, i64 2, !{{.*}}, i64 4, i64 8, !{{.*}}}
114 // CHECK-OLD: [[TS4]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 1, i64 1, [[TAG_CHAR]], i64 2, i64 1, [[TAG_CHAR]]}
115 // CHECK-OLD: [[TS5]] = !{i64 0, i64 1, [[TAG_CHAR]], i64 4, i64 1, [[TAG_CHAR]], i64 5, i64 1, [[TAG_CHAR]]}
117 // CHECK-NEW-DAG: [[TYPE_char:!.*]] = !{{{.*}}, i64 1, !"omnipotent char"}
118 // CHECK-NEW-DAG: [[TAG_char]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 0}
119 // CHECK-NEW-DAG: [[TYPE_short:!.*]] = !{[[TYPE_char]], i64 2, !"short"}
120 // CHECK-NEW-DAG: [[TYPE_int:!.*]] = !{[[TYPE_char]], i64 4, !"int"}
121 // CHECK-NEW-DAG: [[TYPE_A:!.*]] = !{[[TYPE_char]], i64 16, !"_ZTS1A", [[TYPE_short]], i64 0, i64 2, [[TYPE_int]], i64 4, i64 4, [[TYPE_char]], i64 8, i64 1, [[TYPE_int]], i64 12, i64 4}
122 // CHECK-NEW-DAG: [[TAG_A]] = !{[[TYPE_A]], [[TYPE_A]], i64 0, i64 16}
123 // CHECK-NEW-DAG: [[TYPE_B:!.*]] = !{[[TYPE_char]], i64 24, !"_ZTS1B", [[TYPE_char]], i64 0, i64 1, [[TYPE_A]], i64 4, i64 16, [[TYPE_int]], i64 20, i64 4}
124 // CHECK-NEW-DAG: [[TAG_B]] = !{[[TYPE_B]], [[TYPE_B]], i64 0, i64 24}
125 // CHECK-NEW-DAG: [[TAG_U]] = !{[[TYPE_char]], [[TYPE_char]], i64 0, i64 12}
126 // CHECK-NEW-DAG: [[TYPE_C:!.*]] = !{[[TYPE_char]], i64 3, !"_ZTS1C", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 1, i64 1, [[TYPE_char]], i64 2, i64 1}
127 // CHECK-NEW-DAG: [[TAG_C]] = !{[[TYPE_C]], [[TYPE_C]], i64 0, i64 3}
128 // CHECK-NEW-DAG: [[TYPE_D:!.*]] = !{[[TYPE_char]], i64 6, !"_ZTS1D", [[TYPE_char]], i64 0, i64 1, [[TYPE_char]], i64 4, i64 1, [[TYPE_char]], i64 5, i64 1}
129 // CHECK-NEW-DAG: [[TAG_D]] = !{[[TYPE_D]], [[TYPE_D]], i64 0, i64 6}