1// RUN: rm -rf %t
2// 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
4// expected-no-diagnostics
5
6@import templates_left;
7
8void testInlineRedeclEarly() {
9  // instantiate definition now, we'll add another declaration in _right.
10  OutOfLineInline<int>().h();
11}
12
13@import templates_right;
14
15// CHECK-DAG: @list_left = global %class.List { %"struct.List<int>::node"* null, i32 8 }, align 8
16// CHECK-DAG: @list_right = global %class.List { %"struct.List<int>::node"* null, i32 12 }, align 8
17// CHECK-DAG: @_ZZ15testMixedStructvE1l = {{.*}} constant %class.List { %{{.*}}* null, i32 1 }, align 8
18// CHECK-DAG: @_ZZ15testMixedStructvE1r = {{.*}} constant %class.List { %{{.*}}* null, i32 2 }, align 8
19// CHECK-DAG: @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE = external global
20
21void testTemplateClasses() {
22  Vector<int> vec_int;
23  vec_int.push_back(0);
24
25  List<bool> list_bool;
26  list_bool.push_back(false);
27
28  N::Set<char> set_char;
29  set_char.insert('A');
30
31  List<double> list_double;
32  list_double.push_back(0.0);
33}
34
35void testPendingInstantiations() {
36  // CHECK: call {{.*pendingInstantiationEmit}}
37  // CHECK: call {{.*pendingInstantiationEmit}}
38  // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
39  // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
40  triggerPendingInstantiation();
41  triggerPendingInstantiationToo();
42}
43
44void testRedeclDefinition() {
45  // CHECK: define {{.*redeclDefinitionEmit}}
46  redeclDefinitionEmit();
47}
48
49void testInlineRedecl() {
50  outOfLineInlineUseLeftF();
51  outOfLineInlineUseRightG();
52
53  outOfLineInlineUseRightF();
54  outOfLineInlineUseLeftG();
55}
56
57// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
58// CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv(
59// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv(
60// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
61
62// These three are all the same type.
63typedef OuterIntInner_left OuterIntInner;
64typedef OuterIntInner_right OuterIntInner;
65typedef Outer<int>::Inner OuterIntInner;
66
67// CHECK: call {{.*pendingInstantiation}}
68// CHECK: call {{.*redeclDefinitionEmit}}
69
70static_assert(size_left == size_right, "same field both ways");
71void useListInt(List<int> &);
72
73// CHECK-LABEL: define i32 @_Z15testMixedStructv(
74unsigned testMixedStruct() {
75  // CHECK: %[[l:.*]] = alloca %[[ListInt:[^ ]*]], align 8
76  // CHECK: %[[r:.*]] = alloca %[[ListInt]], align 8
77
78  // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1l to i8*), i64 16,
79  ListInt_left l{0, 1};
80
81  // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1r to i8*), i64 16,
82  ListInt_right r{0, 2};
83
84  // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[l]])
85  useListInt(l);
86  // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]])
87  useListInt(r);
88
89  // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*)
90  // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*)
91  return list_left.*size_right + list_right.*size_left;
92}
93
94template<typename T> struct MergePatternDecl {
95  typedef int Type;
96  void f(Type);
97};
98template<typename T> void MergePatternDecl<T>::f(Type type) {}
99// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv(
100template struct ExplicitInstantiation<false, true>;
101template struct ExplicitInstantiation<true, true>;
102
103void testDelayUpdatesImpl() { testDelayUpdates<int>(); }
104
105void testStaticDataMember() {
106  WithUndefinedStaticDataMember<int[]> load_it;
107
108  // CHECK-LABEL: define linkonce_odr i32* @_Z23getStaticDataMemberLeftv(
109  // CHECK: ret i32* getelementptr inbounds ([0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
110  (void) getStaticDataMemberLeft();
111
112  // CHECK-LABEL: define linkonce_odr i32* @_Z24getStaticDataMemberRightv(
113  // CHECK: ret i32* getelementptr inbounds ([0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
114  (void) getStaticDataMemberRight();
115}
116
117
118