2018-06-13 10:06:28 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++98 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX98
|
|
|
|
// RUN: %clang_cc1 -std=c++17 %s -triple x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-CXX17
|
2009-12-17 02:50:27 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
virtual ~A();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B : A { };
|
|
|
|
|
|
|
|
struct C {
|
|
|
|
int i;
|
|
|
|
B b;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: _Z15test_value_initv
|
|
|
|
void test_value_init() {
|
|
|
|
// This value initialization requires zero initialization of the 'B'
|
|
|
|
// subobject followed by a call to its constructor.
|
|
|
|
// PR5800
|
|
|
|
|
|
|
|
// CHECK: store i32 17
|
2010-04-04 11:10:52 +08:00
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
2009-12-17 03:18:40 +08:00
|
|
|
// CHECK: call void @_ZN1BC1Ev
|
2009-12-17 02:50:27 +08:00
|
|
|
C c = { 17 } ;
|
2009-12-17 03:18:40 +08:00
|
|
|
// CHECK: call void @_ZN1CD1Ev
|
2009-12-17 02:50:27 +08:00
|
|
|
}
|
2010-04-28 04:36:09 +08:00
|
|
|
|
|
|
|
enum enum_type { negative_number = -1, magic_number = 42 };
|
|
|
|
|
|
|
|
class enum_holder
|
|
|
|
{
|
|
|
|
enum_type m_enum;
|
|
|
|
|
|
|
|
public:
|
|
|
|
enum_holder() : m_enum(magic_number) { }
|
|
|
|
};
|
|
|
|
|
|
|
|
struct enum_holder_and_int
|
|
|
|
{
|
|
|
|
enum_holder e;
|
|
|
|
int i;
|
|
|
|
};
|
|
|
|
|
|
|
|
// CHECK: _Z24test_enum_holder_and_intv()
|
|
|
|
void test_enum_holder_and_int() {
|
|
|
|
// CHECK: alloca
|
|
|
|
// CHECK-NEXT: bitcast
|
|
|
|
// CHECK-NEXT: call void @llvm.memset
|
|
|
|
// CHECK-NEXT: call void @_ZN19enum_holder_and_intC1Ev
|
|
|
|
enum_holder_and_int();
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
2010-08-07 16:21:30 +08:00
|
|
|
|
|
|
|
// PR7834: don't crash.
|
|
|
|
namespace test1 {
|
|
|
|
struct A {
|
|
|
|
int A::*f;
|
|
|
|
A();
|
|
|
|
A(const A&);
|
|
|
|
A &operator=(const A &);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
A base;
|
|
|
|
};
|
|
|
|
|
|
|
|
void foo() {
|
|
|
|
B();
|
|
|
|
}
|
|
|
|
}
|
2010-08-21 00:57:37 +08:00
|
|
|
|
|
|
|
namespace ptrmem {
|
|
|
|
struct S {
|
|
|
|
int mem1;
|
|
|
|
int S::*mem2;
|
|
|
|
};
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_ZN6ptrmem4testEPNS_1SE
|
2010-08-21 00:57:37 +08:00
|
|
|
int test(S *s) {
|
|
|
|
// CHECK: call void @llvm.memcpy.p0i8.p0i8.i64
|
|
|
|
// CHECK: getelementptr
|
|
|
|
// CHECK: ret
|
|
|
|
return s->*S().mem2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-29 02:53:58 +08:00
|
|
|
namespace PR9801 {
|
|
|
|
|
|
|
|
struct Test {
|
|
|
|
Test() : i(10) {}
|
|
|
|
Test(int i) : i(i) {}
|
|
|
|
int i;
|
|
|
|
private:
|
|
|
|
int j;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Test2 {
|
|
|
|
Test t;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Test3 : public Test { };
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN6PR98011fEv
|
2011-04-29 02:53:58 +08:00
|
|
|
void f() {
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2011-04-29 02:53:58 +08:00
|
|
|
// CHECK: call void @_ZN6PR98014TestC1Ei
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2011-04-29 02:53:58 +08:00
|
|
|
// CHECK: call void @_ZN6PR98014TestC1Ev
|
|
|
|
Test partial[3] = { 1 };
|
|
|
|
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2011-04-29 02:53:58 +08:00
|
|
|
// CHECK: call void @_ZN6PR98014TestC1Ev
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NOT: call void @_ZN6PR98014TestC1Ev
|
2011-04-29 02:53:58 +08:00
|
|
|
Test empty[3] = {};
|
|
|
|
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2018-06-13 10:06:28 +08:00
|
|
|
// CHECK-CXX98: call void @_ZN6PR98015Test2C1Ev
|
|
|
|
// CHECK-CXX17: call void @_ZN6PR98014TestC1Ev
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NOT: call void @_ZN6PR98015Test2C1Ev
|
2011-04-29 02:53:58 +08:00
|
|
|
Test2 empty2[3] = {};
|
|
|
|
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2018-06-13 10:06:28 +08:00
|
|
|
// CHECK-CXX98: call void @_ZN6PR98015Test3C1Ev
|
|
|
|
// CHECK-CXX17: call void @_ZN6PR98014TestC2Ev
|
2011-04-29 06:57:55 +08:00
|
|
|
// CHECK-NOT: call void @llvm.memset.p0i8.i64
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NOT: call void @_ZN6PR98015Test3C1Ev
|
2011-04-29 02:53:58 +08:00
|
|
|
Test3 empty3[3] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-08-21 00:57:37 +08:00
|
|
|
namespace zeroinit {
|
|
|
|
struct S { int i; };
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_ZN8zeroinit4testEv()
|
2010-08-21 00:57:37 +08:00
|
|
|
int test() {
|
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
2011-12-31 05:15:51 +08:00
|
|
|
// CHECK: ret i32 0
|
2010-08-21 00:57:37 +08:00
|
|
|
return S().i;
|
|
|
|
}
|
2010-08-23 00:15:35 +08:00
|
|
|
|
|
|
|
struct X0 {
|
|
|
|
X0() { }
|
|
|
|
int x;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct X1 : X0 {
|
|
|
|
int x1;
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X1Ev
|
2010-08-23 00:15:35 +08:00
|
|
|
void testX0_X1() {
|
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
|
|
|
// CHECK-NEXT: call void @_ZN8zeroinit2X1C1Ev
|
|
|
|
// CHECK-NEXT: call void @_ZN8zeroinit2X11fEv
|
|
|
|
X1().f();
|
|
|
|
}
|
2010-08-23 01:20:18 +08:00
|
|
|
|
|
|
|
template<typename>
|
|
|
|
struct X2 : X0 {
|
|
|
|
int x2;
|
|
|
|
void f();
|
|
|
|
};
|
|
|
|
|
|
|
|
template<typename>
|
|
|
|
struct X3 : X2<int> {
|
|
|
|
X3() : X2<int>() { }
|
2011-04-18 05:49:47 +08:00
|
|
|
int i;
|
2010-08-23 01:20:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN8zeroinit9testX0_X3Ev
|
2010-08-23 01:20:18 +08:00
|
|
|
void testX0_X3() {
|
|
|
|
// CHECK-NOT: call void @llvm.memset
|
|
|
|
// CHECK: call void @_ZN8zeroinit2X3IiEC1Ev
|
|
|
|
// CHECK: call void @_ZN8zeroinit2X2IiE1fEv
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
X3<int>().f();
|
|
|
|
}
|
|
|
|
|
2011-07-09 09:37:26 +08:00
|
|
|
// More checks at EOF
|
2010-08-21 00:57:37 +08:00
|
|
|
}
|
2010-12-03 02:29:00 +08:00
|
|
|
|
|
|
|
namespace PR8726 {
|
|
|
|
class C;
|
|
|
|
struct S {
|
|
|
|
const C &c1;
|
|
|
|
int i;
|
|
|
|
const C &c2;
|
|
|
|
};
|
|
|
|
void f(const C& c) {
|
|
|
|
S s = {c, 42, c};
|
|
|
|
}
|
|
|
|
|
2010-12-21 10:36:58 +08:00
|
|
|
}
|
2011-07-09 09:37:26 +08:00
|
|
|
|
|
|
|
// rdar://problem/9355931
|
|
|
|
namespace test6 {
|
|
|
|
struct A { A(); A(int); };
|
|
|
|
|
|
|
|
void test() {
|
|
|
|
A arr[10][20] = { 5 };
|
|
|
|
};
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN5test64testEv()
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK: [[ARR:%.*]] = alloca [10 x [20 x [[A:%.*]]]],
|
|
|
|
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[INNER:%.*]] = getelementptr inbounds [10 x [20 x [[A]]]], [10 x [20 x [[A]]]]* [[ARR]], i64 0, i64 0
|
|
|
|
// CHECK-NEXT: [[T0:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 0, i64 0
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN5test61AC1Ei([[A]]* {{[^,]*}} [[T0]], i32 5)
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[BEGIN:%.*]] = getelementptr inbounds [[A]], [[A]]* [[T0]], i64 1
|
|
|
|
// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [[A]], [[A]]* [[T0]], i64 20
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[CUR:%.*]] = phi [[A]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* {{[^,]*}} [[CUR]])
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[NEXT]] = getelementptr inbounds [[A]], [[A]]* [[CUR]], i64 1
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[NEXT]], [[END]]
|
|
|
|
// CHECK-NEXT: br i1
|
|
|
|
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[BEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 1
|
|
|
|
// CHECK-NEXT: [[END:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[INNER]], i64 10
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NEXT: br label
|
|
|
|
// CHECK: [[CUR:%.*]] = phi [20 x [[A]]]* [ [[BEGIN]], {{%.*}} ], [ [[NEXT:%.*]], {{%.*}} ]
|
|
|
|
|
2011-07-13 14:10:41 +08:00
|
|
|
// Inner loop.
|
2018-06-13 10:06:28 +08:00
|
|
|
// CHECK-NEXT: [[IBEGIN:%.*]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[CUR]], i{{32|64}} 0, i{{32|64}} 0
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[IEND:%.*]] = getelementptr inbounds [[A]], [[A]]* [[IBEGIN]], i64 20
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NEXT: br label
|
2011-07-13 14:10:41 +08:00
|
|
|
// CHECK: [[ICUR:%.*]] = phi [[A]]* [ [[IBEGIN]], {{%.*}} ], [ [[INEXT:%.*]], {{%.*}} ]
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN5test61AC1Ev([[A]]* {{[^,]*}} [[ICUR]])
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK-NEXT: [[INEXT:%.*]] = getelementptr inbounds [[A]], [[A]]* [[ICUR]], i64 1
|
2011-07-13 14:10:41 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = icmp eq [[A]]* [[INEXT]], [[IEND]]
|
|
|
|
// CHECK-NEXT: br i1 [[T0]],
|
|
|
|
|
2015-02-28 03:18:17 +08:00
|
|
|
// CHECK: [[NEXT]] = getelementptr inbounds [20 x [[A]]], [20 x [[A]]]* [[CUR]], i64 1
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK-NEXT: [[T0:%.*]] = icmp eq [20 x [[A]]]* [[NEXT]], [[END]]
|
|
|
|
// CHECK-NEXT: br i1 [[T0]]
|
|
|
|
// CHECK: ret void
|
|
|
|
}
|
|
|
|
|
2011-10-14 10:27:24 +08:00
|
|
|
namespace PR11124 {
|
|
|
|
// Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
|
|
|
|
struct A { int a; A(); A(int); };
|
|
|
|
struct B : virtual A { int b; };
|
|
|
|
struct C : B { C(); };
|
|
|
|
C::C() : A(3), B() {}
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN7PR111241CC1Ev
|
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: call void @llvm.memset.p0i8.i64(i8* align 8 {{.*}}, i8 0, i64 12, i1 false)
|
2011-10-14 10:27:24 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN7PR111241BC2Ev
|
|
|
|
// Make sure C::C doesn't overwrite parts of A while it is zero-initializing B
|
|
|
|
|
|
|
|
struct B2 : virtual A { int B::*b; };
|
|
|
|
struct C2 : B2 { C2(); };
|
|
|
|
C2::C2() : A(3), B2() {}
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN7PR111242C2C1Ev
|
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: call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 8 %{{.*}}, i8* align 8 {{.*}}, i64 16, i1 false)
|
2011-10-14 10:27:24 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN7PR111242B2C2Ev
|
|
|
|
}
|
|
|
|
|
2012-12-21 11:17:28 +08:00
|
|
|
// Ensure we produce an i1 here, and don't assert.
|
2020-12-31 12:45:56 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z9r170806_bv(
|
2012-12-21 11:17:28 +08:00
|
|
|
// CHECK: call void @_Z9r170806_ab(i1 zeroext false)
|
|
|
|
void r170806_a(bool b = bool());
|
|
|
|
void r170806_b() { r170806_a(); }
|
|
|
|
|
2014-07-11 04:53:43 +08:00
|
|
|
namespace PR20256 {
|
|
|
|
struct data { int i; };
|
|
|
|
|
|
|
|
template<typename T = int>
|
|
|
|
data g() {
|
|
|
|
data d; // not value-init
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
template data g();
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR202561gIiEENS_4dataEv(
|
|
|
|
// CHECK-NOT: store
|
|
|
|
// CHECK-NOT: memset
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
template<typename ...T>
|
|
|
|
data h(T ...t) {
|
|
|
|
data d(t...); // value-init
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
template data h();
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR202561hIJEEENS_4dataEDpT_(
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
|
|
|
|
template<typename T = int>
|
|
|
|
data j() {
|
|
|
|
data d = {}; // value-init
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
template data j();
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR202561jIiEENS_4dataEv(
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
data f() {
|
|
|
|
data d; // not value-init
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR202561fEv(
|
|
|
|
// CHECK-NOT: store
|
|
|
|
// CHECK-NOT: memset
|
|
|
|
// CHECK: }
|
|
|
|
|
|
|
|
data i() {
|
|
|
|
data d = {}; // value-init
|
|
|
|
return d;
|
|
|
|
}
|
|
|
|
// CHECK-LABEL: define {{.*}} @_ZN7PR202561iEv(
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
// CHECK: }
|
|
|
|
}
|
|
|
|
|
2016-12-21 09:57:02 +08:00
|
|
|
// CHECK-LABEL: define {{.*}}@_Z20explicitly_defaultedv
|
|
|
|
int explicitly_defaulted() {
|
|
|
|
struct A { A() = default; int n; };
|
|
|
|
// CHECK: call void @llvm.memset
|
|
|
|
A a = A();
|
|
|
|
return a.n;
|
|
|
|
} // CHECK-LABEL: }
|
|
|
|
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN8zeroinit2X3IiEC2Ev(%"struct.zeroinit::X3"* {{[^,]*}} %this) unnamed_addr
|
2011-07-09 09:37:26 +08:00
|
|
|
// CHECK: call void @llvm.memset.p0i8.i64
|
|
|
|
// CHECK-NEXT: call void @_ZN8zeroinit2X2IiEC2Ev
|
|
|
|
// CHECK-NEXT: ret void
|
2018-06-13 10:06:28 +08:00
|
|
|
|
|
|
|
#if __cplusplus >= 201103L
|
|
|
|
namespace transparent_init_list {
|
|
|
|
struct optional_assign_base {};
|
|
|
|
struct optional_data_dtor_base { char dummy_[24]; };
|
|
|
|
struct optional : optional_data_dtor_base, optional_assign_base {};
|
|
|
|
optional f(optional a) { return {optional(a)}; }
|
|
|
|
}
|
|
|
|
#endif
|