summaryrefslogtreecommitdiffstats
path: root/test/Modules
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2017-06-02 01:55:39 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2017-06-02 01:55:39 +0000
commit146ecad762cb83f8e00d8027188b622c6a8ce15d (patch)
tree17b1d69656572e2a842ac2dcd9ef6dc525b1e290 /test/Modules
parentd4d74154ebb7baf50ad9b9d08c714a961afa59d8 (diff)
Support lazy stat'ing of files referenced by module maps.
This patch adds support for a `header` declaration in a module map to specify certain `stat` information (currently, size and mtime) about that header file. This has two purposes: - It removes the need to eagerly `stat` every file referenced by a module map. Instead, we track a list of unresolved header files with each size / mtime (actually, for simplicity, we track submodules with such headers), and when attempting to look up a header file based on a `FileEntry`, we check if there are any unresolved header directives with that `FileEntry`'s size / mtime and perform deferred `stat`s if so. - It permits a preprocessed module to be compiled without the original files being present on disk. The only reason we used to need those files was to get the `stat` information in order to do header -> module lookups when using the module. If we're provided with the `stat` information in the preprocessed module, we can avoid requiring the files to exist. Unlike most `header` directives, if a `header` directive with `stat` information has no corresponding on-disk file the enclosing module is *not* marked unavailable (so that behavior is consistent regardless of whether we've resolved a header directive, and so that preprocessed modules don't get marked unavailable). We could actually do this for all `header` directives: the only reason we mark the module unavailable if headers are missing is to give a diagnostic slightly earlier (rather than waiting until we actually try to build the module / load and validate its .pcm file). Differential Revision: https://reviews.llvm.org/D33703 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304515 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Modules')
-rw-r--r--test/Modules/Inputs/header-attribs/bar.h1
-rw-r--r--test/Modules/Inputs/header-attribs/baz.h1
-rw-r--r--test/Modules/Inputs/header-attribs/foo.h1
-rw-r--r--test/Modules/Inputs/header-attribs/modular.modulemap5
-rw-r--r--test/Modules/Inputs/header-attribs/textual.modulemap5
-rw-r--r--test/Modules/diagnostics.modulemap14
-rw-r--r--test/Modules/header-attribs.cpp10
-rw-r--r--test/Modules/preprocess-missing.modulemap7
-rw-r--r--test/Modules/preprocess-module.cpp15
9 files changed, 56 insertions, 3 deletions
diff --git a/test/Modules/Inputs/header-attribs/bar.h b/test/Modules/Inputs/header-attribs/bar.h
new file mode 100644
index 0000000000..796b4ebcc7
--- /dev/null
+++ b/test/Modules/Inputs/header-attribs/bar.h
@@ -0,0 +1 @@
+extern int b;
diff --git a/test/Modules/Inputs/header-attribs/baz.h b/test/Modules/Inputs/header-attribs/baz.h
new file mode 100644
index 0000000000..566a522b24
--- /dev/null
+++ b/test/Modules/Inputs/header-attribs/baz.h
@@ -0,0 +1 @@
+extern int c;
diff --git a/test/Modules/Inputs/header-attribs/foo.h b/test/Modules/Inputs/header-attribs/foo.h
new file mode 100644
index 0000000000..a54d4a7067
--- /dev/null
+++ b/test/Modules/Inputs/header-attribs/foo.h
@@ -0,0 +1 @@
+extern int a; \ No newline at end of file
diff --git a/test/Modules/Inputs/header-attribs/modular.modulemap b/test/Modules/Inputs/header-attribs/modular.modulemap
new file mode 100644
index 0000000000..945d7150fd
--- /dev/null
+++ b/test/Modules/Inputs/header-attribs/modular.modulemap
@@ -0,0 +1,5 @@
+module A {
+ header "foo.h" { size 13 }
+ header "bar.h" { size 1000 }
+ header "baz.h" { mtime 1 }
+}
diff --git a/test/Modules/Inputs/header-attribs/textual.modulemap b/test/Modules/Inputs/header-attribs/textual.modulemap
new file mode 100644
index 0000000000..b73f3698aa
--- /dev/null
+++ b/test/Modules/Inputs/header-attribs/textual.modulemap
@@ -0,0 +1,5 @@
+module A {
+ textual header "foo.h" { size 13 }
+ textual header "bar.h" { size 1000 }
+ textual header "baz.h" { mtime 1 }
+}
diff --git a/test/Modules/diagnostics.modulemap b/test/Modules/diagnostics.modulemap
index 3b5b6a5c03..865892b53b 100644
--- a/test/Modules/diagnostics.modulemap
+++ b/test/Modules/diagnostics.modulemap
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%S/Inputs/diagnostics-aux.modulemap -fmodule-map-file=%s -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%S/Inputs/diagnostics-aux.modulemap -fmodule-map-file=%s -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck %s --implicit-check-not error:
// CHECK: In file included from {{.*}}diagnostics-aux.modulemap:3:
// CHECK: diagnostics-aux-2.modulemap:2:3: error: expected
@@ -15,3 +15,15 @@ module bad_use {
// CHECK: diagnostics.modulemap:[[@LINE+1]]:22: error: use declarations are only allowed in top-level modules
module submodule { use foo }
}
+
+module header_attr {
+ // CHECK: diagnostics.modulemap:[[@LINE+1]]:20: error: expected a header attribute name
+ header "foo.h" { x }
+ // CHECK: diagnostics.modulemap:[[@LINE+1]]:27: error: header attribute 'size' specified multiple times
+ header "bar.h" { size 1 size 2 }
+ // CHECK: diagnostics.modulemap:[[@LINE+1]]:25: error: expected integer literal as value for header attribute 'size'
+ header "baz.h" { size "30 kilobytes" }
+
+ header "quux.h" { size 1 mtime 2 }
+ header "no_attrs.h" {}
+}
diff --git a/test/Modules/header-attribs.cpp b/test/Modules/header-attribs.cpp
new file mode 100644
index 0000000000..292a94561e
--- /dev/null
+++ b/test/Modules/header-attribs.cpp
@@ -0,0 +1,10 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -I%S/Inputs/header-attribs -fmodule-map-file=%S/Inputs/header-attribs/textual.modulemap -fmodules-cache-path=%t -verify %s -fmodule-name=A -fmodules-strict-decluse
+// RUN: not %clang_cc1 -fmodules -I%S/Inputs/header-attribs -emit-module -x c++-module-map %S/Inputs/header-attribs/modular.modulemap -fmodules-cache-path=%t -fmodule-name=A 2>&1 | FileCheck %s --check-prefix BUILD-MODULAR
+
+#include "foo.h" // ok, stats match
+#include "bar.h" // expected-error {{does not depend on a module exporting 'bar.h'}}
+#include "baz.h" // expected-error {{does not depend on a module exporting 'baz.h'}}
+
+// FIXME: Explain why the 'bar.h' found on disk doesn't match the module map.
+// BUILD-MODULAR: error: header 'bar.h' not found
diff --git a/test/Modules/preprocess-missing.modulemap b/test/Modules/preprocess-missing.modulemap
new file mode 100644
index 0000000000..300494672f
--- /dev/null
+++ b/test/Modules/preprocess-missing.modulemap
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -fmodules -fmodule-name=A -x c++-module-map %s -emit-module -o /dev/null -verify
+module A {
+ header "does not exist" { size 12345 } // ok, do not need mtime for explicit module build
+ header "also does not exist" { mtime 12345 }
+}
+#pragma clang module contents
+// expected-error@4 {{cannot emit module A: size must be explicitly specified for missing header file "also does not exist"}}
diff --git a/test/Modules/preprocess-module.cpp b/test/Modules/preprocess-module.cpp
index 9d1a2bb680..1e9458e667 100644
--- a/test/Modules/preprocess-module.cpp
+++ b/test/Modules/preprocess-module.cpp
@@ -28,12 +28,21 @@
// RUN: %clang_cc1 -fmodules -fmodule-file=%t/no-rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DINCLUDE -I%S/Inputs/preprocess
// RUN: %clang_cc1 -fmodules -fmodule-file=%t/rewrite.pcm %s -I%t -verify -fno-modules-error-recovery -DREWRITE -DINCLUDE -I%S/Inputs/preprocess
+// Now try building the module when the header files are missing.
+// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -I%t -x c++-module-map %t/module.modulemap -E -frewrite-includes -o %t/copy.ii
+// RUN: rm %t/fwd.h %t/file.h %t/file2.h %t/module.modulemap
+// RUN: %clang_cc1 -fmodules -fmodule-name=file -fmodule-file=%t/fwd.pcm -x c++-module-map-cpp-output %t/copy.ii -emit-module -o %t/copy.pcm
+
+// Finally, check that our module contains correct mapping information for the headers.
+// RUN: cp %S/Inputs/preprocess/fwd.h %S/Inputs/preprocess/file.h %S/Inputs/preprocess/file2.h %S/Inputs/preprocess/module.modulemap %t
+// RUN: %clang_cc1 -fmodules -fmodule-file=%t/copy.pcm %s -I%t -verify -fno-modules-error-recovery -DCOPY -DINCLUDE
// == module map
// CHECK: # 1 "{{.*}}module.modulemap"
// CHECK: module file {
-// CHECK: header "file.h"
-// CHECK: header "file2.h"
+// CHECK: header "file.h" { size
+// CHECK: header "file2.h" { size
// CHECK: }
// == file.h
@@ -98,6 +107,8 @@
__FILE *a; // expected-error {{declaration of '__FILE' must be imported}}
#ifdef REWRITE
// expected-note@rewrite.ii:1 {{here}}
+#elif COPY
+// expected-note@copy.ii:1 {{here}}
#else
// expected-note@no-rewrite.ii:1 {{here}}
#endif