summaryrefslogtreecommitdiff
path: root/test/Import
diff options
context:
space:
mode:
authorSean Callanan <scallanan@apple.com>2016-12-16 23:21:38 +0000
committerSean Callanan <scallanan@apple.com>2016-12-16 23:21:38 +0000
commitf7e51dd6581ead1cdb309bda75a89f6587b9632e (patch)
tree49550852dd0dcad9735cd8b90b436442b1aaf1d6 /test/Import
parent8c0cd53a9006a275f4db5653f9ef28d94db9ed67 (diff)
Testbed and skeleton of a new expression parser
LLVM's JIT is now the foundation of dynamic-compilation features for many languages. Clang also has low-level support for dynamic compilation (ASTImporter and ExternalASTSource, notably). How the compiler is set up for dynamic parsing is generally left up to individual clients, for example LLDB's C/C++/Objective-C expression parser and the ROOT project. Although this arrangement offers external clients the flexibility to implement dynamic features as they see fit, the lack of an in-tree client means that subtle bugs can be introduced that cause regressions in the external clients but aren't caught by tests (or users) until much later. LLDB for example regularly encounters complicated ODR violation scenarios where it is not immediately clear who is at fault. Other external clients (notably, Cling) rely on similar functionality, and another goal is to break this functionality up into composable parts so that any client can be built easily on top of Clang without requiring extensive additional code. I propose that the parts required to build a simple expression parser be added to Clang. Initially, I aim to have the following features: - A piece that looks up external declarations from a variety of sources (e.g., from previous dynamic compilations, from modules, or from DWARF) and uses clear conflict resolution rules to reconcile differences, with easily understood errors. This functionality will be supported by in-tree tests. - A piece that works hand in hand with the LLVM JIT to resolve the locations of external declarations so that e.g. variables can be redeclared and (for high-performance applications like DTrace) external variables can be accessed directly from the registers where they reside. This commit adds a tester that parses a sequence of source files and then uses them as source data for an expression. External references are resolved using an ExternalASTSource that responds to name queries using an ASTImporter. This is the setup that LLDB uses, and the motivating reason for MinimalImport in ASTImporter. When complete, this tester will implement the first of the above goals. Differential Revision: https://reviews.llvm.org/D27180 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290004 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Import')
-rw-r--r--test/Import/clang-flags/Inputs/S.c2
-rw-r--r--test/Import/clang-flags/test.c5
-rw-r--r--test/Import/empty-struct/Inputs/S.c2
-rw-r--r--test/Import/empty-struct/test.c5
-rw-r--r--test/Import/error-in-expression/Inputs/S.c2
-rw-r--r--test/Import/error-in-expression/test.c6
-rw-r--r--test/Import/error-in-import/Inputs/S.c2
-rw-r--r--test/Import/error-in-import/test.c6
-rw-r--r--test/Import/missing-import/test.c6
9 files changed, 36 insertions, 0 deletions
diff --git a/test/Import/clang-flags/Inputs/S.c b/test/Import/clang-flags/Inputs/S.c
new file mode 100644
index 0000000000..742dac8a35
--- /dev/null
+++ b/test/Import/clang-flags/Inputs/S.c
@@ -0,0 +1,2 @@
+STRUCT S {
+};
diff --git a/test/Import/clang-flags/test.c b/test/Import/clang-flags/test.c
new file mode 100644
index 0000000000..7a19ea7ff6
--- /dev/null
+++ b/test/Import/clang-flags/test.c
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/S.c -expression %s -Xcc -DSTRUCT=struct
+void expr() {
+ STRUCT S MyS;
+ void *MyPtr = &MyS;
+}
diff --git a/test/Import/empty-struct/Inputs/S.c b/test/Import/empty-struct/Inputs/S.c
new file mode 100644
index 0000000000..8c90352bc4
--- /dev/null
+++ b/test/Import/empty-struct/Inputs/S.c
@@ -0,0 +1,2 @@
+struct S {
+};
diff --git a/test/Import/empty-struct/test.c b/test/Import/empty-struct/test.c
new file mode 100644
index 0000000000..d51a69706d
--- /dev/null
+++ b/test/Import/empty-struct/test.c
@@ -0,0 +1,5 @@
+// RUN: clang-import-test -import %S/Inputs/S.c -expression %s
+void expr() {
+ struct S MyS;
+ void *MyPtr = &MyS;
+}
diff --git a/test/Import/error-in-expression/Inputs/S.c b/test/Import/error-in-expression/Inputs/S.c
new file mode 100644
index 0000000000..8c90352bc4
--- /dev/null
+++ b/test/Import/error-in-expression/Inputs/S.c
@@ -0,0 +1,2 @@
+struct S {
+};
diff --git a/test/Import/error-in-expression/test.c b/test/Import/error-in-expression/test.c
new file mode 100644
index 0000000000..65d3b4a5dc
--- /dev/null
+++ b/test/Import/error-in-expression/test.c
@@ -0,0 +1,6 @@
+// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s
+// CHECK: {{.*}}no viable conversion{{.*}}
+void expr() {
+ struct S MyS;
+ void *MyPtr = MyS;
+}
diff --git a/test/Import/error-in-import/Inputs/S.c b/test/Import/error-in-import/Inputs/S.c
new file mode 100644
index 0000000000..23ca763f67
--- /dev/null
+++ b/test/Import/error-in-import/Inputs/S.c
@@ -0,0 +1,2 @@
+struct S [
+];
diff --git a/test/Import/error-in-import/test.c b/test/Import/error-in-import/test.c
new file mode 100644
index 0000000000..197d4e3042
--- /dev/null
+++ b/test/Import/error-in-import/test.c
@@ -0,0 +1,6 @@
+// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s
+// CHECK: {{.*}}expected unqualified-id{{.*}}
+void expr() {
+ struct S MyS;
+ void *MyPtr = &MyS;
+}
diff --git a/test/Import/missing-import/test.c b/test/Import/missing-import/test.c
new file mode 100644
index 0000000000..acf6389cc5
--- /dev/null
+++ b/test/Import/missing-import/test.c
@@ -0,0 +1,6 @@
+// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s
+// CHECK: {{.*}}Couldn't open{{.*}}Inputs/S.c{{.*}}
+void expr() {
+ struct S MyS;
+ void *MyPtr = &MyS;
+}