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