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: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 16, i32 4, i1 false), !tbaa.struct [[TS:!.*]]
     16 
     17 struct B {
     18   char c1;
     19   struct A a;
     20   int ii;
     21 };
     22 
     23 void copy2(struct B *a, struct B *b) {
     24   *a = *b;
     25 }
     26 
     27 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 24, i32 4, i1 false), !tbaa.struct [[TS2:!.*]]
     28 
     29 typedef _Complex int T2;
     30 typedef _Complex char T5;
     31 typedef _Complex int T7;
     32 typedef struct T4 { T5 field0; T7 field1; } T4;
     33 typedef union T1 { T2 field0; T4 field1; } T1;
     34 
     35 void copy3 (T1 *a, T1 *b) {
     36   *a = *b;
     37 }
     38 
     39 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 12, i32 4, i1 false), !tbaa.struct [[TS3:!.*]]
     40 
     41 // Make sure that zero-length bitfield works.
     42 #define ATTR __attribute__ ((ms_struct))
     43 struct five {
     44   char a;
     45   int :0;        /* ignored; prior field is not a bitfield. */
     46   char b;
     47   char c;
     48 } ATTR;
     49 void copy4(struct five *a, struct five *b) {
     50   *a = *b;
     51 }
     52 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 3, i32 1, i1 false), !tbaa.struct [[TS4:!.*]]
     53 
     54 struct six {
     55   char a;
     56   int :0;
     57   char b;
     58   char c;
     59 };
     60 void copy5(struct six *a, struct six *b) {
     61   *a = *b;
     62 }
     63 // CHECK: call void @llvm.memcpy.p0i8.p0i8.i64(i8* %{{.*}}, i8* %{{.*}}, i64 6, i32 1, i1 false), !tbaa.struct [[TS5:!.*]]
     64 
     65 // CHECK: [[TS]] = metadata !{i64 0, i64 2, metadata !{{.*}}, i64 4, i64 4, metadata !{{.*}}, i64 8, i64 1, metadata !{{.*}}, i64 12, i64 4, metadata !{{.*}}}
     66 // CHECK: [[CHAR:!.*]] = metadata !{metadata !"omnipotent char", metadata !{{.*}}}
     67 // CHECK: [[TAG_INT:!.*]] = metadata !{metadata [[INT:!.*]], metadata [[INT]], i64 0}
     68 // CHECK: [[INT]] = metadata !{metadata !"int", metadata [[CHAR]]
     69 // CHECK: [[TAG_CHAR:!.*]] = metadata !{metadata [[CHAR]], metadata [[CHAR]], i64 0}
     70 // (offset, size) = (0,1) char; (4,2) short; (8,4) int; (12,1) char; (16,4) int; (20,4) int
     71 // 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 {{.*}}}
     72 // (offset, size) = (0,8) char; (0,2) char; (4,8) char
     73 // CHECK: [[TS3]] = metadata !{i64 0, i64 8, metadata !{{.*}}, i64 0, i64 2, metadata !{{.*}}, i64 4, i64 8, metadata !{{.*}}}
     74 // CHECK: [[TS4]] = metadata !{i64 0, i64 1, metadata [[TAG_CHAR]], i64 1, i64 4, metadata [[TAG_INT]], i64 1, i64 1, metadata [[TAG_CHAR]], i64 2, i64 1, metadata [[TAG_CHAR]]}
     75 // CHECK: [[TS5]] = metadata !{i64 0, i64 1, metadata [[TAG_CHAR]], i64 4, i64 4, metadata [[TAG_INT]], i64 4, i64 1, metadata [[TAG_CHAR]], i64 5, i64 1, metadata [[TAG_CHAR]]}
     76