Merge remote-tracking branch 'origin/swift-4.1-branch' into stable
diff --git a/include/clang/APINotes/APINotesManager.h b/include/clang/APINotes/APINotesManager.h
index 2adc29c..6eb0534 100644
--- a/include/clang/APINotes/APINotesManager.h
+++ b/include/clang/APINotes/APINotesManager.h
@@ -65,9 +65,6 @@
   /// for private headers.
   APINotesReader *CurrentModuleReaders[2] = { nullptr, nullptr };
 
-  /// Whether we have already pruned the API notes cache.
-  bool PrunedCache;
-
   /// A mapping from header file directories to the API notes reader for
   /// that directory, or a redirection to another directory entry that may
   /// have more information, or NULL to indicate that there is no API notes
diff --git a/include/clang/Basic/DiagnosticFrontendKinds.td b/include/clang/Basic/DiagnosticFrontendKinds.td
index 446eb41..38bc726 100644
--- a/include/clang/Basic/DiagnosticFrontendKinds.td
+++ b/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -229,10 +229,6 @@
 def err_invalid_vfs_overlay : Error<
   "invalid virtual filesystem overlay file '%0'">, DefaultFatal;
 
-def err_no_apinotes_cache_path : Error<
-  "-fapinotes was provided without -fapinotes-cache-path=<directory>">,
-  DefaultFatal;
-
 def warn_option_invalid_ocl_version : Warning<
   "OpenCL version %0 does not support the option '%1'">, InGroup<Deprecated>;
 }
diff --git a/include/clang/Basic/FileSystemOptions.h b/include/clang/Basic/FileSystemOptions.h
index 1beb2e2..38f1346 100644
--- a/include/clang/Basic/FileSystemOptions.h
+++ b/include/clang/Basic/FileSystemOptions.h
@@ -25,9 +25,6 @@
   /// \brief If set, paths are resolved as if the working directory was
   /// set to the value of WorkingDir.
   std::string WorkingDir;
-
-  /// The path to the API notes cache.
-  std::string APINotesCachePath;
 };
 
 } // end namespace clang
diff --git a/include/clang/Driver/Options.td b/include/clang/Driver/Options.td
index fcc247c..9f8d189 100644
--- a/include/clang/Driver/Options.td
+++ b/include/clang/Driver/Options.td
@@ -701,8 +701,8 @@
 def fno_apinotes_modules : Flag<["-"], "fno-apinotes-modules">, Group<f_clang_Group>,
   Flags<[CC1Option]>, HelpText<"Disable module-based external API notes support">;
 def fapinotes_cache_path : Joined<["-"], "fapinotes-cache-path=">,
-  Group<i_Group>, Flags<[DriverOption, CC1Option]>, MetaVarName<"<directory>">,
-  HelpText<"Specify the API notes cache path">;
+  Group<i_Group>, Flags<[DriverOption]>, MetaVarName<"<directory>">,
+  HelpText<"Does nothing; API notes are no longer cached separately from modules">;
 def fapinotes_swift_version : Joined<["-"], "fapinotes-swift-version=">,
   Group<f_clang_Group>, Flags<[CC1Option]>, MetaVarName<"<version>">,
   HelpText<"Specify the Swift version to use when filtering API notes">;
diff --git a/lib/APINotes/APINotesManager.cpp b/lib/APINotes/APINotesManager.cpp
index 832f454..6fc0fda 100644
--- a/lib/APINotes/APINotesManager.cpp
+++ b/lib/APINotes/APINotesManager.cpp
@@ -46,12 +46,6 @@
           "header directories searched");
 STATISTIC(NumDirectoryCacheHits,
           "directory cache hits");
-STATISTIC(NumBinaryCacheHits,
-          "binary form cache hits");
-STATISTIC(NumBinaryCacheMisses,
-          "binary form cache misses");
-STATISTIC(NumBinaryCacheRebuilds,
-          "binary form cache rebuilds");
 
 namespace {
   /// Prints two successive strings, which much be kept alive as long as the
@@ -69,8 +63,7 @@
 
 APINotesManager::APINotesManager(SourceManager &sourceMgr,
                                  const LangOptions &langOpts)
-  : SourceMgr(sourceMgr), ImplicitAPINotes(langOpts.APINotes),
-    PrunedCache(false) { }
+  : SourceMgr(sourceMgr), ImplicitAPINotes(langOpts.APINotes) { }
 
 APINotesManager::~APINotesManager() {
   // Free the API notes readers.
@@ -84,78 +77,8 @@
   delete CurrentModuleReaders[1];
 }
 
-/// \brief Write a new timestamp file with the given path.
-static void writeTimestampFile(StringRef TimestampFile) {
-  std::error_code EC;
-  llvm::raw_fd_ostream Out(TimestampFile.str(), EC, llvm::sys::fs::F_None);
-}
-
-/// \brief Prune the API notes cache of API notes that haven't been accessed in
-/// a long time.
-static void pruneAPINotesCache(StringRef APINotesCachePath) {
-  struct stat StatBuf;
-  llvm::SmallString<128> TimestampFile;
-  TimestampFile = APINotesCachePath;
-  llvm::sys::path::append(TimestampFile, "APINotes.timestamp");
-
-  // Try to stat() the timestamp file.
-  if (::stat(TimestampFile.c_str(), &StatBuf)) {
-    // If the timestamp file wasn't there, create one now.
-    if (errno == ENOENT) {
-      llvm::sys::fs::create_directories(APINotesCachePath);
-      writeTimestampFile(TimestampFile);
-    }
-    return;
-  }
-
-  const unsigned APINotesCachePruneInterval = 7 * 24 * 60 * 60;
-  const unsigned APINotesCachePruneAfter = 31 * 24 * 60 * 60;
-
-  // Check whether the time stamp is older than our pruning interval.
-  // If not, do nothing.
-  time_t TimeStampModTime = StatBuf.st_mtime;
-  time_t CurrentTime = time(nullptr);
-  if (CurrentTime - TimeStampModTime <= time_t(APINotesCachePruneInterval))
-    return;
-
-  // Write a new timestamp file so that nobody else attempts to prune.
-  // There is a benign race condition here, if two Clang instances happen to
-  // notice at the same time that the timestamp is out-of-date.
-  writeTimestampFile(TimestampFile);
-
-  // Walk the entire API notes cache, looking for unused compiled API notes.
-  std::error_code EC;
-  SmallString<128> APINotesCachePathNative;
-  llvm::sys::path::native(APINotesCachePath, APINotesCachePathNative);
-  for (llvm::sys::fs::directory_iterator
-         File(APINotesCachePathNative.str(), EC), DirEnd;
-       File != DirEnd && !EC; File.increment(EC)) {
-    StringRef Extension = llvm::sys::path::extension(File->path());
-    if (Extension.empty())
-      continue;
-
-    if (Extension.substr(1) != BINARY_APINOTES_EXTENSION)
-      continue;
-
-    // Look at this file. If we can't stat it, there's nothing interesting
-    // there.
-    if (::stat(File->path().c_str(), &StatBuf))
-      continue;
-
-    // If the file has been used recently enough, leave it there.
-    time_t FileAccessTime = StatBuf.st_atime;
-    if (CurrentTime - FileAccessTime <= time_t(APINotesCachePruneAfter)) {
-      continue;
-    }
-
-    // Remove the file.
-    llvm::sys::fs::remove(File->path());
-  }
-}
-
 std::unique_ptr<APINotesReader>
 APINotesManager::loadAPINotes(const FileEntry *apiNotesFile) {
-  FileManager &fileMgr = SourceMgr.getFileManager();
   PrettyStackTraceDoubleString trace("Loading API notes from ",
                                      apiNotesFile->getName());
 
@@ -174,59 +97,6 @@
     return APINotesReader::getUnmanaged(buffer, SwiftVersion);
   }
 
-  // If we haven't pruned the API notes cache yet during this execution, do
-  // so now.
-  if (!PrunedCache) {
-    pruneAPINotesCache(fileMgr.getFileSystemOpts().APINotesCachePath);
-    PrunedCache = true;
-  }
-
-  // Compute a hash of the API notes file's directory and the Clang version,
-  // to be used as part of the filename for the cached binary copy.
-  auto code = llvm::hash_value(StringRef(apiNotesFile->getDir()->getName()));
-  code = hash_combine(code, getClangFullRepositoryVersion());
-
-  // Determine the file name for the cached binary form.
-  SmallString<128> compiledFileName;
-  compiledFileName += fileMgr.getFileSystemOpts().APINotesCachePath;
-  assert(!compiledFileName.empty() && "No API notes cache path provided?");
-  llvm::sys::path::append(compiledFileName,
-    (llvm::Twine(llvm::sys::path::stem(apiNotesFileName)) + "-"
-     + llvm::APInt(64, code).toString(36, /*Signed=*/false) + "."
-     + BINARY_APINOTES_EXTENSION));
-
-  // Try to open the cached binary form.
-  if (const FileEntry *compiledFile = fileMgr.getFile(compiledFileName,
-                                                      /*openFile=*/true,
-                                                      /*cacheFailure=*/false)) {
-    // Load the file contents.
-    if (auto buffer = fileMgr.getBufferForFile(compiledFile)) {
-      // Load the file.
-      if (auto reader = APINotesReader::get(std::move(buffer.get()),
-                                            SwiftVersion)) {
-        bool outOfDate = false;
-        if (auto sizeAndModTime = reader->getSourceFileSizeAndModTime()) {
-          if (sizeAndModTime->first != apiNotesFile->getSize() ||
-              sizeAndModTime->second != apiNotesFile->getModificationTime())
-            outOfDate = true;
-        }
-
-        if (!outOfDate) {
-          // Success.
-          ++NumBinaryCacheHits;
-          return reader;
-        }
-      }
-    }
-
-    // The cache entry was somehow broken; delete this one so we can build a
-    // new one below.
-    llvm::sys::fs::remove(compiledFileName.str());
-    ++NumBinaryCacheRebuilds;
-  } else {
-    ++NumBinaryCacheMisses;
-  }
-
   // Open the source file.
   auto sourceFileID = SourceMgr.createFileID(apiNotesFile, SourceLocation(), SrcMgr::C_User);
   auto sourceBuffer = SourceMgr.getBuffer(sourceFileID, SourceLocation());
@@ -235,6 +105,8 @@
   // Compile the API notes source into a buffer.
   // FIXME: Either propagate OSType through or, better yet, improve the binary
   // APINotes format to maintain complete availability information.
+  // FIXME: We don't even really need to go through the binary format at all;
+  // we're just going to immediately deserialize it again.
   llvm::SmallVector<char, 1024> apiNotesBuffer;
   std::unique_ptr<llvm::MemoryBuffer> compiledBuffer;
   {
@@ -257,39 +129,6 @@
                StringRef(apiNotesBuffer.data(), apiNotesBuffer.size()));
   }
 
-  // Save the binary form into the cache. Perform this operation
-  // atomically.
-  SmallString<64> temporaryBinaryFileName = compiledFileName.str();
-  temporaryBinaryFileName.erase(
-    temporaryBinaryFileName.end()
-      - llvm::sys::path::extension(temporaryBinaryFileName).size(),
-    temporaryBinaryFileName.end());
-  temporaryBinaryFileName += "-%%%%%%.";
-  temporaryBinaryFileName += BINARY_APINOTES_EXTENSION;
-
-  int temporaryFD;
-  llvm::sys::fs::create_directories(
-    fileMgr.getFileSystemOpts().APINotesCachePath);
-  if (!llvm::sys::fs::createUniqueFile(temporaryBinaryFileName.str(),
-                                       temporaryFD, temporaryBinaryFileName)) {
-    // Write the contents of the buffer.
-    bool hadError;
-    {
-      llvm::raw_fd_ostream out(temporaryFD, /*shouldClose=*/true);
-      out.write(compiledBuffer.get()->getBufferStart(),
-                compiledBuffer.get()->getBufferSize());
-      out.flush();
-
-      hadError = out.has_error();
-    }
-
-    if (!hadError) {
-      // Rename the temporary file to the actual compiled file.
-      llvm::sys::fs::rename(temporaryBinaryFileName.str(),
-                            compiledFileName.str());
-    }
-  }
-
   // Load the binary form we just compiled.
   auto reader = APINotesReader::get(std::move(compiledBuffer), SwiftVersion);
   assert(reader && "Could not load the API notes we just generated?");
diff --git a/lib/Driver/ToolChains/Clang.cpp b/lib/Driver/ToolChains/Clang.cpp
index 56af4e3..d5df32a 100644
--- a/lib/Driver/ToolChains/Clang.cpp
+++ b/lib/Driver/ToolChains/Clang.cpp
@@ -3507,28 +3507,6 @@
                      options::OPT_fno_apinotes_modules, false))
       CmdArgs.push_back("-fapinotes-modules");
 
-    SmallString<128> APINotesCachePath;
-    if (Arg *A = Args.getLastArg(options::OPT_fapinotes_cache_path)) {
-      APINotesCachePath = A->getValue();
-    }
-
-    if (C.isForDiagnostics()) {
-      // When generating crash reports, we want to emit the API notes along with
-      // the reproduction sources, so we ignore any provided API notes path.
-      APINotesCachePath = Output.getFilename();
-      llvm::sys::path::replace_extension(APINotesCachePath, ".cache");
-      llvm::sys::path::append(APINotesCachePath, "apinotes");
-    } else if (APINotesCachePath.empty()) {
-      // No API notes path was provided: use the default.
-      llvm::sys::path::system_temp_directory(/*erasedOnReboot=*/false,
-                                             APINotesCachePath);
-      llvm::sys::path::append(APINotesCachePath, "org.llvm.clang");
-      llvm::sys::path::append(APINotesCachePath, "APINotesCache");
-    }
-    const char Arg[] = "-fapinotes-cache-path=";
-    APINotesCachePath.insert(APINotesCachePath.begin(), Arg, Arg + strlen(Arg));
-    CmdArgs.push_back(Args.MakeArgString(APINotesCachePath));
-
     Args.AddLastArg(CmdArgs, options::OPT_fapinotes_swift_version);
   }
 
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index acb5d88..0a983c1 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1171,7 +1171,6 @@
 
 static void ParseFileSystemArgs(FileSystemOptions &Opts, ArgList &Args) {
   Opts.WorkingDir = Args.getLastArgValue(OPT_working_directory);
-  Opts.APINotesCachePath = Args.getLastArgValue(OPT_fapinotes_cache_path);
 }
 
 /// Parse the argument to the -ftest-module-file-extension
@@ -2696,13 +2695,6 @@
                   Res.getPreprocessorOpts(), Diags);
     if (Res.getFrontendOpts().ProgramAction == frontend::RewriteObjC)
       LangOpts.ObjCExceptions = 1;
-
-    // -fapinotes and -fapinotes-modules requires -fapinotes-cache-path=<directory>.
-    if ((LangOpts.APINotes || LangOpts.APINotesModules) &&
-        Res.getFileSystemOpts().APINotesCachePath.empty()) {
-      Diags.Report(diag::err_no_apinotes_cache_path);
-      Success = false;
-    }
   }
 
   if (LangOpts.CUDA) {
diff --git a/test/APINotes/availability.m b/test/APINotes/availability.m
index f9bee1a..7231eb4 100644
--- a/test/APINotes/availability.m
+++ b/test/APINotes/availability.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
 
 #include "HeaderLib.h"
 #import <SomeKit/SomeKit.h>
diff --git a/test/APINotes/broken_types.m b/test/APINotes/broken_types.m
index 164ae79..ee33ff7 100644
--- a/test/APINotes/broken_types.m
+++ b/test/APINotes/broken_types.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s 2> %t.err
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s 2> %t.err
 // RUN: FileCheck %s < %t.err
 
 #include "BrokenTypes.h"
diff --git a/test/APINotes/cache.m b/test/APINotes/cache.m
deleted file mode 100644
index b87bdf1..0000000
--- a/test/APINotes/cache.m
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: rm -rf %t/APINotesCache
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
-
-// Check for the presence of the cached compiled form.
-// RUN: ls %t/APINotesCache | grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-
-// Run test again to ensure that caching doesn't cause problems.
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks  %s -verify
-
-// Check that the driver provides a default -fapinotes-cache-path=
-// RUN: %clang -fsyntax-only -fapinotes -fapinotes-modules -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -### 2>&1 | FileCheck --check-prefix=CHECK-DEFAULT-PATH %s
-// CHECK-DEFAULT-PATH: -fapinotes-cache-path={{.*}}org.llvm.clang/APINotesCache
-
-// Check that the driver passes through a provided -fapinotes-cache-path=
-// RUN: %clang -fsyntax-only -fapinotes -fapinotes-modules -fapinotes-cache-path=/wobble -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -### 2>&1 | FileCheck --check-prefix=CHECK-PATH %s
-// CHECK-PATH: -fapinotes-cache-path=/wobble
-
-#include "HeaderLib.h"
-#import <SomeKit/SomeKit.h>
-
-int main() {
-  int i;
-  i = unavailable_function(); // expected-error{{'unavailable_function' is unavailable: I beg you not to use this}}
-  // expected-note@HeaderLib.h:8{{'unavailable_function' has been explicitly marked unavailable here}}
-
-  A *a = 0;
-  [a transform:a]; // expected-error{{'transform:' is unavailable: anything but this}}
-  // expected-note@SomeKit/SomeKit.h:6{{'transform:' has been explicitly marked unavailable here}}
-
-  return 0;
-}
diff --git a/test/APINotes/cache_pruning.m b/test/APINotes/cache_pruning.m
deleted file mode 100644
index 1a36570..0000000
--- a/test/APINotes/cache_pruning.m
+++ /dev/null
@@ -1,49 +0,0 @@
-// We need 'touch' and 'find' for this test to work.
-// REQUIRES: shell
-
-// RUN: rm -rf %t/APINotesCache
-
-// Run Clang. This should generated the cached versions of both and a timestamp.
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DINCLUDE_HEADERLIB
-// RUN: ls %t/APINotesCache | grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "APINotes.timestamp"
-
-// Set the timestamp back a very long time. We should try to prune,
-// but nothing gets pruned because the API Notes files are new enough.
-// RUN: touch -m -a -t 201101010000 %t/APINotes.timestamp 
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
-// RUN: ls %t/APINotesCache | grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "APINotes.timestamp"
-
-// Set the HeaderLib access time back a very long time.
-// This shouldn't prune anything, because the timestamp has been updated, so
-// the pruning mechanism won't fire.
-// RUN: find %t/APINotesCache -name APINotes-*.apinotesc | xargs touch -a -t 201101010000
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
-// RUN: ls %t/APINotesCache | grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "APINotes.timestamp"
-
-// Set the timestack back a very long time. This should prune the
-// HeaderLib file, because the pruning mechanism should fire and
-// HeaderLib is both old and not used.
-// RUN: touch -m -a -t 201101010000 %t/APINotesCache/APINotes.timestamp 
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
-// RUN: ls %t/APINotesCache | not grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "APINotes.timestamp"
-
-// Run Clang. This should generated the cached versions of both and a timestamp.
-// RUN: %clang_cc1 -fapinotes -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DINCLUDE_HEADERLIB
-// RUN: ls %t/APINotesCache | grep "APINotes-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "SomeKit-.*.apinotesc"
-// RUN: ls %t/APINotesCache | grep "APINotes.timestamp"
-
-#ifdef INCLUDE_HEADERLIB
-#include "HeaderLib.h"
-#endif
-#include <SomeKit/SomeKit.h>
-
-int main() { return 0; }
diff --git a/test/APINotes/module-cache.m b/test/APINotes/module-cache.m
index 2324697..19d6a27 100644
--- a/test/APINotes/module-cache.m
+++ b/test/APINotes/module-cache.m
@@ -1,36 +1,46 @@
 // RUN: rm -rf %t
 
-// Set up a directory with API notes
+// Set up directories
 // RUN: mkdir -p %t/APINotes
 // RUN: cp %S/Inputs/APINotes/SomeOtherKit.apinotes %t/APINotes/SomeOtherKit.apinotes
+// RUN: mkdir -p %t/Frameworks
+// RUN: cp -r %S/Inputs/Frameworks/SomeOtherKit.framework %t/Frameworks
 
 // First build: check that 'methodB' is unavailable but 'methodA' is available.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/before.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes  -F %t/Frameworks %s > %t/before.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/before.log
 // RUN: FileCheck -check-prefix=CHECK-REBUILD %s < %t/before.log
 // RUN: FileCheck -check-prefix=CHECK-ONE-ERROR %s < %t/before.log
 
 // Do it again; now we're using caches.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/before.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes  -F %t/Frameworks %s > %t/before.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/before.log
 // RUN: FileCheck -check-prefix=CHECK-WITHOUT-REBUILD %s < %t/before.log
 // RUN: FileCheck -check-prefix=CHECK-ONE-ERROR %s < %t/before.log
 
-// Change the API notes file.
+// Add a blank line to the header to force the module to rebuild, without
+// (yet) changing API notes.
+// RUN: echo >> %t/Frameworks/SomeOtherKit.framework/Headers/SomeOtherKit.h
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes  -F %t/Frameworks %s > %t/before.log 2>&1
+// RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/before.log
+// RUN: FileCheck -check-prefix=CHECK-REBUILD %s < %t/before.log
+// RUN: FileCheck -check-prefix=CHECK-ONE-ERROR %s < %t/before.log
+
+// Change the API notes file, after the module has rebuilt once.
 // RUN: echo '      - Selector: "methodA"' >> %t/APINotes/SomeOtherKit.apinotes
 // RUN: echo '        MethodKind: Instance' >> %t/APINotes/SomeOtherKit.apinotes
 // RUN: echo '        Availability: none' >> %t/APINotes/SomeOtherKit.apinotes
 // RUN: echo '        AvailabilityMsg: "not here either"' >> %t/APINotes/SomeOtherKit.apinotes
 
 // Build again: check that both methods are now unavailable and that the module rebuilt.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/after.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes  -F %t/Frameworks %s > %t/after.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODA %s < %t/after.log
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/after.log
 // RUN: FileCheck -check-prefix=CHECK-REBUILD %s < %t/after.log
 // RUN: FileCheck -check-prefix=CHECK-TWO-ERRORS %s < %t/after.log
 
 // Run the build again: check that both methods are now unavailable
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/after.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/APINotes  -F %t/Frameworks %s > %t/after.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODA %s < %t/after.log
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/after.log
 // RUN: FileCheck -check-prefix=CHECK-WITHOUT-REBUILD %s < %t/after.log
@@ -43,13 +53,13 @@
 // RUN: %clang -cc1apinotes -yaml-to-binary -o %t/CompiledAPINotes/SomeOtherKit.apinotesc %S/Inputs/APINotes/SomeOtherKit.apinotes
 
 // First build: check that 'methodB' is unavailable but 'methodA' is available.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/compiled-before.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes  -F %t/Frameworks %s > %t/compiled-before.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/compiled-before.log
 // RUN: FileCheck -check-prefix=CHECK-REBUILD %s < %t/compiled-before.log
 // RUN: FileCheck -check-prefix=CHECK-ONE-ERROR %s < %t/compiled-before.log
 
 // Do it again; now we're using caches.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/compiled-before.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes  -F %t/Frameworks %s > %t/compiled-before.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/compiled-before.log
 // RUN: FileCheck -check-prefix=CHECK-WITHOUT-REBUILD %s < %t/compiled-before.log
 // RUN: FileCheck -check-prefix=CHECK-ONE-ERROR %s < %t/compiled-before.log
@@ -58,14 +68,14 @@
 // RUN: %clang -cc1apinotes -yaml-to-binary -o %t/CompiledAPINotes/SomeOtherKit.apinotesc %t/APINotes/SomeOtherKit.apinotes
 
 // Build again: check that both methods are now unavailable and that the module rebuilt.
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/compiled-after.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes  -F %t/Frameworks %s > %t/compiled-after.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODA %s < %t/compiled-after.log
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/compiled-after.log
 // RUN: FileCheck -check-prefix=CHECK-REBUILD %s < %t/compiled-after.log
 // RUN: FileCheck -check-prefix=CHECK-TWO-ERRORS %s < %t/compiled-after.log
 
 // Run the build again: check that both methods are now unavailable
-// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes -fapinotes-cache-path=%t/APINotesCache -F %S/Inputs/Frameworks %s > %t/compiled-after.log 2>&1
+// RUN: not %clang_cc1 -fmodules -fimplicit-module-maps -Rmodule-build -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %t/CompiledAPINotes  -F %t/Frameworks %s > %t/compiled-after.log 2>&1
 // RUN: FileCheck -check-prefix=CHECK-METHODA %s < %t/compiled-after.log
 // RUN: FileCheck -check-prefix=CHECK-METHODB %s < %t/compiled-after.log
 // RUN: FileCheck -check-prefix=CHECK-WITHOUT-REBUILD %s < %t/compiled-after.log
diff --git a/test/APINotes/nullability.c b/test/APINotes/nullability.c
index 1fcd0ee..e07fc2e 100644
--- a/test/APINotes/nullability.c
+++ b/test/APINotes/nullability.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
 
 #include "HeaderLib.h"
 
diff --git a/test/APINotes/nullability.m b/test/APINotes/nullability.m
index f70c363..65c9c2c 100644
--- a/test/APINotes/nullability.m
+++ b/test/APINotes/nullability.m
@@ -1,9 +1,9 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
 
 // Test with Swift version 3.0. This should only affect the few APIs that have an entry in the 3.0 tables.
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fapinotes-swift-version=3.0 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify -DSWIFT_VERSION_3_0 -fmodules-ignore-macro=SWIFT_VERSION_3_0
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fapinotes-swift-version=3.0 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify -DSWIFT_VERSION_3_0 -fmodules-ignore-macro=SWIFT_VERSION_3_0
 
 #import <SomeKit/SomeKit.h>
 
diff --git a/test/APINotes/objc_designated_inits.m b/test/APINotes/objc_designated_inits.m
index 1df8cf8..24b317c 100644
--- a/test/APINotes/objc_designated_inits.m
+++ b/test/APINotes/objc_designated_inits.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
 
 #include "HeaderLib.h"
 #import <SomeKit/SomeKit.h>
diff --git a/test/APINotes/properties.m b/test/APINotes/properties.m
index b1559b9..fe3c738 100644
--- a/test/APINotes/properties.m
+++ b/test/APINotes/properties.m
@@ -1,7 +1,7 @@
 // RUN: rm -rf %t && mkdir -p %t
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fblocks -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'TestProperties::' | FileCheck -check-prefix=CHECK -check-prefix=CHECK-4 %s
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fblocks -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'TestProperties::' -fapinotes-swift-version=3 | FileCheck -check-prefix=CHECK -check-prefix=CHECK-3 %s
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fblocks -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'TestProperties::' | FileCheck -check-prefix=CHECK -check-prefix=CHECK-4 %s
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fblocks -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'TestProperties::' -fapinotes-swift-version=3 | FileCheck -check-prefix=CHECK -check-prefix=CHECK-3 %s
 
 // I know, FileChecking an AST dump is brittle. However, the attributes being
 // tested aren't used for anything by Clang, and don't even have a spelling.
diff --git a/test/APINotes/search-order.m b/test/APINotes/search-order.m
index 2c667be..aa2f21a 100644
--- a/test/APINotes/search-order.m
+++ b/test/APINotes/search-order.m
@@ -1,10 +1,10 @@
 // RUN: rm -rf %t && mkdir -p %t
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_FRAMEWORK=1 -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_FRAMEWORK=1 -verify
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %S/Inputs/APINotes -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_SEARCH_PATH=1 -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -iapinotes-modules %S/Inputs/APINotes  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_SEARCH_PATH=1 -verify
 
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -iapinotes-modules %S/Inputs/APINotes -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_FRAMEWORK=1 -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -iapinotes-modules %S/Inputs/APINotes  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -DFROM_FRAMEWORK=1 -verify
 
 @import SomeOtherKit;
 
diff --git a/test/APINotes/types.m b/test/APINotes/types.m
index 9f8b970..a0f728b 100644
--- a/test/APINotes/types.m
+++ b/test/APINotes/types.m
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t && mkdir -p %t
-// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fdisable-module-hash -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
+// RUN: %clang_cc1 -fmodules -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache -fapinotes-modules  -fdisable-module-hash -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -verify
 // RUN: %clang_cc1 -ast-print %t/ModulesCache/SimpleKit.pcm | FileCheck %s
 
 #import <SomeKit/SomeKit.h>
diff --git a/test/APINotes/versioned.m b/test/APINotes/versioned.m
index 5657ae1..2f85735 100644
--- a/test/APINotes/versioned.m
+++ b/test/APINotes/versioned.m
@@ -1,14 +1,14 @@
 // RUN: rm -rf %t && mkdir -p %t
 
 // Build and check the unversioned module file.
-// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Unversioned -fdisable-module-hash -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
+// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Unversioned -fdisable-module-hash -fapinotes-modules  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
 // RUN: %clang_cc1 -ast-print %t/ModulesCache/Unversioned/VersionedKit.pcm | FileCheck -check-prefix=CHECK-UNVERSIONED %s
-// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Unversioned -fdisable-module-hash -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'DUMP' | FileCheck -check-prefix=CHECK-DUMP -check-prefix=CHECK-UNVERSIONED-DUMP %s
+// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Unversioned -fdisable-module-hash -fapinotes-modules  -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'DUMP' | FileCheck -check-prefix=CHECK-DUMP -check-prefix=CHECK-UNVERSIONED-DUMP %s
 
 // Build and check the versioned module file.
-// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned -fdisable-module-hash -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fapinotes-swift-version=3 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
+// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned -fdisable-module-hash -fapinotes-modules  -fapinotes-swift-version=3 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s
 // RUN: %clang_cc1 -ast-print %t/ModulesCache/Versioned/VersionedKit.pcm | FileCheck -check-prefix=CHECK-VERSIONED %s
-// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned -fdisable-module-hash -fapinotes-modules -fapinotes-cache-path=%t/APINotesCache -fapinotes-swift-version=3 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'DUMP' | FileCheck -check-prefix=CHECK-DUMP -check-prefix=CHECK-VERSIONED-DUMP %s
+// RUN: %clang_cc1 -fmodules -fblocks -fimplicit-module-maps -fmodules-cache-path=%t/ModulesCache/Versioned -fdisable-module-hash -fapinotes-modules  -fapinotes-swift-version=3 -fsyntax-only -I %S/Inputs/Headers -F %S/Inputs/Frameworks %s -ast-dump -ast-dump-filter 'DUMP' | FileCheck -check-prefix=CHECK-DUMP -check-prefix=CHECK-VERSIONED-DUMP %s
 
 #import <VersionedKit/VersionedKit.h>
 
diff --git a/test/APINotes/yaml-convert-diags.c b/test/APINotes/yaml-convert-diags.c
index e8767f2..8d5c0fb 100644
--- a/test/APINotes/yaml-convert-diags.c
+++ b/test/APINotes/yaml-convert-diags.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: not %clang_cc1 -fsyntax-only -fapinotes -fapinotes-cache-path=%t %s -I %S/Inputs/BrokenHeaders2 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -fsyntax-only -fapinotes  %s -I %S/Inputs/BrokenHeaders2 2>&1 | FileCheck %s
 
 #include "SomeBrokenLib.h"
 
diff --git a/test/APINotes/yaml-parse-diags.c b/test/APINotes/yaml-parse-diags.c
index 4505e29..a7b370a 100644
--- a/test/APINotes/yaml-parse-diags.c
+++ b/test/APINotes/yaml-parse-diags.c
@@ -1,5 +1,5 @@
 // RUN: rm -rf %t
-// RUN: %clang_cc1 -fsyntax-only -fapinotes -fapinotes-cache-path=%t %s -I %S/Inputs/BrokenHeaders -verify
+// RUN: %clang_cc1 -fsyntax-only -fapinotes  %s -I %S/Inputs/BrokenHeaders -verify
 
 #include "SomeBrokenLib.h"