Merge pull request #15658 from gottesmm/pr-5d400dc5d525655aec91f42719f4e45048a1570f

diff --git a/README.md b/README.md
index 54819c2..5264e05 100644
--- a/README.md
+++ b/README.md
@@ -76,7 +76,7 @@
 
 For Ubuntu, you'll need the following development dependencies:
 
-    sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata
+    sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev tzdata rsync
 
 **Note:** LLDB currently requires at least `swig-1.3.40` but will successfully build
 with version 2 shipped with Ubuntu.
diff --git a/include/swift/AST/DiagnosticsParse.def b/include/swift/AST/DiagnosticsParse.def
index cc35d3f..7d70616 100644
--- a/include/swift/AST/DiagnosticsParse.def
+++ b/include/swift/AST/DiagnosticsParse.def
@@ -1098,6 +1098,8 @@
       "expected operator name in operator reference", ())
 ERROR(invalid_postfix_operator,none,
       "operator with postfix spacing cannot start a subexpression", ())
+ERROR(extraneous_amp_prefix,none,
+      "use of extraneous '&'", ())
 
 ERROR(expected_member_name,PointsToFirstBadToken,
       "expected member name following '.'", ())
diff --git a/include/swift/Parse/Parser.h b/include/swift/Parse/Parser.h
index 2f18802..83330a4 100644
--- a/include/swift/Parse/Parser.h
+++ b/include/swift/Parse/Parser.h
@@ -1156,19 +1156,21 @@
 
   //===--------------------------------------------------------------------===//
   // Expression Parsing
-  ParserResult<Expr> parseExpr(Diag<> ID) {
-    return parseExprImpl(ID, /*isExprBasic=*/false);
+  ParserResult<Expr> parseExpr(Diag<> ID, bool allowAmpPrefix = false) {
+    return parseExprImpl(ID, /*isExprBasic=*/false, allowAmpPrefix);
   }
   ParserResult<Expr> parseExprBasic(Diag<> ID) {
     return parseExprImpl(ID, /*isExprBasic=*/true);
   }
-  ParserResult<Expr> parseExprImpl(Diag<> ID, bool isExprBasic = false);
+  ParserResult<Expr> parseExprImpl(Diag<> ID, bool isExprBasic,
+                                   bool allowAmpPrefix = false);
   ParserResult<Expr> parseExprIs();
   ParserResult<Expr> parseExprAs();
   ParserResult<Expr> parseExprArrow();
   ParserResult<Expr> parseExprSequence(Diag<> ID,
                                        bool isExprBasic,
-                                       bool isForConditionalDirective = false);
+                                       bool isForConditionalDirective = false,
+                                       bool allowAmpPrefix = false);
   ParserResult<Expr> parseExprSequenceElement(Diag<> ID,
                                               bool isExprBasic);
   ParserResult<Expr> parseExprPostfixSuffix(ParserResult<Expr> inner,
@@ -1272,7 +1274,8 @@
                              SmallVectorImpl<SourceLoc> &exprLabelLocs,
                              SourceLoc &rightLoc,
                              Expr *&trailingClosure,
-                             syntax::SyntaxKind Kind);
+                             syntax::SyntaxKind Kind,
+                             bool allowAmpPrefix = false);
 
   ParserResult<Expr> parseTrailingClosure(SourceRange calleeRange);
 
diff --git a/lib/Frontend/CompilerInvocation.cpp b/lib/Frontend/CompilerInvocation.cpp
index ef4ce15..174de57 100644
--- a/lib/Frontend/CompilerInvocation.cpp
+++ b/lib/Frontend/CompilerInvocation.cpp
@@ -915,9 +915,15 @@
   return false;
 }
 
+static std::string getScriptFileName(StringRef name, bool isSwiftVersion3) {
+  StringRef langVer = isSwiftVersion3 ? "3" : "4";
+  return (Twine(name) + langVer + ".json").str();
+}
+
 bool ParseMigratorArgs(MigratorOptions &Opts,
                        const FrontendOptions &FrontendOpts,
                        const llvm::Triple &Triple,
+                       const bool isSwiftVersion3,
                        StringRef ResourcePath, const ArgList &Args,
                        DiagnosticEngine &Diags) {
   using namespace options;
@@ -948,19 +954,24 @@
     llvm::SmallString<128> dataPath(ResourcePath);
     llvm::sys::path::append(dataPath, "migrator");
     if (Triple.isMacOSX())
-      llvm::sys::path::append(dataPath, "macos.json");
+      llvm::sys::path::append(dataPath,
+                              getScriptFileName("macos", isSwiftVersion3));
     else if (Triple.isiOS())
-      llvm::sys::path::append(dataPath, "ios.json");
+      llvm::sys::path::append(dataPath,
+                              getScriptFileName("ios", isSwiftVersion3));
     else if (Triple.isTvOS())
-      llvm::sys::path::append(dataPath, "tvos.json");
+      llvm::sys::path::append(dataPath,
+                              getScriptFileName("tvos", isSwiftVersion3));
     else if (Triple.isWatchOS())
-      llvm::sys::path::append(dataPath, "watchos.json");
+      llvm::sys::path::append(dataPath,
+                              getScriptFileName("watchos", isSwiftVersion3));
     else
       Supported = false;
     if (Supported) {
       llvm::SmallString<128> authoredDataPath(ResourcePath);
       llvm::sys::path::append(authoredDataPath, "migrator");
-      llvm::sys::path::append(authoredDataPath, "overlay.json");
+      llvm::sys::path::append(authoredDataPath,
+                              getScriptFileName("overlay", isSwiftVersion3));
       // Add authored list first to take higher priority.
       Opts.APIDigesterDataStorePaths.push_back(authoredDataPath.str());
       Opts.APIDigesterDataStorePaths.push_back(dataPath.str());
@@ -1051,6 +1062,7 @@
   }
 
   if (ParseMigratorArgs(MigratorOpts, FrontendOpts, LangOpts.Target,
+                        LangOpts.isSwiftVersion3(),
                         SearchPathOpts.RuntimeResourcePath, ParsedArgs, Diags)) {
     return true;
   }
diff --git a/lib/IRGen/IRGenModule.cpp b/lib/IRGen/IRGenModule.cpp
index 88d136c..21ed904 100644
--- a/lib/IRGen/IRGenModule.cpp
+++ b/lib/IRGen/IRGenModule.cpp
@@ -909,6 +909,23 @@
   llvm_unreachable("Could not replace old linker options entry?");
 }
 
+/// Returns true if the object file generated by \p IGM will be the "first"
+/// object file in the module. This lets us determine where to put a symbol
+/// that must be unique.
+static bool isFirstObjectFileInModule(IRGenModule &IGM) {
+  if (IGM.getSILModule().isWholeModule())
+    return IGM.IRGen.getPrimaryIGM() == &IGM;
+
+  const DeclContext *DC = IGM.getSILModule().getAssociatedContext();
+  if (!DC)
+    return false;
+
+  assert(!isa<ModuleDecl>(DC) && "that would be a whole module build");
+  assert(isa<FileUnit>(DC) && "compiling something smaller than a file?");
+  ModuleDecl *containingModule = cast<FileUnit>(DC)->getParentModule();
+  return containingModule->getFiles().front() == DC;
+}
+
 void IRGenModule::emitAutolinkInfo() {
   // Collect the linker options already in the module (from ClangCodeGen).
   // FIXME: This constant should be vended by LLVM somewhere.
@@ -963,12 +980,13 @@
     addUsedGlobal(var);
   }
 
-  if (!IRGen.Opts.ForceLoadSymbolName.empty()) {
+  if (!IRGen.Opts.ForceLoadSymbolName.empty() &&
+      isFirstObjectFileInModule(*this)) {
     llvm::SmallString<64> buf;
     encodeForceLoadSymbolName(buf, IRGen.Opts.ForceLoadSymbolName);
     auto ForceImportThunk =
         llvm::Function::Create(llvm::FunctionType::get(VoidTy, false),
-                               llvm::GlobalValue::WeakODRLinkage, buf,
+                               llvm::GlobalValue::ExternalLinkage, buf,
                                &Module);
     if (useDllStorage())
       ForceImportThunk
diff --git a/lib/Migrator/CMakeLists.txt b/lib/Migrator/CMakeLists.txt
index 1649c43..0c1dfe6 100644
--- a/lib/Migrator/CMakeLists.txt
+++ b/lib/Migrator/CMakeLists.txt
@@ -1,9 +1,14 @@
 set(datafiles
-  macos.json
-  ios.json
-  tvos.json
-  watchos.json
-  overlay.json
+  macos3.json
+  macos4.json
+  ios3.json
+  ios4.json
+  tvos3.json
+  tvos4.json
+  watchos3.json
+  watchos4.json
+  overlay3.json
+  overlay4.json
 )
 set(SWIFTLIB_DIR
     "${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib/swift")
diff --git a/lib/Migrator/Migrator.cpp b/lib/Migrator/Migrator.cpp
index e5a9da7..610ab63 100644
--- a/lib/Migrator/Migrator.cpp
+++ b/lib/Migrator/Migrator.cpp
@@ -56,7 +56,10 @@
   }
 
   // Phase 2: Syntactic Transformations
-  if (Invocation.getLangOptions().EffectiveLanguageVersion[0] < 4) {
+  // Don't run these passes if we're already in Swift 4.2
+  auto Opts = Invocation.getLangOptions().EffectiveLanguageVersion;
+  bool isFourTwo = Opts.size() == 2 && Opts[0] == 4 && Opts[1] == 2;
+  if (!isFourTwo) {
     auto FailedSyntacticPasses = M.performSyntacticPasses();
     if (FailedSyntacticPasses) {
       return true;
diff --git a/lib/Migrator/ios.json b/lib/Migrator/ios3.json
similarity index 100%
rename from lib/Migrator/ios.json
rename to lib/Migrator/ios3.json
diff --git a/lib/Migrator/ios4.json b/lib/Migrator/ios4.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/lib/Migrator/ios4.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/lib/Migrator/macos.json b/lib/Migrator/macos3.json
similarity index 100%
rename from lib/Migrator/macos.json
rename to lib/Migrator/macos3.json
diff --git a/lib/Migrator/macos4.json b/lib/Migrator/macos4.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/lib/Migrator/macos4.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/lib/Migrator/overlay.json b/lib/Migrator/overlay3.json
similarity index 100%
rename from lib/Migrator/overlay.json
rename to lib/Migrator/overlay3.json
diff --git a/lib/Migrator/overlay4.json b/lib/Migrator/overlay4.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/lib/Migrator/overlay4.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/lib/Migrator/tvos.json b/lib/Migrator/tvos3.json
similarity index 100%
rename from lib/Migrator/tvos.json
rename to lib/Migrator/tvos3.json
diff --git a/lib/Migrator/tvos4.json b/lib/Migrator/tvos4.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/lib/Migrator/tvos4.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/lib/Migrator/watchos.json b/lib/Migrator/watchos3.json
similarity index 100%
rename from lib/Migrator/watchos.json
rename to lib/Migrator/watchos3.json
diff --git a/lib/Migrator/watchos4.json b/lib/Migrator/watchos4.json
new file mode 100644
index 0000000..0637a08
--- /dev/null
+++ b/lib/Migrator/watchos4.json
@@ -0,0 +1 @@
+[]
\ No newline at end of file
diff --git a/lib/Parse/ParseExpr.cpp b/lib/Parse/ParseExpr.cpp
index dc03da7..06c3d6b 100644
--- a/lib/Parse/ParseExpr.cpp
+++ b/lib/Parse/ParseExpr.cpp
@@ -40,7 +40,9 @@
 ///     expr-sequence(basic | trailing-closure)
 ///
 /// \param isExprBasic Whether we're only parsing an expr-basic.
-ParserResult<Expr> Parser::parseExprImpl(Diag<> Message, bool isExprBasic) {
+ParserResult<Expr> Parser::parseExprImpl(Diag<> Message,
+                                         bool isExprBasic,
+                                         bool allowAmpPrefix) {
   // Start a context for creating expression syntax.
   SyntaxParsingContext ExprParsingContext(SyntaxContext, SyntaxContextKind::Expr);
 
@@ -61,7 +63,9 @@
     return makeParserResult(new (Context) UnresolvedPatternExpr(pattern.get()));
   }
   
-  ParserResult<Expr> expr = parseExprSequence(Message, isExprBasic);
+  auto expr = parseExprSequence(Message, isExprBasic,
+                                /*forConditionalDirective*/false,
+                                allowAmpPrefix);
   if (expr.hasCodeCompletion())
     return expr;
   if (expr.isNull())
@@ -166,7 +170,8 @@
 /// apply to everything to its right.
 ParserResult<Expr> Parser::parseExprSequence(Diag<> Message,
                                              bool isExprBasic,
-                                             bool isForConditionalDirective) {
+                                             bool isForConditionalDirective,
+                                             bool allowAmpPrefix) {
   SyntaxParsingContext ExprSequnceContext(SyntaxContext, SyntaxContextKind::Expr);
 
   SmallVector<Expr*, 8> SequencedExprs;
@@ -178,9 +183,36 @@
     if (isForConditionalDirective && Tok.isAtStartOfLine())
       break;
     
-    // Parse a unary expression.
-    ParserResult<Expr> Primary =
-      parseExprSequenceElement(Message, isExprBasic);
+    ParserResult<Expr> Primary;
+
+    SourceLoc AmpPrefix;
+    if (Tok.is(tok::amp_prefix)) {
+      SyntaxParsingContext AmpCtx(SyntaxContext, SyntaxKind::InOutExpr);
+      AmpPrefix = consumeToken(tok::amp_prefix);
+
+      auto SubExpr = parseExprUnary(Message, isExprBasic);
+      auto allowNextAmpPrefix = Tok.isBinaryOperator();
+      if (SubExpr.hasCodeCompletion()) {
+        Primary = makeParserCodeCompletionResult<Expr>();
+      } else if (SubExpr.isNull()) {
+        Primary = nullptr;
+      } else if (allowAmpPrefix || allowNextAmpPrefix) {
+        Primary = makeParserResult(
+            new (Context) InOutExpr(AmpPrefix, SubExpr.get(), Type()));
+      } else {
+        diagnose(AmpPrefix, diag::extraneous_amp_prefix);
+        // In the long run, we should assign SubExpr to Primary to improve
+        // single-pass diagnostic completeness, but for now, doing so exposes
+        // diagnostic bugs in Sema where '&' is wrongly suggested as a fix.
+        Primary = makeParserErrorResult(new (Context) ErrorExpr(
+            {AmpPrefix, SubExpr.get()->getSourceRange().End}));
+      }
+      allowAmpPrefix = allowNextAmpPrefix;
+    } else {
+      // Parse a unary expression.
+      Primary = parseExprSequenceElement(Message, isExprBasic);
+    }
+
     HasCodeCompletion |= Primary.hasCodeCompletion();
     if (Primary.isNull()) {
       if (Primary.hasCodeCompletion()) {
@@ -224,6 +256,7 @@
                                            SyntaxKind::BinaryOperatorExpr);
       Expr *Operator = parseExprOperator();
       SequencedExprs.push_back(Operator);
+      allowAmpPrefix = true;
       
       // The message is only valid for the first subexpr.
       Message = diag::expected_expr_after_operator;
@@ -475,19 +508,6 @@
     // If the next token is not an operator, just parse this as expr-postfix.
     return parseExprPostfix(Message, isExprBasic);
 
-  case tok::amp_prefix: {
-    SyntaxParsingContext AmpCtx(SyntaxContext, SyntaxKind::InOutExpr);
-    SourceLoc Loc = consumeToken(tok::amp_prefix);
-
-    ParserResult<Expr> SubExpr = parseExprUnary(Message, isExprBasic);
-    if (SubExpr.hasCodeCompletion())
-      return makeParserCodeCompletionResult<Expr>();
-    if (SubExpr.isNull())
-      return nullptr;
-    return makeParserResult(
-        new (Context) InOutExpr(Loc, SubExpr.get(), Type()));
-  }
-
   case tok::backslash:
     return parseExprKeyPath();
 
@@ -897,7 +917,8 @@
                                         indexArgLabelLocs,
                                         rSquareLoc,
                                         trailingClosure,
-                                        SyntaxKind::FunctionCallArgumentList);
+                                        SyntaxKind::FunctionCallArgumentList,
+                                        /*allowAmpPrefix*/true);
     if (status.hasCodeCompletion())
       return makeParserCodeCompletionResult<Expr>();
     if (status.isError())
@@ -1245,7 +1266,8 @@
           tok::l_square, tok::r_square,
           /*isPostfix=*/true, isExprBasic, lSquareLoc, indexArgs,
           indexArgLabels, indexArgLabelLocs, rSquareLoc, trailingClosure,
-          SyntaxKind::FunctionCallArgumentList);
+          SyntaxKind::FunctionCallArgumentList,
+          /*allowAmpPrefix*/true);
       if (status.hasCodeCompletion())
         return makeParserCodeCompletionResult<Expr>();
       if (status.isError() || Result.isNull())
@@ -1676,7 +1698,8 @@
                                           argLabelLocs,
                                           rParenLoc,
                                           trailingClosure,
-                                          SyntaxKind::FunctionCallArgumentList);
+                                          SyntaxKind::FunctionCallArgumentList,
+                                          /*allowAmpPrefix*/true);
       if (status.isError())
         return nullptr;
 
@@ -2911,7 +2934,8 @@
                                    SmallVectorImpl<SourceLoc> &exprLabelLocs,
                                    SourceLoc &rightLoc,
                                    Expr *&trailingClosure,
-                                   SyntaxKind Kind) {
+                                   SyntaxKind Kind,
+                                   bool allowAmpPrefix) {
   trailingClosure = nullptr;
 
   StructureMarkerRAII ParsingExprList(*this, Tok);
@@ -2948,8 +2972,8 @@
                                                    DeclRefKind::Ordinary,
                                                    DeclNameLoc(Loc));
     } else {
-      ParserResult<Expr> ParsedSubExpr 
-        = parseExpr(diag::expected_expr_in_expr_list);
+      auto ParsedSubExpr = parseExpr(diag::expected_expr_in_expr_list,
+                                     /*allowAmpPrefix*/allowAmpPrefix);
       SubExpr = ParsedSubExpr.getPtrOrNull();
       Status = ParsedSubExpr;
     }
@@ -3193,7 +3217,8 @@
                                       argLabelLocs,
                                       rParenLoc,
                                       trailingClosure,
-                                      SyntaxKind::FunctionCallArgumentList);
+                                      SyntaxKind::FunctionCallArgumentList,
+                                      /*allowAmpPrefix*/true);
 
   // Form the call.
   auto Result = makeParserResult(status | fn, 
diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp
index e520705..0ce69e7 100644
--- a/lib/Sema/CSGen.cpp
+++ b/lib/Sema/CSGen.cpp
@@ -2006,7 +2006,7 @@
           if (ty)
             return ty;
           return CS.createTypeVariable(CS.getConstraintLocator(locator),
-                                       TVO_CanBindToInOut);
+                                       /*options*/0);
         case ReferenceOwnership::Weak:
           // For weak variables, use Optional<T>.
           if (ty && ty->getOptionalObjectType())
@@ -2014,7 +2014,7 @@
           // Create a fresh type variable to handle overloaded expressions.
           if (!ty || ty->is<TypeVariableType>())
             ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
-                                       TVO_CanBindToInOut);
+                                       /*options*/0);
           return CS.getTypeChecker().getOptionalType(var->getLoc(), ty);
         }
 
@@ -2055,7 +2055,7 @@
         // TODO: we could try harder here, e.g. for enum elements to provide the
         // enum type.
         return CS.createTypeVariable(CS.getConstraintLocator(locator),
-                                     TVO_CanBindToInOut);
+                                     /*options*/0);
       }
 
       llvm_unreachable("Unhandled pattern kind");
@@ -2329,7 +2329,7 @@
       //
       // where T is a fresh type variable.
       auto lvalue = CS.createTypeVariable(CS.getConstraintLocator(expr),
-                                          TVO_CanBindToInOut);
+                                          /*options*/0);
       auto bound = LValueType::get(lvalue);
       auto result = InOutType::get(lvalue);
       CS.addConstraint(ConstraintKind::Conversion,
@@ -2492,8 +2492,7 @@
 
       // The branches must be convertible to a common type.
       auto resultTy = CS.createTypeVariable(CS.getConstraintLocator(expr),
-                                            TVO_PrefersSubtypeBinding |
-                                            TVO_CanBindToInOut);
+                                            TVO_PrefersSubtypeBinding);
       CS.addConstraint(ConstraintKind::Conversion,
                        CS.getType(expr->getThenExpr()), resultTy,
                        CS.getConstraintLocator(expr->getThenExpr()));
diff --git a/test/Constraints/diagnostics.swift b/test/Constraints/diagnostics.swift
index a4f2010..86ce2e7 100644
--- a/test/Constraints/diagnostics.swift
+++ b/test/Constraints/diagnostics.swift
@@ -457,8 +457,7 @@
 
 // <rdar://problem/21974772> SegFault in FailureDiagnosis::visitInOutExpr
 func r21974772(_ y : Int) {
-  let x = &(1.0 + y)  // expected-error {{binary operator '+' cannot be applied to operands of type 'Double' and 'Int'}}
-   //expected-note @-1 {{overloads for '+' exist with these partially matching parameter lists: }}
+  let x = &(1.0 + y) // expected-error {{use of extraneous '&'}}
 }
 
 // <rdar://problem/22020088> QoI: missing member diagnostic on optional gives worse error message than existential/bound generic/etc
diff --git a/test/Constraints/lvalues.swift b/test/Constraints/lvalues.swift
index 1c2af46..e4e2fda 100644
--- a/test/Constraints/lvalues.swift
+++ b/test/Constraints/lvalues.swift
@@ -158,10 +158,8 @@
 }
 
 // Don't infer inout types.
-var ir = &i // expected-error{{variable has type 'inout Int' which includes nested inout parameters}} \
-            // expected-error{{'&' can only appear immediately in a call argument list}}
-var ir2 = ((&i)) // expected-error{{variable has type 'inout Int' which includes nested inout parameters}} \
-                 // expected-error{{'&' can only appear immediately in a call argument list}}
+var ir = &i // expected-error {{use of extraneous '&'}}
+var ir2 = ((&i)) // expected-error {{use of extraneous '&'}}
 
 // <rdar://problem/17133089>
 func takeArrayRef(_ x: inout Array<String>) { }
diff --git a/test/IRGen/autolink-force-link.swift b/test/IRGen/autolink-force-link.swift
new file mode 100644
index 0000000..bcf3546
--- /dev/null
+++ b/test/IRGen/autolink-force-link.swift
@@ -0,0 +1,29 @@
+// RUN: %empty-directory(%t)
+
+// RUN: %swift -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir %s %S/../Inputs/empty.swift | %FileCheck -check-prefix=CHECK-WMO %s
+
+// CHECK-WMO: source_filename = "-"
+// CHECK-WMO: define void @"_swift_FORCE_LOAD_$_TEST"()
+// CHECK-WMO-NOT: source_filename
+
+
+// RUN: %swift -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir -num-threads 1 %s %S/../Inputs/empty.swift | %FileCheck -check-prefix=CHECK-WMO-THREADED %s
+
+// CHECK-WMO-THREADED: source_filename = "-"
+// CHECK-WMO-THREADED: define void @"_swift_FORCE_LOAD_$_TEST"()
+// CHECK-WMO-THREADED: source_filename = "-"
+// CHECK-WMO-THREADED-NOT: _swift_FORCE_LOAD_$_TEST
+// CHECK-WMO-THREADED-NOT: source_filename
+
+
+// RUN: %swift -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir -primary-file %s %S/../Inputs/empty.swift | %FileCheck -check-prefix=CHECK-SINGLE-FILE-FIRST %s
+// RUN: %swift -target x86_64-apple-macosx10.9 -parse-stdlib -autolink-force-load -module-name TEST -module-link-name TEST -emit-ir %S/../Inputs/empty.swift -primary-file %s | %FileCheck -check-prefix=CHECK-SINGLE-FILE-SECOND %s
+
+// CHECK-SINGLE-FILE-FIRST: source_filename = "-"
+// CHECK-SINGLE-FILE-FIRST: define void @"_swift_FORCE_LOAD_$_TEST"()
+// CHECK-SINGLE-FILE-FIRST-NOT: source_filename
+
+// CHECK-SINGLE-FILE-SECOND: source_filename = "-"
+// CHECK-SINGLE-FILE-SECOND-NOT: _swift_FORCE_LOAD_$_TEST
+// CHECK-SINGLE-FILE-SECOND-NOT: source_filename
+
diff --git a/test/Migrator/no_ast_passes_after_swift4.swift b/test/Migrator/no_ast_passes_after_swift4.swift
index 6c2d805..26b072f 100644
--- a/test/Migrator/no_ast_passes_after_swift4.swift
+++ b/test/Migrator/no_ast_passes_after_swift4.swift
@@ -1,5 +1,5 @@
 // REQUIRES: objc_interop
-// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4
+// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
 // RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
 // RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result
 
diff --git a/test/Migrator/no_ast_passes_after_swift4.swift.expected b/test/Migrator/no_ast_passes_after_swift4.swift.expected
index 6c2d805..26b072f 100644
--- a/test/Migrator/no_ast_passes_after_swift4.swift.expected
+++ b/test/Migrator/no_ast_passes_after_swift4.swift.expected
@@ -1,5 +1,5 @@
 // REQUIRES: objc_interop
-// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4
+// RUN: %empty-directory(%t) && %target-swift-frontend -c -update-code -primary-file %s -F %S/mock-sdk -api-diff-data-file %S/Inputs/DoubleEditAPI.json -emit-migrated-file-path %t/no_ast_passes_after_swift4.swift.result -emit-remap-file-path %t/no_ast_passes_after_swift4.swift.remap -o /dev/null -swift-version 4.2
 // RUN: diff -u %S/no_ast_passes_after_swift4.swift.expected %t/no_ast_passes_after_swift4.swift.result
 // RUN: %target-swift-frontend -typecheck -F %S/mock-sdk -swift-version 4 %t/no_ast_passes_after_swift4.swift.result
 
diff --git a/test/Migrator/swift_version_change.swift b/test/Migrator/swift_version_change.swift
new file mode 100644
index 0000000..d47a988
--- /dev/null
+++ b/test/Migrator/swift_version_change.swift
@@ -0,0 +1,5 @@
+// REQUIRES: OS=macosx
+// RUN: %empty-directory(%t) && %target-swift-frontend -typecheck -update-code -primary-file %s -emit-migrated-file-path %t/dummpy.result -swift-version 3
+// RUN: %target-swift-frontend -typecheck -update-code -primary-file %s -emit-migrated-file-path %t/dummpy.result -swift-version 4
+
+func foo() {}
\ No newline at end of file
diff --git a/test/Parse/pointer_conversion.swift.gyb b/test/Parse/pointer_conversion.swift.gyb
index 88b29ca..cd2a7df 100644
--- a/test/Parse/pointer_conversion.swift.gyb
+++ b/test/Parse/pointer_conversion.swift.gyb
@@ -62,8 +62,8 @@
   takesMutableArrayPointer(&ii)
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafeMutablePointer<Int> = &i // expected-error{{cannot pass immutable value as inout argument: 'i' is immutable}}
-  x = &ii // expected-error{{cannot assign value of type 'inout [Int]' to type 'UnsafeMutablePointer<Int>'}}
+  var x: UnsafeMutablePointer<Int> = &i // expected-error {{use of extraneous '&'}}
+  x = &ii // expected-error {{use of extraneous '&'}}
   _ = x
 }
 
@@ -94,9 +94,9 @@
   takesMutableVoidPointer(ff) // expected-error{{cannot convert value of type '[Int]' to expected argument type 'UnsafeMutableRawPointer${diag_suffix}'}}
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafeMutableRawPointer = &i // expected-error{{cannot convert value of type 'inout Int' to specified type 'UnsafeMutableRawPointer'}}
+  var x: UnsafeMutableRawPointer = &i // expected-error {{use of extraneous '&'}}
   x = p // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Int>' to type 'UnsafeMutableRawPointer'}}
-  x = &ii // expected-error{{cannot assign value of type 'inout [Int]' to type 'UnsafeMutableRawPointer'}}
+  x = &ii // expected-error {{use of extraneous '&'}}
   _ = x
 }
 
@@ -129,9 +129,9 @@
   takesMutableRawPointer(ff) // expected-error{{cannot convert value of type '[Int]' to expected argument type 'UnsafeMutableRawPointer${diag_suffix}'}}
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafeMutableRawPointer = &i // expected-error{{cannot convert value of type 'inout Int' to specified type 'UnsafeMutableRawPointer'}}
+  var x: UnsafeMutableRawPointer = &i // expected-error {{use of extraneous '&'}}
   x = p // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Int>' to type 'UnsafeMutableRawPointer'}}
-  x = &ii // expected-error{{cannot assign value of type 'inout [Int]' to type 'UnsafeMutableRawPointer'}}
+  x = &ii //expected-error {{use of extraneous '&'}}
   _ = x
 }
 
@@ -160,7 +160,7 @@
   takesConstPointer([0.0, 1.0, 2.0]) // expected-error{{cannot convert value of type '[Double]' to expected argument type 'UnsafePointer<Int>}}
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafePointer<Int> = &i // expected-error{{cannot pass immutable value as inout argument: 'i' is immutable}}
+  var x: UnsafePointer<Int> = &i // expected-error {{use of extraneous '&'}}
   x = ii // expected-error{{cannot assign value of type '[Int]' to type 'UnsafePointer<Int>'}}
   x = p // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Int>' to type 'UnsafePointer<Int>'}}
 }
@@ -194,7 +194,7 @@
   takesConstVoidPointer([0.0, 1.0, 2.0])
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafeRawPointer = &i // expected-error{{cannot convert value of type 'inout Int' to specified type 'UnsafeRawPointer'}}
+  var x: UnsafeRawPointer = &i // expected-error {{use of extraneous '&'}}
   x = ii // expected-error{{cannot assign value of type '[Int]' to type 'UnsafeRawPointer'}}
   x = p // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Int>' to type 'UnsafeRawPointer'}}
   x = fp // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Float>' to type 'UnsafeRawPointer'}}
@@ -234,7 +234,7 @@
   takesConstRawPointer([0.0, 1.0, 2.0])
 
   // We don't allow these conversions outside of function arguments.
-  var x: UnsafeRawPointer = &i // expected-error{{cannot convert value of type 'inout Int' to specified type 'UnsafeRawPointer'}}
+  var x: UnsafeRawPointer = &i // expected-error {{use of extraneous '&'}}
   x = ii // expected-error{{cannot assign value of type '[Int]' to type 'UnsafeRawPointer'}}
   x = p // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Int>' to type 'UnsafeRawPointer'}}
   x = fp // expected-error{{cannot assign value of type 'UnsafeMutablePointer<Float>' to type 'UnsafeRawPointer'}}
diff --git a/test/Parse/pointer_conversion_objc.swift.gyb b/test/Parse/pointer_conversion_objc.swift.gyb
index d080e3e..813e2ec 100644
--- a/test/Parse/pointer_conversion_objc.swift.gyb
+++ b/test/Parse/pointer_conversion_objc.swift.gyb
@@ -70,5 +70,5 @@
   takesAutoreleasingPointer(&cc) // expected-error{{cannot convert value of type '[C]' to expected argument type 'C'}}
   takesAutoreleasingPointer(&dd) // expected-error{{cannot convert value of type '[D]' to expected argument type 'C'}}
 
-  let _: AutoreleasingUnsafeMutablePointer<C> = &c // expected-error{{cannot pass immutable value as inout argument: 'c' is immutable}}
+  let _: AutoreleasingUnsafeMutablePointer<C> = &c // expected-error {{use of extraneous '&'}}
 }
diff --git a/test/Parse/recovery.swift b/test/Parse/recovery.swift
index 81aa5d6..ac7ebb6 100644
--- a/test/Parse/recovery.swift
+++ b/test/Parse/recovery.swift
@@ -749,7 +749,7 @@
 // <rdar://problem/23719432> [practicalswift] Compiler crashes on &(Int:_)
 func test23719432() {
   var x = 42
-  &(Int:x)  // expected-error {{expression type 'inout _' is ambiguous without more context}}
+  &(Int:x) // expected-error {{use of extraneous '&'}}
 }
 
 // <rdar://problem/19911096> QoI: terrible recovery when using '·' for an operator
diff --git a/test/Serialization/autolinking.swift b/test/Serialization/autolinking.swift
index 468a226..f8e9ab1 100644
--- a/test/Serialization/autolinking.swift
+++ b/test/Serialization/autolinking.swift
@@ -38,10 +38,10 @@
 // FRAMEWORK-DAG: !{{[0-9]+}} = !{!"-framework", !"someModule"}
 
 // NO-FORCE-LOAD-NOT: FORCE_LOAD
-// FORCE-LOAD: define weak_odr void @"_swift_FORCE_LOAD_$_module"() {
+// FORCE-LOAD: define void @"_swift_FORCE_LOAD_$_module"() {
 // FORCE-LOAD:   ret void
 // FORCE-LOAD: }
-// FORCE-LOAD-HEX: define weak_odr void @"_swift_FORCE_LOAD_$306d6f64756c65"() {
+// FORCE-LOAD-HEX: define void @"_swift_FORCE_LOAD_$306d6f64756c65"() {
 // FORCE-LOAD-HEX:   ret void
 // FORCE-LOAD-HEX: }
 
diff --git a/test/TypeCoercion/overload_noncall.swift b/test/TypeCoercion/overload_noncall.swift
index 2f56637..b59ce8f 100644
--- a/test/TypeCoercion/overload_noncall.swift
+++ b/test/TypeCoercion/overload_noncall.swift
@@ -52,7 +52,7 @@
   x = accept_XY(&xy);
 
   x = xy
-  x = &xy; // expected-error{{cannot assign value of type 'inout X' to type 'X'}}
+  x = &xy; // expected-error {{use of extraneous '&'}}
   accept_Z(&xy); // expected-error{{cannot convert value of type 'X' to expected argument type 'Z'}}
 }
 
diff --git a/test/expr/expressions.swift b/test/expr/expressions.swift
index 9bd1532..38300df 100644
--- a/test/expr/expressions.swift
+++ b/test/expr/expressions.swift
@@ -533,10 +533,8 @@
   takesExplicitInt(x) // expected-error{{passing value of type 'Int' to an inout parameter requires explicit '&'}} {{20-20=&}}
   takesExplicitInt(&x)
   takesInt(&x) // expected-error{{'&' used with non-inout argument of type 'Int'}}
-  var y = &x // expected-error{{'&' can only appear immediately in a call argument list}} \
-             // expected-error {{variable has type 'inout Int' which includes nested inout parameters}}
-  var z = &arg // expected-error{{'&' can only appear immediately in a call argument list}} \
-             // expected-error {{variable has type 'inout Int' which includes nested inout parameters}}
+  var y = &x //expected-error {{use of extraneous '&'}}
+  var z = &arg //expected-error {{use of extraneous '&'}}
 
   takesExplicitInt(5) // expected-error {{cannot pass immutable value as inout argument: literals are not mutable}}
 }
@@ -816,19 +814,16 @@
 // <rdar://problem/18496742> Passing ternary operator expression as inout crashes Swift compiler
 func inoutTests(_ arr: inout Int) {
   var x = 1, y = 2
-  (true ? &x : &y)  // expected-error 2 {{'&' can only appear immediately in a call argument list}}
-  // expected-warning @-1 {{expression of type 'inout Int' is unused}}
-  let a = (true ? &x : &y)  // expected-error 2 {{'&' can only appear immediately in a call argument list}}
+  (true ? &x : &y) // expected-error 2 {{use of extraneous '&'}}
+  let a = (true ? &x : &y) // expected-error 2 {{use of extraneous '&'}}
 
-  inoutTests(true ? &x : &y);  // expected-error 2 {{'&' can only appear immediately in a call argument list}}
+  inoutTests(true ? &x : &y) // expected-error {{use of extraneous '&'}}
 
-  &_ // expected-error {{expression type 'inout _' is ambiguous without more context}}
+  &_ // expected-error {{use of extraneous '&'}}
 
-  // The next error is awful, but we don't want regress and let non-immediate
-  // inout usage slip through.
-  inoutTests((&x, 24).0) // expected-error {{cannot pass immutable value of type 'inout Int' as inout argument}}
+  inoutTests((&x, 24).0) // expected-error {{use of extraneous '&'}}
 
-  inoutTests((&x))   // expected-error {{'&' can only appear immediately in a call argument list}}
+  inoutTests((&x)) // expected-error {{use of extraneous '&'}}
   inoutTests(&x)
   
   // <rdar://problem/17489894> inout not rejected as operand to assignment operator
@@ -847,7 +842,7 @@
 
 // <rdar://problem/20802757> Compiler crash in default argument & inout expr
 var g20802757 = 2
-func r20802757(_ z: inout Int = &g20802757) { // expected-error {{'&' can only appear immediately in a call argument list}}
+func r20802757(_ z: inout Int = &g20802757) { // expected-error {{use of extraneous '&'}}
   print(z)
 }
 
diff --git a/validation-test/compiler_crashers/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift b/validation-test/compiler_crashers_fixed/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift
similarity index 82%
rename from validation-test/compiler_crashers/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift
rename to validation-test/compiler_crashers_fixed/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift
index 1c800b5..6bdd4d2 100644
--- a/validation-test/compiler_crashers/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift
+++ b/validation-test/compiler_crashers_fixed/28628-gettype-e-isassignabletype-setting-access-kind-on-non-l-value.swift
@@ -5,6 +5,6 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// RUN: not --crash %target-swift-frontend %s -emit-ir
-// REQUIRES: asserts
+// RUN: not %target-swift-frontend %s -emit-ir
+
 &(_=nil?=nil
diff --git a/validation-test/compiler_crashers/28834-t-isnull-t-is-inouttype.swift b/validation-test/compiler_crashers_fixed/28834-t-isnull-t-is-inouttype.swift
similarity index 82%
rename from validation-test/compiler_crashers/28834-t-isnull-t-is-inouttype.swift
rename to validation-test/compiler_crashers_fixed/28834-t-isnull-t-is-inouttype.swift
index b29abb8..d6e0559 100644
--- a/validation-test/compiler_crashers/28834-t-isnull-t-is-inouttype.swift
+++ b/validation-test/compiler_crashers_fixed/28834-t-isnull-t-is-inouttype.swift
@@ -5,7 +5,7 @@
 // See https://swift.org/LICENSE.txt for license information
 // See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
 
-// REQUIRES: asserts
-// RUN: not --crash %target-swift-frontend %s -emit-ir
+
+// RUN: not %target-swift-frontend %s -emit-ir
 switch
 &_{case.o