2012-11-08 07:56:21 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -emit-llvm -o - %s -std=c++11 | FileCheck %s
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
A(const A&);
|
|
|
|
A(A&);
|
|
|
|
~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
B();
|
|
|
|
B(B&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
C() {}
|
|
|
|
C(C& other, A a = A());
|
|
|
|
int i, j;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct POD {
|
|
|
|
int array[3][4];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct D : A, B, virtual C {
|
|
|
|
D();
|
|
|
|
int scalar;
|
|
|
|
int scalar_array[2][3];
|
|
|
|
B class_member;
|
|
|
|
C class_member_array[2][3];
|
|
|
|
POD pod_array[2][3];
|
|
|
|
|
|
|
|
union {
|
|
|
|
int x;
|
|
|
|
float f[3];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
void f(D d) {
|
|
|
|
D d2(d);
|
|
|
|
}
|
|
|
|
|
2021-10-15 18:26:07 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1DC1ERS_(%struct.D* {{[^,]*}} %this, %struct.D* noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %0) unnamed_addr
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
// CHECK: call void @_ZN1AC1Ev
|
|
|
|
// CHECK: call void @_ZN1CC2ERS_1A
|
|
|
|
// CHECK: call void @_ZN1AD1Ev
|
|
|
|
// CHECK: call void @_ZN1AC2ERS_
|
|
|
|
// CHECK: call void @_ZN1BC2ERS_
|
2013-02-17 15:22:09 +08:00
|
|
|
// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 28}}
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
// CHECK: call void @_ZN1BC1ERS_
|
2016-12-14 08:03:17 +08:00
|
|
|
// CHECK: br label
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
// CHECK: call void @_ZN1AC1Ev
|
|
|
|
// CHECK: call void @_ZN1CC1ERS_1A
|
|
|
|
// CHECK: call void @_ZN1AD1Ev
|
2016-12-14 08:03:17 +08:00
|
|
|
// CHECK: {{icmp eq.*, 3}}
|
|
|
|
// CHECK: br i1
|
|
|
|
// CHECK: {{icmp eq.*, 2}}
|
|
|
|
// CHECK: br i1
|
2013-02-17 15:22:09 +08:00
|
|
|
// CHECK: {{call void @llvm.memcpy.p0i8.p0i8.i64.*i64 300}}
|
Reimplement code generation for copying fields in the
implicitly-generated copy constructor. Previously, Sema would perform
some checking and instantiation to determine which copy constructors,
etc., would be called, then CodeGen would attempt to figure out which
copy constructor to call... but would get it wrong, or poke at an
uninstantiated default argument, or fail in other ways.
The new scheme is similar to what we now do for the implicit
copy-assignment operator, where Sema performs all of the semantic
analysis and builds specific ASTs that look similar to the ASTs we'd
get from explicitly writing the copy constructor, so that CodeGen need
only do a direct translation.
However, it's not quite that simple because one cannot explicit write
elementwise copy-construction of an array. So, I've extended
CXXBaseOrMemberInitializer to contain a list of indexing variables
used to copy-construct the elements. For example, if we have:
struct A { A(const A&); };
struct B {
A array[2][3];
};
then we generate an implicit copy assignment operator for B that looks
something like this:
B::B(const B &other) : array[i0][i1](other.array[i0][i1]) { }
CodeGen will loop over the invented variables i0 and i1 to visit all
elements in the array, so that each element in the destination array
will be copy-constructed from the corresponding element in the source
array. Of course, if we're dealing with arrays of scalars or class
types with trivial copy-assignment operators, we just generate a
memcpy rather than a loop.
Fixes PR6928, PR5989, and PR6887. Boost.Regex now compiles and passes
all of its regression tests.
Conspicuously missing from this patch is handling for the exceptional
case, where we need to destruct those objects that we have
constructed. I'll address that case separately.
llvm-svn: 103079
2010-05-05 13:51:00 +08:00
|
|
|
// CHECK: ret void
|
|
|
|
|
|
|
|
|
|
|
|
template<class T> struct X0 { void f0(T * ) { } };
|
|
|
|
template <class > struct X1 { X1( X1& , int = 0 ) { } };
|
|
|
|
struct X2 { X1<int> result; };
|
|
|
|
void test_X2()
|
|
|
|
{
|
|
|
|
typedef X2 impl;
|
|
|
|
typedef X0<impl> pimpl;
|
|
|
|
impl* i;
|
|
|
|
pimpl pdata;
|
|
|
|
pdata.f0( new impl(*i));
|
|
|
|
}
|
2011-06-17 08:18:42 +08:00
|
|
|
|
|
|
|
// rdar://problem/9598341
|
|
|
|
namespace test3 {
|
|
|
|
struct A { A(const A&); A&operator=(const A&); };
|
|
|
|
struct B { A a; unsigned : 0; };
|
|
|
|
void test(const B &x) {
|
|
|
|
B y = x;
|
|
|
|
y = x;
|
|
|
|
}
|
|
|
|
}
|
2012-11-08 07:56:21 +08:00
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
// When determining whether to implement an array copy as a memcpy, look at
|
|
|
|
// whether the *selected* constructor is trivial.
|
|
|
|
struct S {
|
|
|
|
int arr[5][5];
|
|
|
|
S(S &);
|
|
|
|
S(const S &) = default;
|
|
|
|
};
|
|
|
|
// CHECK: @_ZN5test42f1
|
|
|
|
void f1(S a) {
|
|
|
|
// CHECK-NOT: memcpy
|
|
|
|
// CHECK: call void @_ZN5test41SC1ERS0_
|
|
|
|
// CHECK-NOT: memcpy
|
|
|
|
S b(a);
|
|
|
|
// CHECK: }
|
|
|
|
}
|
|
|
|
// CHECK: @_ZN5test42f2
|
|
|
|
void f2(const S a) {
|
|
|
|
// CHECK-NOT: call void @_ZN5test41SC1ERS0_
|
|
|
|
// CHECK: memcpy
|
|
|
|
// CHECK-NOT: call void @_ZN5test41SC1ERS0_
|
|
|
|
S b(a);
|
|
|
|
// CHECK: }
|
|
|
|
}
|
|
|
|
}
|