summaryrefslogtreecommitdiffstats
path: root/clang/test/Modules
diff options
context:
space:
mode:
authorBruno Cardoso Lopes <bruno.cardoso@gmail.com>2018-06-25 22:24:17 +0000
committerBruno Cardoso Lopes <bruno.cardoso@gmail.com>2018-06-25 22:24:17 +0000
commit1b3b69fbda70d2cfe67a2b2e29d29dd26c9b0f2c (patch)
tree55b2017a00b27f21ae346c27ed3d1402725c655c /clang/test/Modules
parent9bca7483a537dc37bd686cadc1af78c103248a8a (diff)
downloadbcm5719-llvm-1b3b69fbda70d2cfe67a2b2e29d29dd26c9b0f2c.tar.gz
bcm5719-llvm-1b3b69fbda70d2cfe67a2b2e29d29dd26c9b0f2c.zip
Warning for framework include violation from Headers to PrivateHeaders
Framework vendors usually layout their framework headers in the following way: Foo.framework/Headers -> "public" headers Foo.framework/PrivateHeader -> "private" headers Since both headers in both directories can be found with #import <Foo/some-header.h>, it's easy to make mistakes and include headers in Foo.framework/PrivateHeader from headers in Foo.framework/Headers, which usually configures a layering violation on Darwin ecosystems. One of the problem this causes is dep cycles when modules are used, since it's very common for "private" modules to include from the "public" ones; adding an edge the other way around will trigger cycles. Add a warning to catch those cases such that: ./A.framework/Headers/A.h:1:10: warning: public framework header includes private framework header 'A/APriv.h' #include <A/APriv.h> ^ rdar://problem/38712182 llvm-svn: 335542
Diffstat (limited to 'clang/test/Modules')
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Headers/A.h4
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.modulemap4
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.private.modulemap4
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv.h1
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h1
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/a.hmap.json8
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.h2
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.modulemap4
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.private.modulemap4
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/ZPriv.h1
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/z.hmap.json7
-rw-r--r--clang/test/Modules/Inputs/framework-public-includes-private/z.yaml45
-rw-r--r--clang/test/Modules/framework-public-includes-private.m37
13 files changed, 122 insertions, 0 deletions
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Headers/A.h b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Headers/A.h
new file mode 100644
index 00000000000..03bd90b4945
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Headers/A.h
@@ -0,0 +1,4 @@
+#include <A/APriv.h>
+#include "APriv2.h"
+#include <Z/Z.h>
+int foo();
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.modulemap b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.modulemap
new file mode 100644
index 00000000000..09639b2b50b
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.modulemap
@@ -0,0 +1,4 @@
+// framework-public-includes-private/A.framework/Modules/module.modulemap
+framework module A {
+ header "A.h"
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.private.modulemap b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.private.modulemap
new file mode 100644
index 00000000000..8ede0b0d6ee
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/Modules/module.private.modulemap
@@ -0,0 +1,4 @@
+// framework-public-includes-private/A.framework/Modules/module.private.modulemap
+framework module A_Private {
+ header "APriv.h"
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv.h b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv.h
new file mode 100644
index 00000000000..34cc847512f
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv.h
@@ -0,0 +1 @@
+// framework-public-includes-private/A.framework/PrivateHeaders/APriv.h
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h
new file mode 100644
index 00000000000..8ffeb418374
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h
@@ -0,0 +1 @@
+// framework-public-includes-private/A.framework/PrivateHeaders/APriv2.h
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/a.hmap.json b/clang/test/Modules/Inputs/framework-public-includes-private/a.hmap.json
new file mode 100644
index 00000000000..42aed4551c1
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/a.hmap.json
@@ -0,0 +1,8 @@
+
+{
+ "mappings" :
+ {
+ "A.h" : "A/A.h",
+ "APriv2.h" : "A/APriv2.h"
+ }
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.h b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.h
new file mode 100644
index 00000000000..157c6daa76e
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.h
@@ -0,0 +1,2 @@
+// framework-public-includes-private/flat-header-path/Z.h
+#import "ZPriv.h"
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.modulemap b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.modulemap
new file mode 100644
index 00000000000..0a1a9710c4f
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.modulemap
@@ -0,0 +1,4 @@
+// framework-public-includes-private/flat-header-path/Z.modulemap
+framework module Z {
+ header "Z.h"
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.private.modulemap b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.private.modulemap
new file mode 100644
index 00000000000..f409af8a15a
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/Z.private.modulemap
@@ -0,0 +1,4 @@
+// framework-public-includes-private/flat-header-path/Z.private.modulemap
+framework module Z_Private {
+ header "ZPriv.h"
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/ZPriv.h b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/ZPriv.h
new file mode 100644
index 00000000000..08532fedbfa
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/flat-header-path/ZPriv.h
@@ -0,0 +1 @@
+// framework-public-includes-private/flat-header-path/ZPriv.h
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/z.hmap.json b/clang/test/Modules/Inputs/framework-public-includes-private/z.hmap.json
new file mode 100644
index 00000000000..206b25ec738
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/z.hmap.json
@@ -0,0 +1,7 @@
+
+{
+ "mappings" :
+ {
+ "ZPriv.h" : "Z/ZPriv.h"
+ }
+}
diff --git a/clang/test/Modules/Inputs/framework-public-includes-private/z.yaml b/clang/test/Modules/Inputs/framework-public-includes-private/z.yaml
new file mode 100644
index 00000000000..5793c1ff1f1
--- /dev/null
+++ b/clang/test/Modules/Inputs/framework-public-includes-private/z.yaml
@@ -0,0 +1,45 @@
+{
+ 'version': 0,
+ 'case-sensitive': 'false',
+ 'use-external-names' : 'false',
+ 'roots': [
+ {
+ 'type': 'directory',
+ 'name': "TEST_DIR/Z.framework/Headers",
+ 'contents': [
+ {
+ 'type': 'file',
+ 'name': "Z.h",
+ 'external-contents': "TEST_DIR/flat-header-path/Z.h"
+ }
+ ]
+ },
+ {
+ 'type': 'directory',
+ 'name': "TEST_DIR/Z.framework/PrivateHeaders",
+ 'contents': [
+ {
+ 'type': 'file',
+ 'name': "ZPriv.h",
+ 'external-contents': "TEST_DIR/flat-header-path/ZPriv.h"
+ }
+ ]
+ },
+ {
+ 'type': 'directory',
+ 'name': "TEST_DIR/Z.framework/Modules",
+ 'contents': [
+ {
+ 'type': 'file',
+ 'name': "module.modulemap",
+ 'external-contents': "TEST_DIR/flat-header-path/Z.modulemap"
+ },
+ {
+ 'type': 'file',
+ 'name': "module.private.modulemap",
+ 'external-contents': "TEST_DIR/flat-header-path/Z.private.modulemap"
+ }
+ ]
+ }
+ ]
+}
diff --git a/clang/test/Modules/framework-public-includes-private.m b/clang/test/Modules/framework-public-includes-private.m
new file mode 100644
index 00000000000..e58492091e3
--- /dev/null
+++ b/clang/test/Modules/framework-public-includes-private.m
@@ -0,0 +1,37 @@
+// REQUIRES: shell
+
+// RUN: rm -rf %t
+// RUN: mkdir %t
+
+// RUN: hmaptool write %S/Inputs/framework-public-includes-private/a.hmap.json %t/a.hmap
+// RUN: hmaptool write %S/Inputs/framework-public-includes-private/z.hmap.json %t/z.hmap
+
+// RUN: sed -e "s:TEST_DIR:%S/Inputs/framework-public-includes-private:g" \
+// RUN: %S/Inputs/framework-public-includes-private/z.yaml > %t/z.yaml
+
+// The output with and without modules should be the same, without modules first.
+// RUN: %clang_cc1 \
+// RUN: -iquote %t/z.hmap -iquote %t/a.hmap -ivfsoverlay %t/z.yaml \
+// RUN: -F%S/Inputs/framework-public-includes-private \
+// RUN: -fsyntax-only %s -verify
+
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/cache \
+// RUN: -iquote %t/z.hmap -iquote %t/a.hmap -ivfsoverlay %t/z.yaml \
+// RUN: -F%S/Inputs/framework-public-includes-private \
+// RUN: -fsyntax-only %s \
+// RUN: 2>%t/stderr
+
+// The same warnings show up when modules is on but -verify doesn't get it
+// because they only show up under the module A building context.
+// RUN: FileCheck --input-file=%t/stderr %s
+// CHECK: public framework header includes private framework header 'A/APriv.h'
+// CHECK: public framework header includes private framework header 'A/APriv2.h'
+// CHECK: public framework header includes private framework header 'Z/ZPriv.h'
+
+#import "A.h"
+
+int bar() { return foo(); }
+
+// expected-warning@Inputs/framework-public-includes-private/A.framework/Headers/A.h:1{{public framework header includes private framework header 'A/APriv.h'}}
+// expected-warning@Inputs/framework-public-includes-private/A.framework/Headers/A.h:2{{public framework header includes private framework header 'A/APriv2.h'}}
+// expected-warning@Inputs/framework-public-includes-private/flat-header-path/Z.h:2{{public framework header includes private framework header 'Z/ZPriv.h'}}
OpenPOWER on IntegriCloud