summaryrefslogtreecommitdiff
path: root/test/Modules
diff options
context:
space:
mode:
authorBen Langmuir <blangmuir@apple.com>2015-07-02 13:19:48 +0000
committerBen Langmuir <blangmuir@apple.com>2015-07-02 13:19:48 +0000
commit66f5404ebc08732a21da6e131d92afe3e1fa2012 (patch)
tree76f9f536350d790acba016b14d91ad5c36feb056 /test/Modules
parentb73f25667c9dfb5cf9a136b83c5ddfd9b03668fd (diff)
downloadclang-66f5404ebc08732a21da6e131d92afe3e1fa2012.tar.gz
[Modules] Be consistent about finding a module for framework headers
We use findModuleForHeader() in several places, but in header search we were not calling it when a framework module didn't show up with the expected name, which would then lead to unexpected non-modular includes. Now we will find the module unconditionally for frameworks. For regular frameworks, we use the spelling of the module name from the module map file, and for inferred ones we use the canonical directory name. In the future we might want to lock down framework modules sufficiently that these name mismatches cannot happen. rdar://problem/20465870 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@241258 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/Modules')
-rw-r--r--test/Modules/Inputs/ImportNameInDir.h4
-rw-r--r--test/Modules/Inputs/NameInDir.framework/Headers/NameInDir.h2
-rw-r--r--test/Modules/Inputs/NameInDir.framework/Modules/module.modulemap5
-rw-r--r--test/Modules/Inputs/NameInDir2.framework/Headers/NameInDir2.h1
-rw-r--r--test/Modules/Inputs/NameInDir2.framework/Modules/module.modulemap5
-rw-r--r--test/Modules/Inputs/NameInDirInferred.framework/Headers/NameInDirInferred.h1
-rw-r--r--test/Modules/Inputs/module.map4
-rw-r--r--test/Modules/framework-name.m33
8 files changed, 55 insertions, 0 deletions
diff --git a/test/Modules/Inputs/ImportNameInDir.h b/test/Modules/Inputs/ImportNameInDir.h
new file mode 100644
index 0000000000..ae7b1a0fb2
--- /dev/null
+++ b/test/Modules/Inputs/ImportNameInDir.h
@@ -0,0 +1,4 @@
+#import <NameInDir/NameInDir.h>
+
+// Don't crash.
+#undef NAME_IN_DIR
diff --git a/test/Modules/Inputs/NameInDir.framework/Headers/NameInDir.h b/test/Modules/Inputs/NameInDir.framework/Headers/NameInDir.h
new file mode 100644
index 0000000000..bea2391485
--- /dev/null
+++ b/test/Modules/Inputs/NameInDir.framework/Headers/NameInDir.h
@@ -0,0 +1,2 @@
+// NameInDir.h
+#define NAME_IN_DIR 1
diff --git a/test/Modules/Inputs/NameInDir.framework/Modules/module.modulemap b/test/Modules/Inputs/NameInDir.framework/Modules/module.modulemap
new file mode 100644
index 0000000000..48e1c56749
--- /dev/null
+++ b/test/Modules/Inputs/NameInDir.framework/Modules/module.modulemap
@@ -0,0 +1,5 @@
+framework module NameInModMap {
+ umbrella header "NameInDir.h"
+ export *
+ module * { export * }
+}
diff --git a/test/Modules/Inputs/NameInDir2.framework/Headers/NameInDir2.h b/test/Modules/Inputs/NameInDir2.framework/Headers/NameInDir2.h
new file mode 100644
index 0000000000..6dc3eea149
--- /dev/null
+++ b/test/Modules/Inputs/NameInDir2.framework/Headers/NameInDir2.h
@@ -0,0 +1 @@
+// NameInDir2.h
diff --git a/test/Modules/Inputs/NameInDir2.framework/Modules/module.modulemap b/test/Modules/Inputs/NameInDir2.framework/Modules/module.modulemap
new file mode 100644
index 0000000000..24f15f8e84
--- /dev/null
+++ b/test/Modules/Inputs/NameInDir2.framework/Modules/module.modulemap
@@ -0,0 +1,5 @@
+framework module NameInDir2 {
+ umbrella header "NameInDir2.h"
+ export *
+ module * { export * }
+}
diff --git a/test/Modules/Inputs/NameInDirInferred.framework/Headers/NameInDirInferred.h b/test/Modules/Inputs/NameInDirInferred.framework/Headers/NameInDirInferred.h
new file mode 100644
index 0000000000..c0b12e6f94
--- /dev/null
+++ b/test/Modules/Inputs/NameInDirInferred.framework/Headers/NameInDirInferred.h
@@ -0,0 +1 @@
+// NameInDirInferred.h
diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map
index b9c8e72cfa..ffaa53e18e 100644
--- a/test/Modules/Inputs/module.map
+++ b/test/Modules/Inputs/module.map
@@ -332,3 +332,7 @@ module DebugModule {
header "DebugModule.h"
}
+module ImportNameInDir {
+ header "ImportNameInDir.h"
+ export *
+}
diff --git a/test/Modules/framework-name.m b/test/Modules/framework-name.m
new file mode 100644
index 0000000000..a63e206073
--- /dev/null
+++ b/test/Modules/framework-name.m
@@ -0,0 +1,33 @@
+// REQUIRES: shell
+// RUN: rm -rf %t.mcp %t
+// RUN: mkdir -p %t
+// RUN: ln -s %S/Inputs/NameInDir2.framework %t/NameInImport.framework
+// RUN: ln -s %S/Inputs/NameInDirInferred.framework %t/NameInImportInferred.framework
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t.mcp -fimplicit-module-maps -I %S/Inputs -F %S/Inputs -F %t -Wauto-import -verify %s
+
+// Sanity check that we won't somehow find non-canonical module names or
+// modules where we shouldn't search the framework.
+// RUN: echo '@import NameInModMap' | not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -F %S/Inputs -F %t -Wauto-import -x objective-c - 2>&1 | FileCheck %s
+// RUN: echo '@import NameInDir' | not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -F %S/Inputs -F %t -Wauto-import -x objective-c - 2>&1 | FileCheck %s
+// RUN: echo '@import NameInImport' | not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -F %S/Inputs -F %t -Wauto-import -x objective-c - 2>&1 | FileCheck %s
+// RUN: echo '@import NameInImportInferred' | not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t.mcp -F %S/Inputs -F %t -Wauto-import -x objective-c - 2>&1 | FileCheck %s
+// CHECK: module '{{.*}}' not found
+
+// FIXME: We might want to someday lock down framework modules so that these
+// name mismatches are disallowed. However, as long as we *don't* prevent them
+// it's important that they map correctly to module imports.
+
+// The module map name doesn't match the directory name.
+#import <NameInDir/NameInDir.h> // expected-warning {{import of module 'NameInModMap'}}
+
+// The name in the import doesn't match the module name.
+#import <NameInImport/NameInDir2.h> // expected-warning {{import of module 'NameInDir2'}}
+@import NameInDir2; // OK
+
+// The name in the import doesn't match the module name (inferred framework module).
+#import <NameInImportInferred/NameInDirInferred.h> // expected-warning {{import of module 'NameInDirInferred'}}
+
+@import ImportNameInDir;
+#ifdef NAME_IN_DIR
+#error NAME_IN_DIR should be undef'd
+#endif