aboutsummaryrefslogtreecommitdiff
path: root/test/ASTMerge
diff options
context:
space:
mode:
Diffstat (limited to 'test/ASTMerge')
-rw-r--r--test/ASTMerge/class-template/Inputs/class-template1.cpp5
-rw-r--r--test/ASTMerge/class-template/Inputs/class-template2.cpp4
-rw-r--r--test/ASTMerge/class-template/test.cpp36
-rw-r--r--test/ASTMerge/class/Inputs/class1.cpp28
-rw-r--r--test/ASTMerge/class/Inputs/class2.cpp26
-rw-r--r--test/ASTMerge/class/test.cpp10
-rw-r--r--test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp17
-rw-r--r--test/ASTMerge/exprs-cpp/test.cpp3
-rw-r--r--test/ASTMerge/function-cpp/Inputs/function-1.cpp8
-rw-r--r--test/ASTMerge/function-cpp/test.cpp10
-rw-r--r--test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp2
-rw-r--r--test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp2
-rw-r--r--test/ASTMerge/injected-class-name-decl/test.cpp3
-rw-r--r--test/ASTMerge/interface/Inputs/interface1.m4
-rw-r--r--test/ASTMerge/namespace/test.cpp2
-rw-r--r--test/ASTMerge/std-initializer-list/Inputs/il.cpp9
-rw-r--r--test/ASTMerge/std-initializer-list/test.cpp3
-rw-r--r--test/ASTMerge/struct/Inputs/struct1.c62
-rw-r--r--test/ASTMerge/struct/Inputs/struct2.c62
-rw-r--r--test/ASTMerge/struct/test.c10
-rw-r--r--test/ASTMerge/var-cpp/Inputs/var1.cpp17
-rw-r--r--test/ASTMerge/var-cpp/test.cpp9
22 files changed, 311 insertions, 21 deletions
diff --git a/test/ASTMerge/class-template/Inputs/class-template1.cpp b/test/ASTMerge/class-template/Inputs/class-template1.cpp
index 440b5abfc869..fb5b229e0ac8 100644
--- a/test/ASTMerge/class-template/Inputs/class-template1.cpp
+++ b/test/ASTMerge/class-template/Inputs/class-template1.cpp
@@ -1,5 +1,7 @@
template<typename T>
-struct X0;
+struct X0 {
+ T getValue(T arg) { return arg; }
+};
template<int I>
struct X1;
@@ -26,6 +28,7 @@ extern X0<float> *x0r;
template<>
struct X0<char> {
int member;
+ char getValue(char ch) { return static_cast<char>(member); }
};
template<>
diff --git a/test/ASTMerge/class-template/Inputs/class-template2.cpp b/test/ASTMerge/class-template/Inputs/class-template2.cpp
index 6300301a4ffa..b5d0add13f15 100644
--- a/test/ASTMerge/class-template/Inputs/class-template2.cpp
+++ b/test/ASTMerge/class-template/Inputs/class-template2.cpp
@@ -1,5 +1,7 @@
template<class T>
-struct X0;
+struct X0 {
+ T getValue(T arg);
+};
template<int I>
struct X1;
diff --git a/test/ASTMerge/class-template/test.cpp b/test/ASTMerge/class-template/test.cpp
index 0ab5443db7f6..7e25c5d6ccc3 100644
--- a/test/ASTMerge/class-template/test.cpp
+++ b/test/ASTMerge/class-template/test.cpp
@@ -1,24 +1,28 @@
-// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/class-template1.cpp
-// RUN: %clang_cc1 -emit-pch -o %t.2.ast %S/Inputs/class-template2.cpp
-// RUN: not %clang_cc1 -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/class-template1.cpp
+// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.2.ast %S/Inputs/class-template2.cpp
+// RUN: not %clang_cc1 -std=c++1z -ast-merge %t.1.ast -ast-merge %t.2.ast -fsyntax-only %s 2>&1 | FileCheck %s
-// CHECK: class-template1.cpp:7:14: error: non-type template parameter declared with incompatible types in different translation units ('int' vs. 'long')
-// CHECK: class-template2.cpp:7:15: note: declared here with type 'long'
+static_assert(sizeof(X0<char>().getValue(1)) == sizeof(char));
+static_assert(sizeof(X0<int>().getValue(1)) == sizeof(int));
-// CHECK: class-template1.cpp:10:14: error: template parameter has different kinds in different translation units
-// CHECK: class-template2.cpp:10:10: note: template parameter declared here
+// CHECK: class-template1.cpp:9:14: error: non-type template parameter declared with incompatible types in different translation units ('int' vs. 'long')
+// CHECK: class-template2.cpp:9:15: note: declared here with type 'long'
-// CHECK: class-template1.cpp:16:23: error: non-type template parameter declared with incompatible types in different translation units ('long' vs. 'int')
-// CHECK: class-template2.cpp:16:23: note: declared here with type 'int'
+// CHECK: class-template1.cpp:12:14: error: template parameter has different kinds in different translation units
+// CHECK: class-template2.cpp:12:10: note: template parameter declared here
-// CHECK: class-template1.cpp:19:10: error: template parameter has different kinds in different translation units
-// CHECK: class-template2.cpp:19:10: note: template parameter declared here
+// CHECK: class-template1.cpp:18:23: error: non-type template parameter declared with incompatible types in different translation units ('long' vs. 'int')
+// CHECK: class-template2.cpp:18:23: note: declared here with type 'int'
-// CHECK: class-template2.cpp:25:20: error: external variable 'x0r' declared with incompatible types in different translation units ('X0<double> *' vs. 'X0<float> *')
-// CHECK: class-template1.cpp:24:19: note: declared here with type 'X0<float> *'
+// CHECK: class-template1.cpp:21:10: error: template parameter has different kinds in different translation units
+// CHECK: class-template2.cpp:21:10: note: template parameter declared here
-// CHECK: class-template1.cpp:32:8: warning: type 'X0<wchar_t>' has incompatible definitions in different translation units
-// CHECK: class-template1.cpp:33:7: note: field 'member' has type 'int' here
-// CHECK: class-template2.cpp:34:9: note: field 'member' has type 'float' here
+// CHECK: class-template2.cpp:27:20: error: external variable 'x0r' declared with incompatible types in different translation units ('X0<double> *' vs. 'X0<float> *')
+// CHECK: class-template1.cpp:26:19: note: declared here with type 'X0<float> *'
+
+// CHECK: class-template1.cpp:35:8: warning: type 'X0<wchar_t>' has incompatible definitions in different translation units
+// CHECK: class-template1.cpp:36:7: note: field 'member' has type 'int' here
+// CHECK: class-template2.cpp:36:9: note: field 'member' has type 'float' here
// CHECK: 1 warning and 5 errors generated.
+// CHECK-NOT: static_assert
diff --git a/test/ASTMerge/class/Inputs/class1.cpp b/test/ASTMerge/class/Inputs/class1.cpp
index b0a7645cfe63..2bd5503ecf3d 100644
--- a/test/ASTMerge/class/Inputs/class1.cpp
+++ b/test/ASTMerge/class/Inputs/class1.cpp
@@ -18,3 +18,31 @@ struct C {
enum E {
b = 1
};
+
+//Friend import tests
+void f();
+int g(int a);
+struct X;
+struct Y;
+
+struct F1 {
+public:
+ int x;
+ friend struct X;
+ friend int g(int);
+ friend void f();
+};
+
+struct F2 {
+public:
+ int x;
+ friend struct X;
+ friend void f();
+};
+
+struct F3 {
+public:
+ int x;
+ friend int g(int);
+ friend void f();
+};
diff --git a/test/ASTMerge/class/Inputs/class2.cpp b/test/ASTMerge/class/Inputs/class2.cpp
index 2bed6d775bc4..6fe38b920662 100644
--- a/test/ASTMerge/class/Inputs/class2.cpp
+++ b/test/ASTMerge/class/Inputs/class2.cpp
@@ -12,3 +12,29 @@ enum E {
a = 0,
b = 1
};
+
+//Friend import tests
+void f();
+int g(int a);
+struct X;
+struct Y;
+
+struct F1 {
+public:
+ int x;
+ friend struct X;
+ friend int g(int);
+ friend void f();
+};
+
+struct F2 {
+public:
+ int x;
+ friend struct X;
+};
+
+struct F3 {
+public:
+ int x;
+ friend void f();
+};
diff --git a/test/ASTMerge/class/test.cpp b/test/ASTMerge/class/test.cpp
index a68a2d1d7690..ba553af40720 100644
--- a/test/ASTMerge/class/test.cpp
+++ b/test/ASTMerge/class/test.cpp
@@ -12,3 +12,13 @@
// CHECK: class1.cpp:18:6: warning: type 'E' has incompatible definitions in different translation units
// CHECK: class1.cpp:19:3: note: enumerator 'b' with value 1 here
// CHECK: class2.cpp:12:3: note: enumerator 'a' with value 0 here
+
+// CHECK: class1.cpp:43:8: warning: type 'F3' has incompatible definitions in different translation units
+// CHECK: class1.cpp:46:3: note: friend declared here
+// CHECK: class2.cpp:36:8: note: no corresponding friend here
+
+// CHECK: class1.cpp:36:8: warning: type 'F2' has incompatible definitions in different translation units
+// CHECK: class1.cpp:39:3: note: friend declared here
+// CHECK: class2.cpp:30:8: note: no corresponding friend here
+
+// CHECK: 4 warnings generated.
diff --git a/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp b/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp
index 2a33c35d9ea6..6fdc33fb3919 100644
--- a/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp
+++ b/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp
@@ -122,3 +122,20 @@ void useTemplateType() {
const bool ExpressionTrait = __is_lvalue_expr(1);
const unsigned ArrayRank = __array_rank(int[10][20]);
const unsigned ArrayExtent = __array_extent(int[10][20], 1);
+
+constexpr int testLambdaAdd(int toAdd) {
+ const int Captured1 = 1, Captured2 = 2;
+ constexpr auto LambdaAdd = [Captured1, Captured2](int k) -> int {
+ return Captured1 + Captured2 + k;
+ };
+ return LambdaAdd(toAdd);
+}
+
+template<typename T>
+struct TestLambdaTemplate {
+ T i, j;
+ TestLambdaTemplate(T i, const T &j) : i(i), j(j) {}
+ T testLambda(T k) {
+ return [this](T k) -> decltype(auto) { return i + j + k; }(k);
+ }
+};
diff --git a/test/ASTMerge/exprs-cpp/test.cpp b/test/ASTMerge/exprs-cpp/test.cpp
index 0535aa85330f..c0b282ec0288 100644
--- a/test/ASTMerge/exprs-cpp/test.cpp
+++ b/test/ASTMerge/exprs-cpp/test.cpp
@@ -30,6 +30,8 @@ static_assert(ExpressionTrait == false);
static_assert(ArrayRank == 2);
static_assert(ArrayExtent == 20);
+static_assert(testLambdaAdd(3) == 6);
+
void testImport(int *x, const S1 &cs1, S1 &s1) {
testNewThrowDelete();
testArrayElement(nullptr, 12);
@@ -44,4 +46,5 @@ void testImport(int *x, const S1 &cs1, S1 &s1) {
testDefaultArg();
testDefaultArgExpr();
useTemplateType();
+ TestLambdaTemplate<int>(1, 2).testLambda(3);
}
diff --git a/test/ASTMerge/function-cpp/Inputs/function-1.cpp b/test/ASTMerge/function-cpp/Inputs/function-1.cpp
new file mode 100644
index 000000000000..ee97a1a8a5da
--- /dev/null
+++ b/test/ASTMerge/function-cpp/Inputs/function-1.cpp
@@ -0,0 +1,8 @@
+
+template<typename T> constexpr T add(T arg1, T arg2) {
+ return arg1 + arg2;
+}
+
+template<> constexpr int add(int arg1, int arg2) {
+ return arg1 + arg2 + 2;
+}
diff --git a/test/ASTMerge/function-cpp/test.cpp b/test/ASTMerge/function-cpp/test.cpp
new file mode 100644
index 000000000000..304ce3c634c2
--- /dev/null
+++ b/test/ASTMerge/function-cpp/test.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.1.ast %S/Inputs/function-1.cpp
+// RUN: %clang_cc1 -std=c++1z -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck %s
+// XFAIL: *
+
+static_assert(add(1, 2) == 5);
+
+// FIXME: support of templated function overload is still not implemented.
+static_assert(add('\1', '\2') == 3);
+
+// CHECK-NOT: static_assert
diff --git a/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp b/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp
new file mode 100644
index 000000000000..f6f769746d10
--- /dev/null
+++ b/test/ASTMerge/injected-class-name-decl/Inputs/inject1.cpp
@@ -0,0 +1,2 @@
+template <class X>
+class C { static X x; };
diff --git a/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp b/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp
new file mode 100644
index 000000000000..7cf5fc223285
--- /dev/null
+++ b/test/ASTMerge/injected-class-name-decl/Inputs/inject2.cpp
@@ -0,0 +1,2 @@
+template <class X>
+X C<X>::x;
diff --git a/test/ASTMerge/injected-class-name-decl/test.cpp b/test/ASTMerge/injected-class-name-decl/test.cpp
new file mode 100644
index 000000000000..9f31674108ad
--- /dev/null
+++ b/test/ASTMerge/injected-class-name-decl/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -std=c++1z -emit-pch -o %t.ast %S/Inputs/inject1.cpp
+// RUN: %clang_cc1 -std=c++1z -emit-obj -o /dev/null -ast-merge %t.ast %S/Inputs/inject2.cpp
+// expected-no-diagnostics
diff --git a/test/ASTMerge/interface/Inputs/interface1.m b/test/ASTMerge/interface/Inputs/interface1.m
index 5865c0eff070..6192150089fe 100644
--- a/test/ASTMerge/interface/Inputs/interface1.m
+++ b/test/ASTMerge/interface/Inputs/interface1.m
@@ -100,4 +100,6 @@
@implementation I15 : I12
@end
-
+@interface ImportSelectorSLoc { }
+-(int)addInt:(int)a toInt:(int)b moduloInt:(int)c; // don't crash here
+@end
diff --git a/test/ASTMerge/namespace/test.cpp b/test/ASTMerge/namespace/test.cpp
index f1796c03b07e..ab05f6d72758 100644
--- a/test/ASTMerge/namespace/test.cpp
+++ b/test/ASTMerge/namespace/test.cpp
@@ -7,7 +7,7 @@ static_assert(ContainsInline::z == 10);
void testImport() {
typedef TestUnresolvedTypenameAndValueDecls::Derived<int> Imported;
- Imported a; // Successfull instantiation
+ Imported a; // Successful instantiation
static_assert(sizeof(Imported::foo) == sizeof(int));
static_assert(sizeof(TestUnresolvedTypenameAndValueDecls::Derived<double>::NewUnresolvedUsingType) == sizeof(double));
}
diff --git a/test/ASTMerge/std-initializer-list/Inputs/il.cpp b/test/ASTMerge/std-initializer-list/Inputs/il.cpp
new file mode 100644
index 000000000000..3b2ac187c886
--- /dev/null
+++ b/test/ASTMerge/std-initializer-list/Inputs/il.cpp
@@ -0,0 +1,9 @@
+namespace std {
+template <typename T>
+struct initializer_list {
+ const T *begin, *end;
+ initializer_list();
+};
+} // namespace std
+
+std::initializer_list<int> IL = {1, 2, 3, 4};
diff --git a/test/ASTMerge/std-initializer-list/test.cpp b/test/ASTMerge/std-initializer-list/test.cpp
new file mode 100644
index 000000000000..ca7330d308a8
--- /dev/null
+++ b/test/ASTMerge/std-initializer-list/test.cpp
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 -emit-pch -o %t.1.ast %S/Inputs/il.cpp
+// RUN: %clang_cc1 -ast-merge %t.1.ast -fsyntax-only %s 2>&1 | FileCheck --allow-empty %s
+// CHECK-NOT: unsupported AST node
diff --git a/test/ASTMerge/struct/Inputs/struct1.c b/test/ASTMerge/struct/Inputs/struct1.c
index 0f3e8b9bc3eb..a85aec70a84c 100644
--- a/test/ASTMerge/struct/Inputs/struct1.c
+++ b/test/ASTMerge/struct/Inputs/struct1.c
@@ -77,3 +77,65 @@ typedef struct {
} S13;
S13 x13;
+
+// Matches
+struct Unnamed {
+ union {
+ struct {
+ int i;
+ } S;
+ struct {
+ float i;
+ } R;
+ } U;
+} x14;
+
+// Matches
+struct DeepUnnamed {
+ union {
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ int i;
+ } R;
+ } U1;
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ float i;
+ } T;
+ } U2;
+ } U;
+ struct {
+ long i;
+ } V;
+} x15;
+
+// Mismatch due to unnamed struct used internally
+struct DeepUnnamedError {
+ union {
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ int i;
+ } R;
+ } U1;
+ union {
+ struct {
+ long i; // Mismatch here.
+ } S;
+ struct {
+ float i;
+ } T;
+ } U2;
+ } U;
+ struct {
+ long i;
+ } V;
+} x16;
diff --git a/test/ASTMerge/struct/Inputs/struct2.c b/test/ASTMerge/struct/Inputs/struct2.c
index 7fe17a576b23..49fe36d823d0 100644
--- a/test/ASTMerge/struct/Inputs/struct2.c
+++ b/test/ASTMerge/struct/Inputs/struct2.c
@@ -74,3 +74,65 @@ typedef struct {
} S13;
S13 x13;
+
+// Matches
+struct Unnamed {
+ union {
+ struct {
+ int i;
+ } S;
+ struct {
+ float i;
+ } R;
+ } U;
+} x14;
+
+// Matches
+struct DeepUnnamed {
+ union {
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ int i;
+ } R;
+ } U1;
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ float i;
+ } T;
+ } U2;
+ } U;
+ struct {
+ long i;
+ } V;
+} x15;
+
+// Mismatch due to unnamed struct used internally
+struct DeepUnnamedError {
+ union {
+ union {
+ struct {
+ long i;
+ } S;
+ struct {
+ int i;
+ } R;
+ } U1;
+ union {
+ struct {
+ float i; // Mismatch here.
+ } S;
+ struct {
+ float i;
+ } T;
+ } U2;
+ } U;
+ struct {
+ long i;
+ } V;
+} x16;
diff --git a/test/ASTMerge/struct/test.c b/test/ASTMerge/struct/test.c
index ed7750f6becc..ef339396971d 100644
--- a/test/ASTMerge/struct/test.c
+++ b/test/ASTMerge/struct/test.c
@@ -44,4 +44,12 @@
// CHECK: struct2.c:72:7: note: field 'i' has type 'int' here
// CHECK: struct2.c:76:5: error: external variable 'x13' declared with incompatible types in different translation units ('S13' vs. 'S13')
// CHECK: struct1.c:79:5: note: declared here with type 'S13'
-// CHECK: 9 warnings and 8 errors generated
+// CHECK: struct1.c:130:7: warning: type 'struct DeepUnnamedError::(anonymous at [[PATH_TO_INPUTS:.+]]struct1.c:130:7)' has incompatible definitions in different translation units
+// CHECK: struct1.c:131:14: note: field 'i' has type 'long' here
+// CHECK: struct2.c:128:15: note: field 'i' has type 'float' here
+// CHECK: struct1.c:129:5: warning: type 'union DeepUnnamedError::(anonymous at [[PATH_TO_INPUTS]]struct1.c:129:5)' has incompatible definitions in different translation units
+// CHECK: struct1.c:132:9: note: field 'S' has type 'struct (anonymous struct at [[PATH_TO_INPUTS]]struct1.c:130:7)' here
+// CHECK: struct2.c:129:9: note: field 'S' has type 'struct (anonymous struct at [[PATH_TO_INPUTS]]struct2.c:127:7)' here
+// CHECK: struct2.c:138:3: error: external variable 'x16' declared with incompatible types in different translation units ('struct DeepUnnamedError' vs. 'struct DeepUnnamedError')
+// CHECK: struct1.c:141:3: note: declared here with type 'struct DeepUnnamedError'
+// CHECK: 11 warnings and 9 errors generated
diff --git a/test/ASTMerge/var-cpp/Inputs/var1.cpp b/test/ASTMerge/var-cpp/Inputs/var1.cpp
new file mode 100644
index 000000000000..e29db9d43fbb
--- /dev/null
+++ b/test/ASTMerge/var-cpp/Inputs/var1.cpp
@@ -0,0 +1,17 @@
+
+template <typename T>
+constexpr T my_pi = T(3.1415926535897932385L); // variable template
+
+template <> constexpr char my_pi<char> = '3'; // variable template specialization
+
+template <typename T>
+struct Wrapper {
+ template <typename U> static constexpr U my_const = U(1);
+ // Variable template partial specialization with member variable.
+ template <typename U> static constexpr U *my_const<const U *> = (U *)(0);
+};
+
+constexpr char a[] = "hello";
+
+template <> template <>
+constexpr const char *Wrapper<float>::my_const<const char *> = a;
diff --git a/test/ASTMerge/var-cpp/test.cpp b/test/ASTMerge/var-cpp/test.cpp
new file mode 100644
index 000000000000..28d38d581241
--- /dev/null
+++ b/test/ASTMerge/var-cpp/test.cpp
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-pch -std=c++17 -o %t.1.ast %S/Inputs/var1.cpp
+// RUN: %clang_cc1 -std=c++17 -ast-merge %t.1.ast -fsyntax-only %s 2>&1
+
+static_assert(my_pi<double> == (double)3.1415926535897932385L);
+static_assert(my_pi<char> == '3');
+
+static_assert(Wrapper<int>::my_const<float> == 1.f);
+static_assert(Wrapper<char>::my_const<const float *> == nullptr);
+static_assert(Wrapper<float>::my_const<const char *> == a);