xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenObjCXX/implicit-copy-assign-operator.mm (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc// RUN: %clang_cc1 -fobjc-gc -emit-llvm -triple x86_64-apple-darwin10.0.0 -fobjc-runtime=macosx-fragile-10.5 -o - %s | FileCheck %s -check-prefix=CHECK-OBJ
2f4a2713aSLionel Sambuc// RUN: %clang_cc1 -x c++    -emit-llvm -triple x86_64-apple-darwin10.0.0                                    -o - %s | FileCheck %s -check-prefix=CHECK-CPP
3f4a2713aSLionel Sambuc#ifdef __OBJC__
4f4a2713aSLionel Sambucstruct A {
5f4a2713aSLionel Sambuc  A &operator=(const A&);
6f4a2713aSLionel Sambuc  A &operator=(A&);
7f4a2713aSLionel Sambuc};
8f4a2713aSLionel Sambuc
9f4a2713aSLionel Sambucstruct B {
10f4a2713aSLionel Sambuc  B &operator=(B&);
11f4a2713aSLionel Sambuc};
12f4a2713aSLionel Sambuc
13f4a2713aSLionel Sambucstruct C {
14f4a2713aSLionel Sambuc  virtual C& operator=(const C&);
15f4a2713aSLionel Sambuc};
16f4a2713aSLionel Sambuc
17f4a2713aSLionel Sambucstruct POD {
18f4a2713aSLionel Sambuc  id myobjc;
19f4a2713aSLionel Sambuc  int array[3][4];
20f4a2713aSLionel Sambuc};
21f4a2713aSLionel Sambuc
22f4a2713aSLionel Sambucstruct CopyByValue {
23f4a2713aSLionel Sambuc  CopyByValue(const CopyByValue&);
24f4a2713aSLionel Sambuc  CopyByValue &operator=(CopyByValue);
25f4a2713aSLionel Sambuc};
26f4a2713aSLionel Sambuc
27f4a2713aSLionel Sambucstruct D : A, B, virtual C {
28f4a2713aSLionel Sambuc  int scalar;
29f4a2713aSLionel Sambuc  int scalar_array[2][3];
30f4a2713aSLionel Sambuc  B class_member;
31f4a2713aSLionel Sambuc  C class_member_array[2][3];
32f4a2713aSLionel Sambuc  POD pod_array[2][3];
33f4a2713aSLionel Sambuc
34f4a2713aSLionel Sambuc  union {
35f4a2713aSLionel Sambuc    int x;
36f4a2713aSLionel Sambuc    float f[3];
37f4a2713aSLionel Sambuc  };
38f4a2713aSLionel Sambuc
39f4a2713aSLionel Sambuc  CopyByValue by_value;
40f4a2713aSLionel Sambuc};
41f4a2713aSLionel Sambuc
42f4a2713aSLionel Sambucvoid test_D(D d1, D d2) {
43f4a2713aSLionel Sambuc  d1 = d2;
44f4a2713aSLionel Sambuc}
45f4a2713aSLionel Sambuc
46*0a6a1f1dSLionel Sambuc// CHECK-OBJ-LABEL: define linkonce_odr dereferenceable({{[0-9]+}}) %struct.D* @_ZN1DaSERS_
47f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN1AaSERS_}}
48f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN1BaSERS_}}
49f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN1CaSERKS_}}
50f4a2713aSLionel Sambuc// CHECK-OBJ: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 24}}
51f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN1BaSERS_}}
52f4a2713aSLionel Sambuc// CHECK-OBJ: br
53f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN1CaSERKS_}}
54f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*@objc_memmove_collectable}}
55f4a2713aSLionel Sambuc// CHECK-OBJ: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 12}}
56f4a2713aSLionel Sambuc// CHECK-OBJ: call void @_ZN11CopyByValueC1ERKS_
57f4a2713aSLionel Sambuc// CHECK-OBJ: {{call.*_ZN11CopyByValueaSES_}}
58f4a2713aSLionel Sambuc// CHECK-OBJ: ret
59f4a2713aSLionel Sambuc#endif
60f4a2713aSLionel Sambuc
61f4a2713aSLionel Sambucnamespace PR13329 {
62f4a2713aSLionel Sambuc#ifndef __OBJC__
63f4a2713aSLionel Sambuc  typedef void* id;
64f4a2713aSLionel Sambuc#endif
65f4a2713aSLionel Sambuc  struct POD {
66f4a2713aSLionel Sambuc    id    i;
67f4a2713aSLionel Sambuc    short s;
68f4a2713aSLionel Sambuc  };
69f4a2713aSLionel Sambuc
70f4a2713aSLionel Sambuc  struct NonPOD {
71f4a2713aSLionel Sambuc    id    i;
72f4a2713aSLionel Sambuc    short s;
73f4a2713aSLionel Sambuc
74f4a2713aSLionel Sambuc    NonPOD();
75f4a2713aSLionel Sambuc  };
76f4a2713aSLionel Sambuc
77f4a2713aSLionel Sambuc  struct DerivedNonPOD: NonPOD {
78f4a2713aSLionel Sambuc    char  c;
79f4a2713aSLionel Sambuc  };
80f4a2713aSLionel Sambuc
81f4a2713aSLionel Sambuc  struct DerivedPOD: POD {
82f4a2713aSLionel Sambuc    char  c;
83f4a2713aSLionel Sambuc  };
84f4a2713aSLionel Sambuc
85f4a2713aSLionel Sambuc  void testPOD() {
86f4a2713aSLionel Sambuc    POD a;
87f4a2713aSLionel Sambuc    POD b;
88f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 16
89f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 16
90f4a2713aSLionel Sambuc    b = a;
91f4a2713aSLionel Sambuc  }
92f4a2713aSLionel Sambuc
93f4a2713aSLionel Sambuc  void testNonPOD() {
94f4a2713aSLionel Sambuc    NonPOD a;
95f4a2713aSLionel Sambuc    NonPOD b;
96f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 10
97f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 10
98f4a2713aSLionel Sambuc    b = a;
99f4a2713aSLionel Sambuc  }
100f4a2713aSLionel Sambuc
101f4a2713aSLionel Sambuc  void testDerivedNonPOD() {
102f4a2713aSLionel Sambuc    DerivedNonPOD a;
103f4a2713aSLionel Sambuc    NonPOD        b;
104f4a2713aSLionel Sambuc    DerivedNonPOD c;
105f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 10
106f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 10
107f4a2713aSLionel Sambuc    (NonPOD&) a = b;
108f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 11
109f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 11
110f4a2713aSLionel Sambuc    a = c;
111f4a2713aSLionel Sambuc  };
112f4a2713aSLionel Sambuc
113f4a2713aSLionel Sambuc  void testDerivedPOD() {
114f4a2713aSLionel Sambuc    DerivedPOD a;
115f4a2713aSLionel Sambuc    POD        b;
116f4a2713aSLionel Sambuc    DerivedPOD c;
117f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 16
118f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 16
119f4a2713aSLionel Sambuc    (POD&) a = b;
120f4a2713aSLionel Sambuc    // CHECK-OBJ: @objc_memmove_collectable{{.*}}i64 17
121f4a2713aSLionel Sambuc    // CHECK-CPP: @llvm.memcpy{{.*}}i64 17
122f4a2713aSLionel Sambuc    a = c;
123f4a2713aSLionel Sambuc  };
124f4a2713aSLionel Sambuc}
125