Update aosp/master clang for rebase to r233350

Change-Id: I12d4823f10bc9e445b8b86e7721b71f98d1df442
diff --git a/test/Modules/Inputs/Module.framework/Headers/Module.h b/test/Modules/Inputs/Module.framework/Headers/Module.h
index 3d2476b..7299823 100644
--- a/test/Modules/Inputs/Module.framework/Headers/Module.h
+++ b/test/Modules/Inputs/Module.framework/Headers/Module.h
@@ -25,4 +25,13 @@
 
 __asm("foo");
 
+typedef	struct __sFILE {
+  int _offset;
+} FILE;
+
+extern FILE *myFile;
+
+#define SOME_MACRO_ATTR_GETTING_UNDEFINED __attribute__((objc_method_family(none)))
+#undef SOME_MACRO_ATTR_GETTING_UNDEFINED
+
 #endif // MODULE_H
diff --git a/test/Modules/Inputs/PR21687/a.h b/test/Modules/Inputs/PR21687/a.h
new file mode 100644
index 0000000..023606e
--- /dev/null
+++ b/test/Modules/Inputs/PR21687/a.h
@@ -0,0 +1 @@
+struct X { X(); virtual ~X(); };
diff --git a/test/Modules/Inputs/PR21687/b.h b/test/Modules/Inputs/PR21687/b.h
new file mode 100644
index 0000000..7085b1f
--- /dev/null
+++ b/test/Modules/Inputs/PR21687/b.h
@@ -0,0 +1,2 @@
+#include "a.h"
+X *n = new X;
diff --git a/test/Modules/Inputs/PR21687/c.h b/test/Modules/Inputs/PR21687/c.h
new file mode 100644
index 0000000..5c5d555
--- /dev/null
+++ b/test/Modules/Inputs/PR21687/c.h
@@ -0,0 +1,4 @@
+#include "a.h"
+inline void f() { X x, y(x); }
+#include "b.h"
+X x, y(x);
diff --git a/test/Modules/Inputs/PR21687/module.modulemap b/test/Modules/Inputs/PR21687/module.modulemap
new file mode 100644
index 0000000..77e0a89
--- /dev/null
+++ b/test/Modules/Inputs/PR21687/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
diff --git a/test/Modules/Inputs/anon-namespace/a.h b/test/Modules/Inputs/anon-namespace/a.h
new file mode 100644
index 0000000..fe71f40
--- /dev/null
+++ b/test/Modules/Inputs/anon-namespace/a.h
@@ -0,0 +1 @@
+namespace N {}
diff --git a/test/Modules/Inputs/anon-namespace/b1.h b/test/Modules/Inputs/anon-namespace/b1.h
new file mode 100644
index 0000000..480e8e4
--- /dev/null
+++ b/test/Modules/Inputs/anon-namespace/b1.h
@@ -0,0 +1,2 @@
+namespace N {}
+namespace N { namespace {} }
diff --git a/test/Modules/Inputs/anon-namespace/b2.h b/test/Modules/Inputs/anon-namespace/b2.h
new file mode 100644
index 0000000..8e7535f
--- /dev/null
+++ b/test/Modules/Inputs/anon-namespace/b2.h
@@ -0,0 +1,2 @@
+#include "a.h"
+namespace N {}
diff --git a/test/Modules/Inputs/anon-namespace/c.h b/test/Modules/Inputs/anon-namespace/c.h
new file mode 100644
index 0000000..fe71f40
--- /dev/null
+++ b/test/Modules/Inputs/anon-namespace/c.h
@@ -0,0 +1 @@
+namespace N {}
diff --git a/test/Modules/Inputs/anon-namespace/module.modulemap b/test/Modules/Inputs/anon-namespace/module.modulemap
new file mode 100644
index 0000000..3d390d2
--- /dev/null
+++ b/test/Modules/Inputs/anon-namespace/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" export * }
+module b { module b1 { header "b1.h" export * } module b2 { header "b2.h" export * } }
+module c { header "c.h" export * }
diff --git a/test/Modules/Inputs/cxx-decls-imported.h b/test/Modules/Inputs/cxx-decls-imported.h
index 8c1e74f..a4910fe 100644
--- a/test/Modules/Inputs/cxx-decls-imported.h
+++ b/test/Modules/Inputs/cxx-decls-imported.h
@@ -47,3 +47,6 @@
 
 namespace Aliased { extern int a; }
 namespace Alias = Aliased;
+
+struct InhCtorA { InhCtorA(int); };
+struct InhCtorB : InhCtorA { using InhCtorA::InhCtorA; };
diff --git a/test/Modules/Inputs/cxx-decls-merged.h b/test/Modules/Inputs/cxx-decls-merged.h
index 86e81a9..5eefb44 100644
--- a/test/Modules/Inputs/cxx-decls-merged.h
+++ b/test/Modules/Inputs/cxx-decls-merged.h
@@ -25,3 +25,6 @@
 
 namespace Aliased { extern int b; }
 namespace Alias = Aliased;
+
+struct InhCtorA { InhCtorA(int); };
+struct InhCtorB : InhCtorA { using InhCtorA::InhCtorA; };
diff --git a/test/Modules/Inputs/cxx-dtor/a.h b/test/Modules/Inputs/cxx-dtor/a.h
new file mode 100644
index 0000000..023606e
--- /dev/null
+++ b/test/Modules/Inputs/cxx-dtor/a.h
@@ -0,0 +1 @@
+struct X { X(); virtual ~X(); };
diff --git a/test/Modules/Inputs/cxx-dtor/b.h b/test/Modules/Inputs/cxx-dtor/b.h
new file mode 100644
index 0000000..7595856
--- /dev/null
+++ b/test/Modules/Inputs/cxx-dtor/b.h
@@ -0,0 +1,3 @@
+struct X { X(); virtual ~X(); };
+inline X::~X() {}
+#include "a.h"
diff --git a/test/Modules/Inputs/cxx-dtor/module.modulemap b/test/Modules/Inputs/cxx-dtor/module.modulemap
new file mode 100644
index 0000000..61578a1
--- /dev/null
+++ b/test/Modules/Inputs/cxx-dtor/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
diff --git a/test/Modules/Inputs/declare-use/module.map b/test/Modules/Inputs/declare-use/module.map
index ae86152..2dad0d0 100644
--- a/test/Modules/Inputs/declare-use/module.map
+++ b/test/Modules/Inputs/declare-use/module.map
@@ -3,7 +3,7 @@
 }
 
 module XB {
-  header "b.h"
+  module B { header "b.h" }
 }
 
 module XC {
@@ -39,10 +39,11 @@
   use XE
   use XJ
   use XK
+  use XN
 }
 
 module XH {
-  header "h.h"
+  module H { header "h.h" }
   header "h1.h"
   header "s.h"
   use XC
@@ -66,5 +67,11 @@
   textual header "m2.h"
 }
 
+module XN {
+  module sub {
+    header "sub.h"
+  }
+}
+
 module XS {
 }
diff --git a/test/Modules/Inputs/declare-use/sub.h b/test/Modules/Inputs/declare-use/sub.h
new file mode 100644
index 0000000..63d4234
--- /dev/null
+++ b/test/Modules/Inputs/declare-use/sub.h
@@ -0,0 +1,4 @@
+#ifndef SUB_H
+#define SUB_H
+const int sub = 42;
+#endif
diff --git a/test/Modules/Inputs/diagnostics-aux.modulemap b/test/Modules/Inputs/diagnostics-aux.modulemap
new file mode 100644
index 0000000..d067d04
--- /dev/null
+++ b/test/Modules/Inputs/diagnostics-aux.modulemap
@@ -0,0 +1 @@
+module foo {}
diff --git a/test/Modules/Inputs/empty.h b/test/Modules/Inputs/empty.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/empty.h
diff --git a/test/Modules/Inputs/empty/empty.h b/test/Modules/Inputs/empty/empty.h
new file mode 100644
index 0000000..e26b0ab
--- /dev/null
+++ b/test/Modules/Inputs/empty/empty.h
@@ -0,0 +1 @@
+// This file intentionally left empty.
diff --git a/test/Modules/Inputs/explicit-build/d.h b/test/Modules/Inputs/explicit-build/d.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/explicit-build/d.h
diff --git a/test/Modules/Inputs/explicit-build/module.modulemap b/test/Modules/Inputs/explicit-build/module.modulemap
index bd6ea83..992eed6 100644
--- a/test/Modules/Inputs/explicit-build/module.modulemap
+++ b/test/Modules/Inputs/explicit-build/module.modulemap
@@ -1,3 +1,4 @@
 module a { header "a.h" }
 module b { header "b.h" export * }
 module c { header "c.h" export * }
+module d { header "d.h" }
diff --git a/test/Modules/Inputs/invalidate-identifiers/a.h b/test/Modules/Inputs/invalidate-identifiers/a.h
new file mode 100644
index 0000000..16fe9ed
--- /dev/null
+++ b/test/Modules/Inputs/invalidate-identifiers/a.h
@@ -0,0 +1,17 @@
+// Ensure that loading 'i' introduces enough identifiers to cause the
+// identifier table to be reallocated.
+#define TYPEDEFS(x) typedef x##0 x; typedef x##1 x;
+#define DEPTH_0(x) DEPTH_1(x##0) DEPTH_1(x##1) TYPEDEFS(x)
+#define DEPTH_1(x) DEPTH_2(x##0) DEPTH_2(x##1) TYPEDEFS(x)
+#define DEPTH_2(x) DEPTH_3(x##0) DEPTH_3(x##1) TYPEDEFS(x)
+#define DEPTH_3(x) DEPTH_4(x##0) DEPTH_4(x##1) TYPEDEFS(x)
+#define DEPTH_4(x) DEPTH_5(x##0) DEPTH_5(x##1) TYPEDEFS(x)
+#define DEPTH_5(x) DEPTH_6(x##0) DEPTH_6(x##1) TYPEDEFS(x)
+#define DEPTH_6(x) DEPTH_7(x##0) DEPTH_7(x##1) TYPEDEFS(x)
+#define DEPTH_7(x) DEPTH_8(x##0) DEPTH_8(x##1) TYPEDEFS(x)
+#define DEPTH_8(x) DEPTH_9(x##0) DEPTH_9(x##1) TYPEDEFS(x)
+#define DEPTH_9(x) DEPTH_A(x##0) DEPTH_A(x##1) TYPEDEFS(x)
+#define DEPTH_A(x) DEPTH_B(x##0) DEPTH_B(x##1) TYPEDEFS(x)
+#define DEPTH_B(x) typedef int x;
+DEPTH_0(i)
+extern i v;
diff --git a/test/Modules/Inputs/invalidate-identifiers/b.h b/test/Modules/Inputs/invalidate-identifiers/b.h
new file mode 100644
index 0000000..2af246d
--- /dev/null
+++ b/test/Modules/Inputs/invalidate-identifiers/b.h
@@ -0,0 +1,2 @@
+extern int v;
+#include "a.h"
diff --git a/test/Modules/Inputs/invalidate-identifiers/module.modulemap b/test/Modules/Inputs/invalidate-identifiers/module.modulemap
new file mode 100644
index 0000000..a365682
--- /dev/null
+++ b/test/Modules/Inputs/invalidate-identifiers/module.modulemap
@@ -0,0 +1,2 @@
+module a { header "a.h" }
+module b { header "b.h" }
diff --git a/test/Modules/Inputs/macro-ambiguity/a/quote/a_quote.h b/test/Modules/Inputs/macro-ambiguity/a/quote/a_quote.h
new file mode 100644
index 0000000..efe6fa1
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/a/quote/a_quote.h
@@ -0,0 +1,8 @@
+#ifndef A_QUOTE_H
+#define A_QUOTE_H
+
+#define FOO1_QUOTE(x) x + x
+#define BAR1_QUOTE(x) x + x
+#define BAZ1_QUOTE(x) x + x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/a/system/a_system.h b/test/Modules/Inputs/macro-ambiguity/a/system/a_system.h
new file mode 100644
index 0000000..f9f3287
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/a/system/a_system.h
@@ -0,0 +1,15 @@
+#ifndef A_SYSTEM_H
+#define A_SYSTEM_H
+
+// FIXME: We have to use this to mark the header as a system header in
+// a module because header search didn't actually occur and so we can't have
+// found the header via system header search, even though when we map to this
+// header and load the module we will have mapped to the header by finding it
+// via system header search.
+#pragma GCC system_header
+
+#define FOO1_SYSTEM(x) x + x
+#define BAR1_SYSTEM(x) x + x
+#define BAZ1_SYSTEM(x) x + x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/b/quote/b_quote.h b/test/Modules/Inputs/macro-ambiguity/b/quote/b_quote.h
new file mode 100644
index 0000000..f5e990f
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/b/quote/b_quote.h
@@ -0,0 +1,8 @@
+#ifndef B_QUOTE_H
+#define B_QUOTE_H
+
+#define FOO2_QUOTE(x) x + x
+#define BAR2_QUOTE(x) x + x
+#define BAZ2_QUOTE(x) x + x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/b/system/b_system.h b/test/Modules/Inputs/macro-ambiguity/b/system/b_system.h
new file mode 100644
index 0000000..5b55303
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/b/system/b_system.h
@@ -0,0 +1,15 @@
+#ifndef B_SYSTEM_H
+#define B_SYSTEM_H
+
+// FIXME: We have to use this to mark the header as a system header in
+// a module because header search didn't actually occur and so we can't have
+// found the header via system header search, even though when we map to this
+// header and load the module we will have mapped to the header by finding it
+// via system header search.
+#pragma GCC system_header
+
+#define FOO2_SYSTEM(x) x + x
+#define BAR2_SYSTEM(x) x + x
+#define BAZ2_SYSTEM(x) x + x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/c/quote/c_quote.h b/test/Modules/Inputs/macro-ambiguity/c/quote/c_quote.h
new file mode 100644
index 0000000..1314300
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/c/quote/c_quote.h
@@ -0,0 +1,7 @@
+#ifndef C_QUOTE_H
+#define C_QUOTE_H
+
+#define FOO1_QUOTE(x) 2 * x
+#define FOO2_QUOTE(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/c/system/c_system.h b/test/Modules/Inputs/macro-ambiguity/c/system/c_system.h
new file mode 100644
index 0000000..25e795d
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/c/system/c_system.h
@@ -0,0 +1,14 @@
+#ifndef C_SYSTEM_H
+#define C_SYSTEM_H
+
+// FIXME: We have to use this to mark the header as a system header in
+// a module because header search didn't actually occur and so we can't have
+// found the header via system header search, even though when we map to this
+// header and load the module we will have mapped to the header by finding it
+// via system header search.
+#pragma GCC system_header
+
+#define FOO1_SYSTEM(x) 2 * x
+#define FOO2_SYSTEM(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/d/quote/d_quote.h b/test/Modules/Inputs/macro-ambiguity/d/quote/d_quote.h
new file mode 100644
index 0000000..ac9d43b
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/d/quote/d_quote.h
@@ -0,0 +1,7 @@
+#ifndef D_QUOTE_H
+#define D_QUOTE_H
+
+#define BAR1_QUOTE(x) 2 * x
+#define BAR2_QUOTE(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/d/system/d_system.h b/test/Modules/Inputs/macro-ambiguity/d/system/d_system.h
new file mode 100644
index 0000000..5c10cc1
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/d/system/d_system.h
@@ -0,0 +1,14 @@
+#ifndef D_SYSTEM_H
+#define D_SYSTEM_H
+
+// FIXME: We have to use this to mark the header as a system header in
+// a module because header search didn't actually occur and so we can't have
+// found the header via system header search, even though when we map to this
+// header and load the module we will have mapped to the header by finding it
+// via system header search.
+#pragma GCC system_header
+
+#define BAR1_SYSTEM(x) 2 * x
+#define BAR2_SYSTEM(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/e/quote/e_quote.h b/test/Modules/Inputs/macro-ambiguity/e/quote/e_quote.h
new file mode 100644
index 0000000..7849429
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/e/quote/e_quote.h
@@ -0,0 +1,7 @@
+#ifndef E_QUOTE_H
+#define E_QUOTE_H
+
+#define BAZ1_QUOTE(x) 2 * x
+#define BAZ2_QUOTE(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/e/system/e_system.h b/test/Modules/Inputs/macro-ambiguity/e/system/e_system.h
new file mode 100644
index 0000000..c9e1341
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/e/system/e_system.h
@@ -0,0 +1,7 @@
+#ifndef E_SYSTEM_H
+#define E_SYSTEM_H
+
+#define BAZ1_SYSTEM(x) 2 * x
+#define BAZ2_SYSTEM(x) 2 * x
+
+#endif
diff --git a/test/Modules/Inputs/macro-ambiguity/module.modulemap b/test/Modules/Inputs/macro-ambiguity/module.modulemap
new file mode 100644
index 0000000..23da294
--- /dev/null
+++ b/test/Modules/Inputs/macro-ambiguity/module.modulemap
@@ -0,0 +1,25 @@
+module a {
+  header "Inputs/macro-ambiguity/a/quote/a_quote.h"
+  header "Inputs/macro-ambiguity/a/system/a_system.h"
+  export *
+}
+module b [system] {
+  header "Inputs/macro-ambiguity/b/quote/b_quote.h"
+  header "Inputs/macro-ambiguity/b/system/b_system.h"
+  export *
+}
+module c {
+  header "Inputs/macro-ambiguity/c/quote/c_quote.h"
+  header "Inputs/macro-ambiguity/c/system/c_system.h"
+  export *
+}
+module d [system] {
+  header "Inputs/macro-ambiguity/d/quote/d_quote.h"
+  header "Inputs/macro-ambiguity/d/system/d_system.h"
+  export *
+}
+module e {
+  textual header "Inputs/macro-ambiguity/e/quote/e_quote.h"
+  textual header "Inputs/macro-ambiguity/e/system/e_system.h"
+  export *
+}
diff --git a/test/Modules/Inputs/merge-decl-context/a.h b/test/Modules/Inputs/merge-decl-context/a.h
index bd08eca..89cc712 100644
--- a/test/Modules/Inputs/merge-decl-context/a.h
+++ b/test/Modules/Inputs/merge-decl-context/a.h
@@ -8,6 +8,8 @@
   }
   A(double) {}
   A(double, double) {}
+  A(double, int) {}
+  A(int, double) {}
 };
 
 template <typename T1, typename T2>
diff --git a/test/Modules/Inputs/merge-decl-context/d.h b/test/Modules/Inputs/merge-decl-context/d.h
new file mode 100644
index 0000000..ccc7308
--- /dev/null
+++ b/test/Modules/Inputs/merge-decl-context/d.h
@@ -0,0 +1,7 @@
+#ifndef D_H
+#define D_H
+
+#include "a.h"
+#include "b.h"
+
+#endif
diff --git a/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap b/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap
index fedc5df..46f6954 100644
--- a/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap
+++ b/test/Modules/Inputs/merge-decl-context/merge-decl-context.modulemap
@@ -11,3 +11,8 @@
   export *
   header "c.h"
 }
+
+module "d" {
+  export *
+  header "d.h"
+}
diff --git a/test/Modules/Inputs/merge-target-features/foo.h b/test/Modules/Inputs/merge-target-features/foo.h
new file mode 100644
index 0000000..1c8b3f6
--- /dev/null
+++ b/test/Modules/Inputs/merge-target-features/foo.h
@@ -0,0 +1,8 @@
+#ifndef FOO_H
+#define FOO_H
+
+int foo(int x) {
+  return x + 42;
+}
+
+#endif // FOO_H
diff --git a/test/Modules/Inputs/merge-target-features/module.modulemap b/test/Modules/Inputs/merge-target-features/module.modulemap
new file mode 100644
index 0000000..f2e9932
--- /dev/null
+++ b/test/Modules/Inputs/merge-target-features/module.modulemap
@@ -0,0 +1 @@
+module foo { header "Inputs/merge-target-features/foo.h" export * }
diff --git a/test/Modules/Inputs/merge-template-friend/def.h b/test/Modules/Inputs/merge-template-friend/def.h
new file mode 100644
index 0000000..c75f5f6
--- /dev/null
+++ b/test/Modules/Inputs/merge-template-friend/def.h
@@ -0,0 +1,3 @@
+namespace ns {
+template <typename T> class C {};
+}
diff --git a/test/Modules/Inputs/merge-template-friend/friend.h b/test/Modules/Inputs/merge-template-friend/friend.h
new file mode 100644
index 0000000..97fb758
--- /dev/null
+++ b/test/Modules/Inputs/merge-template-friend/friend.h
@@ -0,0 +1,4 @@
+namespace ns { template <typename T> class C; };
+class A {
+  template <typename T> friend class ::ns::C;
+};
diff --git a/test/Modules/Inputs/merge-template-friend/module.modulemap b/test/Modules/Inputs/merge-template-friend/module.modulemap
new file mode 100644
index 0000000..7737ad9
--- /dev/null
+++ b/test/Modules/Inputs/merge-template-friend/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "friend.h" export * }
+module b { header "def.h" export * }
+
diff --git a/test/Modules/Inputs/redecl-found-building-chains/a.h b/test/Modules/Inputs/redecl-found-building-chains/a.h
new file mode 100644
index 0000000..27f503c
--- /dev/null
+++ b/test/Modules/Inputs/redecl-found-building-chains/a.h
@@ -0,0 +1 @@
+struct A;
diff --git a/test/Modules/Inputs/redecl-found-building-chains/b.h b/test/Modules/Inputs/redecl-found-building-chains/b.h
new file mode 100644
index 0000000..f69dccb
--- /dev/null
+++ b/test/Modules/Inputs/redecl-found-building-chains/b.h
@@ -0,0 +1,2 @@
+struct A; // ensure that loading b's canonical decl doesn't load the definition
+struct A {};
diff --git a/test/Modules/Inputs/redecl-found-building-chains/c.h b/test/Modules/Inputs/redecl-found-building-chains/c.h
new file mode 100644
index 0000000..27f503c
--- /dev/null
+++ b/test/Modules/Inputs/redecl-found-building-chains/c.h
@@ -0,0 +1 @@
+struct A;
diff --git a/test/Modules/Inputs/redecl-found-building-chains/d.h b/test/Modules/Inputs/redecl-found-building-chains/d.h
new file mode 100644
index 0000000..0beef5a
--- /dev/null
+++ b/test/Modules/Inputs/redecl-found-building-chains/d.h
@@ -0,0 +1,6 @@
+#include "a.h" // ensure that our canonical decl is not from b
+struct A;
+#include "b.h"
+struct A;
+#include "c.h" // ensure that our type for A doesn't reference the definition in b
+struct A;
diff --git a/test/Modules/Inputs/redecl-found-building-chains/module.modulemap b/test/Modules/Inputs/redecl-found-building-chains/module.modulemap
new file mode 100644
index 0000000..73a7c41
--- /dev/null
+++ b/test/Modules/Inputs/redecl-found-building-chains/module.modulemap
@@ -0,0 +1,4 @@
+module a { header "a.h" export * }
+module b { header "b.h" export * }
+module c { header "c.h" export * }
+module d { header "d.h" export * }
diff --git a/test/Modules/Inputs/stress1/common.h b/test/Modules/Inputs/stress1/common.h
new file mode 100644
index 0000000..b52520e
--- /dev/null
+++ b/test/Modules/Inputs/stress1/common.h
@@ -0,0 +1,74 @@
+#ifndef STRESS1_COMMON_H
+#define STRESS1_COMMON_H
+
+inline char function00(char x) { return x + x; }
+inline short function00(short x) { return x + x; }
+inline int function00(int x) { return x + x; }
+
+namespace N01 { struct S00; }
+
+namespace N00 {
+struct S00 {
+  char c;
+  short s;
+  int i;
+
+  S00(char x) : c(x) {}
+  S00(short x) : s(x) {}
+  S00(int x) : i(x) {}
+
+  char method00(char x) { return x + x; }
+  short method00(short x) { return x + x; }
+  int method00(int x) { return x + x; }
+
+  operator char() { return c; }
+  operator short() { return s; }
+  operator int() { return i; }
+};
+struct S01 {};
+struct S02 {};
+template <typename T> struct S03 {
+  struct S00 : N00::S00 {};
+};
+template <int I, template <typename> class U> struct S03<U<int>[I]>
+    : U<int>::S00 {
+  S03();
+  S03(int);
+  S03(short);
+  S03(char);
+  template <typename V = decltype(I)> S03(V);
+};
+template <> struct S03<S03<int>[42]> : S00 {};
+}
+
+namespace N01 {
+struct S00 : N00::S00 {
+  using N00::S00::S00;
+};
+struct S01 {};
+struct S02 {};
+}
+
+using namespace N00;
+
+template <int I, template <typename> class U> template <typename V> S03<U<int>[I]>::S03(V x) : S00(x) {}
+template <int I, template <typename> class U> S03<U<int>[I]>::S03() : S00(I) {}
+template <int I, template <typename> class U> S03<U<int>[I]>::S03(char x) : S00(x) {}
+template <int I, template <typename> class U> S03<U<int>[I]>::S03(short x) : S00(x) {}
+template <int I, template <typename> class U> S03<U<int>[I]>::S03(int x) : S00(x) {}
+
+#pragma weak pragma_weak00
+#pragma weak pragma_weak01
+#pragma weak pragma_weak02
+#pragma weak pragma_weak03
+#pragma weak pragma_weak04
+#pragma weak pragma_weak05
+
+extern "C" int pragma_weak00();
+extern "C" int pragma_weak01();
+extern "C" int pragma_weak02();
+extern "C" int pragma_weak03;
+extern "C" int pragma_weak04;
+extern "C" int pragma_weak05;
+
+#endif
diff --git a/test/Modules/Inputs/stress1/m00.h b/test/Modules/Inputs/stress1/m00.h
new file mode 100644
index 0000000..ca5af38
--- /dev/null
+++ b/test/Modules/Inputs/stress1/m00.h
@@ -0,0 +1,6 @@
+#ifndef STRESS1_M00_H
+#define STRESS1_M00_H
+
+#include "common.h"
+
+#endif
diff --git a/test/Modules/Inputs/stress1/m01.h b/test/Modules/Inputs/stress1/m01.h
new file mode 100644
index 0000000..23a3d4b
--- /dev/null
+++ b/test/Modules/Inputs/stress1/m01.h
@@ -0,0 +1,10 @@
+#ifndef STRESS1_M01_H
+#define STRESS1_M01_H
+
+#include "common.h"
+
+// Trigger the use of special members for a class this is also defined in other
+// modules.
+inline N00::S01 m01_special_members() { return N00::S01(); }
+
+#endif
diff --git a/test/Modules/Inputs/stress1/m02.h b/test/Modules/Inputs/stress1/m02.h
new file mode 100644
index 0000000..bb9714f
--- /dev/null
+++ b/test/Modules/Inputs/stress1/m02.h
@@ -0,0 +1,6 @@
+#ifndef STRESS1_M02_H
+#define STRESS1_M02_H
+
+#include "common.h"
+
+#endif
diff --git a/test/Modules/Inputs/stress1/m03.h b/test/Modules/Inputs/stress1/m03.h
new file mode 100644
index 0000000..b6dbb68
--- /dev/null
+++ b/test/Modules/Inputs/stress1/m03.h
@@ -0,0 +1,6 @@
+#ifndef STRESS1_M03_H
+#define STRESS1_M03_H
+
+#include "common.h"
+
+#endif
diff --git a/test/Modules/Inputs/stress1/merge00.h b/test/Modules/Inputs/stress1/merge00.h
new file mode 100644
index 0000000..46d5e41
--- /dev/null
+++ b/test/Modules/Inputs/stress1/merge00.h
@@ -0,0 +1,30 @@
+#ifndef STRESS1_MERGE00_H
+#define STRESS1_MERGE00_H
+
+// These don't match the imported declarations because we import them from
+// modules which are built in isolation of the current header's pragma state
+// much like they are built in isolation of the incoming macro state.
+// FIXME: We should expect warnings here but we can't because verify doesn't
+// work for modules.
+//#pragma weak pragma_weak01 // expected-warning {{weak identifier 'pragma_weak01' never declared}}
+//#pragma weak pragma_weak04 // expected-warning {{weak identifier 'pragma_waek04' never declared}}
+
+#include "common.h"
+#include "m00.h"
+#include "m01.h"
+#include "m02.h"
+#include "m03.h"
+
+inline int g() { return N00::S00('a').method00('b') + (int)S00(42) + function00(42); }
+
+// Use implicit special memebers again for S01 to ensure that we merge them in
+// successfully from m01.
+inline N00::S01 h() { return N00::S01(); }
+
+#pragma weak pragma_weak02
+#pragma weak pragma_weak05
+
+extern "C" int pragma_weak02();
+int pragma_weak05;
+
+#endif
diff --git a/test/Modules/Inputs/stress1/module.modulemap b/test/Modules/Inputs/stress1/module.modulemap
new file mode 100644
index 0000000..2b687b0
--- /dev/null
+++ b/test/Modules/Inputs/stress1/module.modulemap
@@ -0,0 +1,6 @@
+module m00 { header "Inputs/stress1/m00.h" export * }
+module m01 { header "Inputs/stress1/m01.h" export * }
+module m02 { header "Inputs/stress1/m02.h" export * }
+module m03 { header "Inputs/stress1/m03.h" export * }
+
+module merge00 { header "Inputs/stress1/merge00.h" export * }
diff --git a/test/Modules/Inputs/submodules-merge-defs/defs.h b/test/Modules/Inputs/submodules-merge-defs/defs.h
new file mode 100644
index 0000000..16f7184
--- /dev/null
+++ b/test/Modules/Inputs/submodules-merge-defs/defs.h
@@ -0,0 +1,20 @@
+struct A { int a_member; };
+namespace { inline int use_a(A a) { return a.a_member; } }
+
+class B {
+  struct Inner1 {};
+public:
+  struct Inner2;
+};
+// Check that lookup and access checks are performed in the right context.
+struct B::Inner2 : Inner1 {};
+
+// Check that base-specifiers are correctly disambiguated.
+template<int N> struct C_Base { struct D { constexpr operator int() const { return 0; } }; };
+const int C_Const = 0;
+struct C1 : C_Base<C_Base<0>::D{}> {} extern c1;
+struct C2 : C_Base<C_Const<0>::D{} extern c2;
+
+typedef struct { int a; void f(); struct X; } D;
+struct D::X { int dx; } extern dx;
+namespace { inline int use_dx(D::X dx) { return dx.dx; } }
diff --git a/test/Modules/Inputs/submodules-merge-defs/empty.h b/test/Modules/Inputs/submodules-merge-defs/empty.h
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/test/Modules/Inputs/submodules-merge-defs/empty.h
diff --git a/test/Modules/Inputs/submodules-merge-defs/import-and-redefine.h b/test/Modules/Inputs/submodules-merge-defs/import-and-redefine.h
new file mode 100644
index 0000000..8d695bc
--- /dev/null
+++ b/test/Modules/Inputs/submodules-merge-defs/import-and-redefine.h
@@ -0,0 +1,5 @@
+// Trigger import of definitions, but don't make them visible.
+#include "empty.h"
+
+// Now parse the definitions again.
+#include "defs.h"
diff --git a/test/Modules/Inputs/submodules-merge-defs/module.modulemap b/test/Modules/Inputs/submodules-merge-defs/module.modulemap
new file mode 100644
index 0000000..5c7ee8a
--- /dev/null
+++ b/test/Modules/Inputs/submodules-merge-defs/module.modulemap
@@ -0,0 +1,11 @@
+module "stuff" {
+  textual header "defs.h"
+  module "empty" { header "empty.h" }
+  module "use" { header "use-defs.h" }
+}
+
+module "redef" {
+  header "import-and-redefine.h"
+  // Do not re-export stuff.use
+  use "stuff"
+}
diff --git a/test/Modules/Inputs/submodules-merge-defs/use-defs.h b/test/Modules/Inputs/submodules-merge-defs/use-defs.h
new file mode 100644
index 0000000..31c69c6
--- /dev/null
+++ b/test/Modules/Inputs/submodules-merge-defs/use-defs.h
@@ -0,0 +1 @@
+#include "defs.h"
diff --git a/test/Modules/Inputs/update-exception-spec/a.h b/test/Modules/Inputs/update-exception-spec/a.h
new file mode 100644
index 0000000..078ebf9
--- /dev/null
+++ b/test/Modules/Inputs/update-exception-spec/a.h
@@ -0,0 +1,2 @@
+struct A { ~A() throw(int); };
+struct B { A a; };
diff --git a/test/Modules/Inputs/update-exception-spec/b.h b/test/Modules/Inputs/update-exception-spec/b.h
new file mode 100644
index 0000000..f75b559
--- /dev/null
+++ b/test/Modules/Inputs/update-exception-spec/b.h
@@ -0,0 +1,3 @@
+struct A { ~A() throw(int); };
+struct B { A a; };
+inline void f(B *p) { p->~B(); }
diff --git a/test/Modules/Inputs/update-exception-spec/c.h b/test/Modules/Inputs/update-exception-spec/c.h
new file mode 100644
index 0000000..067dbb6
--- /dev/null
+++ b/test/Modules/Inputs/update-exception-spec/c.h
@@ -0,0 +1,3 @@
+#include "a.h"
+#include "b.h"
+inline void g(B *p) { p->~B(); }
diff --git a/test/Modules/Inputs/update-exception-spec/module.modulemap b/test/Modules/Inputs/update-exception-spec/module.modulemap
new file mode 100644
index 0000000..880ae38
--- /dev/null
+++ b/test/Modules/Inputs/update-exception-spec/module.modulemap
@@ -0,0 +1,3 @@
+module a { header "a.h" }
+module b { header "b.h" }
+module c { header "c.h" }
diff --git a/test/Modules/anon-namespace.cpp b/test/Modules/anon-namespace.cpp
new file mode 100644
index 0000000..6c085eb
--- /dev/null
+++ b/test/Modules/anon-namespace.cpp
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/anon-namespace -verify %s
+// expected-no-diagnostics
+#include "b1.h"
+#include "c.h"
+using namespace N;
diff --git a/test/Modules/autolink.m b/test/Modules/autolink.m
index 5f2e9bd..e650770 100644
--- a/test/Modules/autolink.m
+++ b/test/Modules/autolink.m
@@ -39,9 +39,9 @@
 // CHECK: !llvm.module.flags = !{{{.*}}}
 // CHECK: !{{[0-9]+}} = !{i32 6, !"Linker Options", ![[AUTOLINK_OPTIONS:[0-9]+]]}
 // CHECK: ![[AUTOLINK_OPTIONS]] = !{![[AUTOLINK_PCH:[0-9]+]], ![[AUTOLINK_FRAMEWORK:[0-9]+]], ![[AUTOLINK:[0-9]+]], ![[DEPENDSONMODULE:[0-9]+]], ![[MODULE:[0-9]+]], ![[NOUMBRELLA:[0-9]+]]}
-// CHECK: ![[AUTOLINK_PCH]] = !{!"{{(-l|/DEFAULTLIB:)}}autolink_from_pch{{(\.lib)?}}"}
+// CHECK: ![[AUTOLINK_PCH]] = !{!"{{(\\01|-l|/DEFAULTLIB:)}}autolink_from_pch{{(\.lib)?}}"}
 // CHECK: ![[AUTOLINK_FRAMEWORK]] = !{!"-framework", !"autolink_framework"}
-// CHECK: ![[AUTOLINK]] = !{!"{{(-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"}
+// CHECK: ![[AUTOLINK]] = !{!"{{(\\01|-l|/DEFAULTLIB:)}}autolink{{(\.lib)?}}"}
 // CHECK: ![[DEPENDSONMODULE]] = !{!"-framework", !"DependsOnModule"}
 // CHECK: ![[MODULE]] = !{!"-framework", !"Module"}
 // CHECK: ![[NOUMBRELLA]] = !{!"-framework", !"NoUmbrella"}
diff --git a/test/Modules/crashes.m b/test/Modules/crashes.m
new file mode 100644
index 0000000..edefd37
--- /dev/null
+++ b/test/Modules/crashes.m
@@ -0,0 +1,16 @@
+// RUN: rm -rf %t.mcp
+// RUN: %clang_cc1 -fmodules-cache-path=%t.mcp -fmodules -F %S/Inputs -fobjc-arc %s -verify
+
+@import Module;
+
+__attribute__((objc_root_class))
+@interface Test
+// rdar://19904648
+// The diagnostic will try to find a suitable macro name to use (instead of raw __attribute__).
+// While iterating through the macros it would dereference a null pointer if the macro was undefined in the same module as it was originally defined in.
+@property (assign) id newFile; // expected-error {{property follows Cocoa naming convention for returning 'owned' objects}} \
+                               // expected-note {{explicitly declare getter '-newFile' with '__attribute__((objc_method_family(none)))' to return an 'unowned' object}}
+@end
+
+@implementation Test
+@end
diff --git a/test/Modules/cxx-decls.cpp b/test/Modules/cxx-decls.cpp
index 109306e..4064040 100644
--- a/test/Modules/cxx-decls.cpp
+++ b/test/Modules/cxx-decls.cpp
@@ -52,5 +52,7 @@
 
 void use_extern_c_function_2() { ExternCFunction(); }
 
+InhCtorB inhctorb(2);
+
 // CHECK: VarDecl [[mergeUsedFlag:0x[0-9a-f]*]] {{.*}} in cxx_decls.imported used mergeUsedFlag
 // CHECK: VarDecl {{0x[0-9a-f]*}} prev [[mergeUsedFlag]] {{.*}} in cxx_decls_merged used mergeUsedFlag
diff --git a/test/Modules/cxx-dtor.cpp b/test/Modules/cxx-dtor.cpp
new file mode 100644
index 0000000..ead67ec
--- /dev/null
+++ b/test/Modules/cxx-dtor.cpp
@@ -0,0 +1,3 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 -fmodules-cache-path=%t -I %S/Inputs/cxx-dtor -emit-llvm-only %s
+#include "b.h"
diff --git a/test/Modules/cxx-templates.cpp b/test/Modules/cxx-templates.cpp
index 46c2f33..41b0f2c 100644
--- a/test/Modules/cxx-templates.cpp
+++ b/test/Modules/cxx-templates.cpp
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t
 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump-lookups | FileCheck %s --check-prefix=CHECK-GLOBAL
 // RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump-lookups -ast-dump-filter N | FileCheck %s --check-prefix=CHECK-NAMESPACE-N
-// RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump | FileCheck %s --check-prefix=CHECK-DUMP
+// RUN: not %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -std=c++11 -ast-dump -ast-dump-filter SomeTemplate | FileCheck %s --check-prefix=CHECK-DUMP
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11
 // RUN: %clang_cc1 -x objective-c++ -fmodules -fno-modules-error-recovery -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 -DEARLY_IMPORT
 
@@ -125,9 +125,10 @@
 static_assert(Outer<int>::Inner<int>::f() == 1, "");
 static_assert(Outer<int>::Inner<int>::g() == 2, "");
 
-#ifndef EARLY_IMPORT
-// FIXME: The textual inclusion above shouldn't cause this to fail!
-static_assert(MergeTemplateDefinitions<int>::f() == 1, "");
+// FIXME: We're too lazy in merging class definitions to find the definition
+// of this function.
+static_assert(MergeTemplateDefinitions<int>::f() == 1, ""); // expected-error {{constant expression}} expected-note {{undefined}}
+// expected-note@cxx-templates-c.h:10 {{here}}
 static_assert(MergeTemplateDefinitions<int>::g() == 2, "");
 
 RedeclaredAsFriend<int> raf1;
@@ -140,7 +141,6 @@
 MergeSpecializations<char>::explicitly_specialized_in_a spec_in_a_2;
 MergeSpecializations<double>::explicitly_specialized_in_b spec_in_b_2;
 MergeSpecializations<bool>::explicitly_specialized_in_c spec_in_c_2;
-#endif
 
 MergeAnonUnionMember<> maum_main;
 typedef DontWalkPreviousDeclAfterMerging<int> dwpdam_typedef_2;
diff --git a/test/Modules/declare-use1.cpp b/test/Modules/declare-use1.cpp
index 5fc4336..adba595 100644
--- a/test/Modules/declare-use1.cpp
+++ b/test/Modules/declare-use1.cpp
@@ -5,4 +5,5 @@
 #include "e.h"
 #include "f.h" // expected-error {{module XG does not depend on a module exporting 'f.h'}}
 #include "i.h"
-const int g2 = g1 + e + f + aux_i;
+#include "sub.h"
+const int g2 = g1 + e + f + aux_i + sub;
diff --git a/test/Modules/declare-use5.cpp b/test/Modules/declare-use5.cpp
new file mode 100644
index 0000000..b34be0f
--- /dev/null
+++ b/test/Modules/declare-use5.cpp
@@ -0,0 +1,9 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodule-maps -fmodules-cache-path=%t -fmodules-decluse -fmodule-name=XN -I %S/Inputs/declare-use %s -verify
+
+
+#include "sub.h"
+
+const int a = sub;
+
+// expected-no-diagnostics
diff --git a/test/Modules/dependency-gen.modulemap b/test/Modules/dependency-gen.modulemap
index 5cb8a4d..6aa2e00 100644
--- a/test/Modules/dependency-gen.modulemap
+++ b/test/Modules/dependency-gen.modulemap
@@ -1,5 +1,3 @@
-// REQUIRES: shell
-//
 // RUN: cd %S
 // RUN: rm -f %t.cpm %t-base.pcm %t-base.d %t.d
 // RUN: %clang_cc1 -I. -x c++ -fmodule-maps -fmodule-name=test-base -fno-modules-implicit-maps -fmodules -emit-module -fno-validate-pch -fmodules-strict-decluse Inputs/dependency-gen-base.modulemap -dependency-file %t-base.d -MT %t-base.pcm -o %t-base.pcm -fmodule-map-file-home-is-cwd
@@ -14,5 +12,5 @@
 extern module "test-base2" "Inputs/dependency-gen-base2.modulemap"
 extern module "test-base" "Inputs/dependency-gen-base.modulemap"
 
-// CHECK: {{ |\./}}Inputs/dependency-gen-included2.h
-// CHECK: {{ |\./}}Inputs/dependency-gen-base.modulemap
+// CHECK: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-included2.h
+// CHECK: {{ |\.[/\\]}}Inputs{{[/\\]}}dependency-gen-base.modulemap
diff --git a/test/Modules/diagnostics.modulemap b/test/Modules/diagnostics.modulemap
index 14eb408..aef094d 100644
--- a/test/Modules/diagnostics.modulemap
+++ b/test/Modules/diagnostics.modulemap
@@ -1,12 +1,14 @@
-// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%s -fsyntax-only -x c++ /dev/null 2>&1
-//
-// RUN: cp %s %t-duplicate.modulemap
-// RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -fmodule-map-file=%s -fmodule-map-file=%t-duplicate.modulemap -fsyntax-only -x c++ /dev/null 2>&1 | FileCheck --check-prefix=CHECK-DUPLICATE %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
 
 // PR22299: Ensure we can produce diagnostics for duplicate modules from -fmodule-map-file=.
 //
-// CHECK-DUPLICATE: duplicate.modulemap:[[@LINE+2]]:8: error: redefinition of module 'foo'
-// CHECK-DUPLICATE: diagnostics.modulemap:[[@LINE+1]]:8: note: previously defined here
+// CHECK: diagnostics.modulemap:[[@LINE+2]]:8: error: redefinition of module 'foo'
+// CHECK: diagnostics-aux.modulemap:1:8: note: previously defined here
 module foo {}
 
 //* Check that we accept BCPL comments properly, not just as an extension. */
+
+module bad_use {
+  // CHECK: diagnostics.modulemap:[[@LINE+1]]:22: error: use declarations are only allowed in top-level modules
+  module submodule { use foo }
+}
diff --git a/test/Modules/empty.modulemap b/test/Modules/empty.modulemap
new file mode 100644
index 0000000..ef1d4a8
--- /dev/null
+++ b/test/Modules/empty.modulemap
@@ -0,0 +1,15 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -emit-module -fmodule-name=empty -o %t/base.pcm \
+// RUN:   %s
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -emit-module -fmodule-name=empty -o %t/check.pcm \
+// RUN:   %s
+//
+// RUN: diff %t/base.pcm %t/check.pcm
+
+module empty { header "Inputs/empty.h" export * }
diff --git a/test/Modules/explicit-build-relpath.cpp b/test/Modules/explicit-build-relpath.cpp
index d9c1566..f165566 100644
--- a/test/Modules/explicit-build-relpath.cpp
+++ b/test/Modules/explicit-build-relpath.cpp
@@ -1,5 +1,3 @@
-// REQUIRES: shell
-//
 // RUN: rm -rf %t
 // RUN: mkdir %t
 // RUN: cd %t
diff --git a/test/Modules/explicit-build.cpp b/test/Modules/explicit-build.cpp
index ce3a1af..6fe9f7e 100644
--- a/test/Modules/explicit-build.cpp
+++ b/test/Modules/explicit-build.cpp
@@ -64,6 +64,19 @@
 // RUN:            -fmodule-file=%t/c.pcm \
 // RUN:            -verify %s -DHAVE_A -DHAVE_B -DHAVE_C
 
+// -------------------------------
+// Check that -fmodule-file= in a module build makes the file transitively
+// available even if it's not used.
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \
+// RUN:            -fmodule-file=%t/b.pcm \
+// RUN:            -fmodule-name=d -emit-module %S/Inputs/explicit-build/module.modulemap -o %t/d.pcm \
+// RUN:            2>&1 | FileCheck --check-prefix=CHECK-NO-IMPLICIT-BUILD %s --allow-empty
+//
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fno-implicit-modules -Rmodule-build -fno-modules-error-recovery \
+// RUN:            -I%S/Inputs/explicit-build \
+// RUN:            -fmodule-file=%t/d.pcm \
+// RUN:            -verify %s -DHAVE_A -DHAVE_B
+
 #if HAVE_A
   #include "a.h"
   static_assert(a == 1, "");
@@ -148,11 +161,24 @@
 // RUN:            -fmodule-file=%t/not.pcm \
 // RUN:            %s 2>&1 | FileCheck --check-prefix=CHECK-BAD-FILE %s
 //
+// CHECK-BAD-FILE: fatal error: file '{{.*}}not.pcm' is not a valid precompiled module file
+
 // RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
 // RUN:            -fmodule-file=%t/nonexistent.pcm \
-// RUN:            %s 2>&1 | FileCheck --check-prefix=CHECK-BAD-FILE %s
+// RUN:            %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE %s
 //
-// CHECK-BAD-FILE: fatal error: file '{{.*}}t.pcm' is not a precompiled module file
+// CHECK-NO-FILE: fatal error: module file '{{.*}}nonexistent.pcm' not found
+
+// RUN: mv %t/a.pcm %t/a-tmp.pcm
+// RUN: not %clang_cc1 -x c++ -std=c++11 -fmodules -fmodules-cache-path=%t -Rmodule-build -fno-modules-error-recovery \
+// RUN:            -I%S/Inputs/explicit-build \
+// RUN:            -fmodule-file=%t/c.pcm \
+// RUN:            %s 2>&1 | FileCheck --check-prefix=CHECK-NO-FILE-INDIRECT %s
+// RUN: mv %t/a-tmp.pcm %t/a.pcm
+//
+// CHECK-NO-FILE-INDIRECT:      error: module file '{{.*}}a.pcm' not found
+// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'b' in '{{.*}}b.pcm'
+// CHECK-NO-FILE-INDIRECT-NEXT: note: imported by module 'c' in '{{.*}}c.pcm'
 
 // -------------------------------
 // Check that we don't get upset if B's timestamp is newer than C's.
diff --git a/test/Modules/exponential-paths.cpp b/test/Modules/exponential-paths.cpp
index e7c0afc..34ab420 100644
--- a/test/Modules/exponential-paths.cpp
+++ b/test/Modules/exponential-paths.cpp
@@ -51,66 +51,87 @@
 //
 // Build the corresponding headers.
 //
+// RUN: echo 'template<int> struct X {}; extern X<0> x0;' > %t/x.h
 // RUN: echo 'extern int n;' > %t/a0.h
 // RUN: cp %t/a0.h %t/b0.h
-// RUN: echo '#include "a0.h"' > %t/a1.h
+// RUN: echo '#include "x.h"' > %t/a1.h
+// RUN: echo '#include "a0.h"' >> %t/a1.h
 // RUN: echo '#include "b0.h"' >> %t/a1.h
 // RUN: cp %t/a1.h %t/b1.h
-// RUN: echo '#include "a1.h"' > %t/a2.h
+// RUN: echo '#include "x.h"' > %t/a2.h
+// RUN: echo '#include "a1.h"' >> %t/a2.h
 // RUN: echo '#include "b1.h"' >> %t/a2.h
 // RUN: cp %t/a2.h %t/b2.h
-// RUN: echo '#include "a2.h"' > %t/a3.h
+// RUN: echo '#include "x.h"' > %t/a3.h
+// RUN: echo '#include "a2.h"' >> %t/a3.h
 // RUN: echo '#include "b2.h"' >> %t/a3.h
 // RUN: cp %t/a3.h %t/b3.h
-// RUN: echo '#include "a3.h"' > %t/a4.h
+// RUN: echo '#include "x.h"' > %t/a4.h
+// RUN: echo '#include "a3.h"' >> %t/a4.h
 // RUN: echo '#include "b3.h"' >> %t/a4.h
 // RUN: cp %t/a4.h %t/b4.h
-// RUN: echo '#include "a4.h"' > %t/a5.h
+// RUN: echo '#include "x.h"' > %t/a5.h
+// RUN: echo '#include "a4.h"' >> %t/a5.h
 // RUN: echo '#include "b4.h"' >> %t/a5.h
 // RUN: cp %t/a5.h %t/b5.h
-// RUN: echo '#include "a5.h"' > %t/a6.h
+// RUN: echo '#include "x.h"' > %t/a6.h
+// RUN: echo '#include "a5.h"' >> %t/a6.h
 // RUN: echo '#include "b5.h"' >> %t/a6.h
 // RUN: cp %t/a6.h %t/b6.h
-// RUN: echo '#include "a6.h"' > %t/a7.h
+// RUN: echo '#include "x.h"' > %t/a7.h
+// RUN: echo '#include "a6.h"' >> %t/a7.h
 // RUN: echo '#include "b6.h"' >> %t/a7.h
 // RUN: cp %t/a7.h %t/b7.h
-// RUN: echo '#include "a7.h"' > %t/a8.h
+// RUN: echo '#include "x.h"' > %t/a8.h
+// RUN: echo '#include "a7.h"' >> %t/a8.h
 // RUN: echo '#include "b7.h"' >> %t/a8.h
 // RUN: cp %t/a8.h %t/b8.h
-// RUN: echo '#include "a8.h"' > %t/a9.h
+// RUN: echo '#include "x.h"' > %t/a9.h
+// RUN: echo '#include "a8.h"' >> %t/a9.h
 // RUN: echo '#include "b8.h"' >> %t/a9.h
 // RUN: cp %t/a9.h %t/b9.h
-// RUN: echo '#include "a9.h"' > %t/a10.h
+// RUN: echo '#include "x.h"' > %t/a10.h
+// RUN: echo '#include "a9.h"' >> %t/a10.h
 // RUN: echo '#include "b9.h"' >> %t/a10.h
 // RUN: cp %t/a10.h %t/b10.h
-// RUN: echo '#include "a10.h"' > %t/a11.h
+// RUN: echo '#include "x.h"' > %t/a11.h
+// RUN: echo '#include "a10.h"' >> %t/a11.h
 // RUN: echo '#include "b10.h"' >> %t/a11.h
 // RUN: cp %t/a11.h %t/b11.h
-// RUN: echo '#include "a11.h"' > %t/a12.h
+// RUN: echo '#include "x.h"' > %t/a12.h
+// RUN: echo '#include "a11.h"' >> %t/a12.h
 // RUN: echo '#include "b11.h"' >> %t/a12.h
 // RUN: cp %t/a12.h %t/b12.h
-// RUN: echo '#include "a12.h"' > %t/a13.h
+// RUN: echo '#include "x.h"' > %t/a13.h
+// RUN: echo '#include "a12.h"' >> %t/a13.h
 // RUN: echo '#include "b12.h"' >> %t/a13.h
 // RUN: cp %t/a13.h %t/b13.h
-// RUN: echo '#include "a13.h"' > %t/a14.h
+// RUN: echo '#include "x.h"' > %t/a14.h
+// RUN: echo '#include "a13.h"' >> %t/a14.h
 // RUN: echo '#include "b13.h"' >> %t/a14.h
 // RUN: cp %t/a14.h %t/b14.h
-// RUN: echo '#include "a14.h"' > %t/a15.h
+// RUN: echo '#include "x.h"' > %t/a15.h
+// RUN: echo '#include "a14.h"' >> %t/a15.h
 // RUN: echo '#include "b14.h"' >> %t/a15.h
 // RUN: cp %t/a15.h %t/b15.h
-// RUN: echo '#include "a15.h"' > %t/a16.h
+// RUN: echo '#include "x.h"' > %t/a16.h
+// RUN: echo '#include "a15.h"' >> %t/a16.h
 // RUN: echo '#include "b15.h"' >> %t/a16.h
 // RUN: cp %t/a16.h %t/b16.h
-// RUN: echo '#include "a16.h"' > %t/a17.h
+// RUN: echo '#include "x.h"' > %t/a17.h
+// RUN: echo '#include "a16.h"' >> %t/a17.h
 // RUN: echo '#include "b16.h"' >> %t/a17.h
 // RUN: cp %t/a17.h %t/b17.h
-// RUN: echo '#include "a17.h"' > %t/a18.h
+// RUN: echo '#include "x.h"' > %t/a18.h
+// RUN: echo '#include "a17.h"' >> %t/a18.h
 // RUN: echo '#include "b17.h"' >> %t/a18.h
 // RUN: cp %t/a18.h %t/b18.h
-// RUN: echo '#include "a18.h"' > %t/a19.h
+// RUN: echo '#include "x.h"' > %t/a19.h
+// RUN: echo '#include "a18.h"' >> %t/a19.h
 // RUN: echo '#include "b18.h"' >> %t/a19.h
 // RUN: cp %t/a19.h %t/b19.h
-// RUN: echo '#include "a19.h"' > %t/a20.h
+// RUN: echo '#include "x.h"' > %t/a20.h
+// RUN: echo '#include "a19.h"' >> %t/a20.h
 // RUN: echo '#include "b19.h"' >> %t/a20.h
 // RUN: cp %t/a20.h %t/b20.h
 //
diff --git a/test/Modules/filename.cpp b/test/Modules/filename.cpp
index 66891a0..460b6e6 100644
--- a/test/Modules/filename.cpp
+++ b/test/Modules/filename.cpp
@@ -1,6 +1,5 @@
 // RUN: cd %S
 // RUN: %clang_cc1 -I. -fmodule-maps -fmodule-name=A  -fmodule-map-file=%S/Inputs/filename/module.map %s -E | FileCheck %s
-// REQUIRES: shell
 
 #include "Inputs/filename/a.h"
 
diff --git a/test/Modules/include-relative.c b/test/Modules/include-relative.c
index 9ca76ee..264df5f 100644
--- a/test/Modules/include-relative.c
+++ b/test/Modules/include-relative.c
@@ -3,7 +3,6 @@
 // RUN: cp -r %S/Inputs/include-relative %t/include-relative
 // RUN: cd %t
 // RUN: %clang_cc1 -fmodules -x c -verify -fmodules-cache-path=%t -I include-relative %s
-// REQUIRES: shell
 
 // expected-no-diagnostics
 
diff --git a/test/Modules/invalidate-identifiers.c b/test/Modules/invalidate-identifiers.c
new file mode 100644
index 0000000..de3aa10
--- /dev/null
+++ b/test/Modules/invalidate-identifiers.c
@@ -0,0 +1,4 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/invalidate-identifiers -emit-llvm-only %s
+
+#include "b.h"
diff --git a/test/Modules/linkage-merge.cpp b/test/Modules/linkage-merge.cpp
index 664716d..3ac8053 100644
--- a/test/Modules/linkage-merge.cpp
+++ b/test/Modules/linkage-merge.cpp
@@ -7,5 +7,9 @@
 int f(int);
 
 static void g(int);
-// expected-error@-1 {{functions that differ only in their return type cannot be overloaded}}
+// FIXME: Whether we notice the problem here depends on the order in which we
+// happen to find lookup results for 'g'; LookupResult::resolveKind needs to
+// be taught to prefer a visible result over a non-visible one.
+//
+// expected-error@9 {{functions that differ only in their return type cannot be overloaded}}
 // expected-note@Inputs/linkage-merge-foo.h:2 {{previous declaration is here}}
diff --git a/test/Modules/macro-ambiguity.cpp b/test/Modules/macro-ambiguity.cpp
new file mode 100644
index 0000000..ea9e4f5
--- /dev/null
+++ b/test/Modules/macro-ambiguity.cpp
@@ -0,0 +1,115 @@
+// RUN: rm -rf %t
+// RUN: cd %S
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -v \
+// RUN:   -iquote Inputs/macro-ambiguity/a/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/a/system \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=a -o %t/a.pcm \
+// RUN:   Inputs/macro-ambiguity/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -v \
+// RUN:   -iquote Inputs/macro-ambiguity/b/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/b/system \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=b -o %t/b.pcm \
+// RUN:   Inputs/macro-ambiguity/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -v \
+// RUN:   -iquote Inputs/macro-ambiguity/c/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/c/system \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=c -o %t/c.pcm \
+// RUN:   Inputs/macro-ambiguity/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -v \
+// RUN:   -iquote Inputs/macro-ambiguity/d/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/d/system \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=d -o %t/d.pcm \
+// RUN:   Inputs/macro-ambiguity/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -v \
+// RUN:   -iquote Inputs/macro-ambiguity/a/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/a/system \
+// RUN:   -iquote Inputs/macro-ambiguity/b/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/b/system \
+// RUN:   -iquote Inputs/macro-ambiguity/c/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/c/system \
+// RUN:   -iquote Inputs/macro-ambiguity/d/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/d/system \
+// RUN:   -iquote Inputs/macro-ambiguity/e/quote \
+// RUN:   -isystem Inputs/macro-ambiguity/e/system \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/macro-ambiguity/module.modulemap \
+// RUN:   -fmodule-file=%t/a.pcm \
+// RUN:   -fmodule-file=%t/b.pcm \
+// RUN:   -fmodule-file=%t/c.pcm \
+// RUN:   -fmodule-file=%t/d.pcm \
+// RUN:   -Wambiguous-macro -verify macro-ambiguity.cpp
+
+// Include the textual headers first to maximize the ways in which things can
+// become ambiguous.
+#include "e_quote.h"
+#include <e_system.h>
+
+#include "a_quote.h"
+#include <a_system.h>
+#include "b_quote.h"
+#include <b_system.h>
+#include "c_quote.h"
+#include <c_system.h>
+#include "d_quote.h"
+#include <d_system.h>
+
+int test(int x) {
+  // We expect to get warnings for all of the quoted includes but none of the
+  // system includes here because the first module is a non-system module and
+  // the quote macros come from non-system-headers.
+  x = FOO1_QUOTE(x); // expected-warning {{ambiguous expansion of macro}}
+  // expected-note@Inputs/macro-ambiguity/c/quote/c_quote.h:4 {{expanding this definition}}
+  // expected-note@Inputs/macro-ambiguity/a/quote/a_quote.h:4 {{other definition}}
+
+  x = FOO1_SYSTEM(x);
+
+  x = BAR1_QUOTE(x); // expected-warning {{ambiguous expansion of macro}}
+  // expected-note@Inputs/macro-ambiguity/d/quote/d_quote.h:4 {{expanding this definition}}
+  // expected-note@Inputs/macro-ambiguity/a/quote/a_quote.h:5 {{other definition}}
+
+  x = BAR1_SYSTEM(x);
+
+  x = BAZ1_QUOTE(x); // expected-warning {{ambiguous expansion of macro}}
+  // expected-note@Inputs/macro-ambiguity/a/quote/a_quote.h:6 {{expanding this definition}}
+  // expected-note@Inputs/macro-ambiguity/e/quote/e_quote.h:4 {{other definition}}
+
+  x = BAZ1_SYSTEM(x);
+
+  // Here, we don't even warn on bar because in that cas both b and d are
+  // system modules and so the use of non-system headers is irrelevant.
+  x = FOO2_QUOTE(x); // expected-warning {{ambiguous expansion of macro}}
+  // expected-note@Inputs/macro-ambiguity/c/quote/c_quote.h:5 {{expanding this definition}}
+  // expected-note@Inputs/macro-ambiguity/b/quote/b_quote.h:4 {{other definition}}
+
+  x = FOO2_SYSTEM(x);
+
+  x = BAR2_QUOTE(x);
+
+  x = BAR2_SYSTEM(x);
+
+  x = BAZ2_QUOTE(x); // expected-warning {{ambiguous expansion of macro}}
+  // expected-note@Inputs/macro-ambiguity/b/quote/b_quote.h:6 {{expanding this definition}}
+  // expected-note@Inputs/macro-ambiguity/e/quote/e_quote.h:5 {{other definition}}
+
+  x = BAZ2_SYSTEM(x);
+  return x;
+}
diff --git a/test/Modules/malformed.cpp b/test/Modules/malformed.cpp
index 2554c3a..2d07c4c 100644
--- a/test/Modules/malformed.cpp
+++ b/test/Modules/malformed.cpp
@@ -1,8 +1,6 @@
 // This test explicitly cd's to the test/Modules directory so that we can test
 // that filenames found via relative -I paths are printed correctly.
 //
-// REQUIRES: shell
-//
 // RUN: rm -rf %t
 // RUN: cd %S
 // RUN: not %clang_cc1 -fmodules -fmodules-cache-path=%t -I Inputs/malformed -DHEADER="a1.h" %s 2>&1 | FileCheck %s --check-prefix=CHECK-A
@@ -32,6 +30,6 @@
 void test() { f<int>(); }
 // Test that we use relative paths to name files within an imported module.
 //
-// CHECK-C: In module 'c' imported from malformed.cpp:14:
+// CHECK-C: In module 'c' imported from malformed.cpp:12:
 // CHECK-C: {{^}}Inputs/malformed/c.h:1:33: error: type 'int' cannot be used prior to '::'
 // CHECK-C: {{^}}malformed.cpp:[[@LINE-5]]:15: note: in instantiation of
diff --git a/test/Modules/merge-decl-context.cpp b/test/Modules/merge-decl-context.cpp
index 90c234b..208ba92 100644
--- a/test/Modules/merge-decl-context.cpp
+++ b/test/Modules/merge-decl-context.cpp
@@ -4,21 +4,25 @@
 // RUN:     -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
 // RUN:     -I %S/Inputs/merge-decl-context
 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=c -o %t/c.pcm -fmodule-maps \
-// RUN:     -fmodule-file=%t/b.pcm \
+// RUN:     -fmodule-file=%t/b.pcm -fno-implicit-modules \
+// RUN:     -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
+// RUN:     -I %S/Inputs/merge-decl-context
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-name=d -o %t/d.pcm -fmodule-maps \
+// RUN:     -fmodule-file=%t/b.pcm -fno-implicit-modules \
 // RUN:     -emit-module %S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
 // RUN:     -I %S/Inputs/merge-decl-context
 
 // Use the two modules in a single compile.
 // RUN: %clang_cc1 -x c++ -std=c++11 -fmodules -fmodule-file=%t/c.pcm -fmodule-file=%t/b.pcm \
+// RUN:     -fmodule-file=%t/d.pcm -fno-implicit-modules \
 // RUN:     -fmodule-map-file=%S/Inputs/merge-decl-context/merge-decl-context.modulemap -I%S/Inputs \
 // RUN:     -emit-llvm -o %t/test.o %s
 
 #include "Inputs/merge-decl-context/a.h"
 #include "Inputs/merge-decl-context/b.h"
 #include "Inputs/merge-decl-context/c.h"
+#include "Inputs/merge-decl-context/d.h"
 
 void t() {
   ff(42);
 }
-
-
diff --git a/test/Modules/merge-target-features.cpp b/test/Modules/merge-target-features.cpp
new file mode 100644
index 0000000..ccf3aab
--- /dev/null
+++ b/test/Modules/merge-target-features.cpp
@@ -0,0 +1,66 @@
+// RUN: rm -rf %t
+// RUN: cd %S
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -iquote Inputs/merge-target-features \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=foo -o %t/foo.pcm \
+// RUN:   -triple i386-unknown-unknown \
+// RUN:   -target-cpu i386 -target-feature +sse2 \
+// RUN:   Inputs/merge-target-features/module.modulemap
+//
+// RUN: not %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -iquote Inputs/merge-target-features \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/merge-target-features/module.modulemap \
+// RUN:   -fmodule-file=%t/foo.pcm \
+// RUN:   -triple i386-unknown-unknown \
+// RUN:   -target-cpu i386 \
+// RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
+// RUN:   | FileCheck --check-prefix=SUBSET %s
+// SUBSET: AST file was compiled with the target feature'+sse2' but the current translation unit is not
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -iquote Inputs/merge-target-features \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/merge-target-features/module.modulemap \
+// RUN:   -fmodule-file=%t/foo.pcm \
+// RUN:   -triple i386-unknown-unknown \
+// RUN:   -target-cpu i386 -target-feature +sse2 \
+// RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
+// RUN:   | FileCheck --allow-empty --check-prefix=SAME %s
+// SAME-NOT: error:
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -iquote Inputs/merge-target-features \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/merge-target-features/module.modulemap \
+// RUN:   -fmodule-file=%t/foo.pcm \
+// RUN:   -triple i386-unknown-unknown \
+// RUN:   -target-cpu i386 -target-feature +sse2 -target-feature +sse3 \
+// RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
+// RUN:   | FileCheck --allow-empty --check-prefix=SUPERSET %s
+// SUPERSET-NOT: error:
+//
+// RUN: not %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -iquote Inputs/merge-target-features \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/merge-target-features/module.modulemap \
+// RUN:   -fmodule-file=%t/foo.pcm \
+// RUN:   -triple i386-unknown-unknown \
+// RUN:   -target-cpu i386 -target-feature +cx16 \
+// RUN:   -fsyntax-only merge-target-features.cpp 2>&1 \
+// RUN:   | FileCheck --check-prefix=MISMATCH %s
+// MISMATCH: AST file was compiled with the target feature'+sse2' but the current translation unit is not
+// MISMATCH: current translation unit was compiled with the target feature'+cx16' but the AST file was not
+
+#include "foo.h"
+
+int test(int x) {
+  return foo(x);
+}
diff --git a/test/Modules/merge-template-friend.cpp b/test/Modules/merge-template-friend.cpp
new file mode 100644
index 0000000..8a1910d
--- /dev/null
+++ b/test/Modules/merge-template-friend.cpp
@@ -0,0 +1,22 @@
+// RUN: rm -rf %t
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -emit-module -fmodule-name=a -o %t/a.pcm \
+// RUN:   %S/Inputs/merge-template-friend/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -emit-module -fmodule-name=b -o %t/b.pcm \
+// RUN:   %S/Inputs/merge-template-friend/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -fmodules-cache-path=%t \
+// RUN:   -I%S/Inputs/merge-template-friend \
+// RUN:   -fmodule-file=%t/a.pcm \
+// RUN:   -fmodule-file=%t/b.pcm \
+// RUN:   -verify %s
+
+#include "friend.h"
+#include "def.h"
+
+::ns::C<int> c;
+
+// expected-no-diagnostics
diff --git a/test/Modules/modular_maps.cpp b/test/Modules/modular_maps.cpp
index 606c979..bedf2e0 100644
--- a/test/Modules/modular_maps.cpp
+++ b/test/Modules/modular_maps.cpp
@@ -11,9 +11,6 @@
 // RUN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -fmodule-map-file=Inputs/modular_maps/modulea-cwd.map -fmodule-map-file=Inputs/modular_maps/modulec-cwd.map -I Inputs/modular_maps %s -verify -fmodule-map-file-home-is-cwd
 // RxN: %clang_cc1 -x objective-c++ -fmodules-cache-path=%t -fmodules -fmodule-map-file=Inputs/modular_maps/modulec-cwd.map -fmodule-map-file=Inputs/modular_maps/modulea-cwd.map -I Inputs/modular_maps %s -verify -fmodule-map-file-home-is-cwd
 
-// chdir is unsupported on Lit internal runner.
-// REQUIRES: shell
-
 #include "common.h"
 #include "a.h"
 #include "b.h" // expected-error {{private header}}
diff --git a/test/Modules/odr.cpp b/test/Modules/odr.cpp
index 120ca20..4ac257c 100644
--- a/test/Modules/odr.cpp
+++ b/test/Modules/odr.cpp
@@ -15,9 +15,9 @@
 int x = f() + g();
 
 // expected-note@a.h:5 {{definition has no member 'e2'}}
-// expected-note@a.h:3 {{declaration of 'f' does not match}}
-// expected-note@a.h:1 {{definition has no member 'm'}}
+// expected-note@b.h:3 {{declaration of 'f' does not match}}
+// expected-note@b.h:1 {{definition has no member 'n'}}
 
 // expected-error@b.h:5 {{'E::e2' from module 'b' is not present in definition of 'E' in module 'a'}}
-// expected-error@b.h:3 {{'Y::f' from module 'b' is not present in definition of 'Y' in module 'a'}}
-// expected-error@b.h:2 {{'Y::m' from module 'b' is not present in definition of 'Y' in module 'a'}}
+// expected-error@a.h:3 {{'Y::f' from module 'a' is not present in definition of 'Y' in module 'b'}}
+// expected-error@a.h:2 {{'Y::n' from module 'a' is not present in definition of 'Y' in module 'b'}}
diff --git a/test/Modules/pr21687.cpp b/test/Modules/pr21687.cpp
new file mode 100644
index 0000000..ad67489
--- /dev/null
+++ b/test/Modules/pr21687.cpp
@@ -0,0 +1,3 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/PR21687 -emit-llvm-only %s
+#include "c.h"
diff --git a/test/Modules/public-private.modulemap b/test/Modules/public-private.modulemap
new file mode 100644
index 0000000..ef4ae98
--- /dev/null
+++ b/test/Modules/public-private.modulemap
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/empty.h" /dev/null
+// RUN: %clang_cc1 -fmodules -fmodule-map-file=%s -I%S -include "Inputs/dummy.h" /dev/null
+module A {
+  header "Inputs/empty.h"
+  private header "Inputs/empty.h"
+}
+module B {
+  private header "Inputs/dummy.h"
+  header "Inputs/dummy.h"
+}
diff --git a/test/Modules/redecl-add-after-load.cpp b/test/Modules/redecl-add-after-load.cpp
index 68deaf8..53e54c8 100644
--- a/test/Modules/redecl-add-after-load.cpp
+++ b/test/Modules/redecl-add-after-load.cpp
@@ -29,7 +29,7 @@
   static constexpr int function(); // expected-note {{here}}
 };
 typedef D::A DB;
-constexpr int D_test(bool b) { return b ? D::variable : D::function(); } // expected-note {{subexpression}} expected-note {{undefined}}
+constexpr int D_test(bool b) { return b ? D::variable : D::function(); } // expected-note {{undefined}}
 #endif
 
 @import redecl_add_after_load;
@@ -54,6 +54,6 @@
 constexpr int merged_struct_function_test = D_test(false);
 #ifndef IMPORT_DECLS
 // expected-error@-4 {{incomplete}}
-// expected-error@-4 {{constant}} expected-note@-4 {{in call to}}
+// @-4: definition of D::variable must be emitted, so it gets imported eagerly
 // expected-error@-4 {{constant}} expected-note@-4 {{in call to}}
 #endif
diff --git a/test/Modules/redecl-found-building-chains.cpp b/test/Modules/redecl-found-building-chains.cpp
new file mode 100644
index 0000000..1173863c
--- /dev/null
+++ b/test/Modules/redecl-found-building-chains.cpp
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fmodules -fmodules-cache-path=%t -I%S/Inputs/redecl-found-building-chains -verify %s
+// expected-no-diagnostics
+int n, m;
+#include "d.h"
+A a;
diff --git a/test/Modules/relative-dep-gen.cpp b/test/Modules/relative-dep-gen.cpp
index c817177..86c4651 100644
--- a/test/Modules/relative-dep-gen.cpp
+++ b/test/Modules/relative-dep-gen.cpp
@@ -1,20 +1,18 @@
-// REQUIRES: shell
-//
 // RUN: cd %S
 // RUN: rm -rf %t
 // RUN: mkdir %t
 //
-// RUN: %clang_cc1 -cc1 -fmodule-name=relative-dep-gen -emit-module -x c++ Inputs/relative-dep-gen.modulemap -dependency-file %t/build.d -MT mod.pcm -o %t/mod.pcm
-// RUN: %clang_cc1 -cc1 -fmodule-map-file=Inputs/relative-dep-gen.modulemap -fmodule-file=%t/mod.pcm -dependency-file %t/use-explicit.d -MT use.o relative-dep-gen.cpp -fsyntax-only
-// RUN: %clang_cc1 -cc1 -fmodule-map-file=Inputs/relative-dep-gen.modulemap -dependency-file %t/use-implicit.d relative-dep-gen.cpp -MT use.o -fsyntax-only
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-name=relative-dep-gen -emit-module -x c++ Inputs/relative-dep-gen.modulemap -dependency-file %t/build.d -MT mod.pcm -o %t/mod.pcm
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-map-file=Inputs/relative-dep-gen.modulemap -fmodule-file=%t/mod.pcm -dependency-file %t/use-explicit.d -MT use.o relative-dep-gen.cpp -fsyntax-only
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-map-file=Inputs/relative-dep-gen.modulemap -dependency-file %t/use-implicit.d relative-dep-gen.cpp -MT use.o -fsyntax-only
 //
 // RUN: FileCheck --check-prefix=CHECK-BUILD %s < %t/build.d
 // RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit.d
 // RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-implicit.d
 //
-// RUN: %clang_cc1 -cc1 -fmodule-name=relative-dep-gen -emit-module -x c++ Inputs/relative-dep-gen-cwd.modulemap -dependency-file %t/build-cwd.d -MT mod.pcm -o %t/mod-cwd.pcm -fmodule-map-file-home-is-cwd
-// RUN: %clang_cc1 -cc1 -fmodule-map-file=Inputs/relative-dep-gen-cwd.modulemap -fmodule-file=%t/mod-cwd.pcm -dependency-file %t/use-explicit-cwd.d -MT use.o relative-dep-gen.cpp -fsyntax-only -fmodule-map-file-home-is-cwd
-// RUN: %clang_cc1 -cc1 -fmodule-map-file=Inputs/relative-dep-gen-cwd.modulemap -dependency-file %t/use-implicit-cwd.d relative-dep-gen.cpp -MT use.o -fsyntax-only -fmodule-map-file-home-is-cwd
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-name=relative-dep-gen -emit-module -x c++ Inputs/relative-dep-gen-cwd.modulemap -dependency-file %t/build-cwd.d -MT mod.pcm -o %t/mod-cwd.pcm -fmodule-map-file-home-is-cwd
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-map-file=Inputs/relative-dep-gen-cwd.modulemap -fmodule-file=%t/mod-cwd.pcm -dependency-file %t/use-explicit-cwd.d -MT use.o relative-dep-gen.cpp -fsyntax-only -fmodule-map-file-home-is-cwd
+// RUN: %clang_cc1 -cc1 -fno-implicit-modules -fmodule-map-file=Inputs/relative-dep-gen-cwd.modulemap -dependency-file %t/use-implicit-cwd.d relative-dep-gen.cpp -MT use.o -fsyntax-only -fmodule-map-file-home-is-cwd
 //
 // RUN: FileCheck --check-prefix=CHECK-BUILD %s < %t/build-cwd.d
 // RUN: FileCheck --check-prefix=CHECK-USE %s < %t/use-explicit-cwd.d
diff --git a/test/Modules/stress1.cpp b/test/Modules/stress1.cpp
new file mode 100644
index 0000000..df690aa
--- /dev/null
+++ b/test/Modules/stress1.cpp
@@ -0,0 +1,114 @@
+// RUN: rm -rf %t
+// RUN: cd %S
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m00 -o %t/m00.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m00 -o %t/m00_check.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: diff %t/m00.pcm %t/m00_check.pcm
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 -fdelayed-template-parsing \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m01 -o %t/m01.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 -fdelayed-template-parsing \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m01 -o %t/m01_check.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: diff %t/m01.pcm %t/m01_check.pcm
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m02 -o %t/m02.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -emit-module -fmodule-name=m03 -o %t/m03.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-file=%t/m00.pcm \
+// RUN:   -fmodule-file=%t/m01.pcm \
+// RUN:   -fmodule-file=%t/m02.pcm \
+// RUN:   -fmodule-file=%t/m03.pcm \
+// RUN:   -emit-module -fmodule-name=merge00 -o %t/merge00.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-file=%t/m00.pcm \
+// RUN:   -fmodule-file=%t/m01.pcm \
+// RUN:   -fmodule-file=%t/m02.pcm \
+// RUN:   -fmodule-file=%t/m03.pcm \
+// RUN:   -emit-module -fmodule-name=merge00 -o %t/merge00_check.pcm \
+// RUN:   Inputs/stress1/module.modulemap
+//
+// RUN: diff %t/merge00.pcm %t/merge00_check.pcm
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/stress1/module.modulemap \
+// RUN:   -fmodule-file=%t/m00.pcm \
+// RUN:   -fmodule-file=%t/m01.pcm \
+// RUN:   -fmodule-file=%t/m02.pcm \
+// RUN:   -fmodule-file=%t/m03.pcm \
+// RUN:   -fmodule-file=%t/merge00.pcm \
+// RUN:   -verify stress1.cpp -S -emit-llvm -o %t/stress1.ll
+//
+// RUN: %clang_cc1 -fmodules -x c++ -std=c++11 \
+// RUN:   -I Inputs/stress1 \
+// RUN:   -fno-implicit-modules -fno-modules-implicit-maps \
+// RUN:   -fmodule-map-file-home-is-cwd \
+// RUN:   -fmodule-map-file=Inputs/stress1/module.modulemap \
+// RUN:   -fmodule-file=%t/m00.pcm \
+// RUN:   -fmodule-file=%t/m01.pcm \
+// RUN:   -fmodule-file=%t/m02.pcm \
+// RUN:   -fmodule-file=%t/m03.pcm \
+// RUN:   -fmodule-file=%t/merge00.pcm \
+// RUN:   -verify stress1.cpp -S -emit-llvm -o %t/stress1_check.ll
+//
+// RUN: diff -u %t/stress1.ll %t/stress1_check.ll
+//
+// expected-no-diagnostics
+
+#include "m00.h"
+#include "m01.h"
+#include "m02.h"
+#include "m03.h"
+
+#include "merge00.h"
+
+int f() { return N01::S00('a').method00('b') + (int)N00::S00(42) + function00(42) + g(); }
+
+int f2() {
+  return pragma_weak00() + pragma_weak01() + pragma_weak02() +
+         pragma_weak03 + pragma_weak04 + pragma_weak05;
+}
diff --git a/test/Modules/submodules-merge-defs.cpp b/test/Modules/submodules-merge-defs.cpp
new file mode 100644
index 0000000..cdda48e
--- /dev/null
+++ b/test/Modules/submodules-merge-defs.cpp
@@ -0,0 +1,33 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -x c++ -std=c++11 -fmodules-cache-path=%t -fmodules -I %S/Inputs/submodules-merge-defs %s -verify -fno-modules-error-recovery
+
+// Trigger import of definitions, but don't make them visible.
+#include "empty.h"
+
+A pre_a; // expected-error {{must be imported}} expected-error {{must use 'struct'}}
+// expected-note@defs.h:1 {{here}}
+
+B::Inner2 pre_bi; // expected-error +{{must be imported}}
+// expected-note@defs.h:4 +{{here}}
+// expected-note@defs.h:10 +{{here}}
+
+C_Base<1> pre_cb1; // expected-error +{{must be imported}}
+// expected-note@defs.h:13 +{{here}}
+C1 pre_c1; // expected-error +{{must be imported}} expected-error {{must use 'struct'}}
+// expected-note@defs.h:15 +{{here}}
+C2 pre_c2; // expected-error +{{must be imported}} expected-error {{must use 'struct'}}
+// expected-note@defs.h:16 +{{here}}
+
+D::X pre_dx; // expected-error +{{must be imported}}
+// expected-note@defs.h:18 +{{here}}
+// expected-note@defs.h:19 +{{here}}
+
+// Make definitions from second module visible.
+#include "import-and-redefine.h"
+
+A post_a;
+B::Inner2 post_bi;
+C_Base<1> post_cb1;
+C1 c1;
+C2 c2;
+D::X post_dx;
diff --git a/test/Modules/templates.mm b/test/Modules/templates.mm
index d60b873..aafe018 100644
--- a/test/Modules/templates.mm
+++ b/test/Modules/templates.mm
@@ -86,8 +86,8 @@
   // CHECK: call void @_Z10useListIntR4ListIiE(%[[ListInt]]* dereferenceable({{[0-9]+}}) %[[r]])
   useListInt(r);
 
-  // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*)
-  // CHECK: load i32* bitcast (i8* getelementptr inbounds (i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*)
+  // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_left to i8*), i64 8) to i32*)
+  // CHECK: load i32, i32* bitcast (i8* getelementptr inbounds (i8, i8* bitcast ({{.*}}* @list_right to i8*), i64 8) to i32*)
   return list_left.*size_right + list_right.*size_left;
 }
 
@@ -106,11 +106,11 @@
   WithUndefinedStaticDataMember<int[]> load_it;
 
   // CHECK-LABEL: define linkonce_odr i32* @_Z23getStaticDataMemberLeftv(
-  // CHECK: ret i32* getelementptr inbounds ([0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
+  // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
   (void) getStaticDataMemberLeft();
 
   // CHECK-LABEL: define linkonce_odr i32* @_Z24getStaticDataMemberRightv(
-  // CHECK: ret i32* getelementptr inbounds ([0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
+  // CHECK: ret i32* getelementptr inbounds ([0 x i32], [0 x i32]* @_ZN29WithUndefinedStaticDataMemberIA_iE9undefinedE, i32 0, i32 0)
   (void) getStaticDataMemberRight();
 }
 
diff --git a/test/Modules/update-exception-spec.cpp b/test/Modules/update-exception-spec.cpp
new file mode 100644
index 0000000..bccdddc
--- /dev/null
+++ b/test/Modules/update-exception-spec.cpp
@@ -0,0 +1,6 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -fexceptions -fcxx-exceptions -fmodules -fmodules-cache-path=%t -I%S/Inputs/update-exception-spec -emit-llvm-only %s
+#include "a.h"
+void use(B *p);
+#include "c.h"
+void use(B *p) { g(p); }
diff --git a/test/Modules/warn-unused-local-typedef.cpp b/test/Modules/warn-unused-local-typedef.cpp
index 60e0612..030a52d 100644
--- a/test/Modules/warn-unused-local-typedef.cpp
+++ b/test/Modules/warn-unused-local-typedef.cpp
@@ -1,3 +1,4 @@
+// XFAIL: hexagon
 // RUN: rm -rf %t
 // RUN: %clang -Wunused-local-typedef -c -x objective-c++ -fcxx-modules -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=CHECK_1
 // RUN: %clang -Wunused-local-typedef -c -x objective-c++ -fcxx-modules -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -o /dev/null 2>&1 | FileCheck %s -check-prefix=CHECK_2 -allow-empty