blob: aafe0186c3ec071fc5c3b515882359f67e33268e [file] [log] [blame]
Axel Naumann39d26c32012-10-02 09:09:43 +00001// RUN: rm -rf %t
Richard Smith4ed01222013-10-07 08:02:11 +00002// 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 Gibbs8e8fb3b2012-10-19 12:44:48 +00004// expected-no-diagnostics
Axel Naumann39d26c32012-10-02 09:09:43 +00005
Douglas Gregor1b257af2012-12-11 22:11:52 +00006@import templates_left;
Stephen Hinesc568f1e2014-07-21 00:47:37 -07007
8void testInlineRedeclEarly() {
9 // instantiate definition now, we'll add another declaration in _right.
10 OutOfLineInline<int>().h();
11}
12
Douglas Gregor1b257af2012-12-11 22:11:52 +000013@import templates_right;
Axel Naumann39d26c32012-10-02 09:09:43 +000014
Stephen Hines176edba2014-12-01 14:53:08 -080015// 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 Naumann39d26c32012-10-02 09:09:43 +000020
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');
Stephen Hines6bcf27b2014-05-29 04:14:42 -070030
31 List<double> list_double;
32 list_double.push_back(0.0);
Axel Naumann39d26c32012-10-02 09:09:43 +000033}
34
35void testPendingInstantiations() {
Axel Naumann38c3bb42012-10-02 12:18:46 +000036 // CHECK: call {{.*pendingInstantiationEmit}}
37 // CHECK: call {{.*pendingInstantiationEmit}}
38 // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
39 // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
Axel Naumann39d26c32012-10-02 09:09:43 +000040 triggerPendingInstantiation();
41 triggerPendingInstantiationToo();
42}
Axel Naumann38c3bb42012-10-02 12:18:46 +000043
44void testRedeclDefinition() {
45 // CHECK: define {{.*redeclDefinitionEmit}}
46 redeclDefinitionEmit();
47}
48
Stephen Hinesc568f1e2014-07-21 00:47:37 -070049void testInlineRedecl() {
50 outOfLineInlineUseLeftF();
51 outOfLineInlineUseRightG();
52
53 outOfLineInlineUseRightF();
54 outOfLineInlineUseLeftG();
55}
56
Stephen Hines6bcf27b2014-05-29 04:14:42 -070057// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
58// CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv(
59// CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv(
60// CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
61
Richard Smithb60fae52013-09-09 16:55:27 +000062// These three are all the same type.
63typedef OuterIntInner_left OuterIntInner;
64typedef OuterIntInner_right OuterIntInner;
65typedef Outer<int>::Inner OuterIntInner;
66
Axel Naumann38c3bb42012-10-02 12:18:46 +000067// CHECK: call {{.*pendingInstantiation}}
68// CHECK: call {{.*redeclDefinitionEmit}}
Richard Smith4ed01222013-10-07 08:02:11 +000069
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
Stephen Hines176edba2014-12-01 14:53:08 -080084 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[l]])
Richard Smith4ed01222013-10-07 08:02:11 +000085 useListInt(l);
Stephen Hines176edba2014-12-01 14:53:08 -080086 // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]])
Richard Smith4ed01222013-10-07 08:02:11 +000087 useListInt(r);
88
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -070089 // 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 Smith4ed01222013-10-07 08:02:11 +000091 return list_left.*size_right + list_right.*size_left;
92}
Stephen Hines6bcf27b2014-05-29 04:14:42 -070093
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>(); }
Stephen Hines176edba2014-12-01 14:53:08 -0800104
105void testStaticDataMember() {
106 WithUndefinedStaticDataMember<int[]> load_it;
107
108 // CHECK-LABEL: define linkonce_odr i32* @_Z23getStaticDataMemberLeftv(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700109 // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
Stephen Hines176edba2014-12-01 14:53:08 -0800110 (void) getStaticDataMemberLeft();
111
112 // CHECK-LABEL: define linkonce_odr i32* @_Z24getStaticDataMemberRightv(
Pirama Arumuga Nainar3ea9e332015-04-08 08:57:32 -0700113 // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
Stephen Hines176edba2014-12-01 14:53:08 -0800114 (void) getStaticDataMemberRight();
115}
116
117