summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-05-05 22:18:51 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-05-05 22:18:51 +0000
commit8128f3327f13fa2e51bf090435c2bd3d7d14dea2 (patch)
tree194914ad1e7c4338503488b537b7c78a9073ac7b /clang/test
parent6512dabcd3250853633923c21ec0c122d020fefe (diff)
downloadbcm5719-llvm-8128f3327f13fa2e51bf090435c2bd3d7d14dea2.tar.gz
bcm5719-llvm-8128f3327f13fa2e51bf090435c2bd3d7d14dea2.zip
Add support for building modules from preprocessed source.
To support this, an optional marker "#pragma clang module contents" is recognized in module map files, and the rest of the module map file from that point onwards is treated as the source of the module. Preprocessing a module map produces the input module followed by the marker and then the preprocessed contents of the module. Ignoring line markers, a preprocessed module might look like this: module A { header "a.h" } #pragma clang module contents #pragma clang module begin A // ... a.h ... #pragma clang module end The preprocessed output generates line markers, which are not accepted by the module map parser, so -x c++-module-map-cpp-output should be used to compile such outputs. A couple of major parts do not work yet: 1) The files that are listed in the module map must exist on disk, in order to build the on-disk header -> module lookup table in the PCM file. To fix this, we need the preprocessed output to track the file size and other stat information we might use to build the lookup table. 2) Declaration ownership semantics don't work properly yet, since mapping from a source location to a module relies on mapping from FileIDs to modules, which we can't do if module transitions can occur in the middle of a file. llvm-svn: 302309
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Modules/preprocess-module.cpp40
1 files changed, 38 insertions, 2 deletions
diff --git a/clang/test/Modules/preprocess-module.cpp b/clang/test/Modules/preprocess-module.cpp
index 337cafbf65b..a3b78923838 100644
--- a/clang/test/Modules/preprocess-module.cpp
+++ b/clang/test/Modules/preprocess-module.cpp
@@ -1,10 +1,35 @@
// RUN: rm -rf %t
+// RUN: mkdir %t
// RUN: not %clang_cc1 -fmodules -fmodule-name=file -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E 2>&1 | FileCheck %s --check-prefix=MISSING-FWD
// MISSING-FWD: module 'fwd' is needed
-// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodules-cache-path=%t -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E | FileCheck %s --check-prefix=CHECK --check-prefix=NO-REWRITE
-// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodules-cache-path=%t -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes | FileCheck %s --check-prefix=CHECK --check-prefix=REWRITE
+// RUN: %clang_cc1 -fmodules -fmodule-name=fwd -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -emit-module -o %t/fwd.pcm
+
+// Check that we can preprocess modules, and get the expected output.
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -o %t/no-rewrite.ii
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%S/Inputs/preprocess -x c++-module-map %S/Inputs/preprocess/module.modulemap -E -frewrite-includes -o %t/rewrite.ii
+//
+// RUN: FileCheck %s --input-file %t/no-rewrite.ii --check-prefix=CHECK --check-prefix=NO-REWRITE
+// RUN: FileCheck %s --input-file %t/rewrite.ii --check-prefix=CHECK --check-prefix=REWRITE
+
+// Check that we can build a module from the preprocessed output.
+// FIXME: For now, we need the headers to exist.
+// RUN: touch %t/file.h %t/file2.h
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/no-rewrite.ii -emit-module -o %t/no-rewrite.pcm
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/rewrite.ii -emit-module -o %t/rewrite.pcm
+
+// Check the module we built works.
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -verify
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -verify
+
+
+// == module map
+// CHECK: # 1 "{{.*}}module.modulemap"
+// CHECK: module file {
+// CHECK: header "file.h"
+// CHECK: header "file2.h"
+// CHECK: }
// == file.h
// CHECK: # 1 "<module-includes>"
@@ -63,3 +88,14 @@
// REWRITE: #pragma clang module end
// CHECK: # 3 "<module-includes>" 2
// NO-REWRITE: #pragma clang module end
+
+
+// expected-no-diagnostics
+
+// FIXME: This should be rejected: we have not imported the submodule defining it yet.
+__FILE *a;
+
+#pragma clang module import file
+
+FILE *b;
+int x = file2;
OpenPOWER on IntegriCloud