2021-11-09 01:09:49 +08:00
|
|
|
// RUN: %clang_cc1 -triple armv7-none-eabi -emit-llvm -o - %s | FileCheck %s
|
2009-12-25 07:33:34 +08:00
|
|
|
|
|
|
|
struct A { int x; A(int); ~A(); };
|
|
|
|
A f() { return A(0); }
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_Z1fv
|
2011-06-14 06:51:21 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN1AC1Ei
|
2009-12-25 07:33:34 +08:00
|
|
|
// CHECK-NEXT: ret void
|
2010-08-23 02:27:02 +08:00
|
|
|
|
|
|
|
// Verify that we do not elide copies when constructing a base class.
|
|
|
|
namespace no_elide_base {
|
2018-10-15 23:43:00 +08:00
|
|
|
struct Base {
|
2010-08-23 02:27:02 +08:00
|
|
|
Base(const Base&);
|
|
|
|
~Base();
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Other {
|
|
|
|
operator Base() const;
|
|
|
|
};
|
|
|
|
|
2018-10-15 23:43:00 +08:00
|
|
|
struct Derived : public virtual Base {
|
2010-08-23 02:27:02 +08:00
|
|
|
Derived(const Other &O);
|
|
|
|
};
|
|
|
|
|
2020-11-17 07:04:55 +08:00
|
|
|
// CHECK: define {{.*}} @_ZN13no_elide_base7DerivedC1ERKNS_5OtherE(%"struct.no_elide_base::Derived"* {{[^,]*}} returned {{[^,]*}} %this, %"struct.no_elide_base::Other"* nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %O) unnamed_addr
|
2018-10-15 23:43:00 +08:00
|
|
|
Derived::Derived(const Other &O)
|
2011-06-14 06:51:21 +08:00
|
|
|
// CHECK: call {{.*}} @_ZNK13no_elide_base5OthercvNS_4BaseEEv
|
|
|
|
// CHECK: call {{.*}} @_ZN13no_elide_base4BaseC2ERKS0_
|
|
|
|
// CHECK: call {{.*}} @_ZN13no_elide_base4BaseD1Ev
|
2010-08-23 02:27:02 +08:00
|
|
|
: Base(O)
|
|
|
|
{
|
2011-06-14 06:51:21 +08:00
|
|
|
// CHECK: ret
|
2010-08-23 02:27:02 +08:00
|
|
|
}
|
|
|
|
}
|
2010-11-29 00:40:49 +08:00
|
|
|
|
|
|
|
// PR8683.
|
|
|
|
|
|
|
|
namespace PR8683 {
|
|
|
|
|
|
|
|
struct A {
|
|
|
|
A();
|
|
|
|
A(const A&);
|
|
|
|
A& operator=(const A&);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct B {
|
|
|
|
A a;
|
|
|
|
};
|
|
|
|
|
|
|
|
void f() {
|
|
|
|
// Verify that we don't mark the copy constructor in this expression as elidable.
|
2011-06-15 05:20:53 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN6PR86831AC1ERKS0_
|
2010-11-29 00:40:49 +08:00
|
|
|
A a = (B().a);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-03-10 14:53:13 +08:00
|
|
|
|
|
|
|
namespace PR12139 {
|
|
|
|
struct A {
|
|
|
|
A() : value(1) { }
|
|
|
|
A(A const &, int value = 2) : value(value) { }
|
|
|
|
int value;
|
|
|
|
|
|
|
|
static A makeA() { A a; a.value = 2; return a; }
|
|
|
|
};
|
|
|
|
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} i32 @_ZN7PR121394testEv
|
2012-03-10 14:53:13 +08:00
|
|
|
int test() {
|
|
|
|
// CHECK: call void @_ZN7PR121391A5makeAEv
|
2012-09-11 07:06:08 +08:00
|
|
|
// CHECK-NEXT: call %"struct.PR12139::A"* @_ZN7PR121391AC1ERKS0_i
|
2012-03-10 14:53:13 +08:00
|
|
|
A a(A::makeA(), 3);
|
|
|
|
// CHECK-NEXT: getelementptr inbounds
|
|
|
|
// CHECK-NEXT: load
|
|
|
|
// CHECK-NEXT: ret i32
|
|
|
|
return a.value;
|
|
|
|
}
|
|
|
|
}
|
2016-09-07 10:14:33 +08:00
|
|
|
|
|
|
|
namespace ElidableCallIsNotCopyCtor {
|
|
|
|
struct A { A(const A&); };
|
|
|
|
struct B : A {
|
|
|
|
B(B&);
|
|
|
|
B(A);
|
|
|
|
B(int);
|
|
|
|
};
|
|
|
|
void f() {
|
|
|
|
// Here, we construct via B(int) then B(A). The B(A) construction is
|
|
|
|
// elidable, but we don't have an AST representation for the case where we
|
|
|
|
// must elide not only a constructor call but also some argument
|
|
|
|
// conversions, so we don't elide it.
|
2020-12-31 16:27:11 +08:00
|
|
|
// CHECK-LABEL: define{{.*}} void @_ZN25ElidableCallIsNotCopyCtor1fEv(
|
2016-09-07 10:14:33 +08:00
|
|
|
// CHECK: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1BC1Ei(
|
|
|
|
// CHECK: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1AC1ERKS0_(
|
|
|
|
// CHECK: call {{.*}} @_ZN25ElidableCallIsNotCopyCtor1BC1ENS_1AE(
|
|
|
|
B b = 0;
|
|
|
|
}
|
|
|
|
}
|