xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/assign-construct-memcpy.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin12 -emit-llvm -o - -std=c++11 %s -DPOD | FileCheck %s -check-prefix=CHECK-POD
2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin12 -emit-llvm -o - -std=c++11 %s | FileCheck %s -check-prefix=CHECK-NONPOD
3*f4a2713aSLionel Sambuc 
4*f4a2713aSLionel Sambuc // Declare the reserved placement operators.
5*f4a2713aSLionel Sambuc typedef __typeof__(sizeof(0)) size_t;
6*f4a2713aSLionel Sambuc void *operator new(size_t, void*) throw();
7*f4a2713aSLionel Sambuc void operator delete(void*, void*) throw();
8*f4a2713aSLionel Sambuc void *operator new[](size_t, void*) throw();
9*f4a2713aSLionel Sambuc void operator delete[](void*, void*) throw();
10*f4a2713aSLionel Sambuc template<typename T> T &&move(T&);
11*f4a2713aSLionel Sambuc 
12*f4a2713aSLionel Sambuc struct foo {
13*f4a2713aSLionel Sambuc #ifndef POD
foofoo14*f4a2713aSLionel Sambuc   foo() {} // non-POD
15*f4a2713aSLionel Sambuc #endif
16*f4a2713aSLionel Sambuc   void *a, *b;
17*f4a2713aSLionel Sambuc   bool c;
18*f4a2713aSLionel Sambuc };
19*f4a2713aSLionel Sambuc 
20*f4a2713aSLionel Sambuc // It is not legal to copy the tail padding in all cases, but if it is it can
21*f4a2713aSLionel Sambuc // yield better codegen.
22*f4a2713aSLionel Sambuc 
test1(void * f,const foo & x)23*f4a2713aSLionel Sambuc foo *test1(void *f, const foo &x) {
24*f4a2713aSLionel Sambuc   return new (f) foo(x);
25*f4a2713aSLionel Sambuc // CHECK-POD: test1
26*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
27*f4a2713aSLionel Sambuc 
28*f4a2713aSLionel Sambuc // CHECK-NONPOD: test1
29*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
30*f4a2713aSLionel Sambuc }
31*f4a2713aSLionel Sambuc 
test2(const foo & x)32*f4a2713aSLionel Sambuc foo *test2(const foo &x) {
33*f4a2713aSLionel Sambuc   return new foo(x);
34*f4a2713aSLionel Sambuc // CHECK-POD: test2
35*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
36*f4a2713aSLionel Sambuc 
37*f4a2713aSLionel Sambuc // CHECK-NONPOD: test2
38*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
39*f4a2713aSLionel Sambuc }
40*f4a2713aSLionel Sambuc 
test3(const foo & x)41*f4a2713aSLionel Sambuc foo test3(const foo &x) {
42*f4a2713aSLionel Sambuc   foo f = x;
43*f4a2713aSLionel Sambuc   return f;
44*f4a2713aSLionel Sambuc // CHECK-POD: test3
45*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
46*f4a2713aSLionel Sambuc 
47*f4a2713aSLionel Sambuc // CHECK-NONPOD: test3
48*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
49*f4a2713aSLionel Sambuc }
50*f4a2713aSLionel Sambuc 
test4(foo && x)51*f4a2713aSLionel Sambuc foo *test4(foo &&x) {
52*f4a2713aSLionel Sambuc   return new foo(x);
53*f4a2713aSLionel Sambuc // CHECK-POD: test4
54*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
55*f4a2713aSLionel Sambuc 
56*f4a2713aSLionel Sambuc // CHECK-NONPOD: test4
57*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
58*f4a2713aSLionel Sambuc }
59*f4a2713aSLionel Sambuc 
test5(foo & f,const foo & x)60*f4a2713aSLionel Sambuc void test5(foo &f, const foo &x) {
61*f4a2713aSLionel Sambuc   f = x;
62*f4a2713aSLionel Sambuc // CHECK-POD: test5
63*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
64*f4a2713aSLionel Sambuc 
65*f4a2713aSLionel Sambuc // CHECK-NONPOD: test5
66*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 17, i32 8
67*f4a2713aSLionel Sambuc }
68*f4a2713aSLionel Sambuc 
69*f4a2713aSLionel Sambuc extern foo globtest;
70*f4a2713aSLionel Sambuc 
test6(foo && x)71*f4a2713aSLionel Sambuc void test6(foo &&x) {
72*f4a2713aSLionel Sambuc   globtest = move(x);
73*f4a2713aSLionel Sambuc // CHECK-POD: test6
74*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
75*f4a2713aSLionel Sambuc 
76*f4a2713aSLionel Sambuc // CHECK-NONPOD: test6
77*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 17, i32 8
78*f4a2713aSLionel Sambuc }
79*f4a2713aSLionel Sambuc 
80*f4a2713aSLionel Sambuc void byval(foo f);
81*f4a2713aSLionel Sambuc 
test7(const foo & x)82*f4a2713aSLionel Sambuc void test7(const foo &x) {
83*f4a2713aSLionel Sambuc   byval(x);
84*f4a2713aSLionel Sambuc // CHECK-POD: test7
85*f4a2713aSLionel Sambuc // CHECK-POD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
86*f4a2713aSLionel Sambuc 
87*f4a2713aSLionel Sambuc // CHECK-NONPOD: test7
88*f4a2713aSLionel Sambuc // CHECK-NONPOD: call void @llvm.memcpy.p0i8.p0i8.i64({{.*}}i64 24, i32 8
89*f4a2713aSLionel Sambuc }
90