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
4 // expected-no-diagnostics
5 // REQUIRES: x86-registered-target
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 %[[LIST:.*]] { ptr null, i32 8 }, align 8
16 // CHECK-DAG: @list_right ={{.*}} global %[[LIST]] { ptr null, i32 12 }, align 8
17 // CHECK-DAG: @__const._Z15testMixedStructv.l = {{.*}} constant %[[LIST]] { ptr null, i32 1 }, align 8
18 // CHECK-DAG: @__const._Z15testMixedStructv.r = {{.*}} constant %[[LIST]] { ptr 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 static_assert(sizeof(List<long>) == sizeof(List<short>), "");
33 List<double> list_double;
34 list_double.push_back(0.0);
37 void testPendingInstantiations() {
38 // CHECK: call {{.*pendingInstantiationEmit}}
39 // CHECK: call {{.*pendingInstantiationEmit}}
40 // CHECK: define {{.*pendingInstantiationEmit.*[(]i}}
41 // CHECK: define {{.*pendingInstantiationEmit.*[(]double}}
42 triggerPendingInstantiation();
43 triggerPendingInstantiationToo();
46 void testRedeclDefinition() {
47 // CHECK: define {{.*redeclDefinitionEmit}}
48 redeclDefinitionEmit();
51 void testInlineRedecl() {
52 outOfLineInlineUseLeftF();
53 outOfLineInlineUseRightG();
55 outOfLineInlineUseRightF();
56 outOfLineInlineUseLeftG();
59 // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
60 // CHECK: declare {{.*}}@_ZN21ExplicitInstantiationILb1ELb0EE1fEv(
61 // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb1ELb1EE1fEv(
62 // CHECK-NOT: @_ZN21ExplicitInstantiationILb0ELb0EE1fEv(
64 // These three are all the same type.
65 typedef OuterIntInner_left OuterIntInner;
66 typedef OuterIntInner_right OuterIntInner;
67 typedef Outer<int>::Inner OuterIntInner;
69 // CHECK: call {{.*pendingInstantiation}}
70 // CHECK: call {{.*redeclDefinitionEmit}}
72 static_assert(size_left == size_right, "same field both ways");
73 void useListInt(List<int> &);
75 // CHECK-LABEL: define{{.*}} i32 @_Z15testMixedStructv(
76 unsigned testMixedStruct() {
77 // CHECK: %[[l:.*]] = alloca %[[ListInt:[^ ]*]], align 8
78 // CHECK: %[[r:.*]] = alloca %[[ListInt]], align 8
80 // CHECK: call {{.*}}memcpy{{.*}}(ptr align {{[0-9]+}} %{{.*}}, ptr align {{[0-9]+}} @__const._Z15testMixedStructv.l, i64 16,
83 // CHECK: call {{.*}}memcpy{{.*}}(ptr align {{[0-9]+}} %{{.*}}, ptr align {{[0-9]+}} @__const._Z15testMixedStructv.r, i64 16,
84 ListInt_right r{0, 2};
86 // CHECK: call void @_Z10useListIntR4ListIiE(ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %[[l]])
88 // CHECK: call void @_Z10useListIntR4ListIiE(ptr noundef nonnull align {{[0-9]+}} dereferenceable({{[0-9]+}}) %[[r]])
91 // CHECK: load i32, ptr getelementptr inbounds (i8, ptr @list_left, i64 8)
92 // CHECK: load i32, ptr getelementptr inbounds (i8, ptr @list_right, i64 8)
93 return list_left.*size_right + list_right.*size_left;
96 template<typename T> struct MergePatternDecl {
100 template<typename T> void MergePatternDecl<T>::f(Type type) {}
101 // CHECK: define {{.*}}@_ZN21ExplicitInstantiationILb0ELb1EE1fEv(
102 template struct ExplicitInstantiation<false, true>;
103 template struct ExplicitInstantiation<true, true>;
105 void testDelayUpdatesImpl() { testDelayUpdates<int>(); }
107 void testStaticDataMember() {
108 WithUndefinedStaticDataMember<int[]> load_it;
110 // CHECK-LABEL: define linkonce_odr noundef ptr @_Z23getStaticDataMemberLeftv(
111 // CHECK: ret ptr @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE
112 (void) getStaticDataMemberLeft();
114 // CHECK-LABEL: define linkonce_odr noundef ptr @_Z24getStaticDataMemberRightv(
115 // CHECK: ret ptr @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE
116 (void) getStaticDataMemberRight();
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, "");
126 // Check that returnNonTrivial doesn't return Class0<S0> directly in registers.
128 // CHECK: declare void @_Z16returnNonTrivialv(ptr dead_on_unwind writable sret(%struct.Class0) align 8)
130 @import template_nontrivial0;
131 @import template_nontrivial1;
133 S1::S1() : a(returnNonTrivial()) {