xref: /llvm-project/clang/test/CodeGen/tbaa-struct-bitfield-endianness.cpp (revision 29441e4f5fa5f5c7709f7cf180815ba97f611297)
1 // RUN: %clang_cc1 -triple aarch64_be-apple-darwin -emit-llvm -o - -O1 %s | \
2 // RUN:     FileCheck -check-prefixes=CHECK %s
3 // RUN: %clang_cc1 -triple aarch64-apple-darwin -emit-llvm -o - -O1 %s | \
4 // RUN:     FileCheck -check-prefixes=CHECK %s
5 //
6 // Check that TBAA metadata for structs containing bitfields is
7 // consistent between big and little endian layouts.
8 
9 struct NamedBitfields {
10   int f1 : 8;
11   int f2 : 8;
12   unsigned f3 : 1;
13   unsigned f4 : 15;
14   int f5;
15   double f6;
16 };
17 
18 // CHECK-LABEL: _Z4copyP14NamedBitfieldsS0_
19 // CHECK-SAME: ptr noundef writeonly captures(none) initializes((0, 16)) [[A1:%.*]], ptr noundef readonly captures(none) [[A2:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
20 // CHECK-NEXT:  entry:
21 // CHECK-NEXT:    tail call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 8 dereferenceable(16) [[A1]], ptr noundef nonnull align 8 dereferenceable(16) [[A2]], i64 16, i1 false), !tbaa.struct [[TBAA_STRUCT2:![0-9]+]]
22 // CHECK-NEXT:    ret void
23 //
24 void copy(NamedBitfields *a1, NamedBitfields *a2) {
25   *a1 = *a2;
26 }
27 
28 // CHECK: [[TBAA_STRUCT2]] = !{i64 0, i64 4, [[META3:![0-9]+]], i64 4, i64 4, [[META6:![0-9]+]], i64 8, i64 8, [[META8:![0-9]+]]}
29 // CHECK: [[META3]] = !{[[META4:![0-9]+]], [[META4]], i64 0}
30 // CHECK: [[META4]] = !{!"omnipotent char", [[META5:![0-9]+]], i64 0}
31 // CHECK: [[META5]] = !{!"Simple C++ TBAA"}
32 // CHECK: [[META6]] = !{[[META7:![0-9]+]], [[META7]], i64 0}
33 // CHECK: [[META7]] = !{!"int", [[META4]], i64 0}
34 // CHECK: [[META8]] = !{[[META9:![0-9]+]], [[META9]], i64 0}
35 // CHECK: [[META9]] = !{!"double", [[META4]], i64 0}
36