2015-01-22 08:24:57 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple x86_64-apple-macosx10.7.0 -emit-llvm -o - %s -w | FileCheck %s
|
2012-02-21 03:44:39 +08:00
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_Z11inline_funci
|
2012-02-21 03:44:39 +08:00
|
|
|
inline void inline_func(int n) {
|
|
|
|
// CHECK: call i32 @_ZZ11inline_funciENKUlvE_clEv
|
|
|
|
int i = []{ return 1; }();
|
|
|
|
|
|
|
|
// CHECK: call i32 @_ZZ11inline_funciENKUlvE0_clEv
|
|
|
|
int j = [=] { return n + i; }();
|
|
|
|
|
|
|
|
// CHECK: call double @_ZZ11inline_funciENKUlvE1_clEv
|
|
|
|
int k = [=] () -> double { return n + i; }();
|
|
|
|
|
|
|
|
// CHECK: call i32 @_ZZ11inline_funciENKUliE_clEi
|
|
|
|
int l = [=] (int x) -> int { return x + i; }(n);
|
|
|
|
|
2012-02-21 12:17:39 +08:00
|
|
|
int inner(int i = []{ return 17; }());
|
2012-02-21 08:37:24 +08:00
|
|
|
// CHECK: call i32 @_ZZ11inline_funciENKUlvE2_clEv
|
|
|
|
// CHECK-NEXT: call i32 @_Z5inneri
|
|
|
|
inner();
|
|
|
|
|
|
|
|
// CHECK-NEXT: ret void
|
2012-02-21 03:44:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void call_inline_func() {
|
|
|
|
inline_func(17);
|
|
|
|
}
|
2012-02-21 08:37:24 +08:00
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32* @_ZNK10inline_varMUlvE_clEv(
|
|
|
|
// CHECK: @_ZZNK10inline_varMUlvE_clEvE1n
|
|
|
|
inline auto inline_var = [] {
|
|
|
|
static int n = 5;
|
|
|
|
return &n;
|
|
|
|
};
|
|
|
|
|
|
|
|
int *use_inline_var = inline_var();
|
|
|
|
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32* @_ZNK12var_templateIiEMUlvE_clEv(
|
|
|
|
// CHECK: @_ZZNK12var_templateIiEMUlvE_clEvE1n
|
|
|
|
template<typename T> auto var_template = [] {
|
|
|
|
static int n = 9;
|
|
|
|
return &n;
|
|
|
|
};
|
|
|
|
|
|
|
|
int *use_var_template = var_template<int>();
|
|
|
|
|
2012-02-21 08:37:24 +08:00
|
|
|
struct S {
|
|
|
|
void f(int = []{return 1;}()
|
|
|
|
+ []{return 2;}(),
|
|
|
|
int = []{return 3;}());
|
|
|
|
void g(int, int);
|
|
|
|
};
|
|
|
|
|
|
|
|
void S::g(int i = []{return 1;}(),
|
|
|
|
int j = []{return 2; }()) {}
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z6test_S1S
|
2012-02-21 08:37:24 +08:00
|
|
|
void test_S(S s) {
|
|
|
|
// CHECK: call i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
|
|
|
|
// CHECK-NEXT: call i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
|
|
|
|
// CHECK-NEXT: add nsw i32
|
|
|
|
// CHECK-NEXT: call i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
|
|
|
|
// CHECK-NEXT: call void @_ZN1S1fEii
|
|
|
|
s.f();
|
|
|
|
|
|
|
|
// NOTE: These manglings don't actually matter that much, because
|
|
|
|
// the lambdas in the default arguments of g() won't be seen by
|
|
|
|
// multiple translation units. We check them mainly to ensure that they don't
|
|
|
|
// get the special mangling for lambdas in in-class default arguments.
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: call i32 @"_ZNK1S3$_0clEv"
|
|
|
|
// CHECK-NEXT: call i32 @"_ZNK1S3$_1clEv"
|
2012-02-21 08:37:24 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN1S1gEi
|
|
|
|
s.g();
|
|
|
|
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
|
|
|
|
2012-02-21 12:17:39 +08:00
|
|
|
// Check the linkage of the lambda call operators used in test_S.
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 1
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd0_NKUlvE0_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 2
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZN1S1fEiiEd_NKUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 3
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal i32 @"_ZNK1S3$_0clEv"
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 1
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal i32 @"_ZNK1S3$_1clEv"
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 2
|
|
|
|
|
2012-02-21 08:37:24 +08:00
|
|
|
template<typename T>
|
|
|
|
struct ST {
|
|
|
|
void f(T = []{return T() + 1;}()
|
|
|
|
+ []{return T() + 2;}(),
|
|
|
|
T = []{return T(3);}());
|
|
|
|
};
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z7test_ST2STIdE
|
2012-02-21 08:37:24 +08:00
|
|
|
void test_ST(ST<double> st) {
|
2012-07-23 07:45:10 +08:00
|
|
|
// CHECK: call double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
|
|
|
|
// CHECK-NEXT: call double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
|
2012-02-21 08:37:24 +08:00
|
|
|
// CHECK-NEXT: fadd double
|
2012-07-23 07:45:10 +08:00
|
|
|
// CHECK-NEXT: call double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
|
2012-02-21 08:37:24 +08:00
|
|
|
// CHECK-NEXT: call void @_ZN2STIdE1fEdd
|
|
|
|
st.f();
|
|
|
|
|
|
|
|
// CHECK-NEXT: ret void
|
|
|
|
}
|
2012-02-21 10:22:07 +08:00
|
|
|
|
2012-02-21 12:17:39 +08:00
|
|
|
// Check the linkage of the lambda call operators used in test_ST.
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret double 1
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd0_NKUlvE0_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret double 2
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr double @_ZZN2STIdE1fEddEd_NKUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret double 3
|
|
|
|
|
2012-02-21 10:22:07 +08:00
|
|
|
template<typename T>
|
|
|
|
struct StaticMembers {
|
|
|
|
static T x;
|
|
|
|
static T y;
|
|
|
|
static T z;
|
2013-06-14 03:39:48 +08:00
|
|
|
static int (*f)();
|
2012-02-21 10:22:07 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
template<typename T> int accept_lambda(T);
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T StaticMembers<T>::x = []{return 1;}() + []{return 2;}();
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T StaticMembers<T>::y = []{return 3;}();
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
T StaticMembers<T>::z = accept_lambda([]{return 4;});
|
|
|
|
|
2013-06-14 03:39:48 +08:00
|
|
|
template<typename T>
|
|
|
|
int (*StaticMembers<T>::f)() = []{return 5;};
|
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
2012-02-21 10:22:07 +08:00
|
|
|
// CHECK: call i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
|
|
|
|
// CHECK-NEXT: call i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
|
|
|
|
// CHECK-NEXT: add nsw
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 1
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1xMUlvE0_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 2
|
2012-02-21 10:22:07 +08:00
|
|
|
template float StaticMembers<float>::x;
|
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
2012-02-21 10:22:07 +08:00
|
|
|
// CHECK: call i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK13StaticMembersIfE1yMUlvE_clEv
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 3
|
2012-02-21 10:22:07 +08:00
|
|
|
template float StaticMembers<float>::y;
|
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
2012-02-21 10:22:07 +08:00
|
|
|
// CHECK: call i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: declare i32 @_Z13accept_lambdaIN13StaticMembersIfE1zMUlvE_EEiT_()
|
2012-02-21 10:22:07 +08:00
|
|
|
template float StaticMembers<float>::z;
|
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
2013-06-14 03:39:48 +08:00
|
|
|
// CHECK: call {{.*}} @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr i32 ()* @_ZNK13StaticMembersIfE1fMUlvE_cvPFivEEv
|
2013-06-14 03:39:48 +08:00
|
|
|
template int (*StaticMembers<float>::f)();
|
|
|
|
|
2017-09-22 12:25:05 +08:00
|
|
|
// CHECK-LABEL: define internal void @__cxx_global_var_init
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: call i32 @"_ZNK13StaticMembersIdE3$_2clEv"
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define internal i32 @"_ZNK13StaticMembersIdE3$_2clEv"
|
2012-02-21 12:17:39 +08:00
|
|
|
// CHECK: ret i32 42
|
|
|
|
template<> double StaticMembers<double>::z = []{return 42; }();
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void func_template(T = []{ return T(); }());
|
|
|
|
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define void @_Z17use_func_templatev()
|
2012-02-21 12:17:39 +08:00
|
|
|
void use_func_template() {
|
2013-07-03 01:52:28 +08:00
|
|
|
// CHECK: call i32 @"_ZZ13func_templateIiEvT_ENK3$_3clEv"
|
2012-02-21 12:17:39 +08:00
|
|
|
func_template<int>();
|
|
|
|
}
|
|
|
|
|
2012-09-26 12:34:21 +08:00
|
|
|
namespace std {
|
2019-10-10 09:14:22 +08:00
|
|
|
struct type_info {
|
|
|
|
bool before(const type_info &) const noexcept;
|
|
|
|
};
|
2012-09-26 12:34:21 +08:00
|
|
|
}
|
|
|
|
namespace PR12123 {
|
|
|
|
struct A { virtual ~A(); } g;
|
2019-10-10 09:14:22 +08:00
|
|
|
struct C { virtual ~C(); } k;
|
2012-09-26 12:34:21 +08:00
|
|
|
struct B {
|
|
|
|
void f(const std::type_info& x = typeid([]()->A& { return g; }()));
|
|
|
|
void h();
|
2019-10-10 09:14:22 +08:00
|
|
|
void j(bool cond = typeid([]() -> A & { return g; }()).before(typeid([]() -> C & { return k; }())));
|
2012-09-26 12:34:21 +08:00
|
|
|
};
|
2019-10-10 09:14:22 +08:00
|
|
|
void B::h() { f(); j(); }
|
2012-09-26 12:34:21 +08:00
|
|
|
}
|
2015-01-22 08:24:57 +08:00
|
|
|
|
2020-05-19 02:29:11 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1fERKSt9type_infoEd_NKUlvE_clEv
|
|
|
|
// CHECK-LABEL: define linkonce_odr nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::A"* @_ZZN7PR121231B1jEbEd_NKUlvE_clEv
|
|
|
|
// CHECK-LABEL: define linkonce_odr nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %"struct.PR12123::C"* @_ZZN7PR121231B1jEbEd_NKUlvE0_clEv
|
2012-09-26 12:34:21 +08:00
|
|
|
|
2016-10-23 12:53:03 +08:00
|
|
|
// CHECK-LABEL: define {{.*}} @_Z{{[0-9]*}}testVarargsLambdaNumberingv(
|
|
|
|
inline int testVarargsLambdaNumbering() {
|
|
|
|
// CHECK: testVarargsLambdaNumberingvE{{.*}}UlzE_
|
|
|
|
auto a = [](...) { static int n; return ++n; };
|
|
|
|
// CHECK: testVarargsLambdaNumberingvE{{.*}}UlvE_
|
|
|
|
auto b = []() { static int n; return ++n; };
|
|
|
|
return a() + b();
|
|
|
|
}
|
|
|
|
int k = testVarargsLambdaNumbering();
|
|
|
|
|
2015-01-22 08:24:57 +08:00
|
|
|
// Check linkage of the various lambdas.
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE_clEv
|
|
|
|
// CHECK: ret i32 1
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE0_clEv
|
|
|
|
// CHECK: ret i32
|
|
|
|
// CHECK-LABEL: define linkonce_odr double @_ZZ11inline_funciENKUlvE1_clEv
|
|
|
|
// CHECK: ret double
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUliE_clEi
|
|
|
|
// CHECK: ret i32
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZ11inline_funciENKUlvE2_clEv
|
|
|
|
// CHECK: ret i32 17
|
|
|
|
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZN7MembersC2Ev
|
|
|
|
// CHECK: call i32 @_ZNK7Members1xMUlvE_clEv
|
|
|
|
// CHECK-NEXT: call i32 @_ZNK7Members1xMUlvE0_clE
|
|
|
|
// CHECK-NEXT: add nsw i32
|
|
|
|
// CHECK: call i32 @_ZNK7Members1yMUlvE_clEv
|
|
|
|
// CHECK: ret void
|
|
|
|
|
|
|
|
|
|
|
|
// Check the linkage of the lambdas used in test_Members.
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE_clEv
|
|
|
|
// CHECK: ret i32 1
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1xMUlvE0_clEv
|
|
|
|
// CHECK: ret i32 2
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZNK7Members1yMUlvE_clEv
|
|
|
|
// CHECK: ret i32 3
|
|
|
|
|
|
|
|
// CHECK-LABEL: define linkonce_odr void @_Z1fIZZNK23TestNestedInstantiationclEvENKUlvE_clEvEUlvE_EvT_
|
|
|
|
|
|
|
|
|
2012-09-19 09:35:20 +08:00
|
|
|
namespace PR12808 {
|
|
|
|
template <typename> struct B {
|
|
|
|
int a;
|
|
|
|
template <typename L> constexpr B(L&& x) : a(x()) { }
|
|
|
|
};
|
|
|
|
template <typename> void b(int) {
|
|
|
|
[&]{ (void)B<int>([&]{ return 1; }); }();
|
|
|
|
}
|
|
|
|
void f() {
|
|
|
|
b<int>(1);
|
|
|
|
}
|
2013-08-15 14:47:53 +08:00
|
|
|
// CHECK-LABEL: define linkonce_odr void @_ZZN7PR128081bIiEEviENKUlvE_clEv
|
|
|
|
// CHECK-LABEL: define linkonce_odr i32 @_ZZZN7PR128081bIiEEviENKUlvE_clEvENKUlvE_clEv
|
2012-09-19 09:35:20 +08:00
|
|
|
}
|
2012-07-23 07:45:10 +08:00
|
|
|
|
2012-04-05 01:40:10 +08:00
|
|
|
|
2012-02-21 10:22:07 +08:00
|
|
|
struct Members {
|
|
|
|
int x = [] { return 1; }() + [] { return 2; }();
|
|
|
|
int y = [] { return 3; }();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_Members() {
|
|
|
|
Members members;
|
|
|
|
}
|
2012-02-21 12:17:39 +08:00
|
|
|
|
2012-04-05 01:40:10 +08:00
|
|
|
template<typename P> void f(P) { }
|
|
|
|
|
|
|
|
struct TestNestedInstantiation {
|
|
|
|
void operator()() const {
|
|
|
|
[]() -> void {
|
|
|
|
return f([]{});
|
|
|
|
}();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_NestedInstantiation() {
|
|
|
|
TestNestedInstantiation()();
|
|
|
|
}
|