Merge pull request #14395 from jckarter/class-init-writeback-di-4.1

[4.1] DefiniteInitialization: Storing back to the 'self' box in a class init is OK.
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index a840b8d..cc7464f 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -1252,10 +1252,17 @@
 }
 
 // Lifted from the clang driver.
-static void PrintArg(raw_ostream &OS, const char *Arg, bool Quote) {
+static void PrintArg(raw_ostream &OS, const char *Arg, StringRef TempDir) {
   const bool Escape = std::strpbrk(Arg, "\"\\$ ");
 
-  if (!Quote && !Escape) {
+  if (StringRef(Arg).startswith(TempDir)) {
+    // Don't write temporary file names in the debug info. This would prevent
+    // incremental llvm compilation because we would generate different IR on
+    // every compiler invocation.
+    Arg = "<temporary-file>";
+  }
+
+  if (!Escape) {
     OS << Arg;
     return;
   }
@@ -1479,9 +1486,14 @@
                                               const ArrayRef<const char*> &Args,
                                               StringRef SDKPath,
                                               StringRef ResourceDir) {
+  // This isn't guaranteed to be the same temp directory as what the driver
+  // uses, but it's highly likely.
+  llvm::SmallString<128> TDir;
+  llvm::sys::path::system_temp_directory(true, TDir);
+
   llvm::raw_string_ostream OS(Output);
   interleave(Args,
-             [&](const char *Argument) { PrintArg(OS, Argument, false); },
+             [&](const char *Argument) { PrintArg(OS, Argument, TDir.str()); },
              [&] { OS << " "; });
 
   // Inject the SDK path and resource dir if they are nonempty and missing.
@@ -1497,11 +1509,11 @@
   }
   if (!haveSDKPath) {
     OS << " -sdk ";
-    PrintArg(OS, SDKPath.data(), false);
+    PrintArg(OS, SDKPath.data(), TDir.str());
   }
   if (!haveResourceDir) {
     OS << " -resource-dir ";
-    PrintArg(OS, ResourceDir.data(), false);
+    PrintArg(OS, ResourceDir.data(), TDir.str());
   }
 }
 
diff --git a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
index c7837d6..830b8c7 100644
--- a/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
+++ b/lib/SILOptimizer/SILCombiner/SILCombinerMiscVisitors.cpp
@@ -477,11 +477,18 @@
   // Given a load with multiple struct_extracts/tuple_extracts and no other
   // uses, canonicalize the load into several (struct_element_addr (load))
   // pairs.
-  using ProjInstPairTy = std::pair<Projection, SingleValueInstruction *>;
+
+  struct ProjInstPair {
+    Projection P;
+    SingleValueInstruction *I;
+
+    // When sorting, just look at the projection and ignore the instruction.
+    bool operator<(const ProjInstPair &RHS) const { return P < RHS.P; }
+  };
 
   // Go through the loads uses and add any users that are projections to the
   // projection list.
-  llvm::SmallVector<ProjInstPairTy, 8> Projections;
+  llvm::SmallVector<ProjInstPair, 8> Projections;
   for (auto *UI : getNonDebugUses(LI)) {
     auto *User = UI->getUser();
 
@@ -503,8 +510,8 @@
   Projection *LastProj = nullptr;
   LoadInst *LastNewLoad = nullptr;
   for (auto &Pair : Projections) {
-    auto &Proj = Pair.first;
-    auto *Inst = Pair.second;
+    auto &Proj = Pair.P;
+    auto *Inst = Pair.I;
 
     // If this projection is the same as the last projection we processed, just
     // replace all uses of the projection with the load we created previously.
diff --git a/test/DebugInfo/compiler-flags.swift b/test/DebugInfo/compiler-flags.swift
index affcc6f..a68fd68 100644
--- a/test/DebugInfo/compiler-flags.swift
+++ b/test/DebugInfo/compiler-flags.swift
@@ -21,3 +21,8 @@
 // CHECK-LLDB-NOT: debug_pubnames
 // CHECK-LLDB:     apple_names
 // CHECK-LLDB-NOT: debug_pubnames
+
+// Check that we don't write temporary file names in the debug info
+// RUN: TMPDIR=abc/def %target-swift-frontend %s -I abc/def/xyz -g -emit-ir -o - | %FileCheck --check-prefix CHECK-TEMP %s
+// CHECK-TEMP: !DICompileUnit({{.*}} flags: "{{.*}} -I <temporary-file>
+
diff --git a/tools/SourceKit/tools/sourcekitd/bin/XPC/Service/XPCService.cpp b/tools/SourceKit/tools/sourcekitd/bin/XPC/Service/XPCService.cpp
index 418da9e..da326f6 100644
--- a/tools/SourceKit/tools/sourcekitd/bin/XPC/Service/XPCService.cpp
+++ b/tools/SourceKit/tools/sourcekitd/bin/XPC/Service/XPCService.cpp
@@ -209,7 +209,7 @@
 }
 
 static void sourcekitdServer_peer_event_handler(xpc_connection_t peer,
-                                            xpc_object_t event) {
+                                                xpc_object_t event) {
   xpc_type_t type = xpc_get_type(event);
   if (type == XPC_TYPE_ERROR) {
     if (event == XPC_ERROR_CONNECTION_INVALID) {
@@ -305,6 +305,10 @@
     sourcekitdServer_peer_event_handler(peer, event);
   });
 
+  // Update the main connection
+  xpc_retain(peer);
+  if (MainConnection)
+    xpc_release(MainConnection);
   MainConnection = peer;
 
   // This will tell the connection to begin listening for events. If you
diff --git a/utils/build-presets.ini b/utils/build-presets.ini
index fbd4996..0f0f66b 100644
--- a/utils/build-presets.ini
+++ b/utils/build-presets.ini
@@ -1237,6 +1237,8 @@
 no-assertions
 swift-assertions
 
+clang-user-visible-version=9.1.0
+
 compiler-vendor=apple
 dash-dash
 
@@ -1265,12 +1267,10 @@
 
 [preset: remote_mirror_ios_customization]
 
-clang-user-visible-version=8.0.0
-
 dash-dash
 
 darwin-xcrun-toolchain=ios
-darwin-deployment-version-ios=10.0
+darwin-deployment-version-ios=11.0
 skip-build-osx
 skip-test-osx
 skip-build-tvos
@@ -1289,12 +1289,10 @@
 
 [preset: remote_mirror_watchos_customization]
 
-clang-user-visible-version=8.0.0
-
 dash-dash
 
 darwin-xcrun-toolchain=watchos
-darwin-deployment-version-watchos=3.0
+darwin-deployment-version-watchos=4.0
 skip-build-osx
 skip-test-osx
 skip-build-tvos
@@ -1313,12 +1311,10 @@
 
 [preset: remote_mirror_tvos_customization]
 
-clang-user-visible-version=8.0.0
-
 dash-dash
 
 darwin-xcrun-toolchain=tvos
-darwin-deployment-version-tvos=10.0
+darwin-deployment-version-tvos=11.0
 skip-build-osx
 skip-test-osx
 skip-build-watchos