Axel Naumann | 63469422c | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 1 | // RUN: rm -rf %t |
Richard Smith | 47972af | 2015-06-16 00:08:24 +0000 | [diff] [blame] | 2 | // RUN: %clang_cc1 -triple x86_64-linux-gnu -std=c++11 -x objective-c++ -fmodules -fimplicit-module-maps -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 -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs -emit-llvm %s -o - -Wno-objc-root-class | FileCheck %s |
Andy Gibbs | c6e68da | 2012-10-19 12:44:48 +0000 | [diff] [blame] | 4 | // expected-no-diagnostics |
Adrian Prantl | bc06858 | 2015-07-08 01:00:30 +0000 | [diff] [blame] | 5 | // REQUIRES: x86-registered-target |
Douglas Gregor | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 6 | @import templates_left; |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [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 | c50d492 | 2012-12-11 22:11:52 +0000 | [diff] [blame] | 13 | @import templates_right; |
Axel Naumann | 63469422c | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 14 | |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 15 | // CHECK-DAG: @list_left = global %[[LIST:.*]] { %[[LISTNODE:.*]]* null, i32 8 }, align 8 |
| 16 | // CHECK-DAG: @list_right = global %[[LIST]] { %[[LISTNODE]]* null, i32 12 }, align 8 |
JF Bastien | 3a881e6 | 2018-11-15 00:19:18 +0000 | [diff] [blame] | 17 | // CHECK-DAG: @__const._Z15testMixedStructv.l = {{.*}} constant %[[LIST]] { %{{.*}}* null, i32 1 }, align 8 |
| 18 | // CHECK-DAG: @__const._Z15testMixedStructv.r = {{.*}} constant %[[LIST]] { %{{.*}}* null, i32 2 }, align 8 |
Richard Smith | 73b21d8 | 2014-09-03 02:33:22 +0000 | [diff] [blame] | 19 | // CHECK-DAG: @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE = external global |
Axel Naumann | 63469422c | 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'); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 30 | |
Richard Smith | 9c9173d | 2015-08-11 22:00:24 +0000 | [diff] [blame] | 31 | static_assert(sizeof(List<long>) == sizeof(List<short>), ""); |
| 32 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 33 | List<double> list_double; |
| 34 | list_double.push_back(0.0); |
Axel Naumann | 63469422c | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | void testPendingInstantiations() { |
Axel Naumann | d9a25b3 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 38 | // CHECK: call {{.*pendingInstantiationEmit}} |
| 39 | // CHECK: call {{.*pendingInstantiationEmit}} |
| 40 | // CHECK: define {{.*pendingInstantiationEmit.*[(]i}} |
| 41 | // CHECK: define {{.*pendingInstantiationEmit.*[(]double}} |
Axel Naumann | 63469422c | 2012-10-02 09:09:43 +0000 | [diff] [blame] | 42 | triggerPendingInstantiation(); |
| 43 | triggerPendingInstantiationToo(); |
| 44 | } |
Axel Naumann | d9a25b3 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 45 | |
| 46 | void testRedeclDefinition() { |
| 47 | // CHECK: define {{.*redeclDefinitionEmit}} |
| 48 | redeclDefinitionEmit(); |
| 49 | } |
| 50 | |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 51 | void testInlineRedecl() { |
| 52 | outOfLineInlineUseLeftF(); |
| 53 | outOfLineInlineUseRightG(); |
| 54 | |
| 55 | outOfLineInlineUseRightF(); |
| 56 | outOfLineInlineUseLeftG(); |
| 57 | } |
| 58 | |
Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 59 | // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv( |
| 60 | // CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv( |
| 61 | // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv( |
| 62 | // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv( |
| 63 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 64 | // These three are all the same type. |
| 65 | typedef OuterIntInner_left OuterIntInner; |
| 66 | typedef OuterIntInner_right OuterIntInner; |
| 67 | typedef Outer<int>::Inner OuterIntInner; |
| 68 | |
Axel Naumann | d9a25b3 | 2012-10-02 12:18:46 +0000 | [diff] [blame] | 69 | // CHECK: call {{.*pendingInstantiation}} |
| 70 | // CHECK: call {{.*redeclDefinitionEmit}} |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 71 | |
| 72 | static_assert(size_left == size_right, "same field both ways"); |
| 73 | void useListInt(List<int> &); |
| 74 | |
| 75 | // CHECK-LABEL: define i32 @_Z15testMixedStructv( |
| 76 | unsigned testMixedStruct() { |
| 77 | // CHECK: %[[l:.*]] = alloca %[[ListInt:[^ ]*]], align 8 |
| 78 | // CHECK: %[[r:.*]] = alloca %[[ListInt]], align 8 |
| 79 | |
JF Bastien | 3a881e6 | 2018-11-15 00:19:18 +0000 | [diff] [blame] | 80 | // CHECK: call {{.*}}memcpy{{.*}}(i8* align {{[0-9]+}} %{{.*}}, i8* align {{[0-9]+}} bitcast ({{.*}}* @__const._Z15testMixedStructv.l to i8*), i64 16, |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 81 | ListInt_left l{0, 1}; |
| 82 | |
JF Bastien | 3a881e6 | 2018-11-15 00:19:18 +0000 | [diff] [blame] | 83 | // CHECK: call {{.*}}memcpy{{.*}}(i8* align {{[0-9]+}} %{{.*}}, i8* align {{[0-9]+}} bitcast ({{.*}}* @__const._Z15testMixedStructv.r to i8*), i64 16, |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 84 | ListInt_right r{0, 2}; |
| 85 | |
Hal Finkel | a2347ba | 2014-07-18 15:52:10 +0000 | [diff] [blame] | 86 | // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[l]]) |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 87 | useListInt(l); |
Hal Finkel | a2347ba | 2014-07-18 15:52:10 +0000 | [diff] [blame] | 88 | // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]]) |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 89 | useListInt(r); |
| 90 | |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 91 | // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*) |
| 92 | // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*) |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 93 | return list_left.*size_right + list_right.*size_left; |
| 94 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 95 | |
| 96 | template<typename T> struct MergePatternDecl { |
| 97 | typedef int Type; |
| 98 | void f(Type); |
| 99 | }; |
| 100 | template<typename T> void MergePatternDecl<T>::f(Type type) {} |
Richard Smith | eb36ddf | 2014-04-24 22:45:46 +0000 | [diff] [blame] | 101 | // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv( |
| 102 | template struct ExplicitInstantiation<false, true>; |
| 103 | template struct ExplicitInstantiation<true, true>; |
Richard Smith | d1c4674 | 2014-04-30 02:24:17 +0000 | [diff] [blame] | 104 | |
| 105 | void testDelayUpdatesImpl() { testDelayUpdates<int>(); } |
Richard Smith | 73b21d8 | 2014-09-03 02:33:22 +0000 | [diff] [blame] | 106 | |
| 107 | void testStaticDataMember() { |
| 108 | WithUndefinedStaticDataMember<int[]> load_it; |
| 109 | |
| 110 | // CHECK-LABEL: define linkonce_odr i32* @_Z23getStaticDataMemberLeftv( |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 111 | // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0) |
Richard Smith | 73b21d8 | 2014-09-03 02:33:22 +0000 | [diff] [blame] | 112 | (void) getStaticDataMemberLeft(); |
| 113 | |
| 114 | // CHECK-LABEL: define linkonce_odr i32* @_Z24getStaticDataMemberRightv( |
David Blaikie | bdf40a6 | 2015-03-13 18:21:46 +0000 | [diff] [blame] | 115 | // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0) |
Richard Smith | 73b21d8 | 2014-09-03 02:33:22 +0000 | [diff] [blame] | 116 | (void) getStaticDataMemberRight(); |
| 117 | } |
| 118 | |
Richard Smith | 842e46e | 2016-10-26 02:31:56 +0000 | [diff] [blame] | 119 | void testWithAttributes() { |
| 120 | auto a = make_with_attributes_left(); |
| 121 | auto b = make_with_attributes_right(); |
| 122 | static_assert(alignof(decltype(a)) == 2, ""); |
| 123 | static_assert(alignof(decltype(b)) == 2, ""); |
| 124 | } |
Akira Hatanaka | d791e92 | 2018-03-19 17:38:40 +0000 | [diff] [blame] | 125 | |
| 126 | // Check that returnNonTrivial doesn't return Class0<S0> directly in registers. |
| 127 | |
| 128 | // CHECK: declare void @_Z16returnNonTrivialv(%struct.Class0* sret) |
| 129 | |
| 130 | @import template_nontrivial0; |
| 131 | @import template_nontrivial1; |
| 132 | |
| 133 | S1::S1() : a(returnNonTrivial()) { |
| 134 | } |