summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorSean Silva <chisophugis@gmail.com>2015-08-17 16:39:30 +0000
committerSean Silva <chisophugis@gmail.com>2015-08-17 16:39:30 +0000
commit8b7c0398b6a30d40de29e6f982a766c5016fc544 (patch)
tree7e3b23283141c20fde6118681aebe3fe4a8e85eb /clang/test
parent06044f97d21dfdabe4f9599447005b08e13344c1 (diff)
downloadbcm5719-llvm-8b7c0398b6a30d40de29e6f982a766c5016fc544.tar.gz
bcm5719-llvm-8b7c0398b6a30d40de29e6f982a766c5016fc544.zip
[modules] PR20507: Avoid silent textual inclusion.
Summary: If a module was unavailable (either a missing requirement on the module being imported, or a missing file anywhere in the top-level module (and not dominated by an unsatisfied `requires`)), we would silently treat inclusions as textual. This would cause all manner of crazy and confusing errors (and would also silently "work" sometimes, making the problem difficult to track down). I'm really not a fan of the `M->isAvailable(getLangOpts(), getTargetInfo(), Requirement, MissingHeader)` function; it seems to do too many things at once, but for now I've done things in a sort of awkward way. The changes to test/Modules/Inputs/declare-use/module.map were necessitated because the thing that was meant to be tested there (introduced in r197805) was predicated on silently falling back to textual inclusion, which we no longer do. The changes to test/Modules/Inputs/macro-reexport/module.modulemap are just an overlooked missing header that seems to have been missing since this code was committed (r213922), which is now caught. Reviewers: rsmith, benlangmuir, djasper Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D10423 llvm-svn: 245228
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h1
-rw-r--r--clang/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h1
-rw-r--r--clang/test/Modules/Inputs/auto-import-unavailable/module.modulemap19
-rw-r--r--clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h1
-rw-r--r--clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h1
-rw-r--r--clang/test/Modules/Inputs/available-is-better/available-is-better.h2
-rw-r--r--clang/test/Modules/Inputs/available-is-better/module.modulemap17
-rw-r--r--clang/test/Modules/Inputs/declare-use/module.map2
-rw-r--r--clang/test/Modules/Inputs/macro-reexport/module.modulemap1
-rw-r--r--clang/test/Modules/auto-import-unavailable.cpp47
-rw-r--r--clang/test/Modules/available-is-better.cpp5
11 files changed, 94 insertions, 3 deletions
diff --git a/clang/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h b/clang/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h
new file mode 100644
index 00000000000..5bab8334a4e
--- /dev/null
+++ b/clang/test/Modules/Inputs/auto-import-unavailable/missing_header/not_missing.h
@@ -0,0 +1 @@
+// missing_header/not_missing.h
diff --git a/clang/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h b/clang/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h
new file mode 100644
index 00000000000..7090978c9bc
--- /dev/null
+++ b/clang/test/Modules/Inputs/auto-import-unavailable/missing_requirement.h
@@ -0,0 +1 @@
+// missing_requirement.h
diff --git a/clang/test/Modules/Inputs/auto-import-unavailable/module.modulemap b/clang/test/Modules/Inputs/auto-import-unavailable/module.modulemap
new file mode 100644
index 00000000000..26196dcb373
--- /dev/null
+++ b/clang/test/Modules/Inputs/auto-import-unavailable/module.modulemap
@@ -0,0 +1,19 @@
+module missing_header {
+ module missing { header "missing_header/missing.h" }
+ module error_importing_this { header "missing_header/not_missing.h" }
+}
+
+module nonrequired_missing_header {
+ module unsatisfied_requires {
+ requires nonexistent_feature
+ header "nonrequired_missing_header/missing.h"
+ }
+ module fine_to_import {
+ header "nonrequired_missing_header/not_missing.h"
+ }
+}
+
+module missing_requirement {
+ requires nonexistent_feature
+ header "missing_requirement.h"
+}
diff --git a/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h b/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
new file mode 100644
index 00000000000..3ccfcb1b474
--- /dev/null
+++ b/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/not_missing.h
@@ -0,0 +1 @@
+// nonrequired_missing_header/not_missing.h
diff --git a/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h b/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
new file mode 100644
index 00000000000..1bcb70d2afc
--- /dev/null
+++ b/clang/test/Modules/Inputs/auto-import-unavailable/nonrequired_missing_header/requires_feature_you_dont_have.h
@@ -0,0 +1 @@
+// nonrequired_missing_header/requires_feature_you_dont_have.h
diff --git a/clang/test/Modules/Inputs/available-is-better/available-is-better.h b/clang/test/Modules/Inputs/available-is-better/available-is-better.h
new file mode 100644
index 00000000000..8ed032081af
--- /dev/null
+++ b/clang/test/Modules/Inputs/available-is-better/available-is-better.h
@@ -0,0 +1,2 @@
+#pragma once
+int available;
diff --git a/clang/test/Modules/Inputs/available-is-better/module.modulemap b/clang/test/Modules/Inputs/available-is-better/module.modulemap
new file mode 100644
index 00000000000..19ffabdffbe
--- /dev/null
+++ b/clang/test/Modules/Inputs/available-is-better/module.modulemap
@@ -0,0 +1,17 @@
+// There is some order-dependence to how clang chooses modules, so make
+// sure that both the first and last modules here are ones that would
+// cause a test failure if they were picked.
+
+module unavailable_before {
+ requires nonexistent_feature
+ header "available-is-better.h"
+}
+
+module available {
+ header "available-is-better.h"
+}
+
+module unavailable_after {
+ requires nonexistent_feature
+ header "available-is-better.h"
+}
diff --git a/clang/test/Modules/Inputs/declare-use/module.map b/clang/test/Modules/Inputs/declare-use/module.map
index 2dad0d061cf..14551fde7e1 100644
--- a/clang/test/Modules/Inputs/declare-use/module.map
+++ b/clang/test/Modules/Inputs/declare-use/module.map
@@ -20,14 +20,12 @@ module XD {
module XE {
header "e.h"
- header "unavailable.h"
use XA
use XB
}
module XF {
header "f.h"
- header "unavailable.h"
use XA
use XB
}
diff --git a/clang/test/Modules/Inputs/macro-reexport/module.modulemap b/clang/test/Modules/Inputs/macro-reexport/module.modulemap
index 896bda041c3..f861ff89555 100644
--- a/clang/test/Modules/Inputs/macro-reexport/module.modulemap
+++ b/clang/test/Modules/Inputs/macro-reexport/module.modulemap
@@ -19,5 +19,4 @@ module e {
}
module f {
module f1 { header "f1.h" export * }
- module f2 { header "f2.h" export * }
}
diff --git a/clang/test/Modules/auto-import-unavailable.cpp b/clang/test/Modules/auto-import-unavailable.cpp
new file mode 100644
index 00000000000..a35695d42a2
--- /dev/null
+++ b/clang/test/Modules/auto-import-unavailable.cpp
@@ -0,0 +1,47 @@
+// RUN: rm -rf %t
+// RUN: not %clang_cc1 -x c++ -Rmodule-build -DMISSING_HEADER -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=MISSING-HEADER
+// RUN: %clang_cc1 -x c++ -Rmodule-build -DNONREQUIRED_MISSING_HEADER -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=NONREQUIRED-MISSING-HEADER
+// RUN: not %clang_cc1 -x c++ -Rmodule-build -DMISSING_REQUIREMENT -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/auto-import-unavailable %s 2>&1 | FileCheck %s --check-prefix=MISSING-REQUIREMENT
+
+#ifdef MISSING_HEADER
+
+// Even if the header we ask for is not missing, if the top-level module
+// containing it has a missing header, then the whole top-level is
+// unavailable and we issue an error.
+
+// MISSING-HEADER: module.modulemap:2:27: error: header 'missing_header/missing.h' not found
+// MISSING-HEADER-DAG: auto-import-unavailable.cpp:[[@LINE+1]]:10: note: submodule of top-level module 'missing_header' implicitly imported here
+#include "missing_header/not_missing.h"
+
+// We should not attempt to build the module.
+// MISSING-HEADER-NOT: remark: building module
+
+#endif // #ifdef MISSING_HEADER
+
+
+#ifdef NONREQUIRED_MISSING_HEADER
+
+// However, if the missing header is dominated by an unsatisfied
+// `requires`, then that is acceptable.
+// This also tests that an unsatisfied `requires` elsewhere in the
+// top-level module doesn't affect an available module.
+
+// NONREQUIRED-MISSING-HEADER: auto-import-unavailable.cpp:[[@LINE+2]]:10: remark: building module 'nonrequired_missing_header'
+// NONREQUIRED-MISSING-HEADER: auto-import-unavailable.cpp:[[@LINE+1]]:10: remark: finished building module 'nonrequired_missing_header'
+#include "nonrequired_missing_header/not_missing.h"
+
+#endif // #ifdef NONREQUIRED_MISSING_HEADER
+
+
+#ifdef MISSING_REQUIREMENT
+
+// If the header is unavailable due to a missing requirement, an error
+// should be emitted if a user tries to include it.
+
+// MISSING-REQUIREMENT:module.modulemap:16:8: error: module 'missing_requirement' requires feature 'nonexistent_feature'
+// MISSING-REQUIREMENT: auto-import-unavailable.cpp:[[@LINE+1]]:10: note: submodule of top-level module 'missing_requirement' implicitly imported here
+#include "missing_requirement.h"
+
+// MISSING-REQUIREMENT-NOT: remark: building module
+
+#endif // #ifdef MISSING_REQUIREMENT
diff --git a/clang/test/Modules/available-is-better.cpp b/clang/test/Modules/available-is-better.cpp
new file mode 100644
index 00000000000..39d37c405e2
--- /dev/null
+++ b/clang/test/Modules/available-is-better.cpp
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -Rmodule-build -fmodules -fimplicit-module-maps -fmodules-cache-path=%t -I %S/Inputs/available-is-better %s 2>&1 | FileCheck %s
+
+#include "available-is-better.h"
+// CHECK: remark: building module
OpenPOWER on IntegriCloud