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
6 @import templates_left;
8 void testInlineRedeclEarly() {
9 // instantiate definition now, we'll add another declaration in _right.
10 OutOfLineInline<int>().h();
13 @import templates_right;
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
21 void testTemplateClasses() {
26 list_bool.push_back(false);
28 N::Set<char> set_char;
31 List<double> list_double;
32 list_double.push_back(0.0);
35 void testPendingInstantiations() {
36 // CHECK: call {{.*pendingInstantiationEmit}}
37 // CHECK: call {{.*pendingInstantiationEmit}}
38 // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
39 // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
40 triggerPendingInstantiation();
41 triggerPendingInstantiationToo();
44 void testRedeclDefinition() {
45 // CHECK: define {{.*redeclDefinitionEmit}}
46 redeclDefinitionEmit();
49 void testInlineRedecl() {
50 outOfLineInlineUseLeftF();
51 outOfLineInlineUseRightG();
53 outOfLineInlineUseRightF();
54 outOfLineInlineUseLeftG();
57 // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
58 // CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv(
59 // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv(
60 // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
62 // These three are all the same type.
63 typedef OuterIntInner_left OuterIntInner;
64 typedef OuterIntInner_right OuterIntInner;
65 typedef Outer<int>::Inner OuterIntInner;
67 // CHECK: call {{.*pendingInstantiation}}
68 // CHECK: call {{.*redeclDefinitionEmit}}
70 static_assert(size_left == size_right, "same field both ways");
71 void useListInt(List<int> &);
73 // CHECK-LABEL: define i32 @_Z15testMixedStructv(
74 unsigned testMixedStruct() {
75 // CHECK: %[[l:.*]] = alloca %[[ListInt:[^ ]*]], align 8
76 // CHECK: %[[r:.*]] = alloca %[[ListInt]], align 8
78 // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1l to i8*), i64 16,
81 // CHECK: call {{.*}}memcpy{{.*}}(i8* %{{.*}}, i8* bitcast ({{.*}}* @_ZZ15testMixedStructvE1r to i8*), i64 16,
82 ListInt_right r{0, 2};
84 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[l]])
86 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]])
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;
94 template<typename T> struct MergePatternDecl {
98 template<typename T> void MergePatternDecl<T>::f(Type type) {}
99 // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv(
100 template struct ExplicitInstantiation<false, true>;
101 template struct ExplicitInstantiation<true, true>;
103 void testDelayUpdatesImpl() { testDelayUpdates<int>(); }
105 void testStaticDataMember() {
106 WithUndefinedStaticDataMember<int[]> load_it;
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();
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();