blob: feeae85cc12a71545ec63e357534dafd7336dc3f [file] [log] [blame]
Axel Naumann63469422c2012-10-02 09:09:43 +00001// RUN: rm -rf %t
Richard Smith0b87e072013-10-07 08:02:11 +00002// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs -verify %s -Wno-objc-root-class
3// RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | FileCheck %s
Andy Gibbsc6e68da2012-10-19 12:44:48 +00004// expected-no-diagnostics
Axel Naumann63469422c2012-10-02 09:09:43 +00005
Douglas Gregorc50d4922012-12-11 22:11:52 +00006@import templates_left;
7@import templates_right;
Axel Naumann63469422c2012-10-02 09:09:43 +00008
Richard Smith0b87e072013-10-07 08:02:11 +00009// CHECK: @list_left = global { %{{.*}}*, i32, [4 x i8] } { %{{.*}}* null, i32 8,
10// CHECK: @list_right = global { %{{.*}}*, i32, [4 x i8] } { %{{.*}}* null, i32 12,
11// CHECK: @_ZZ15testMixedStructvE1l = {{.*}} constant { %{{.*}}*, i32, [4 x i8] } { %{{.*}}* null, i32 1,
12// CHECK: @_ZZ15testMixedStructvE1r = {{.*}} constant { %{{.*}}*, i32, [4 x i8] } { %{{.*}}* null, i32 2,
Axel Naumann63469422c2012-10-02 09:09:43 +000013
14void testTemplateClasses() {
15 Vector<int> vec_int;
16 vec_int.push_back(0);
17
18 List<bool> list_bool;
19 list_bool.push_back(false);
20
21 N::Set<char> set_char;
22 set_char.insert('A');
Richard Smithcd45dbc2014-04-19 03:48:30 +000023
24 List<double> list_double;
25 list_double.push_back(0.0);
Axel Naumann63469422c2012-10-02 09:09:43 +000026}
27
28void testPendingInstantiations() {
Axel Naumannd9a25b32012-10-02 12:18:46 +000029 // CHECK: call {{.*pendingInstantiationEmit}}
30 // CHECK: call {{.*pendingInstantiationEmit}}
31 // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
32 // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
Axel Naumann63469422c2012-10-02 09:09:43 +000033 triggerPendingInstantiation();
34 triggerPendingInstantiationToo();
35}
Axel Naumannd9a25b32012-10-02 12:18:46 +000036
37void testRedeclDefinition() {
38 // CHECK: define {{.*redeclDefinitionEmit}}
39 redeclDefinitionEmit();
40}
41
Richard Smitheb36ddf2014-04-24 22:45:46 +000042// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
43// CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv(
44// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv(
45// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
46
Richard Smithd55889a2013-09-09 16:55:27 +000047// These three are all the same type.
48typedef OuterIntInner_left OuterIntInner;
49typedef OuterIntInner_right OuterIntInner;
50typedef Outer<int>::Inner OuterIntInner;
51
Axel Naumannd9a25b32012-10-02 12:18:46 +000052// CHECK: call {{.*pendingInstantiation}}
53// CHECK: call {{.*redeclDefinitionEmit}}
Richard Smith0b87e072013-10-07 08:02:11 +000054
55static_assert(size_left == size_right, "same field both ways");
56void useListInt(List<int> &);
57
58// CHECK-LABEL: define i32 @_Z15testMixedStructv(
59unsigned testMixedStruct() {
60 // CHECK: %[[l:.*]] = alloca %[[ListInt:[^ ]*]], align 8
61 // CHECK: %[[r:.*]] = alloca %[[ListInt]], align 8
62
63 // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1l to i8*), i64 16,
64 ListInt_left l{0, 1};
65
66 // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1r to i8*), i64 16,
67 ListInt_right r{0, 2};
68
69 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* %[[l]])
70 useListInt(l);
71 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* %[[r]])
72 useListInt(r);
73
74 // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*)
75 // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*)
76 return list_left.*size_right + list_right.*size_left;
77}
Richard Smithf17fdbd2014-04-24 02:25:27 +000078
79template<typename T> struct MergePatternDecl {
80 typedef int Type;
81 void f(Type);
82};
83template<typename T> void MergePatternDecl<T>::f(Type type) {}
Richard Smitheb36ddf2014-04-24 22:45:46 +000084// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv(
85template struct ExplicitInstantiation<false, true>;
86template struct ExplicitInstantiation<true, true>;