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