Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | 4ed0122 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 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 |
Andy Gibbs | 8e8fb3b | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 4 | // expected-no-diagnostics |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 5 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 6 | @import templates_left; |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 7 | |
| 8 | void testInlineRedeclEarly() { |
| 9 | // instantiate definition now, we'll add another declaration in _right. |
| 10 | OutOfLineInline<int>().h(); |
| 11 | } |
| 12 | |
Douglas Gregor | 1b257af | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 13 | @import templates_right; |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 14 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 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 |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 20 | |
| 21 | void 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'); |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 30 | |
| 31 | List<double> list_double; |
| 32 | list_double.push_back(0.0); |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | void testPendingInstantiations() { |
Axel Naumann | 38c3bb4 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 36 | // CHECK: call {{.*pendingInstantiationEmit}} |
| 37 | // CHECK: call {{.*pendingInstantiationEmit}} |
| 38 | // CHECK: define {{.*pendingInstantiationEmit.*[(]i}} |
| 39 | // CHECK: define {{.*pendingInstantiationEmit.*[(]double}} |
Axel Naumann | 39d26c3 | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 40 | triggerPendingInstantiation(); |
| 41 | triggerPendingInstantiationToo(); |
| 42 | } |
Axel Naumann | 38c3bb4 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 43 | |
| 44 | void testRedeclDefinition() { |
| 45 | // CHECK: define {{.*redeclDefinitionEmit}} |
| 46 | redeclDefinitionEmit(); |
| 47 | } |
| 48 | |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 49 | void testInlineRedecl() { |
| 50 | outOfLineInlineUseLeftF(); |
| 51 | outOfLineInlineUseRightG(); |
| 52 | |
| 53 | outOfLineInlineUseRightF(); |
| 54 | outOfLineInlineUseLeftG(); |
| 55 | } |
| 56 | |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 57 | // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv( |
| 58 | // CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv( |
| 59 | // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv( |
| 60 | // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv( |
| 61 | |
Richard Smith | b60fae5 | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 62 | // These three are all the same type. |
| 63 | typedef OuterIntInner_left OuterIntInner; |
| 64 | typedef OuterIntInner_right OuterIntInner; |
| 65 | typedef Outer<int>::Inner OuterIntInner; |
| 66 | |
Axel Naumann | 38c3bb4 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 67 | // CHECK: call {{.*pendingInstantiation}} |
| 68 | // CHECK: call {{.*redeclDefinitionEmit}} |
Richard Smith | 4ed0122 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 69 | |
| 70 | static_assert(size_left == size_right, "same field both ways"); |
| 71 | void useListInt(List<int> &); |
| 72 | |
| 73 | // CHECK-LABEL: define i32 @_Z15testMixedStructv( |
| 74 | unsigned 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 | |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 84 | // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[l]]) |
Richard Smith | 4ed0122 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 85 | useListInt(l); |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 86 | // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]]) |
Richard Smith | 4ed0122 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 87 | useListInt(r); |
| 88 | |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 89 | // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*) |
| 90 | // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*) |
Richard Smith | 4ed0122 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 91 | return list_left.*size_right + list_right.*size_left; |
| 92 | } |
Stephen Hines | 6bcf27b | 2014-05-29 04:14:42 -0700 | [diff] [blame] | 93 | |
| 94 | template<typename T> struct MergePatternDecl { |
| 95 | typedef int Type; |
| 96 | void f(Type); |
| 97 | }; |
| 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>; |
| 102 | |
| 103 | void testDelayUpdatesImpl() { testDelayUpdates<int>(); } |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 104 | |
| 105 | void testStaticDataMember() { |
| 106 | WithUndefinedStaticDataMember<int[]> load_it; |
| 107 | |
| 108 | // CHECK-LABEL: define linkonce_odr i32* @_Z23getStaticDataMemberLeftv( |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 109 | // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 110 | (void) getStaticDataMemberLeft(); |
| 111 | |
| 112 | // CHECK-LABEL: define linkonce_odr i32* @_Z24getStaticDataMemberRightv( |
Pirama Arumuga Nainar | 3ea9e33 | 2015-04-08 08:57:32 -0700 | [diff] [blame] | 113 | // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0) |
Stephen Hines | 176edba | 2014-12-01 14:53:08 -0800 | [diff] [blame] | 114 | (void) getStaticDataMemberRight(); |
| 115 | } |
| 116 | |
| 117 | |