2010-03-30 10:53:30 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
|
2009-08-09 07:32:22 +08:00
|
|
|
|
|
|
|
extern "C" int printf(...);
|
|
|
|
|
|
|
|
int init = 100;
|
|
|
|
|
|
|
|
struct M {
|
|
|
|
int iM;
|
|
|
|
M() : iM(init++) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct N {
|
|
|
|
int iN;
|
|
|
|
N() : iN(200) {}
|
|
|
|
N(N const & arg){this->iN = arg.iN; }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct P {
|
|
|
|
int iP;
|
|
|
|
P() : iP(init++) {}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN1XC1ERKS_(%struct.X* %this, %struct.X* dereferenceable({{[0-9]+}}) %0) unnamed_addr
|
2009-08-09 07:32:22 +08:00
|
|
|
struct X : M, N, P { // ...
|
2009-09-09 23:08:12 +08:00
|
|
|
X() : f1(1.0), d1(2.0), i1(3), name("HELLO"), bf1(0xff), bf2(0xabcd),
|
|
|
|
au_i1(1234), au1_4("MASKED") {}
|
|
|
|
P p0;
|
|
|
|
void pr() {
|
|
|
|
printf("iM = %d iN = %d, m1.iM = %d\n", iM, iN, m1.iM);
|
|
|
|
printf("im = %d p0.iP = %d, p1.iP = %d\n", iP, p0.iP, p1.iP);
|
|
|
|
printf("f1 = %f d1 = %f i1 = %d name(%s) \n", f1, d1, i1, name);
|
|
|
|
printf("bf1 = %x bf2 = %x\n", bf1, bf2);
|
|
|
|
printf("au_i2 = %d\n", au_i2);
|
|
|
|
printf("au1_1 = %s\n", au1_1);
|
|
|
|
}
|
|
|
|
M m1;
|
|
|
|
P p1;
|
|
|
|
float f1;
|
|
|
|
double d1;
|
|
|
|
int i1;
|
|
|
|
const char *name;
|
|
|
|
unsigned bf1 : 8;
|
|
|
|
unsigned bf2 : 16;
|
2009-11-17 05:47:41 +08:00
|
|
|
int arr[2];
|
|
|
|
_Complex float complex;
|
2009-08-12 02:49:54 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
union {
|
|
|
|
int au_i1;
|
|
|
|
int au_i2;
|
|
|
|
};
|
|
|
|
union {
|
|
|
|
const char * au1_1;
|
|
|
|
float au1_2;
|
|
|
|
int au1_3;
|
|
|
|
const char * au1_4;
|
|
|
|
};
|
2009-08-09 07:32:22 +08:00
|
|
|
};
|
|
|
|
|
2009-08-22 02:30:26 +08:00
|
|
|
static int ix = 1;
|
|
|
|
// class with user-defined copy constructor.
|
|
|
|
struct S {
|
|
|
|
S() : iS(ix++) { }
|
|
|
|
S(const S& arg) { *this = arg; }
|
|
|
|
int iS;
|
|
|
|
};
|
|
|
|
|
|
|
|
// class with trivial copy constructor.
|
|
|
|
struct I {
|
|
|
|
I() : iI(ix++) { }
|
|
|
|
int iI;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct XM {
|
|
|
|
XM() { }
|
|
|
|
double dXM;
|
|
|
|
S ARR_S[3][4][2];
|
|
|
|
void pr() {
|
|
|
|
for (unsigned i = 0; i < 3; i++)
|
|
|
|
for (unsigned j = 0; j < 4; j++)
|
|
|
|
for (unsigned k = 0; k < 2; k++)
|
|
|
|
printf("ARR_S[%d][%d][%d] = %d\n", i,j,k, ARR_S[i][j][k].iS);
|
|
|
|
for (unsigned i = 0; i < 3; i++)
|
|
|
|
for (unsigned k = 0; k < 2; k++)
|
|
|
|
printf("ARR_I[%d][%d] = %d\n", i,k, ARR_I[i][k].iI);
|
|
|
|
}
|
|
|
|
I ARR_I[3][2];
|
|
|
|
};
|
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
int main() {
|
|
|
|
X a;
|
|
|
|
X b(a);
|
|
|
|
b.pr();
|
|
|
|
X x;
|
|
|
|
X c(x);
|
|
|
|
c.pr();
|
2009-08-22 02:30:26 +08:00
|
|
|
|
2009-09-09 23:08:12 +08:00
|
|
|
XM m0;
|
|
|
|
XM m1 = m0;
|
|
|
|
m1.pr();
|
2009-08-09 07:32:22 +08:00
|
|
|
}
|
2009-09-09 23:08:12 +08:00
|
|
|
|
2009-11-25 05:08:10 +08:00
|
|
|
struct A {
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : A {
|
|
|
|
A &a;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f(const B &b1) {
|
|
|
|
B b2(b1);
|
|
|
|
}
|
2010-03-30 10:57:48 +08:00
|
|
|
|
|
|
|
// PR6628
|
|
|
|
namespace PR6628 {
|
|
|
|
|
|
|
|
struct T {
|
|
|
|
T();
|
|
|
|
~T();
|
|
|
|
|
|
|
|
double d;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
A(const A &other, const T &t = T(), const T& t2 = T());
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : A {
|
|
|
|
A a1;
|
|
|
|
A a2;
|
2010-03-30 11:30:08 +08:00
|
|
|
A a[10];
|
2010-03-30 10:57:48 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
// Force the copy constructor to be synthesized.
|
|
|
|
void f(B b1) {
|
|
|
|
B b2 = b1;
|
|
|
|
}
|
|
|
|
|
2014-07-18 23:52:10 +08:00
|
|
|
// CHECK: define linkonce_odr dereferenceable({{[0-9]+}}) [[A:%.*]]* @_ZN12rdar138169401AaSERKS0_(
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[THIS:%.*]] = load [[A]]*, [[A]]**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[OTHER:%.*]] = load [[A]]*, [[A]]**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OTHER]], i32 0, i32 1
|
Complete Rewrite of CGRecordLayoutBuilder
CGRecordLayoutBuilder was aging, complex, multi-pass, and shows signs of
existing before ASTRecordLayoutBuilder. It redundantly performed many
layout operations that are now performed by ASTRecordLayoutBuilder and
asserted that the results were the same. With the addition of support
for the MS-ABI, such as placement of vbptrs, vtordisps, different
bitfield layout and a variety of other features, CGRecordLayoutBuilder
was growing unwieldy in its redundancy.
This patch re-architects CGRecordLayoutBuilder to not perform any
redundant layout but rather, as directly as possible, lower an
ASTRecordLayout to an llvm::type. The new architecture is significantly
smaller and simpler than the CGRecordLayoutBuilder and contains fewer
ABI-specific code paths. It's also one pass.
The architecture of the new system is described in the comments. For the
most part, the new system simply takes all of the fields and bases from
an ASTRecordLayout, sorts them, inserts padding and dumps a record.
Bitfields, unions and primary virtual bases make this process a bit more
complicated. See the inline comments.
In addition, this patch updates a few lit tests due to the fact that the
new system computes more accurate llvm types than CGRecordLayoutBuilder.
Each change is commented individually in the review.
Differential Revision: http://llvm-reviews.chandlerc.com/D2795
llvm-svn: 201907
2014-02-22 07:49:50 +08:00
|
|
|
// CHECK-NEXT: [[T4:%.*]] = bitcast i16* [[T0]] to i8*
|
|
|
|
// CHECK-NEXT: [[T5:%.*]] = bitcast i16* [[T2]] to i8*
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[T4]], i8* align 8 [[T5]], i64 8, i1 false)
|
2013-05-07 13:20:46 +08:00
|
|
|
// CHECK-NEXT: ret [[A]]* [[THIS]]
|
|
|
|
|
2019-08-03 22:28:34 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN6PR66281BC2ERKS0_(%"struct.PR6628::B"* %this, %"struct.PR6628::B"* dereferenceable({{[0-9]+}}) %0) unnamed_addr
|
2010-03-30 10:57:48 +08:00
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281AC2ERKS0_RKNS_1TES5_
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TC1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281AC1ERKS0_RKNS_1TES5_
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
|
|
|
// CHECK: call void @_ZN6PR66281TD1Ev
|
2015-01-22 08:24:57 +08:00
|
|
|
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN12rdar138169401AC2ERKS0_(
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK: [[THIS:%.*]] = load [[A]]*, [[A]]**
|
2015-01-22 08:24:57 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = bitcast [[A]]* [[THIS]] to i32 (...)***
|
2016-12-14 04:50:44 +08:00
|
|
|
// CHECK-NEXT: store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTVN12rdar138169401AE, i32 0, inrange i32 0, i32 2) to i32 (...)**), i32 (...)*** [[T0]]
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [[A]], [[A]]* [[THIS]], i32 0, i32 1
|
2015-02-28 05:19:58 +08:00
|
|
|
// CHECK-NEXT: [[OTHER:%.*]] = load [[A]]*, [[A]]**
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[T2:%.*]] = getelementptr inbounds [[A]], [[A]]* [[OTHER]], i32 0, i32 1
|
2015-01-22 08:24:57 +08:00
|
|
|
// CHECK-NEXT: [[T4:%.*]] = bitcast i16* [[T0]] to i8*
|
|
|
|
// CHECK-NEXT: [[T5:%.*]] = bitcast i16* [[T2]] to i8*
|
Change memcpy/memove/memset to have dest and source alignment attributes (Step 1).
Summary:
Upstream LLVM is changing the the prototypes of the @llvm.memcpy/memmove/memset
intrinsics. This change updates the Clang tests for this change.
The @llvm.memcpy/memmove/memset intrinsics currently have an explicit argument
which is required to be a constant integer. It represents the alignment of the
dest (and source), and so must be the minimum of the actual alignment of the
two.
This change removes the alignment argument in favour of placing the alignment
attribute on the source and destination pointers of the memory intrinsic call.
For example, code which used to read:
call void @llvm.memcpy.p0i8.p0i8.i32(i8* %dest, i8* %src, i32 100, i32 4, i1 false)
will now read
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %dest, i8* align 4 %src, i32 100, i1 false)
At this time the source and destination alignments must be the same (Step 1).
Step 2 of the change, to be landed shortly, will relax that contraint and allow
the source and destination to have different alignments.
llvm-svn: 322964
2018-01-20 01:12:54 +08:00
|
|
|
// CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 [[T4]], i8* align 8 [[T5]], i64 8, i1 false)
|
2015-01-22 08:24:57 +08:00
|
|
|
// CHECK-NEXT: ret void
|
2010-03-30 10:57:48 +08:00
|
|
|
}
|
|
|
|
|
2013-05-07 13:20:46 +08:00
|
|
|
// rdar://13816940
|
|
|
|
// Test above because things get weirdly re-ordered.
|
|
|
|
namespace rdar13816940 {
|
|
|
|
struct A {
|
|
|
|
virtual ~A();
|
|
|
|
unsigned short a : 1;
|
|
|
|
unsigned short : 15;
|
|
|
|
unsigned other;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(A &a) {
|
|
|
|
A x = a; // force copy constructor into existence
|
|
|
|
x = a; // also force the copy assignment operator
|
|
|
|
}
|
|
|
|
}
|